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 17, 2025
1 parent b8531e7 commit 835153f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
36 changes: 36 additions & 0 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,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 @@ -341,6 +341,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 );
void ProcessStage( drawSurf_t* drawSurf, shaderStage_t* pStage, shader_t* shader, uint32_t* packIDs, uint32_t& stage,
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 @@ -1103,6 +1103,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();
}
}

/*
Expand Down
40 changes: 4 additions & 36 deletions src/engine/renderer/tr_vbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,26 +727,6 @@ static void R_InitLightUBO()
}
}

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 +770,9 @@ void R_InitVBOs()

R_InitLightUBO();

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

GL_CheckErrors();
}
Expand Down Expand Up @@ -861,21 +843,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 835153f

Please sign in to comment.