diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-02-13 08:45:32 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-02-13 08:45:32 +0300 |
commit | e4790aef46f7ca0b4ab01c34f043be9e7b1fa7f1 (patch) | |
tree | 0d83145e454cc7b5947ec657dbd9e415aac9d809 /source/gameengine/Rasterizer | |
parent | 6c325d74f534d259820c2b2d94d5b73b3acf0a35 (diff) |
Improved OpenGL Shader Language support for game engine. The python interface is much simplified. Drawback is that scripts need to be updated next release. Testfiles:
http://www.continuousphysics.com/ftp/pub/test/index.php?dir=blender/&file=demos-2.42.zip
patch by Charlie Carley (snailrose @ elysiun.com)
Diffstat (limited to 'source/gameengine/Rasterizer')
13 files changed, 235 insertions, 210 deletions
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index 3e296c2b88b..6eef1647167 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -130,6 +130,7 @@ public: { return false; } + virtual void ActivateMeshSlot(const class KX_MeshSlot & ms, RAS_IRasterizer* rasty) const {} virtual bool Equals(const RAS_IPolyMaterial& lhs) const; bool Less(const RAS_IPolyMaterial& rhs) const; @@ -148,7 +149,6 @@ public: * PreCalculate texture gen */ virtual void OnConstruction(){} - }; inline bool operator ==( const RAS_IPolyMaterial & rhs,const RAS_IPolyMaterial & lhs) diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 68a9429d066..7f44afec74e 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -98,6 +98,25 @@ public: RAS_STEREO_MAXSTEREO }; + + /** + * Texture gen modes. + */ + enum TexCoGen { + RAS_TEXCO_GEN, //< GPU will generate texture coordinates + RAS_TEXCO_ORCO, //< Vertex coordinates (object space) + RAS_TEXCO_GLOB, //< Vertex coordinates (world space) + RAS_TEXCO_UV1, //< UV coordinates + RAS_TEXCO_OBJECT, //< Use another object's position as coordinates + RAS_TEXCO_LAVECTOR, //< Light vector as coordinates + RAS_TEXCO_VIEW, //< View vector as coordinates + RAS_TEXCO_STICKY, //< Sticky coordinates + RAS_TEXCO_WINDOW, //< Window coordinates + RAS_TEXCO_NORM, //< Normal coordinates + RAS_TEXTANGENT, //< + RAS_TEXCO_DISABLE //< Disable this texture unit (cached) + }; + /** * Render pass identifiers for stereo. */ @@ -369,6 +388,11 @@ public: virtual void SetPolygonOffset(float mult, float add) = 0; virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0; + + virtual void SetTexCoords(TexCoGen coords, int unit) = 0; + virtual void SetAttrib(int type) = 0; + virtual void GetViewMatrix(MT_Matrix4x4 &mat) const = 0; + }; #endif //__RAS_IRASTERIZER diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index b1d32326048..3aded0568cb 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -135,8 +135,6 @@ void RAS_MaterialBucket::MarkVisibleMeshSlot(KX_MeshSlot& ms, (*it).m_RGBAcolor= rgbavec; } - - bool RAS_MaterialBucket::IsTransparant() const { return (m_material->IsTransparant()); @@ -180,10 +178,11 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I bool dolights = false; const unsigned int flag = m_material->GetFlag(); + if( flag & RAS_BLENDERMAT) - dolights = flag &RAS_MULTILIGHT; + dolights = (flag &RAS_MULTILIGHT)!=0; else - dolights = m_material->GetDrawingMode()&16; + dolights = (m_material->GetDrawingMode()&16)!=0; if ((rasty->GetDrawingMode() <= RAS_IRasterizer::KX_SOLID) || !dolights) { @@ -206,6 +205,7 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa if (!ms.m_bVisible) return; + m_material->ActivateMeshSlot(ms, rasty); rendertools->SetClientObject(ms.m_clientObj); /* __NLA Do the deformation */ @@ -311,7 +311,6 @@ void RAS_MaterialBucket::Render(const MT_Transform& cameratrans, } int drawmode; - for (T_MeshSlotList::const_iterator it = m_meshSlots.begin(); ! (it == m_meshSlots.end()); ++it) { diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 52f835a4575..448cbc6e343 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -78,7 +78,6 @@ public: mutable bool m_bVisible; // for visibility mutable bool m_bObjectColor; mutable MT_Vector4 m_RGBAcolor; - KX_MeshSlot() : m_pDeformer(NULL), m_bVisible(true) @@ -124,7 +123,7 @@ public: bool visible, bool color, const MT_Vector4& rgbavec); - + void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, int drawmode); bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 6bc3b75fd5a..54e5364bc88 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -249,6 +249,7 @@ void RAS_MeshObject::ScheduleWireframePoly(const KX_VertexIndex& idx, int RAS_MeshObject::FindOrAddVertex(int vtxarray, const MT_Point3& xyz, const MT_Point2& uv, + const MT_Vector4& tangent, const unsigned int rgbacolor, const MT_Vector3& normal, RAS_IPolyMaterial* mat, @@ -257,7 +258,7 @@ int RAS_MeshObject::FindOrAddVertex(int vtxarray, KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]); int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray]; - RAS_TexVert newvert(xyz,uv,rgbacolor,normal, 0); + RAS_TexVert newvert(xyz,uv,tangent,rgbacolor,normal, 0); #define KX_FIND_SHARED_VERTICES #ifdef KX_FIND_SHARED_VERTICES @@ -425,7 +426,6 @@ void RAS_MeshObject::MarkVisible(double* oglmatrix, } - void RAS_MeshObject::RemoveFromBuckets(double* oglmatrix, void* clientobj) { diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 367aab750e0..d4884363731 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -236,6 +236,7 @@ public: int vtxarray, const MT_Point3& xyz, const MT_Point2& uv, + const MT_Vector4& tangent, const unsigned int rgbacolor, const MT_Vector3& normal, RAS_IPolyMaterial* mat, diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/ARB_multitexture.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/ARB_multitexture.h index 2a760b09f5e..a2f27ce3361 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/ARB_multitexture.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/ARB_multitexture.h @@ -7,12 +7,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_multitexture ---------------------------------------------------------------------------- */ -/* defined in glext.h -#ifndef GL_ARB_multitexture -#define GL_ARB_multitexture 1 -#endif -*/ - #ifdef GL_ARB_multitexture #define GL_TEXTURE0_ARB 0x84C0 #define GL_TEXTURE1_ARB 0x84C1 @@ -34,12 +28,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_texture_env_combine ---------------------------------------------------------------------------- */ -/* -#ifndef GL_ARB_texture_env_combine - #define GL_ARB_texture_env_combine 1 -#endif -*/ - #ifdef GL_ARB_texture_env_combine #define GL_COMBINE_ARB 0x8570 #define GL_COMBINE_RGB_ARB 0x8571 @@ -68,12 +56,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_texture_cube_map ---------------------------------------------------------------------------- */ -/* -#ifndef GL_ARB_texture_cube_map - #define GL_ARB_texture_cube_map 1 -#endif -*/ - #ifdef GL_ARB_texture_cube_map #define GL_NORMAL_MAP_ARB 0x8511 #define GL_REFLECTION_MAP_ARB 0x8512 @@ -92,11 +74,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_shader_objects ---------------------------------------------------------------------------- */ -/* -#ifndef GL_ARB_shader_objects - #define GL_ARB_shader_objects 1 -#endif -*/ #ifdef GL_ARB_shader_objects #define GL_PROGRAM_OBJECT_ARB 0x8B40 #define GL_SHADER_OBJECT_ARB 0x8B48 @@ -137,12 +114,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_vertex_shader ---------------------------------------------------------------------------- */ -/* -#ifndef GL_ARB_vertex_shader - #define GL_ARB_vertex_shader 1 -#endif -*/ - #ifdef GL_ARB_vertex_shader #define GL_VERTEX_SHADER_ARB 0x8B31 #define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A @@ -157,12 +128,6 @@ /* ---------------------------------------------------------------------------- GL_ARB_fragment_shader ---------------------------------------------------------------------------- */ -/* -#ifndef GL_ARB_fragment_shader - #define GL_ARB_fragment_shader 1 -#endif -*/ - #ifdef GL_ARB_fragment_shader #define GL_FRAGMENT_SHADER_ARB 0x8B30 #define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 @@ -170,4 +135,16 @@ #endif +/* ---------------------------------------------------------------------------- + GL_ARB_depth_texture +---------------------------------------------------------------------------- */ +#ifndef GL_ARB_depth_texture + #define GL_DEPTH_COMPONENT16_ARB 0x81A5 + #define GL_DEPTH_COMPONENT24_ARB 0x81A6 + #define GL_DEPTH_COMPONENT32_ARB 0x81A7 + #define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A + #define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + + #endif//__ARB_MULTITEXTURE_H__ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp index af3a9bca03e..58cd8dc2aa1 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp @@ -406,6 +406,22 @@ PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB; PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB; #endif + +#ifdef GL_ARB_vertex_program + PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB; + PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB; + PFNGLVERTEXATTRIB2FARBPROC blVertexAttrib2fARB; + PFNGLVERTEXATTRIB2FVARBPROC blVertexAttrib2fvARB; + PFNGLVERTEXATTRIB3FARBPROC blVertexAttrib3fARB; + PFNGLVERTEXATTRIB3FVARBPROC blVertexAttrib3fvARB; + PFNGLVERTEXATTRIB4FARBPROC blVertexAttrib4fARB; + PFNGLVERTEXATTRIB4FVARBPROC blVertexAttrib4fvARB; + PFNGLGETPROGRAMSTRINGARBPROC blGetProgramStringARB; + PFNGLGETVERTEXATTRIBDVARBPROC blGetVertexAttribdvARB; + PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB; + PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB; +#endif + } // namespace bgl using namespace bgl; @@ -589,6 +605,44 @@ static void LinkExtensions() } #endif +#if defined(GL_ARB_vertex_program) + if (QueryExtension("GL_ARB_vertex_program")) + { + bgl::blVertexAttrib1fARB = reinterpret_cast<PFNGLVERTEXATTRIB1FARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib1fARB")); + bgl::blVertexAttrib1fvARB = reinterpret_cast<PFNGLVERTEXATTRIB1FVARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib1fvARB")); + bgl::blVertexAttrib2fARB = reinterpret_cast<PFNGLVERTEXATTRIB2FARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib2fARB")); + bgl::blVertexAttrib2fvARB = reinterpret_cast<PFNGLVERTEXATTRIB2FVARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib2fvARB")); + bgl::blVertexAttrib3fARB = reinterpret_cast<PFNGLVERTEXATTRIB3FARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib3fARB")); + bgl::blVertexAttrib3fvARB = reinterpret_cast<PFNGLVERTEXATTRIB3FVARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib3fvARB")); + bgl::blVertexAttrib4fARB = reinterpret_cast<PFNGLVERTEXATTRIB4FARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib4fARB")); + bgl::blVertexAttrib4fvARB = reinterpret_cast<PFNGLVERTEXATTRIB4FVARBPROC>(bglGetProcAddress((const GLubyte *) "glVertexAttrib4fvARB")); + bgl::blGetVertexAttribdvARB = reinterpret_cast<PFNGLGETVERTEXATTRIBDVARBPROC>(bglGetProcAddress((const GLubyte *) "glGetVertexAttribdvARB")); + bgl::blGetVertexAttribfvARB = reinterpret_cast<PFNGLGETVERTEXATTRIBFVARBPROC>(bglGetProcAddress((const GLubyte *) "glGetVertexAttribfvARB")); + bgl::blGetVertexAttribivARB = reinterpret_cast<PFNGLGETVERTEXATTRIBIVARBPROC>(bglGetProcAddress((const GLubyte *) "glGetVertexAttribivARB")); + if (bgl::blVertexAttrib1fARB && bgl::blVertexAttrib1fvARB && bgl::blVertexAttrib2fARB && bgl::blVertexAttrib2fvARB && bgl::blVertexAttrib3fARB && bgl::blVertexAttrib3fvARB && bgl::blGetVertexAttribdvARB) { + EnableExtension(_GL_ARB_vertex_program); + RAS_EXT_support._ARB_vertex_program = 1; + if (doDebugMessages) + std::cout << "Enabled GL_ARB_vertex_program" << std::endl; + } else { + std::cout << "ERROR: GL_ARB_vertex_program implementation is broken!" << std::endl; + } + } +#endif + + +#ifdef GL_ARB_depth_texture + if (QueryExtension("GL_ARB_depth_texture")) + { + EnableExtension(_GL_ARB_depth_texture); + RAS_EXT_support._ARB_depth_texture = 1; + if (doDebugMessages) + { + std::cout << "Detected GL_ARB_depth_texture" << std::endl; + } + } +#endif + if (QueryExtension("GL_EXT_separate_specular_color")) { EnableExtension(_GL_EXT_separate_specular_color); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h index a5dad19222b..00d1d0c9d05 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h @@ -397,7 +397,9 @@ typedef struct BL_EXTInfo _ARB_shader_objects(0), _ARB_vertex_shader(0), _ARB_fragment_shader(0), - _EXT_texture3D(0) + _EXT_texture3D(0), + _ARB_vertex_program(0), + _ARB_depth_texture(0) { // } @@ -409,6 +411,8 @@ typedef struct BL_EXTInfo bool _ARB_vertex_shader; bool _ARB_fragment_shader; bool _EXT_texture3D; + bool _ARB_vertex_program; + bool _ARB_depth_texture; }BL_EXTInfo; extern BL_EXTInfo RAS_EXT_support; @@ -500,6 +504,22 @@ extern PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB; extern PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB; #endif +#ifdef GL_ARB_vertex_program +extern PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB; +extern PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB; +extern PFNGLVERTEXATTRIB2FARBPROC blVertexAttrib2fARB; +extern PFNGLVERTEXATTRIB2FVARBPROC blVertexAttrib2fvARB; +extern PFNGLVERTEXATTRIB3FARBPROC blVertexAttrib3fARB; +extern PFNGLVERTEXATTRIB3FVARBPROC blVertexAttrib3fvARB; +extern PFNGLVERTEXATTRIB4FARBPROC blVertexAttrib4fARB; +extern PFNGLVERTEXATTRIB4FVARBPROC blVertexAttrib4fvARB; +extern PFNGLGETPROGRAMSTRINGARBPROC blGetProgramStringARB; +extern PFNGLGETVERTEXATTRIBDVARBPROC blGetVertexAttribdvARB; +extern PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB; +extern PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB; +#endif + + } /* namespace bgl */ diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 38dfb7836b2..794562675ad 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -81,6 +81,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) m_focallength(0.0), m_setfocallength(false), m_noOfScanlines(32), + m_useTang(0), m_materialCachingInfo(0) { m_viewmatrix.Identity(); @@ -603,6 +604,15 @@ void RAS_OpenGLRasterizer::SwapBuffers() +void RAS_OpenGLRasterizer::GetViewMatrix(MT_Matrix4x4 &mat) const +{ + float viewmat[16]; + glGetFloatv(GL_MODELVIEW_MATRIX, viewmat); + mat.setValue(viewmat); +} + + + void RAS_OpenGLRasterizer::IndexPrimitives(const vecVertexArray & vertexarrays, const vecIndexArrays & indexarrays, int mode, @@ -1191,6 +1201,59 @@ void RAS_OpenGLRasterizer::IndexPrimitives_3DText(const vecVertexArray & vertexa } //for each vertexarray } +void RAS_OpenGLRasterizer::SetAttrib(int type) +{ + if(type == RAS_TEXTANGENT) m_useTang=true; +} + + +void RAS_OpenGLRasterizer::SetTexCoords(TexCoGen coords,int unit) +{ + // this changes from material to material + if(unit <= RAS_MAX) + m_texco[unit] = coords; +} + + +void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv, int enabled) +{ +#ifdef GL_ARB_multitexture + if(bgl::RAS_EXT_support._ARB_multitexture) + { + for(int unit=0; unit<enabled; unit++) + { + if( tv.getFlag() & TV_2NDUV && tv.getUnit() == unit ) { + bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, tv.getUV2()); + continue; + } + switch(m_texco[unit]) + { + case RAS_TEXCO_DISABLE: + case RAS_TEXCO_OBJECT: + case RAS_TEXCO_GEN: + break; + case RAS_TEXCO_ORCO: + case RAS_TEXCO_GLOB: + bgl::blMultiTexCoord3fvARB(GL_TEXTURE0_ARB+unit, tv.getLocalXYZ()); + break; + case RAS_TEXCO_UV1: + bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, tv.getUV1()); + break; + case RAS_TEXCO_NORM: + bgl::blMultiTexCoord3fvARB(GL_TEXTURE0_ARB+unit, tv.getNormal()); + break; + + } + } + } +#endif +#ifdef GL_ARB_vertex_program + if(m_useTang && bgl::RAS_EXT_support._ARB_vertex_program) + bgl::blVertexAttrib4fvARB(1/*tangent*/, tv.getTangent()); +#endif +} + + void RAS_OpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, @@ -1259,65 +1322,28 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti( { glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]); - + + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; } @@ -1330,69 +1356,32 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti( // However it depends on the way the colors are packed into // the m_rgba field of RAS_TexVert + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); + glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; } @@ -1410,52 +1399,21 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti( { glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]); - + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; } @@ -1464,53 +1422,24 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti( { for (unsigned int i=0;i<numindices;i+=3) { + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ - + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; + // glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA())); glNormal3fv(vertexarray[(indexarray[vindex])].getNormal()); - // ------------------------------ - for(unit =0; unit<enabled; unit++) { - if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV && - vertexarray[(indexarray[vindex])].getUnit() == unit ) - { - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2()); - continue; - } - bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1()); - } - // ------------------------------ + TexCoord(vertexarray[(indexarray[vindex])],enabled ); glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ()); vindex++; } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 7e45b1c434b..6b1925340b2 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -44,6 +44,8 @@ using namespace std; #include "RAS_MaterialBucket.h" #include "RAS_ICanvas.h" +#define RAS_MAX 3// match in BL_Material + struct OglDebugLine { MT_Vector3 m_from; @@ -87,6 +89,8 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer float m_focallength; bool m_setfocallength; int m_noOfScanlines; + TexCoGen m_texco[RAS_MAX]; + bool m_useTang; bool InterlacedStereo() const; @@ -278,6 +282,11 @@ public: std::vector <OglDebugLine> m_debugLines; + virtual void SetTexCoords(TexCoGen coords,int enabled); + void TexCoord(const RAS_TexVert &tv, int unit); + virtual void SetAttrib(int type); + virtual void GetViewMatrix(MT_Matrix4x4 &mat) const; + }; #endif //__RAS_OPENGLRASTERIZER diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp index 9e9b5725b6b..f6174f6de62 100644 --- a/source/gameengine/Rasterizer/RAS_TexVert.cpp +++ b/source/gameengine/Rasterizer/RAS_TexVert.cpp @@ -39,6 +39,7 @@ RAS_TexVert::RAS_TexVert(const MT_Point3& xyz, const MT_Point2& uv, + const MT_Vector4& tangent, const unsigned int rgba, const MT_Vector3& normal, const short flag) @@ -48,6 +49,7 @@ RAS_TexVert::RAS_TexVert(const MT_Point3& xyz, uv.getValue(m_uv2); // ..py access SetRGBA(rgba); SetNormal(normal); + tangent.getValue(m_tangent); m_flag = flag; m_unit = 2; } @@ -127,6 +129,12 @@ const float* RAS_TexVert::getNormal() const return m_normal; } +const float* RAS_TexVert::getTangent() const +{ + return m_tangent; +} + + const float* RAS_TexVert::getLocalXYZ() const { return m_localxyz; diff --git a/source/gameengine/Rasterizer/RAS_TexVert.h b/source/gameengine/Rasterizer/RAS_TexVert.h index f58eca7637f..822262aad48 100644 --- a/source/gameengine/Rasterizer/RAS_TexVert.h +++ b/source/gameengine/Rasterizer/RAS_TexVert.h @@ -71,6 +71,7 @@ public: {} RAS_TexVert(const MT_Point3& xyz, const MT_Point2& uv, + const MT_Vector4& tangent, const unsigned int rgba, const MT_Vector3& normal, const short flag); @@ -94,6 +95,10 @@ public: return m_normal; } + const float* getTangent() const { + return m_tangent; + } + const unsigned char* getRGBA() const { return (unsigned char *) &m_rgba; } |