Skip to content

Commit

Permalink
Fix glsl_restart with material system
Browse files Browse the repository at this point in the history
  • Loading branch information
VReaperV committed Jan 27, 2025
1 parent efe9430 commit aea7820
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
36 changes: 36 additions & 0 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,42 @@ void MaterialSystem::GeneratePortalBoundingSpheres() {
portalSurfacesTmp.clear();
}

void MaterialSystem::InitGLBuffers() {
materialsUBO.GenBuffer();
texDataBuffer.GenBuffer();
lightMapDataUBO.GenBuffer();

surfaceDescriptorsSSBO.GenBuffer();
surfaceCommandsSSBO.GenBuffer();
culledCommandsBuffer.GenBuffer();
surfaceBatchesUBO.GenBuffer();
atomicCommandCountersBuffer.GenBuffer();

portalSurfacesSSBO.GenBuffer();

if ( r_materialDebug.Get() ) {
debugSSBO.GenBuffer();
}
}

void MaterialSystem::FreeGLBuffers() {
materialsUBO.DelBuffer();
texDataBuffer.DelBuffer();
lightMapDataUBO.DelBuffer();

surfaceDescriptorsSSBO.DelBuffer();
surfaceCommandsSSBO.DelBuffer();
culledCommandsBuffer.DelBuffer();
surfaceBatchesUBO.DelBuffer();
atomicCommandCountersBuffer.DelBuffer();

portalSurfacesSSBO.DelBuffer();

if ( r_materialDebug.Get() ) {
debugSSBO.DelBuffer();
}
}

void MaterialSystem::Free() {
generatedWorldCommandBuffer = false;

Expand Down
3 changes: 3 additions & 0 deletions src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ class MaterialSystem {

void GenerateDepthImages( const int width, const int height, imageParams_t imageParms );

void InitGLBuffers();
void FreeGLBuffers();

void AddStageTextures( drawSurf_t* drawSurf, const uint32_t stage, Material* material );
void AddStage( drawSurf_t* drawSurf, shaderStage_t* pStage, uint32_t stage,
const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright );
Expand Down
13 changes: 13 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,19 @@ 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 regenerate all the material stuff here */
const uint8_t maxStages = materialSystem.maxStages;
materialSystem.Free();
materialSystem.FreeGLBuffers();

materialSystem.InitGLBuffers();
materialSystem.maxStages = maxStages;

materialSystem.GenerateWorldMaterials();
}
}
};
static GlslRestartCmd glslRestartCmdRegistration;
Expand Down
41 changes: 4 additions & 37 deletions src/engine/renderer/tr_vbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,27 +726,6 @@ static void R_InitLightUBO()
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
}
}

static void R_InitMaterialBuffers() {
if( glConfig2.usingMaterialSystem ) {
materialsUBO.GenBuffer();
texDataBuffer.GenBuffer();
lightMapDataUBO.GenBuffer();

surfaceDescriptorsSSBO.GenBuffer();
surfaceCommandsSSBO.GenBuffer();
culledCommandsBuffer.GenBuffer();
surfaceBatchesUBO.GenBuffer();
atomicCommandCountersBuffer.GenBuffer();

portalSurfacesSSBO.GenBuffer();

if ( r_materialDebug.Get() ) {
debugSSBO.GenBuffer();
}
}
}

/*
============
R_InitVBOs
Expand Down Expand Up @@ -790,7 +769,9 @@ void R_InitVBOs()

R_InitLightUBO();

R_InitMaterialBuffers();
if ( glConfig2.usingMaterialSystem ) {
materialSystem.InitGLBuffers();
}

GL_CheckErrors();
}
Expand Down Expand Up @@ -861,21 +842,7 @@ void R_ShutdownVBOs()
}

if ( glConfig2.usingMaterialSystem ) {
materialsUBO.DelBuffer();
texDataBuffer.DelBuffer();
lightMapDataUBO.DelBuffer();

surfaceDescriptorsSSBO.DelBuffer();
surfaceCommandsSSBO.DelBuffer();
culledCommandsBuffer.DelBuffer();
surfaceBatchesUBO.DelBuffer();
atomicCommandCountersBuffer.DelBuffer();

portalSurfacesSSBO.DelBuffer();

if ( r_materialDebug.Get() ) {
debugSSBO.DelBuffer();
}
materialSystem.FreeGLBuffers();
}

tess.verts = tess.vertsBuffer = nullptr;
Expand Down

0 comments on commit aea7820

Please sign in to comment.