From a0c31120d9e0fdd4a2008fb03bf7397dad4c26c2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 6 Jan 2024 18:38:53 +0300 Subject: [PATCH] ref: add R_GammaChanged function that engine calls on every gamma change --- engine/ref_api.h | 1 + ref/gl/gl_context.c | 1 + ref/gl/gl_local.h | 2 +- ref/gl/gl_rmain.c | 16 ++++++++++++++++ ref/soft/r_context.c | 1 + ref/soft/r_local.h | 1 + ref/soft/r_main.c | 8 ++++++++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/ref_api.h b/engine/ref_api.h index 11c78a02..fbbefda6 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -463,6 +463,7 @@ typedef struct ref_interface_s void (*GL_ClearExtensions)( void ); // scene rendering + void (*R_GammaChanged)( qboolean do_reset_gamma ); void (*R_BeginFrame)( qboolean clearScene ); void (*R_RenderScene)( void ); void (*R_EndFrame)( void ); diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index dd665d90..db05733d 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -372,6 +372,7 @@ ref_interface_t gReffuncs = GL_InitExtensions, GL_ClearExtensions, + R_GammaChanged, R_BeginFrame, R_RenderScene, R_EndFrame, diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index d91044f2..0446a442 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -402,7 +402,6 @@ void R_AllowFog( qboolean allowed ); qboolean R_OpaqueEntity( cl_entity_t *ent ); void R_SetupFrustum( void ); void R_FindViewLeaf( void ); -void R_CheckGamma( void ); void R_PushScene( void ); void R_PopScene( void ); void R_DrawFog( void ); @@ -534,6 +533,7 @@ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ); void GL_FreeImage( const char *name ); qboolean VID_ScreenShot( const char *filename, int shot_type ); qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot ); +void R_GammaChanged( qboolean do_reset_gamma ); void R_BeginFrame( qboolean clearScene ); void R_RenderFrame( const struct ref_viewpass_s *vp ); void R_EndFrame( void ); diff --git a/ref/gl/gl_rmain.c b/ref/gl/gl_rmain.c index fc64695d..2a35a94f 100644 --- a/ref/gl/gl_rmain.c +++ b/ref/gl/gl_rmain.c @@ -985,6 +985,22 @@ void R_RenderScene( void ) R_EndGL(); } +void R_GammaChanged( qboolean do_reset_gamma ) +{ + if( do_reset_gamma ) + { + // paranoia cubemap rendering + if( gEngfuncs.drawFuncs->GL_BuildLightmaps ) + gEngfuncs.drawFuncs->GL_BuildLightmaps( ); + } + else + { + glConfig.softwareGammaUpdate = true; + GL_RebuildLightmaps(); + glConfig.softwareGammaUpdate = false; + } +} + /* =============== R_BeginFrame diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index cac75f82..ecf3db2b 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -418,6 +418,7 @@ ref_interface_t gReffuncs = GL_InitExtensions, GL_ClearExtensions, + R_GammaChanged, R_BeginFrame, R_RenderScene, R_EndFrame, diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index a9a918ce..1f2a1d5f 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -607,6 +607,7 @@ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ); void GL_FreeImage( const char *name ); qboolean VID_ScreenShot( const char *filename, int shot_type ); qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot ); +void R_GammaChanged( qboolean do_reset_gamma ); void R_BeginFrame( qboolean clearScene ); void R_RenderFrame( const struct ref_viewpass_s *vp ); void R_EndFrame( void ); diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index fb9d3f90..2304b4cf 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -1636,6 +1636,14 @@ qboolean R_DoResetGamma( void ) #endif } +void R_GammaChanged( qboolean do_reset_gamma ) +{ + if( do_reset_gamma ) // unused + return; + + D_FlushCaches( ); +} + /* =============== R_BeginFrame