From c6e314629094bcafa24d2cfac457a6a0d1dce58e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 26 Dec 2024 03:49:12 +0300 Subject: [PATCH] ref: gl: fix broken water texture when it was discarded by R_UploadRipples --- ref/gl/gl_local.h | 4 ++-- ref/gl/gl_rsurf.c | 9 ++------- ref/gl/gl_warp.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index 292054eab0..a078573eb1 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -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" diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index 6d92ed5659..5d27e55a99 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -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 ); @@ -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; } diff --git a/ref/gl/gl_warp.c b/ref/gl/gl_warp.c index 079eae1381..cd82268cdb 100644 --- a/ref/gl/gl_warp.c +++ b/ref/gl/gl_warp.c @@ -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; @@ -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]; @@ -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; @@ -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 ) @@ -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; }