Skip to content

Commit afee459

Browse files
committed
Warn when nonexistent vertex attribute is requested
1 parent 5608c87 commit afee459

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

src/engine/renderer/tr_backend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ void GL_VertexAttribPointers( uint32_t attribBits )
714714
frame = glState.vertexAttribsOldFrame;
715715
}
716716

717+
if ( !( glState.currentVBO->attribBits & bit ) )
718+
{
719+
Log::Warn( "GL_VertexAttribPointers: %s does not have %s",
720+
glState.currentVBO->name, attributeNames[ i ] );
721+
}
722+
717723
glVertexAttribPointer( i, layout->numComponents, layout->componentType, layout->normalize, layout->stride, BUFFER_OFFSET( layout->ofs + ( frame * layout->frameOffset + base ) ) );
718724
glState.vertexAttribPointersSet |= bit;
719725
}

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,6 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
697697
ATTR_QTANGENT2 = BIT( ATTR_INDEX_QTANGENT2 ),
698698

699699
ATTR_INTERP_BITS = ATTR_POSITION2 | ATTR_QTANGENT2,
700-
701-
ATTR_BITS = ATTR_POSITION |
702-
ATTR_TEXCOORD |
703-
ATTR_QTANGENT |
704-
ATTR_COLOR // |
705-
706-
//ATTR_BONE_INDEXES |
707-
//ATTR_BONE_WEIGHTS
708700
};
709701

710702
struct vboAttributeLayout_t
@@ -754,7 +746,7 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
754746
vboAttributeLayout_t attribs[ ATTR_INDEX_MAX ]; // info for buffer manipulation
755747

756748
vboLayout_t layout;
757-
uint32_t attribBits;
749+
uint32_t attribBits; // Which attributes it has. Mostly for detecting errors
758750
GLenum usage;
759751
};
760752

src/engine/renderer/tr_model_md3.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )
345345
vboSurf->numVerts = surf->numVerts;
346346

347347
vboSurf->vbo = R_CreateStaticVBO( va( "staticMD3Mesh_VBO '%s'", surf->name ), data, vboLayout_t::VBO_LAYOUT_VERTEX_ANIMATION );
348+
349+
// MD3 does not have color, but shaders always request it and the "vertex animation"
350+
// vertex layout includes a color field, which is zeroed by default.
351+
vboSurf->vbo->attribBits |= ATTR_COLOR;
348352

349353
ri.Hunk_FreeTempMemory( data.st );
350354
ri.Hunk_FreeTempMemory( data.qtangent );

src/engine/renderer/tr_model_skel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ void R_AddSurfaceToVBOSurfacesList(
182182

183183
vboSurf->ibo = R_CreateStaticIBO( va( "staticMD5Mesh_IBO %i", ( int )vboSurfaces.size() ), indexes, indexesNum );
184184

185+
// MD5 does not have color, but shaders always request it and the skeletal animation
186+
// vertex layout includes a color field, which is zeroed by default.
187+
vboSurf->vbo->attribBits |= ATTR_COLOR;
188+
185189
ri.Hunk_FreeTempMemory( indexes );
186190
ri.Hunk_FreeTempMemory( data.st );
187191
ri.Hunk_FreeTempMemory( data.boneWeights );

src/engine/renderer/tr_vbo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ R_InitVBOs
10361036
*/
10371037
void R_InitVBOs()
10381038
{
1039-
uint32_t attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_COLOR;
1039+
// ATTR_QTANGENT and ATTR_ORIENTATION are mutually exclusive, but we don't know in advance
1040+
// which attributes will be used as this buffer is used for many purposes.
1041+
uint32_t attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_ORIENTATION | ATTR_COLOR;
10401042

10411043
Log::Debug("------- R_InitVBOs -------" );
10421044

0 commit comments

Comments
 (0)