move palshader code out of HWR_DrawScreenFinalTexture

and make the whole handling safer so we have less chance of ending up with blackscreens should the palette render shader fail
This commit is contained in:
alufolie91 committed 2026-05-01 03:49:55 +02:00
1 parent 2b9d9b2fdd
commit 1cc94f379d
5 files changed
+34 -29

No files matched your search

+2 -1
View File
@@ -63,7 +63,7 @@ void GL_FlushScreenTextures(void);
void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags);
void GL_DoScreenWipe(int wipeStart, int wipeEnd);
void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize);
void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean useshader);
void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height);
void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]);
@@ -72,6 +72,7 @@ void GL_LoadShader(int slot, char *code, hwdshaderstage_t stage);
boolean GL_CompileShader(int slot);
void GL_SetShader(int slot);
void GL_UnSetShader(void);
void GL_EnableShader(void);
void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value);
+2 -2
View File
@@ -161,9 +161,9 @@ FUNCINLINE static ATTRINLINE void HWR_MakeScreenFinalTexture(void)
GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC2);
}
FUNCINLINE static ATTRINLINE void HWR_DrawScreenFinalTexture(INT32 width, INT32 height, boolean useshader)
FUNCINLINE static ATTRINLINE void HWR_DrawScreenFinalTexture(INT32 width, INT32 height)
{
GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height, useshader);
GL_DrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height);
}
// hw_main.c: Segs
+8 -19
View File
@@ -151,7 +151,6 @@ typedef struct
static fboobj_t framebufferobject = {};
int supportFBO = FBO_NONE;
boolean fbo_shader = false;
// older gl versions might not have these, so prevent compile errors
// this should still give a simple depth only rbo
@@ -1072,6 +1071,13 @@ void GL_SetShader(int slot)
gl_shadersenabled = false;
}
void GL_EnableShader(void)
{
// we can just use GL_Shader_SetUniforms as itll enable the shader for us
// and handle any failures
GL_Shader_SetUniforms(NULL, NULL, NULL, NULL);
}
void GL_UnSetShader(void)
{
if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed
@@ -3355,8 +3361,6 @@ void GL_Framebuffer_Disable(void)
if (!supportFBO || !framebufferobject.init)
return;
fbo_shader = false;
pglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
pglBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
@@ -3742,7 +3746,7 @@ void GL_MakeScreenTexture(int tex)
tex_downloaded = screenTextures[tex];
}
void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean useshader)
void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height)
{
float xfix, yfix;
float origaspect, newaspect;
@@ -3795,18 +3799,6 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh
pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]);
if (useshader)
{
// godawful but you can only ever run ONE shader per renderpass and since i dont want to draw an extra screen texture when you downsample from higher resolution
// so i combined the palette postprocess with this crap
#ifdef USE_FBO_OGL
if (fbo_shader)
pglUseProgram(gl_shaders[SHADER_DOWNSAMPLE].program);
else
#endif
pglUseProgram(gl_shaders[SHADER_PALETTE_POSTPROCESS].program); // Final postprocess step of palette rendering, after everything else has been drawn.
}
pglColor4ubv(white);
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
@@ -3814,9 +3806,6 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
if (useshader)
pglUseProgram(0);
tex_downloaded = screenTextures[tex];
}
-1
View File
@@ -102,7 +102,6 @@ void GL_Framebuffer_Unbind(void);
void GL_Framebuffer_Enable(void);
void GL_Framebuffer_Disable(void);
extern int supportFBO;
extern boolean fbo_shader;
#endif
// ==========================================================================
+22 -6
View File
@@ -233,6 +233,7 @@ void OglSdlFinishUpdate(SDL_Window *window)
#ifdef USE_FBO_OGL
const boolean usefbo = UseScreenFBO();
boolean fboshader = (usefbo && !WipeInAction && HWR_UseShader());
#endif
SDL_GetWindowSize(window, &sdlw, &sdlh);
@@ -242,17 +243,32 @@ void OglSdlFinishUpdate(SDL_Window *window)
if (usefbo)
{
GL_Framebuffer_Unbind();
fbo_shader = (HWR_UseShader() && !WipeInAction); // this looks awful with wipes
}
else
fbo_shader = false;
#endif
#ifdef USE_FBO_OGL
HWR_DrawScreenFinalTexture(sdlw, sdlh, (HWR_ShouldUsePaletteRendering() || fbo_shader));
if (HWR_ShouldUsePaletteRendering() || fboshader)
#else
HWR_DrawScreenFinalTexture(sdlw, sdlh, HWR_ShouldUsePaletteRendering());
if (HWR_ShouldUsePaletteRendering())
#endif
{
// godawful but you can only ever run ONE shader per renderpass and since i dont want to draw an extra screen texture when you downsample from higher resolution
// so i combined the palette postprocess with this crap
#ifdef USE_FBO_OGL
if (fboshader) // this looks awful with wipes
GL_SetShader(HWR_GetShaderFromTarget(SHADER_DOWNSAMPLE));
else
#endif
GL_SetShader(HWR_GetShaderFromTarget(SHADER_PALETTE_POSTPROCESS)); // Final postprocess step of palette rendering, after everything else has been drawn.
GL_EnableShader();
HWR_DrawScreenFinalTexture(sdlw, sdlh);
GL_UnSetShader();
}
else
{
HWR_DrawScreenFinalTexture(sdlw, sdlh);
}
#ifdef USE_FBO_OGL
if (usefbo)
@@ -273,7 +289,7 @@ void OglSdlFinishUpdate(SDL_Window *window)
#else
if (!I_CheckNativeRes() || WipeInAction)
#endif
HWR_DrawScreenFinalTexture(realwidth, realheight, false);
HWR_DrawScreenFinalTexture(realwidth, realheight);
}
#endif //HWRENDER