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.
This commit is contained in:
@@ -80,7 +80,7 @@ void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat)
|
|||||||
{
|
{
|
||||||
GPUVertexAttribs attribs;
|
GPUVertexAttribs attribs;
|
||||||
GPUMaterial *gpumat;
|
GPUMaterial *gpumat;
|
||||||
int i, attrib_num;
|
int i, attrib_num, uv = 0;
|
||||||
|
|
||||||
ras->SetAttribNum(0);
|
ras->SetAttribNum(0);
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (attribs.layer[i].type == CD_MTFACE)
|
if (attribs.layer[i].type == CD_MTFACE)
|
||||||
ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV, attribs.layer[i].glindex);
|
ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV, attribs.layer[i].glindex, uv++);
|
||||||
else if (attribs.layer[i].type == CD_TANGENT)
|
else if (attribs.layer[i].type == CD_TANGENT)
|
||||||
ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, attribs.layer[i].glindex);
|
ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, attribs.layer[i].glindex);
|
||||||
else if (attribs.layer[i].type == CD_ORCO)
|
else if (attribs.layer[i].type == CD_ORCO)
|
||||||
|
@@ -396,7 +396,7 @@ public:
|
|||||||
virtual void SetTexCoordNum(int num) = 0;
|
virtual void SetTexCoordNum(int num) = 0;
|
||||||
virtual void SetAttribNum(int num) = 0;
|
virtual void SetAttribNum(int num) = 0;
|
||||||
virtual void SetTexCoord(TexCoGen coords, int unit) = 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& GetViewMatrix() const = 0;
|
||||||
virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
|
virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
|
||||||
|
@@ -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*/)
|
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_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_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
|
||||||
m_storage_type = RAS_VBO;
|
m_storage_type = RAS_VBO;
|
||||||
}
|
}
|
||||||
else if ((m_storage_type == RAS_VA) || (m_storage_type == RAS_AUTO_STORAGE && GLEW_VERSION_1_1))
|
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_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_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
|
||||||
m_storage_type = RAS_VA;
|
m_storage_type = RAS_VA;
|
||||||
}
|
}
|
||||||
else
|
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;
|
m_storage_type = RAS_IMMEDIATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -740,11 +740,13 @@ void RAS_OpenGLRasterizer::SetTexCoord(TexCoGen coords, int unit)
|
|||||||
m_texco[unit] = coords;
|
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
|
// this changes from material to material
|
||||||
if (unit < RAS_MAX_ATTRIB)
|
if (unit < RAS_MAX_ATTRIB) {
|
||||||
m_attrib[unit] = coords;
|
m_attrib[unit] = coords;
|
||||||
|
m_attrib_layer[unit] = layer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAS_OpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
|
void RAS_OpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
|
||||||
|
@@ -109,6 +109,7 @@ protected:
|
|||||||
int m_drawingmode;
|
int m_drawingmode;
|
||||||
TexCoGen m_texco[RAS_MAX_TEXCO];
|
TexCoGen m_texco[RAS_MAX_TEXCO];
|
||||||
TexCoGen m_attrib[RAS_MAX_ATTRIB];
|
TexCoGen m_attrib[RAS_MAX_ATTRIB];
|
||||||
|
int m_attrib_layer[RAS_MAX_ATTRIB];
|
||||||
int m_texco_num;
|
int m_texco_num;
|
||||||
int m_attrib_num;
|
int m_attrib_num;
|
||||||
//int m_last_alphablend;
|
//int m_last_alphablend;
|
||||||
@@ -296,7 +297,7 @@ public:
|
|||||||
virtual void SetTexCoordNum(int num);
|
virtual void SetTexCoordNum(int num);
|
||||||
virtual void SetAttribNum(int num);
|
virtual void SetAttribNum(int num);
|
||||||
virtual void SetTexCoord(TexCoGen coords, int unit);
|
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);
|
void TexCoord(const RAS_TexVert &tv);
|
||||||
|
|
||||||
|
@@ -39,11 +39,12 @@ extern "C"{
|
|||||||
#include "BKE_DerivedMesh.h"
|
#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_texco_num(texco_num),
|
||||||
m_attrib_num(attrib_num),
|
m_attrib_num(attrib_num),
|
||||||
m_texco(texco),
|
m_texco(texco),
|
||||||
m_attrib(attrib)
|
m_attrib(attrib),
|
||||||
|
m_attrib_layer(attrib_layer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
RAS_StorageIM::~RAS_StorageIM()
|
RAS_StorageIM::~RAS_StorageIM()
|
||||||
@@ -95,7 +96,6 @@ void RAS_StorageIM::TexCoord(const RAS_TexVert &tv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (GLEW_ARB_vertex_program) {
|
if (GLEW_ARB_vertex_program) {
|
||||||
int uv = 0;
|
|
||||||
for (unit = 0; unit < *m_attrib_num; unit++) {
|
for (unit = 0; unit < *m_attrib_num; unit++) {
|
||||||
switch (m_attrib[unit]) {
|
switch (m_attrib[unit]) {
|
||||||
case RAS_IRasterizer::RAS_TEXCO_ORCO:
|
case RAS_IRasterizer::RAS_TEXCO_ORCO:
|
||||||
@@ -103,7 +103,7 @@ void RAS_StorageIM::TexCoord(const RAS_TexVert &tv)
|
|||||||
glVertexAttrib3fvARB(unit, tv.getXYZ());
|
glVertexAttrib3fvARB(unit, tv.getXYZ());
|
||||||
break;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_UV:
|
case RAS_IRasterizer::RAS_TEXCO_UV:
|
||||||
glVertexAttrib2fvARB(unit, tv.getUV(uv++));
|
glVertexAttrib2fvARB(unit, tv.getUV(m_attrib_layer[unit]));
|
||||||
break;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_NORM:
|
case RAS_IRasterizer::RAS_TEXCO_NORM:
|
||||||
glVertexAttrib3fvARB(unit, tv.getNormal());
|
glVertexAttrib3fvARB(unit, tv.getNormal());
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
class RAS_StorageIM : public RAS_IStorage
|
class RAS_StorageIM : public RAS_IStorage
|
||||||
{
|
{
|
||||||
public:
|
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 ~RAS_StorageIM();
|
||||||
|
|
||||||
virtual bool Init();
|
virtual bool Init();
|
||||||
@@ -51,6 +51,7 @@ protected:
|
|||||||
int* m_attrib_num;
|
int* m_attrib_num;
|
||||||
RAS_IRasterizer::TexCoGen* m_texco;
|
RAS_IRasterizer::TexCoGen* m_texco;
|
||||||
RAS_IRasterizer::TexCoGen* m_attrib;
|
RAS_IRasterizer::TexCoGen* m_attrib;
|
||||||
|
int* m_attrib_layer;
|
||||||
|
|
||||||
void TexCoord(const RAS_TexVert &tv);
|
void TexCoord(const RAS_TexVert &tv);
|
||||||
void SetCullFace(bool enable);
|
void SetCullFace(bool enable);
|
||||||
|
@@ -29,13 +29,14 @@
|
|||||||
|
|
||||||
#include "GL/glew.h"
|
#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_texco_num(texco_num),
|
||||||
m_attrib_num(attrib_num),
|
m_attrib_num(attrib_num),
|
||||||
m_last_texco_num(0),
|
m_last_texco_num(0),
|
||||||
m_last_attrib_num(0),
|
m_last_attrib_num(0),
|
||||||
m_texco(texco),
|
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) {
|
if (GLEW_ARB_vertex_program) {
|
||||||
int uv = 0;
|
|
||||||
for (unit = 0; unit < *m_attrib_num; unit++) {
|
for (unit = 0; unit < *m_attrib_num; unit++) {
|
||||||
switch (m_attrib[unit]) {
|
switch (m_attrib[unit]) {
|
||||||
case RAS_IRasterizer::RAS_TEXCO_ORCO:
|
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());
|
glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getXYZ());
|
||||||
break;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_UV:
|
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;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_NORM:
|
case RAS_IRasterizer::RAS_TEXCO_NORM:
|
||||||
glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal());
|
glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal());
|
||||||
|
@@ -37,7 +37,7 @@ class RAS_StorageVA : public RAS_IStorage
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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 ~RAS_StorageVA();
|
||||||
|
|
||||||
virtual bool Init();
|
virtual bool Init();
|
||||||
@@ -59,6 +59,7 @@ protected:
|
|||||||
|
|
||||||
RAS_IRasterizer::TexCoGen* m_texco;
|
RAS_IRasterizer::TexCoGen* m_texco;
|
||||||
RAS_IRasterizer::TexCoGen* m_attrib;
|
RAS_IRasterizer::TexCoGen* m_attrib;
|
||||||
|
int* m_attrib_layer;
|
||||||
|
|
||||||
RAS_IRasterizer::TexCoGen m_last_texco[RAS_MAX_TEXCO];
|
RAS_IRasterizer::TexCoGen m_last_texco[RAS_MAX_TEXCO];
|
||||||
RAS_IRasterizer::TexCoGen m_last_attrib[RAS_MAX_ATTRIB];
|
RAS_IRasterizer::TexCoGen m_last_attrib[RAS_MAX_ATTRIB];
|
||||||
|
@@ -101,7 +101,7 @@ void VBO::UpdateIndices()
|
|||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, space, &data->m_index[0], GL_STATIC_DRAW);
|
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;
|
int unit;
|
||||||
|
|
||||||
@@ -159,7 +159,6 @@ void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num,
|
|||||||
|
|
||||||
if (GLEW_ARB_vertex_program)
|
if (GLEW_ARB_vertex_program)
|
||||||
{
|
{
|
||||||
int uv = 0;
|
|
||||||
for (unit = 0; unit < attrib_num; ++unit)
|
for (unit = 0; unit < attrib_num; ++unit)
|
||||||
{
|
{
|
||||||
switch (attrib[unit]) {
|
switch (attrib[unit]) {
|
||||||
@@ -169,8 +168,7 @@ void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num,
|
|||||||
glEnableVertexAttribArrayARB(unit);
|
glEnableVertexAttribArrayARB(unit);
|
||||||
break;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_UV:
|
case RAS_IRasterizer::RAS_TEXCO_UV:
|
||||||
glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+uv));
|
glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+attrib_layer[unit]*sizeof(GLfloat)*2));
|
||||||
uv += sizeof(GLfloat)*2;
|
|
||||||
glEnableVertexAttribArrayARB(unit);
|
glEnableVertexAttribArrayARB(unit);
|
||||||
break;
|
break;
|
||||||
case RAS_IRasterizer::RAS_TEXCO_NORM:
|
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);
|
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_texco_num(texco_num),
|
||||||
m_attrib_num(attrib_num),
|
m_attrib_num(attrib_num),
|
||||||
m_texco(texco),
|
m_texco(texco),
|
||||||
m_attrib(attrib)
|
m_attrib(attrib),
|
||||||
|
m_attrib_layer(attrib_layer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +253,6 @@ void RAS_StorageVBO::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi)
|
|||||||
vbo->UpdateData();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ public:
|
|||||||
VBO(RAS_DisplayArray *data, unsigned int indices);
|
VBO(RAS_DisplayArray *data, unsigned int indices);
|
||||||
~VBO();
|
~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 UpdateData();
|
||||||
void UpdateIndices();
|
void UpdateIndices();
|
||||||
@@ -66,7 +66,7 @@ class RAS_StorageVBO : public RAS_IStorage
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
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 ~RAS_StorageVBO();
|
||||||
|
|
||||||
virtual bool Init();
|
virtual bool Init();
|
||||||
@@ -85,6 +85,7 @@ protected:
|
|||||||
|
|
||||||
RAS_IRasterizer::TexCoGen* m_texco;
|
RAS_IRasterizer::TexCoGen* m_texco;
|
||||||
RAS_IRasterizer::TexCoGen* m_attrib;
|
RAS_IRasterizer::TexCoGen* m_attrib;
|
||||||
|
int* m_attrib_layer;
|
||||||
|
|
||||||
std::map<RAS_DisplayArray*, class VBO*> m_vbo_lookup;
|
std::map<RAS_DisplayArray*, class VBO*> m_vbo_lookup;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user