[gl,glsl] Copy fog color rather than return pointer

The static variable meant that Fog_GetColor was not thread-safe (though
multiple calls in the one thread look to be ok for now). However, this
change takes it one step closer to being more generally usable.

Patch found in an old stash.
This commit is contained in:
Bill Currie 2020-12-24 16:39:05 +09:00
parent fefb32bf13
commit 9db80259d1
8 changed files with 41 additions and 41 deletions

View file

@ -31,7 +31,7 @@ void Fog_Update (float density, float red, float green, float blue,
struct plitem_s;
void Fog_ParseWorldspawn (struct plitem_s *worldspawn);
float *Fog_GetColor (void);
void Fog_GetColor (quat_t fogcolor);
float Fog_GetDensity (void) __attribute__((pure));
void Fog_SetupFrame (void);
void Fog_EnableGFog (void);

View file

@ -189,32 +189,29 @@ gl_Fog_ParseWorldspawn (plitem_t *worldspawn)
calculates fog color for this frame, taking into account fade times
*/
float *
gl_Fog_GetColor (void)
void
gl_Fog_GetColor (quat_t fogcolor)
{
static float c[4];
float f;
int i;
if (fade_done > vr_data.realtime) {
f = (fade_done - vr_data.realtime) / fade_time;
c[0] = f * old_red + (1.0 - f) * fog_red;
c[1] = f * old_green + (1.0 - f) * fog_green;
c[2] = f * old_blue + (1.0 - f) * fog_blue;
c[3] = 1.0;
fogcolor[0] = f * old_red + (1.0 - f) * fog_red;
fogcolor[1] = f * old_green + (1.0 - f) * fog_green;
fogcolor[2] = f * old_blue + (1.0 - f) * fog_blue;
fogcolor[3] = 1.0;
} else {
c[0] = fog_red;
c[1] = fog_green;
c[2] = fog_blue;
c[3] = 1.0;
fogcolor[0] = fog_red;
fogcolor[1] = fog_green;
fogcolor[2] = fog_blue;
fogcolor[3] = 1.0;
}
//find closest 24-bit RGB value, so solid-colored sky can match the fog
//perfectly
for (i = 0; i < 3; i++)
c[i] = (float) (rint (c[i] * 255)) / 255.0f;
return c;
fogcolor[i] = (float) (rint (fogcolor[i] * 255)) / 255.0f;
}
/*
@ -243,7 +240,10 @@ gl_Fog_GetDensity (void)
void
gl_Fog_SetupFrame (void)
{
qfglFogfv (GL_FOG_COLOR, gl_Fog_GetColor ());
quat_t fogcolor;
gl_Fog_GetColor (fogcolor);
qfglFogfv (GL_FOG_COLOR, fogcolor);
qfglFogf (GL_FOG_DENSITY, gl_Fog_GetDensity () / 64.0);
}
@ -294,8 +294,11 @@ gl_Fog_StartAdditive (void)
void
gl_Fog_StopAdditive (void)
{
if (gl_Fog_GetDensity () > 0)
qfglFogfv (GL_FOG_COLOR, gl_Fog_GetColor ());
if (gl_Fog_GetDensity () > 0) {
quat_t fogcolor;
gl_Fog_GetColor (fogcolor);
qfglFogfv (GL_FOG_COLOR, fogcolor);
}
}
//==============================================================================

View file

@ -333,7 +333,7 @@ glsl_R_AliasBegin (void)
qfeglDisableVertexAttribArray (quake_mdl.colora.location);
qfeglDisableVertexAttribArray (quake_mdl.colorb.location);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_mdl.fog.location, 1, fog);

View file

@ -360,7 +360,7 @@ static void
update_lightmap (msurface_t *surf)
{
int maps;
return;
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
if (d_lightstylevalue[surf->styles[maps]] != surf->cached_light[maps])
goto dynamic;
@ -871,7 +871,7 @@ bsp_begin (void)
qfeglVertexAttrib4fv (quake_bsp.color.location, default_color);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_bsp.fog.location, 1, fog);
@ -926,7 +926,7 @@ turb_begin (void)
qfeglVertexAttrib4fv (quake_turb.color.location, default_color);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_turb.fog.location, 1, fog);
@ -1030,7 +1030,7 @@ sky_begin (void)
qfeglEnable (GL_TEXTURE_2D);
}
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (sky_params.fog->location, 1, fog);

View file

@ -189,32 +189,29 @@ glsl_Fog_ParseWorldspawn (plitem_t *worldspawn)
calculates fog color for this frame, taking into account fade times
*/
float *
glsl_Fog_GetColor (void)
void
glsl_Fog_GetColor (quat_t fogcolor)
{
static float c[4];
float f;
int i;
if (fade_done > vr_data.realtime) {
f = (fade_done - vr_data.realtime) / fade_time;
c[0] = f * old_red + (1.0 - f) * fog_red;
c[1] = f * old_green + (1.0 - f) * fog_green;
c[2] = f * old_blue + (1.0 - f) * fog_blue;
c[3] = 1.0;
fogcolor[0] = f * old_red + (1.0 - f) * fog_red;
fogcolor[1] = f * old_green + (1.0 - f) * fog_green;
fogcolor[2] = f * old_blue + (1.0 - f) * fog_blue;
fogcolor[3] = 1.0;
} else {
c[0] = fog_red;
c[1] = fog_green;
c[2] = fog_blue;
c[3] = 1.0;
fogcolor[0] = fog_red;
fogcolor[1] = fog_green;
fogcolor[2] = fog_blue;
fogcolor[3] = 1.0;
}
//find closest 24-bit RGB value, so solid-colored sky can match the fog
//perfectly
for (i = 0; i < 3; i++)
c[i] = (float) (rint (c[i] * 255)) / 255.0f;
return c;
fogcolor[i] = (float) (rint (fogcolor[i] * 255)) / 255.0f;
}
/*

View file

@ -278,7 +278,7 @@ glsl_R_IQMBegin (void)
qfeglUseProgram (iqm_shader.program);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (iqm_shader.fog.location, 1, fog);

View file

@ -1579,7 +1579,7 @@ draw_qf_particles (void)
qfeglEnableVertexAttribArray (quake_part.color.location);
qfeglEnableVertexAttribArray (quake_part.st.location);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_part.fog.location, 1, fog);
@ -1725,7 +1725,7 @@ draw_id_particles (void)
qfeglUniformMatrix4fv (quake_point.mvp_matrix.location, 1, false, vp_mat);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_point.fog.location, 1, fog);

View file

@ -335,7 +335,7 @@ R_SpriteBegin (void)
qfeglDisableVertexAttribArray (quake_sprite.colorb.location);
qfeglDisableVertexAttribArray (quake_sprite.blend.location);
VectorCopy (glsl_Fog_GetColor (), fog);
glsl_Fog_GetColor (fog);
fog[3] = glsl_Fog_GetDensity () / 64.0;
qfeglUniform4fv (quake_sprite.fog.location, 1, fog);