Skip to content

Commit

Permalink
ref: gl: fix broken water texture when it was discarded by R_UploadRi…
Browse files Browse the repository at this point in the history
…pples
  • Loading branch information
a1batross committed Dec 26, 2024
1 parent 9811988 commit c6e3146
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ref/gl/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ void R_ClearSkyBox( void );
void R_DrawSkyBox( void );
void R_DrawClouds( void );
void R_UnloadSkybox( void );
void EmitWaterPolys( msurface_t *warp, qboolean reverse );
void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples );
void R_InitRipples( void );
void R_ResetRipples( void );
void R_AnimateRipples( void );
void R_UploadRipples( texture_t *image );
qboolean R_UploadRipples( const texture_t *image );

//#include "vid_common.h"

Expand Down
9 changes: 2 additions & 7 deletions ref/gl/gl_rsurf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,8 @@ static void R_RenderBrushPoly( msurface_t *fa, int cull_type )

if( FBitSet( fa->flags, SURF_DRAWTURB ))
{
R_UploadRipples( t );

// warp texture, no lightmaps
EmitWaterPolys( fa, (cull_type == CULL_BACKSIDE));
EmitWaterPolys( fa, cull_type == CULL_BACKSIDE, R_UploadRipples( t ));
return;
}
else GL_Bind( XASH_TEXTURE0, t->gl_texturenum );
Expand Down Expand Up @@ -1500,11 +1498,8 @@ void R_DrawWaterSurfaces( void )
if( !FBitSet( s->flags, SURF_DRAWTURB ))
continue;

// set modulate mode explicitly
R_UploadRipples( t );

for( ; s; s = s->texturechain )
EmitWaterPolys( s, false );
EmitWaterPolys( s, false, R_UploadRipples( t ));

t->texturechain = NULL;
}
Expand Down
14 changes: 8 additions & 6 deletions ref/gl/gl_warp.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ EmitWaterPolys
Does a water warp on the pre-fragmented glpoly_t chain
=============
*/
void EmitWaterPolys( msurface_t *warp, qboolean reverse )
void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples )
{
float *v, nv, waveHeight;
float s, t, os, ot;
Expand Down Expand Up @@ -609,7 +609,7 @@ void EmitWaterPolys( msurface_t *warp, qboolean reverse )
os = v[3];
ot = v[4];

if( !r_ripple.value )
if( !ripples )
{
s = os + r_turbsin[(int)((ot * 0.125f + gp_cl->time) * TURBSCALE) & 255];
t = ot + r_turbsin[(int)((os * 0.125f + gp_cl->time) * TURBSCALE) & 255];
Expand Down Expand Up @@ -750,7 +750,7 @@ void R_AnimateRipples( void )
R_RunRipplesAnimation( g_ripple.oldbuf, g_ripple.curbuf );
}

void R_UploadRipples( texture_t *image )
qboolean R_UploadRipples( const texture_t *image )
{
gl_texture_t *glt;
uint32_t *pixels;
Expand All @@ -761,21 +761,21 @@ void R_UploadRipples( texture_t *image )
if( !r_ripple.value || image->width > RIPPLES_CACHEWIDTH || image->width != image->height )
{
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
return;
return false;
}

glt = R_GetTexture( image->gl_texturenum );
if( !glt || !glt->original || !glt->original->buffer || !FBitSet( glt->flags, TF_EXPAND_SOURCE ))
{
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
return;
return false;
}

GL_Bind( XASH_TEXTURE0, g_ripple.rippletexturenum );

// no updates this frame
if( !g_ripple.update && image->gl_texturenum == g_ripple.gl_texturenum )
return;
return true;

g_ripple.gl_texturenum = image->gl_texturenum;
if( r_ripple.value == 1.0f )
Expand Down Expand Up @@ -813,4 +813,6 @@ void R_UploadRipples( texture_t *image )

pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->width, 0,
GL_RGBA, GL_UNSIGNED_BYTE, g_ripple.texture );

return true;
}

0 comments on commit c6e3146

Please sign in to comment.