diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-03-02 00:45:42 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-03-02 00:45:42 +0400 |
commit | 2822a14e5d5dac398d8e1563e9b9ec6c183540bd (patch) | |
tree | a8571bdbe86e868ef2afae9edf3cdfac20b0ee92 /source/gameengine/Rasterizer | |
parent | 70fba545457dd2ae8b36a367280ea6bd0c2c5e40 (diff) |
Fix #34483: game engine multi UV glsl materials not working correct after changes
to support more than 2 UV maps. This code indirectly depended on the order of
OpenGL attribute ID's assigned by the OpenGL driver being the same as the
attributes being declared in the GLSL shader code, which is not always the case.
Diffstat (limited to 'source/gameengine/Rasterizer')
9 files changed, 35 insertions, 30 deletions
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 99026fa259a..c04b62bc5da 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -396,7 +396,7 @@ public: virtual void SetTexCoordNum(int num) = 0; virtual void SetAttribNum(int num) = 0; virtual void SetTexCoord(TexCoGen coords, int unit) = 0; - virtual void SetAttrib(TexCoGen coords, int unit) = 0; + virtual void SetAttrib(TexCoGen coords, int unit, int layer = 0) = 0; virtual const MT_Matrix4x4& GetViewMatrix() const = 0; virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 0186e99f78a..f995f7ddb3d 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -116,19 +116,19 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas, int storage) if (m_storage_type == RAS_VBO /*|| m_storage_type == RAS_AUTO_STORAGE && GLEW_ARB_vertex_buffer_object*/) { - m_storage = new RAS_StorageVBO(&m_texco_num, m_texco, &m_attrib_num, m_attrib); - m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib); + m_storage = new RAS_StorageVBO(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer); + m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer); m_storage_type = RAS_VBO; } else if ((m_storage_type == RAS_VA) || (m_storage_type == RAS_AUTO_STORAGE && GLEW_VERSION_1_1)) { - m_storage = new RAS_StorageVA(&m_texco_num, m_texco, &m_attrib_num, m_attrib); - m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib); + m_storage = new RAS_StorageVA(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer); + m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer); m_storage_type = RAS_VA; } else { - m_storage = m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib); + m_storage = m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer); m_storage_type = RAS_IMMEDIATE; } } @@ -740,11 +740,13 @@ void RAS_OpenGLRasterizer::SetTexCoord(TexCoGen coords, int unit) m_texco[unit] = coords; } -void RAS_OpenGLRasterizer::SetAttrib(TexCoGen coords, int unit) +void RAS_OpenGLRasterizer::SetAttrib(TexCoGen coords, int unit, int layer) { // this changes from material to material - if (unit < RAS_MAX_ATTRIB) + if (unit < RAS_MAX_ATTRIB) { m_attrib[unit] = coords; + m_attrib_layer[unit] = layer; + } } void RAS_OpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms) diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 64c07358d95..94589f84197 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -109,6 +109,7 @@ protected: int m_drawingmode; TexCoGen m_texco[RAS_MAX_TEXCO]; TexCoGen m_attrib[RAS_MAX_ATTRIB]; + int m_attrib_layer[RAS_MAX_ATTRIB]; int m_texco_num; int m_attrib_num; //int m_last_alphablend; @@ -296,7 +297,7 @@ public: virtual void SetTexCoordNum(int num); virtual void SetAttribNum(int num); virtual void SetTexCoord(TexCoGen coords, int unit); - virtual void SetAttrib(TexCoGen coords, int unit); + virtual void SetAttrib(TexCoGen coords, int unit, int layer = 0); void TexCoord(const RAS_TexVert &tv); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp index 7bcc8dc9034..900d6f387ff 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp @@ -39,11 +39,12 @@ extern "C"{ #include "BKE_DerivedMesh.h" } -RAS_StorageIM::RAS_StorageIM(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib) : +RAS_StorageIM::RAS_StorageIM(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer) : m_texco_num(texco_num), m_attrib_num(attrib_num), m_texco(texco), - m_attrib(attrib) + m_attrib(attrib), + m_attrib_layer(attrib_layer) { } RAS_StorageIM::~RAS_StorageIM() @@ -95,7 +96,6 @@ void RAS_StorageIM::TexCoord(const RAS_TexVert &tv) } if (GLEW_ARB_vertex_program) { - int uv = 0; for (unit = 0; unit < *m_attrib_num; unit++) { switch (m_attrib[unit]) { case RAS_IRasterizer::RAS_TEXCO_ORCO: @@ -103,7 +103,7 @@ void RAS_StorageIM::TexCoord(const RAS_TexVert &tv) glVertexAttrib3fvARB(unit, tv.getXYZ()); break; case RAS_IRasterizer::RAS_TEXCO_UV: - glVertexAttrib2fvARB(unit, tv.getUV(uv++)); + glVertexAttrib2fvARB(unit, tv.getUV(m_attrib_layer[unit])); break; case RAS_IRasterizer::RAS_TEXCO_NORM: glVertexAttrib3fvARB(unit, tv.getNormal()); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.h index de4ff30d394..54ba2a57b61 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.h @@ -34,7 +34,7 @@ class RAS_StorageIM : public RAS_IStorage { public: - RAS_StorageIM(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib); + RAS_StorageIM(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer); virtual ~RAS_StorageIM(); virtual bool Init(); @@ -51,6 +51,7 @@ protected: int* m_attrib_num; RAS_IRasterizer::TexCoGen* m_texco; RAS_IRasterizer::TexCoGen* m_attrib; + int* m_attrib_layer; void TexCoord(const RAS_TexVert &tv); void SetCullFace(bool enable); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp index 7182525ea71..d45365dde04 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp @@ -29,13 +29,14 @@ #include "GL/glew.h" -RAS_StorageVA::RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib) : +RAS_StorageVA::RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer) : m_texco_num(texco_num), m_attrib_num(attrib_num), m_last_texco_num(0), m_last_attrib_num(0), m_texco(texco), - m_attrib(attrib) + m_attrib(attrib), + m_attrib_layer(attrib_layer) { } @@ -214,7 +215,6 @@ void RAS_StorageVA::TexCoordPtr(const RAS_TexVert *tv) } if (GLEW_ARB_vertex_program) { - int uv = 0; for (unit = 0; unit < *m_attrib_num; unit++) { switch (m_attrib[unit]) { case RAS_IRasterizer::RAS_TEXCO_ORCO: @@ -222,7 +222,7 @@ void RAS_StorageVA::TexCoordPtr(const RAS_TexVert *tv) glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getXYZ()); break; case RAS_IRasterizer::RAS_TEXCO_UV: - glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV(uv++)); + glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV(m_attrib_layer[unit])); break; case RAS_IRasterizer::RAS_TEXCO_NORM: glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal()); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h index da7766ec5ca..e4d00310a11 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h @@ -37,7 +37,7 @@ class RAS_StorageVA : public RAS_IStorage { public: - RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib); + RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer); virtual ~RAS_StorageVA(); virtual bool Init(); @@ -59,6 +59,7 @@ protected: RAS_IRasterizer::TexCoGen* m_texco; RAS_IRasterizer::TexCoGen* m_attrib; + int* m_attrib_layer; RAS_IRasterizer::TexCoGen m_last_texco[RAS_MAX_TEXCO]; RAS_IRasterizer::TexCoGen m_last_attrib[RAS_MAX_ATTRIB]; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp index 077dfad80bb..3de77951fa7 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp @@ -101,10 +101,10 @@ void VBO::UpdateIndices() glBufferData(GL_ELEMENT_ARRAY_BUFFER, space, &data->m_index[0], GL_STATIC_DRAW); } -void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, bool multi) +void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, int *attrib_layer, bool multi) { int unit; - + // Bind buffers glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo); glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id); @@ -159,7 +159,6 @@ void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, if (GLEW_ARB_vertex_program) { - int uv = 0; for (unit = 0; unit < attrib_num; ++unit) { switch (attrib[unit]) { @@ -169,8 +168,7 @@ void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXCO_UV: - glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+uv)); - uv += sizeof(GLfloat)*2; + glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+attrib_layer[unit]*sizeof(GLfloat)*2)); glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXCO_NORM: @@ -204,11 +202,12 @@ void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } -RAS_StorageVBO::RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib): +RAS_StorageVBO::RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer): m_texco_num(texco_num), m_attrib_num(attrib_num), m_texco(texco), - m_attrib(attrib) + m_attrib(attrib), + m_attrib_layer(attrib_layer) { } @@ -240,7 +239,7 @@ void RAS_StorageVBO::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) { RAS_MeshSlot::iterator it; VBO *vbo; - + for (ms.begin(it); !ms.end(it); ms.next(it)) { vbo = m_vbo_lookup[it.array]; @@ -254,6 +253,6 @@ void RAS_StorageVBO::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) vbo->UpdateData(); } - vbo->Draw(*m_texco_num, m_texco, *m_attrib_num, m_attrib, multi); + vbo->Draw(*m_texco_num, m_texco, *m_attrib_num, m_attrib, m_attrib_layer, multi); } } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h index d8d8192e482..2fe0c32f399 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h @@ -42,7 +42,7 @@ public: VBO(RAS_DisplayArray *data, unsigned int indices); ~VBO(); - void Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, bool multi); + void Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, int *attrib_layer, bool multi); void UpdateData(); void UpdateIndices(); @@ -66,7 +66,7 @@ class RAS_StorageVBO : public RAS_IStorage { public: - RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib); + RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer); virtual ~RAS_StorageVBO(); virtual bool Init(); @@ -85,6 +85,7 @@ protected: RAS_IRasterizer::TexCoGen* m_texco; RAS_IRasterizer::TexCoGen* m_attrib; + int* m_attrib_layer; std::map<RAS_DisplayArray*, class VBO*> m_vbo_lookup; |