Skip to content

Commit

Permalink
Warn when nonexistent vertex attribute is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Jul 12, 2024
1 parent 5608c87 commit afee459
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ void GL_VertexAttribPointers( uint32_t attribBits )
frame = glState.vertexAttribsOldFrame;
}

if ( !( glState.currentVBO->attribBits & bit ) )
{
Log::Warn( "GL_VertexAttribPointers: %s does not have %s",
glState.currentVBO->name, attributeNames[ i ] );
}

glVertexAttribPointer( i, layout->numComponents, layout->componentType, layout->normalize, layout->stride, BUFFER_OFFSET( layout->ofs + ( frame * layout->frameOffset + base ) ) );
glState.vertexAttribPointersSet |= bit;
}
Expand Down
10 changes: 1 addition & 9 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,6 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
ATTR_QTANGENT2 = BIT( ATTR_INDEX_QTANGENT2 ),

ATTR_INTERP_BITS = ATTR_POSITION2 | ATTR_QTANGENT2,

ATTR_BITS = ATTR_POSITION |
ATTR_TEXCOORD |
ATTR_QTANGENT |
ATTR_COLOR // |

//ATTR_BONE_INDEXES |
//ATTR_BONE_WEIGHTS
};

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

vboLayout_t layout;
uint32_t attribBits;
uint32_t attribBits; // Which attributes it has. Mostly for detecting errors
GLenum usage;
};

Expand Down
4 changes: 4 additions & 0 deletions src/engine/renderer/tr_model_md3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )
vboSurf->numVerts = surf->numVerts;

vboSurf->vbo = R_CreateStaticVBO( va( "staticMD3Mesh_VBO '%s'", surf->name ), data, vboLayout_t::VBO_LAYOUT_VERTEX_ANIMATION );

// MD3 does not have color, but shaders always request it and the "vertex animation"
// vertex layout includes a color field, which is zeroed by default.
vboSurf->vbo->attribBits |= ATTR_COLOR;

ri.Hunk_FreeTempMemory( data.st );
ri.Hunk_FreeTempMemory( data.qtangent );
Expand Down
4 changes: 4 additions & 0 deletions src/engine/renderer/tr_model_skel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ void R_AddSurfaceToVBOSurfacesList(

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

// MD5 does not have color, but shaders always request it and the skeletal animation
// vertex layout includes a color field, which is zeroed by default.
vboSurf->vbo->attribBits |= ATTR_COLOR;

ri.Hunk_FreeTempMemory( indexes );
ri.Hunk_FreeTempMemory( data.st );
ri.Hunk_FreeTempMemory( data.boneWeights );
Expand Down
4 changes: 3 additions & 1 deletion src/engine/renderer/tr_vbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,9 @@ R_InitVBOs
*/
void R_InitVBOs()
{
uint32_t attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_COLOR;
// ATTR_QTANGENT and ATTR_ORIENTATION are mutually exclusive, but we don't know in advance
// which attributes will be used as this buffer is used for many purposes.
uint32_t attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT | ATTR_ORIENTATION | ATTR_COLOR;

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

Expand Down

0 comments on commit afee459

Please sign in to comment.