Instead of querying the vertex attribute location. Let's bind it to where CG expects it to be as well. Was causing problems when we were trying to activate the components below and they weren't available. This fixes cubivore with GLSL shader. Also any other game that uses 3 normal pointers.

This commit is contained in:
Ryan Houdek 2011-12-11 06:18:01 -06:00 committed by Sonicadvance1
parent d70726b035
commit ba12c0b4f5
3 changed files with 6 additions and 31 deletions

View File

@ -192,15 +192,8 @@ void GLVertexFormat::SetupVertexPointers() {
if (vtx_decl.num_normals >= 1) { if (vtx_decl.num_normals >= 1) {
glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0])); glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0]));
if (vtx_decl.num_normals == 3) { if (vtx_decl.num_normals == 3) {
GLint varLocation1 = SHADER_NORM1_ATTRIB, varLocation2 = SHADER_NORM2_ATTRIB; glVertexAttribPointer(SHADER_NORM1_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[1]));
if(g_ActiveConfig.bUseGLSL){ glVertexAttribPointer(SHADER_NORM2_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[2]));
varLocation1 = OGL::ProgramShaderCache::GetAttr(0);
varLocation2 = OGL::ProgramShaderCache::GetAttr(1);
}
if(varLocation1 > 0)
glVertexAttribPointer(varLocation1, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[1]));
if(varLocation2 > 0)
glVertexAttribPointer(varLocation2, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[2]));
} }
} }
@ -224,11 +217,7 @@ void GLVertexFormat::SetupVertexPointers() {
} }
if (vtx_decl.posmtx_offset != -1) { if (vtx_decl.posmtx_offset != -1) {
GLint varLocation = SHADER_POSMTX_ATTRIB; glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset));
if(g_ActiveConfig.bUseGLSL)
varLocation = OGL::ProgramShaderCache::GetAttr(2);
if(varLocation > 0)
glVertexAttribPointer(varLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset));
} }
#endif #endif
} }

View File

@ -121,18 +121,10 @@ namespace OGL
// Need to get some attribute locations // Need to get some attribute locations
if(uid.uid.vsid != 0) // We have no vertex Shader if(uid.uid.vsid != 0) // We have no vertex Shader
{ {
entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1"); glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2"); glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx"); glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
if(entry.program.attrLoc[0] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[0]);
if(entry.program.attrLoc[1] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[1]);
if(entry.program.attrLoc[2] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[2]);
} }
else
entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0;
pshaders[ShaderPair] = entry; pshaders[ShaderPair] = entry;
@ -154,10 +146,6 @@ namespace OGL
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
GLint ProgramShaderCache::GetAttr(int num)
{
return pshaders[CurrentShaderProgram].program.attrLoc[num];
}
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void) PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
{ {
return pshaders[CurrentShaderProgram].program; return pshaders[CurrentShaderProgram].program;

View File

@ -72,7 +72,6 @@ struct PROGRAMSHADER
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){} PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){}
GLuint glprogid; // opengl program id GLuint glprogid; // opengl program id
GLuint vsid, psid; GLuint vsid, psid;
GLint attrLoc[3];
GLint UniformLocations[NUM_UNIFORMS]; GLint UniformLocations[NUM_UNIFORMS];
}; };
@ -100,7 +99,6 @@ class ProgramShaderCache
public: public:
static PROGRAMSHADER GetShaderProgram(void); static PROGRAMSHADER GetShaderProgram(void);
static GLint GetAttr(int num);
static void SetBothShaders(GLuint PS, GLuint VS); static void SetBothShaders(GLuint PS, GLuint VS);
static GLuint GetCurrentProgram(void); static GLuint GetCurrentProgram(void);