Skip to content

Commit

Permalink
vboData_t
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 11, 2024
1 parent 220c185 commit 5cd8db6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/engine/client/hunk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ void Hunk_FreeTempMemory( void *buf )

if ( hdr->magic != (int) HUNK_MAGIC )
{
ASSERT( false );
Sys::Error( "Hunk_FreeTempMemory: bad magic" );
}

Expand Down
8 changes: 7 additions & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,13 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
vec3_t *xyz;
i16vec4_t *qtangent;
u8vec4_t *color;
union { f16vec2_t *st; f16vec4_t *stpq; vec2_t *stf; };

union {
f16vec2_t *f16st;
f16vec4_t *f16stpq;
vec2_t *st;
};

int (*boneIndexes)[ 4 ];
vec4_t *boneWeights;
f16vec4_t *f16SpriteOrientation;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_model_iqm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
vboData.qtangent = qtangentbuf;
vboData.numFrames = 0;
vboData.color = (u8vec4_t *)IQModel->colors;
vboData.st = (f16vec2_t *)IQModel->f16TexCoords;
vboData.f16st = (f16vec2_t *)IQModel->f16TexCoords;
vboData.noLightCoords = true;
vboData.boneIndexes = (int (*)[4])indexbuf;
vboData.boneWeights = (vec4_t *)weightbuf;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/renderer/tr_model_md3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )
data.xyz = ( vec3_t * ) ri.Hunk_AllocateTempMemory( sizeof( *data.xyz ) * mdvModel->numFrames * surf->numVerts );
data.qtangent = ( i16vec4_t * ) ri.Hunk_AllocateTempMemory( sizeof( i16vec4_t ) * mdvModel->numFrames * surf->numVerts );
data.numFrames = mdvModel->numFrames;
data.st = ( f16vec2_t * ) ri.Hunk_AllocateTempMemory( sizeof( f16vec2_t ) * surf->numVerts );
data.f16st = ( f16vec2_t * ) ri.Hunk_AllocateTempMemory( sizeof( f16vec2_t ) * surf->numVerts );
data.noLightCoords = true;
data.numVerts = surf->numVerts;

Expand All @@ -275,8 +275,8 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )
// feed vertex texcoords
for ( j = 0; j < surf->numVerts; j++ )
{
data.st[ j ][ 0 ] = floatToHalf( surf->st[ j ].st[ 0 ] );
data.st[ j ][ 1 ] = floatToHalf( surf->st[ j ].st[ 1 ] );
data.f16st[ j ][ 0 ] = floatToHalf( surf->st[ j ].st[ 0 ] );
data.f16st[ j ][ 1 ] = floatToHalf( surf->st[ j ].st[ 1 ] );
}

// calc and feed tangent spaces
Expand Down Expand Up @@ -348,7 +348,7 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )

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

