summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_glsl.c
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-11-12 19:21:51 -0800
committerTim Angus <tim@ngus.net>2014-06-17 17:43:36 +0100
commit38af27b32b1302fd5ddd83d992fc8ec73209b3ad (patch)
tree0af9a9e571ffd1120d4603bd8d09f092875786e3 /src/renderergl2/tr_glsl.c
parent1efea34f7dc0afa21c1ddaa62705c8f4e6b76d9e (diff)
OpenGL2: Calculate bitangent in shader, and store normal/tangent as normalized byte arrays.
Diffstat (limited to 'src/renderergl2/tr_glsl.c')
-rw-r--r--src/renderergl2/tr_glsl.c83
1 files changed, 16 insertions, 67 deletions
diff --git a/src/renderergl2/tr_glsl.c b/src/renderergl2/tr_glsl.c
index d67744f8..d0573b97 100644
--- a/src/renderergl2/tr_glsl.c
+++ b/src/renderergl2/tr_glsl.c
@@ -528,9 +528,6 @@ static int GLSL_InitGPUShader2(shaderProgram_t * program, const char *name, int
#ifdef USE_VERT_TANGENT_SPACE
if(attribs & ATTR_TANGENT)
qglBindAttribLocationARB(program->program, ATTR_INDEX_TANGENT, "attr_Tangent");
-
- if(attribs & ATTR_BITANGENT)
- qglBindAttribLocationARB(program->program, ATTR_INDEX_BITANGENT, "attr_Bitangent");
#endif
if(attribs & ATTR_NORMAL)
@@ -554,9 +551,6 @@ static int GLSL_InitGPUShader2(shaderProgram_t * program, const char *name, int
#ifdef USE_VERT_TANGENT_SPACE
if(attribs & ATTR_TANGENT2)
qglBindAttribLocationARB(program->program, ATTR_INDEX_TANGENT2, "attr_Tangent2");
-
- if(attribs & ATTR_BITANGENT2)
- qglBindAttribLocationARB(program->program, ATTR_INDEX_BITANGENT2, "attr_Bitangent2");
#endif
GLSL_LinkProgram(program->program);
@@ -1069,7 +1063,7 @@ void GLSL_InitGPUShaders(void)
#ifdef USE_VERT_TANGENT_SPACE
Q_strcat(extradefines, 1024, "#define USE_VERT_TANGENT_SPACE\n");
- attribs |= ATTR_TANGENT | ATTR_BITANGENT;
+ attribs |= ATTR_TANGENT;
#endif
if ((i & LIGHTDEF_USE_PARALLAXMAP) && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer)
@@ -1133,7 +1127,7 @@ void GLSL_InitGPUShaders(void)
#ifdef USE_VERT_TANGENT_SPACE
if (r_normalMapping->integer)
{
- attribs |= ATTR_TANGENT2 | ATTR_BITANGENT2;
+ attribs |= ATTR_TANGENT2;
}
#endif
}
@@ -1400,12 +1394,10 @@ void GLSL_ShutdownGPUShaders(void)
qglDisableVertexAttribArrayARB(ATTR_INDEX_NORMAL);
#ifdef USE_VERT_TANGENT_SPACE
qglDisableVertexAttribArrayARB(ATTR_INDEX_TANGENT);
- qglDisableVertexAttribArrayARB(ATTR_INDEX_BITANGENT);
#endif
qglDisableVertexAttribArrayARB(ATTR_INDEX_NORMAL2);
#ifdef USE_VERT_TANGENT_SPACE
qglDisableVertexAttribArrayARB(ATTR_INDEX_TANGENT2);
- qglDisableVertexAttribArrayARB(ATTR_INDEX_BITANGENT2);
#endif
qglDisableVertexAttribArrayARB(ATTR_INDEX_COLOR);
qglDisableVertexAttribArrayARB(ATTR_INDEX_LIGHTDIRECTION);
@@ -1565,20 +1557,6 @@ void GLSL_VertexAttribsState(uint32_t stateBits)
qglDisableVertexAttribArrayARB(ATTR_INDEX_TANGENT);
}
}
-
- if(diff & ATTR_BITANGENT)
- {
- if(stateBits & ATTR_BITANGENT)
- {
- GLimp_LogComment("qglEnableVertexAttribArrayARB( ATTR_INDEX_BITANGENT )\n");
- qglEnableVertexAttribArrayARB(ATTR_INDEX_BITANGENT);
- }
- else
- {
- GLimp_LogComment("qglDisableVertexAttribArrayARB( ATTR_INDEX_BITANGENT )\n");
- qglDisableVertexAttribArrayARB(ATTR_INDEX_BITANGENT);
- }
- }
#endif
if(diff & ATTR_COLOR)
@@ -1651,20 +1629,6 @@ void GLSL_VertexAttribsState(uint32_t stateBits)
qglDisableVertexAttribArrayARB(ATTR_INDEX_TANGENT2);
}
}
-
- if(diff & ATTR_BITANGENT2)
- {
- if(stateBits & ATTR_BITANGENT2)
- {
- GLimp_LogComment("qglEnableVertexAttribArrayARB( ATTR_INDEX_BITANGENT2 )\n");
- qglEnableVertexAttribArrayARB(ATTR_INDEX_BITANGENT2);
- }
- else
- {
- GLimp_LogComment("qglDisableVertexAttribArrayARB( ATTR_INDEX_BITANGENT2 )\n");
- qglDisableVertexAttribArrayARB(ATTR_INDEX_BITANGENT2);
- }
- }
#endif
glState.vertexAttribsState = stateBits;
@@ -1674,17 +1638,18 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
qboolean animated;
int newFrame, oldFrame;
+ VBO_t *vbo = glState.currentVBO;
- if(!glState.currentVBO)
+ if(!vbo)
{
ri.Error(ERR_FATAL, "GL_VertexAttribPointers: no VBO bound");
return;
}
// don't just call LogComment, or we will get a call to va() every frame!
- GLimp_LogComment(va("--- GL_VertexAttribPointers( %s ) ---\n", glState.currentVBO->name));
+ GLimp_LogComment(va("--- GL_VertexAttribPointers( %s ) ---\n", vbo->name));
- // position/normal/tangent/bitangent are always set in case of animation
+ // position/normal/tangent are always set in case of animation
oldFrame = glState.vertexAttribsOldFrame;
newFrame = glState.vertexAttribsNewFrame;
animated = glState.vertexAnimation;
@@ -1693,7 +1658,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_POSITION )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_POSITION, 3, GL_FLOAT, 0, glState.currentVBO->stride_xyz, BUFFER_OFFSET(glState.currentVBO->ofs_xyz + newFrame * glState.currentVBO->size_xyz));
+ qglVertexAttribPointerARB(ATTR_INDEX_POSITION, 3, GL_FLOAT, 0, vbo->stride_xyz, BUFFER_OFFSET(vbo->ofs_xyz + newFrame * vbo->size_xyz));
glState.vertexAttribPointersSet |= ATTR_POSITION;
}
@@ -1701,7 +1666,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_TEXCOORD )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_TEXCOORD0, 2, GL_FLOAT, 0, glState.currentVBO->stride_st, BUFFER_OFFSET(glState.currentVBO->ofs_st));
+ qglVertexAttribPointerARB(ATTR_INDEX_TEXCOORD0, 2, GL_FLOAT, 0, vbo->stride_st, BUFFER_OFFSET(vbo->ofs_st));
glState.vertexAttribPointersSet |= ATTR_TEXCOORD;
}
@@ -1709,7 +1674,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_LIGHTCOORD )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_TEXCOORD1, 2, GL_FLOAT, 0, glState.currentVBO->stride_lightmap, BUFFER_OFFSET(glState.currentVBO->ofs_lightmap));
+ qglVertexAttribPointerARB(ATTR_INDEX_TEXCOORD1, 2, GL_FLOAT, 0, vbo->stride_lightmap, BUFFER_OFFSET(vbo->ofs_lightmap));
glState.vertexAttribPointersSet |= ATTR_LIGHTCOORD;
}
@@ -1717,7 +1682,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_NORMAL )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_NORMAL, 3, GL_FLOAT, 0, glState.currentVBO->stride_normal, BUFFER_OFFSET(glState.currentVBO->ofs_normal + newFrame * glState.currentVBO->size_normal));
+ qglVertexAttribPointerARB(ATTR_INDEX_NORMAL, 3, GL_UNSIGNED_BYTE, GL_TRUE, vbo->stride_normal, BUFFER_OFFSET(vbo->ofs_normal + newFrame * vbo->size_normal));
glState.vertexAttribPointersSet |= ATTR_NORMAL;
}
@@ -1726,24 +1691,16 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_TANGENT )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_TANGENT, 3, GL_FLOAT, 0, glState.currentVBO->stride_tangent, BUFFER_OFFSET(glState.currentVBO->ofs_tangent + newFrame * glState.currentVBO->size_normal)); // FIXME
+ qglVertexAttribPointerARB(ATTR_INDEX_TANGENT, 4, GL_UNSIGNED_BYTE, GL_TRUE, vbo->stride_tangent, BUFFER_OFFSET(vbo->ofs_tangent + newFrame * vbo->size_normal)); // FIXME
glState.vertexAttribPointersSet |= ATTR_TANGENT;
}
-
- if((attribBits & ATTR_BITANGENT) && (!(glState.vertexAttribPointersSet & ATTR_BITANGENT) || animated))
- {
- GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_BITANGENT )\n");
-
- qglVertexAttribPointerARB(ATTR_INDEX_BITANGENT, 3, GL_FLOAT, 0, glState.currentVBO->stride_bitangent, BUFFER_OFFSET(glState.currentVBO->ofs_bitangent + newFrame * glState.currentVBO->size_normal)); // FIXME
- glState.vertexAttribPointersSet |= ATTR_BITANGENT;
- }
#endif
if((attribBits & ATTR_COLOR) && !(glState.vertexAttribPointersSet & ATTR_COLOR))
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_COLOR )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_COLOR, 4, GL_FLOAT, 0, glState.currentVBO->stride_vertexcolor, BUFFER_OFFSET(glState.currentVBO->ofs_vertexcolor));
+ qglVertexAttribPointerARB(ATTR_INDEX_COLOR, 4, GL_FLOAT, 0, vbo->stride_vertexcolor, BUFFER_OFFSET(vbo->ofs_vertexcolor));
glState.vertexAttribPointersSet |= ATTR_COLOR;
}
@@ -1751,7 +1708,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_LIGHTDIRECTION )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_LIGHTDIRECTION, 3, GL_FLOAT, 0, glState.currentVBO->stride_lightdir, BUFFER_OFFSET(glState.currentVBO->ofs_lightdir));
+ qglVertexAttribPointerARB(ATTR_INDEX_LIGHTDIRECTION, 3, GL_FLOAT, 0, vbo->stride_lightdir, BUFFER_OFFSET(vbo->ofs_lightdir));
glState.vertexAttribPointersSet |= ATTR_LIGHTDIRECTION;
}
@@ -1759,7 +1716,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_POSITION2 )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_POSITION2, 3, GL_FLOAT, 0, glState.currentVBO->stride_xyz, BUFFER_OFFSET(glState.currentVBO->ofs_xyz + oldFrame * glState.currentVBO->size_xyz));
+ qglVertexAttribPointerARB(ATTR_INDEX_POSITION2, 3, GL_FLOAT, 0, vbo->stride_xyz, BUFFER_OFFSET(vbo->ofs_xyz + oldFrame * vbo->size_xyz));
glState.vertexAttribPointersSet |= ATTR_POSITION2;
}
@@ -1767,7 +1724,7 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_NORMAL2 )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_NORMAL2, 3, GL_FLOAT, 0, glState.currentVBO->stride_normal, BUFFER_OFFSET(glState.currentVBO->ofs_normal + oldFrame * glState.currentVBO->size_normal));
+ qglVertexAttribPointerARB(ATTR_INDEX_NORMAL2, 3, GL_UNSIGNED_BYTE, GL_TRUE, vbo->stride_normal, BUFFER_OFFSET(vbo->ofs_normal + oldFrame * vbo->size_normal));
glState.vertexAttribPointersSet |= ATTR_NORMAL2;
}
@@ -1776,17 +1733,9 @@ void GLSL_VertexAttribPointers(uint32_t attribBits)
{
GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_TANGENT2 )\n");
- qglVertexAttribPointerARB(ATTR_INDEX_TANGENT2, 3, GL_FLOAT, 0, glState.currentVBO->stride_tangent, BUFFER_OFFSET(glState.currentVBO->ofs_tangent + oldFrame * glState.currentVBO->size_normal)); // FIXME
+ qglVertexAttribPointerARB(ATTR_INDEX_TANGENT2, 4, GL_UNSIGNED_BYTE, GL_TRUE, vbo->stride_tangent, BUFFER_OFFSET(vbo->ofs_tangent + oldFrame * vbo->size_normal)); // FIXME
glState.vertexAttribPointersSet |= ATTR_TANGENT2;
}
-
- if((attribBits & ATTR_BITANGENT2) && (!(glState.vertexAttribPointersSet & ATTR_BITANGENT2) || animated))
- {
- GLimp_LogComment("qglVertexAttribPointerARB( ATTR_INDEX_BITANGENT2 )\n");
-
- qglVertexAttribPointerARB(ATTR_INDEX_BITANGENT2, 3, GL_FLOAT, 0, glState.currentVBO->stride_bitangent, BUFFER_OFFSET(glState.currentVBO->ofs_bitangent + oldFrame * glState.currentVBO->size_normal)); // FIXME
- glState.vertexAttribPointersSet |= ATTR_BITANGENT2;
- }
#endif
}