Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glsl_restart with material system #1507

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,13 @@ void MaterialSystem::ProcessStage( drawSurf_t* drawSurf, shaderStage_t* pStage,
pStage->materialProcessor( &material, pStage, drawSurf );
pStage->paddedSize = material.shader->GetPaddedSize();

// HACK: Copy the shaderStage_t and drawSurf_t that we need into the material, so we can use it with glsl_restart
material.refStage = pStage;
material.refDrawSurf = *drawSurf;
material.refDrawSurf.entity = nullptr;
material.refDrawSurf.depthSurface = nullptr;
material.refDrawSurf.fogSurface = nullptr;

std::vector<Material>& materials = materialPacks[materialPack].materials;
std::vector<Material>::iterator currentSearchIt = materials.begin();
std::vector<Material>::iterator materialIt;
Expand Down Expand Up @@ -1507,6 +1514,16 @@ void MaterialSystem::AddAllWorldSurfaces() {
generatingWorldCommandBuffer = false;
}

void MaterialSystem::GLSLRestart() {
for ( MaterialPack& materialPack : materialPacks ) {
for ( Material& material : materialPack.materials ) {
/* We only really need to reset material.shader here,
but we keep a copy of the original shaderStage_t and drawSurf_t used for it so we don't change the actual material data */
material.refStage->materialProcessor( &material, material.refStage, &material.refDrawSurf );
}
}
}

void MaterialSystem::AddStageTextures( drawSurf_t* drawSurf, const uint32_t stage, Material* material ) {
TextureData textureData;
const shaderStage_t* pStage = &drawSurf->shader->stages[stage];
Expand Down
6 changes: 6 additions & 0 deletions src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ struct Material {
GLuint program = 0;
GLShader* shader;

// Used only for glsl_restart
shaderStage_t* refStage;
drawSurf_t refDrawSurf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "ref" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refDrawSurf isn't a reference though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, as in "reference to the values used for this material". Might not be a good name for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like original[DrawSurf/Stage] might be better.


int deformIndex;
bool tcGenEnvironment;
bool tcGen_Lightmap;
Expand Down Expand Up @@ -369,6 +373,8 @@ class MaterialSystem {

void AddAllWorldSurfaces();

void GLSLRestart();

void Free();

private:
Expand Down
6 changes: 6 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,12 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
stage->deformIndex = deformIndex;
}
}

if ( glConfig2.usingMaterialSystem ) {
/* GLSL shaders linked to materials will be invalidated by glsl_restart,
so we need to reset them here */
materialSystem.GLSLRestart();
}
}
};
static GlslRestartCmd glslRestartCmdRegistration;
Expand Down