ri.Hunk_FreeTempMemory( data.st );
ri.Hunk_FreeTempMemory( data.f16st );
ri.Hunk_FreeTempMemory( data.qtangent );
ri.Hunk_FreeTempMemory( data.xyz );

Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/tr_model_skel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void R_AddSurfaceToVBOSurfacesList(
data.qtangent = ( i16vec4_t * ) ri.Hunk_AllocateTempMemory( sizeof( i16vec4_t ) * vertexesNum );
data.boneIndexes = ( int (*)[ 4 ] ) ri.Hunk_AllocateTempMemory( sizeof( *data.boneIndexes ) * vertexesNum );
data.boneWeights = ( vec4_t * ) ri.Hunk_AllocateTempMemory( sizeof( *data.boneWeights ) * vertexesNum );
data.st = ( f16vec2_t * ) ri.Hunk_AllocateTempMemory( sizeof( f16vec2_t ) * vertexesNum );
data.f16st = ( f16vec2_t * ) ri.Hunk_AllocateTempMemory( sizeof( f16vec2_t ) * vertexesNum );
data.noLightCoords = true;
data.numVerts = vertexesNum;

Expand Down Expand Up @@ -164,7 +164,7 @@ void R_AddSurfaceToVBOSurfacesList(
surf->verts[ j ].normal, data.qtangent[ j ] );

// Model only supports half float for now.
Vector2Copy( surf->verts[ j ].f16TexCoords, data.st[ j ] );
Vector2Copy( surf->verts[ j ].f16TexCoords, data.f16st[ j ] );

for (unsigned k = 0; k < MAX_WEIGHTS; k++ )
{
Expand All @@ -186,7 +186,7 @@ void R_AddSurfaceToVBOSurfacesList(
vboSurf->ibo = R_CreateStaticIBO( va( "staticMD5Mesh_IBO %i", ( int )vboSurfaces.size() ), indexes, indexesNum );

ri.Hunk_FreeTempMemory( indexes );
ri.Hunk_FreeTempMemory( data.st );
ri.Hunk_FreeTempMemory( data.f16st );
ri.Hunk_FreeTempMemory( data.boneWeights );
ri.Hunk_FreeTempMemory( data.boneIndexes );
ri.Hunk_FreeTempMemory( data.qtangent );
Expand Down
28 changes: 17 additions & 11 deletions src/engine/renderer/tr_vbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static uint32_t R_DeriveAttrBits( const vboData_t &data )
stateBits |= ATTR_COLOR;
}

if ( data.st )
if ( data.f16st )
{
stateBits |= ATTR_TEXCOORD;
}
Expand Down Expand Up @@ -379,11 +379,12 @@ static void R_CopyVertexData( VBO_t *vbo, byte *outData, vboData_t inData )
{
if ( glConfig2.halfFloatVertexAvailable )
{
Vector2Copy( inData.st[ v ], ptr[ v ].f16TexCoords );
Vector2Copy( inData.f16st[ v ], ptr[ v ].f16TexCoords );
}
else
{
halfToFloat2( inData.st[ v ], ptr[ v ].texCoords );
// Model only supports half float for now.
halfToFloat2( inData.f16st[ v ], ptr[ v ].texCoords );
}
}

Expand Down Expand Up @@ -425,13 +426,14 @@ static void R_CopyVertexData( VBO_t *vbo, byte *outData, vboData_t inData )

if ( ( vbo->attribBits & ATTR_TEXCOORD ) )
{
// What is this?
if ( glConfig2.halfFloatVertexAvailable )
{
Vector4Copy( inData.stpq[ v ], ptr[ v ].f16TexCoords );
Vector4Copy( inData.f16stpq[ v ], ptr[ v ].f16TexCoords );
}
else
{
halfToFloat( inData.stpq[ v ], ptr[ v ].texCoords );
halfToFloat( inData.f16stpq[ v ], ptr[ v ].texCoords );
}
}

Expand Down Expand Up @@ -461,7 +463,8 @@ static void R_CopyVertexData( VBO_t *vbo, byte *outData, vboData_t inData )

if ( ( vbo->attribBits & ATTR_TEXCOORD ) )
{
Vector2Copy( inData.stf[ v ], ptr[ 2 * v + 1 ] );
// This is always float, only usage of st.
Vector2Copy( inData.st[ v ], ptr[ 2 * v + 1 ] );
}
} else if ( vbo->layout == vboLayout_t::VBO_LAYOUT_VERTEX_ANIMATION ) {
struct fmtVertexAnim2 *ptr = ( struct fmtVertexAnim2 * )( outData + ( vbo->framesNum * vbo->vertexesNum ) * sizeVertexAnim1 );
Expand All @@ -470,11 +473,12 @@ static void R_CopyVertexData( VBO_t *vbo, byte *outData, vboData_t inData )
{
if ( glConfig2.halfFloatVertexAvailable )
{
Vector2Copy( inData.st[ v ], ptr[ v ].f16TexCoords );
Vector2Copy( inData.f16st[ v ], ptr[ v ].f16TexCoords );
}
else
{
halfToFloat2( inData.st[ v ], ptr[ v ].texCoords );
// Model only supports half float for now.
halfToFloat2( inData.f16st[ v ], ptr[ v ].texCoords );
}
}

Expand Down Expand Up @@ -1095,23 +1099,25 @@ static void R_InitTileVBO()
data.numVerts = w * h;

data.xyz = ( vec3_t * ) ri.Hunk_AllocateTempMemory( data.numVerts * sizeof( *data.xyz ) );
data.stf = ( vec2_t * ) ri.Hunk_AllocateTempMemory( data.numVerts * sizeof( *data.stf ) );
data.st = ( vec2_t * ) ri.Hunk_AllocateTempMemory( data.numVerts * sizeof( *data.st ) );

for (y = 0; y < h; y++ ) {
for (x = 0; x < w; x++ ) {
VectorSet( data.xyz[ y * w + x ],
(2 * x - w + 1) * (1.0f / w),
(2 * y - h + 1) * (1.0f / h),
0.0f );
Vector2Set( data.stf[ y * w + x ],

// This is always float, only usage of st.
Vector2Set( data.st[ y * w + x ],
2 * x * glState.tileStep[ 0 ] + glState.tileStep[ 0 ] - 1.0f,
2 * y * glState.tileStep[ 1 ] + glState.tileStep[ 1 ] - 1.0f );
}
}

tr.lighttileVBO = R_CreateStaticVBO( "lighttile_VBO", data, vboLayout_t::VBO_LAYOUT_XYST );

ri.Hunk_FreeTempMemory( data.stf );
ri.Hunk_FreeTempMemory( data.st );
ri.Hunk_FreeTempMemory( data.xyz );
}

Expand Down

0 comments on commit 5cd8db6

Please sign in to comment.