Skip to content

Commit

Permalink
Fix stage variants upload
Browse files Browse the repository at this point in the history
Also removed some now useless code.
  • Loading branch information
VReaperV committed Dec 26, 2024
1 parent 65bc11f commit 981f302
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
57 changes: 9 additions & 48 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, shader
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

gl_genericShaderMaterial->BindProgram( material.deformIndex );

// u_AlphaThreshold
Expand Down Expand Up @@ -181,12 +175,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, sha
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

gl_lightMappingShaderMaterial->BindProgram( material.deformIndex );

// u_ColorModulate
Expand Down Expand Up @@ -246,12 +234,6 @@ void UpdateSurfaceDataReflection( uint32_t* materials, Material& /* material */,
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

// bind u_ColorMap
vec3_t position;
if ( backEnd.currentEntity && ( backEnd.currentEntity != &tr.worldEntity ) ) {
Expand Down Expand Up @@ -294,12 +276,6 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, Material& material, shaderSta
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

gl_skyboxShaderMaterial->BindProgram( material.deformIndex );

// u_AlphaThreshold
Expand All @@ -314,12 +290,6 @@ void UpdateSurfaceDataScreen( uint32_t* materials, Material& /* material */, sha
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

gl_screenShaderMaterial->BindProgram( pStage->deformIndex );

// bind u_CurrentMap
Expand All @@ -336,12 +306,6 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, Material& /* material */, s
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

float deformMagnitude = RB_EvalExpression( &pStage->deformMagnitudeExp, 1.0 );
gl_heatHazeShaderMaterial->SetUniform_DeformMagnitude( deformMagnitude );

Expand All @@ -362,12 +326,6 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, Material& /* material */, sha
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

float fogDensity = RB_EvalExpression( &pStage->fogDensityExp, 0.001 );
vec4_t fogColor;
Tess_ComputeColor( pStage );
Expand Down Expand Up @@ -421,12 +379,6 @@ void UpdateSurfaceDataFog( uint32_t* materials, Material& material, shaderStage_
const uint32_t paddedOffset = pStage->bufferOffset;
materials += paddedOffset;

bool updated = !pStage->bufferInitialized || pStage->dynamic;
if ( !updated ) {
return;
}
pStage->bufferInitialized = true;

const fog_t* fog = material.fog;

// u_Color
Expand Down Expand Up @@ -569,7 +521,11 @@ void MaterialSystem::GenerateMaterialsBuffer( std::vector<shaderStage_t*>& stage
pStage->vertexLit = i & Util::ordinal( ShaderStageVariant::VERTEX_LIT );
pStage->fullbright = i & Util::ordinal( ShaderStageVariant::FULLBRIGHT );
pStage->currentOffset = pStage->variantOffsets[i];

const uint32_t variantOffset = pStage->variantOffsets[i] * material.shader->GetPaddedSize();
pStage->bufferOffset += variantOffset;
pStage->surfaceDataUpdater( materialsData, material, pStage );
pStage->bufferOffset -= variantOffset;
variants++;
}
}
Expand Down Expand Up @@ -1403,6 +1359,11 @@ void MaterialSystem::AddStage( drawSurf_t* drawSurf, shaderStage_t* pStage, uint

pStage->materialRemappedStage = pStage2;

if ( pStage2->variantOffsets[variant] == -1 ) {
pStage2->variantOffsets[variant] = pStage2->variantOffset;
pStage2->variantOffset++;
}

return;
}

Expand Down
1 change: 0 additions & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,6 @@ enum class shaderProfilerRenderSubGroupsMode {
uint32_t dynamicBufferOffset = 0;

bool initialized = false;
bool bufferInitialized = false;

uint materialPackID = 0;
uint materialID = 0;
Expand Down

0 comments on commit 981f302

Please sign in to comment.