From 5be982cc7232d02b8a6802d78882556cbc8e7c41 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 15 Apr 2019 01:43:43 +0300 Subject: [PATCH] ref: remove shared textures enum, instead use hardcoded texture names --- engine/client/cl_game.c | 2 +- engine/client/cl_gameui.c | 2 +- engine/client/console.c | 4 ++-- engine/client/ref_common.h | 5 +++-- engine/common/mod_bmodel.c | 12 +++++------ engine/ref_api.h | 17 +++++++--------- ref_gl/gl_context.c | 41 -------------------------------------- ref_gl/gl_image.c | 8 ++++---- ref_gl/gl_warp.c | 4 ++-- 9 files changed, 26 insertions(+), 69 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index fc158583..8869b605 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -633,7 +633,7 @@ void CL_DrawScreenFade( void ) ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); else ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( 0, 0, refState.width, refState.height, 0, 0, 1, 1, - ref.dllFuncs.R_GetBuiltinTexture( REF_WHITE_TEXTURE )); + R_GetBuiltinTexture( REF_WHITE_TEXTURE )); ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index aee9a893..67d5c541 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -555,7 +555,7 @@ static void pfnFillRGBA( int x, int y, int width, int height, int r, int g, int a = bound( 0, a, 255 ); ref.dllFuncs.Color4ub( r, g, b, a ); ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); - ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, ref.dllFuncs.R_GetBuiltinTexture( REF_WHITE_TEXTURE ) ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, R_GetBuiltinTexture( REF_WHITE_TEXTURE ) ); ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } diff --git a/engine/client/console.c b/engine/client/console.c index 7420d23e..700dc1fd 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -2387,8 +2387,8 @@ void Con_VidInit( void ) } // missed console image will be replaced as gray background like X-Ray or Crysis - if( con.background == ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ) || con.background == 0 ) - con.background = ref.dllFuncs.R_GetBuiltinTexture( REF_GRAY_TEXTURE ); + if( con.background == R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ) || con.background == 0 ) + con.background = R_GetBuiltinTexture( REF_GRAY_TEXTURE ); } /* diff --git a/engine/client/ref_common.h b/engine/client/ref_common.h index d5f63d2a..2b5f6e88 100644 --- a/engine/client/ref_common.h +++ b/engine/client/ref_common.h @@ -34,8 +34,9 @@ extern ref_globals_t refState; // handy API wrappers void R_GetTextureParms( int *w, int *h, int texnum ); #define REF_GET_PARM( parm, arg ) ref.dllFuncs.RefGetParm( (parm), (arg) ) -#define GL_LoadTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( name, pic, flags, false ) -#define GL_UpdateTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( name, pic, flags, true ) +#define GL_LoadTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( (name), (pic), (flags), false ) +#define GL_UpdateTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( (name), (pic), (flags), true ) +#define R_GetBuiltinTexture( name ) ref.dllFuncs.GL_LoadTexture( (name), 0, 0, 0 ) int GL_RenderFrame( const struct ref_viewpass_s *rvp ); diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index af76a3d2..0994a8d4 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1803,8 +1803,8 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) // release old sky layers first if( !Host_IsDedicated() ) { - ref.dllFuncs.R_FreeSharedTexture( REF_ALPHASKY_TEXTURE ); - ref.dllFuncs.R_FreeSharedTexture( REF_SOLIDSKY_TEXTURE ); + ref.dllFuncs.GL_FreeTexture( R_GetBuiltinTexture( REF_ALPHASKY_TEXTURE )); + ref.dllFuncs.GL_FreeTexture( R_GetBuiltinTexture( REF_SOLIDSKY_TEXTURE )); } #endif } @@ -1832,7 +1832,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) #ifndef XASH_DEDICATED if( !Host_IsDedicated() ) { - tx->gl_texturenum = ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); + tx->gl_texturenum = R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); tx->width = tx->height = 16; } #endif @@ -1882,8 +1882,8 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) { ref.dllFuncs.R_InitSkyClouds( mt, tx, custom_palette ); // load quake sky - if( ref.dllFuncs.R_GetBuiltinTexture( REF_SOLIDSKY_TEXTURE ) && - ref.dllFuncs.R_GetBuiltinTexture( REF_ALPHASKY_TEXTURE ) ) + if( R_GetBuiltinTexture( REF_SOLIDSKY_TEXTURE ) && + R_GetBuiltinTexture( REF_ALPHASKY_TEXTURE ) ) SetBits( world.flags, FWORLD_SKYSPHERE ); continue; } @@ -1928,7 +1928,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) { if( host.type != HOST_DEDICATED ) Con_DPrintf( S_ERROR "unable to find %s.mip\n", mt->name ); - tx->gl_texturenum = ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); + tx->gl_texturenum = R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); } // check for luma texture diff --git a/engine/ref_api.h b/engine/ref_api.h index e3f13e20..83247361 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -124,14 +124,13 @@ enum // r_speeds counters RS_ACTIVE_TENTS = 0, }; -enum ref_shared_texture_e -{ - REF_DEFAULT_TEXTURE, - REF_GRAY_TEXTURE, - REF_WHITE_TEXTURE, - REF_SOLIDSKY_TEXTURE, - REF_ALPHASKY_TEXTURE, -}; +// refdll must expose this default textures using this names +#define REF_DEFAULT_TEXTURE "*default" +#define REF_GRAY_TEXTURE "*gray" +#define REF_WHITE_TEXTURE "*white" +#define REF_BLACK_TEXTURE "*black" +#define REF_SOLIDSKY_TEXTURE "solid_sky" +#define REF_ALPHASKY_TEXTURE "alpha_sky" typedef enum connstate_e { @@ -472,8 +471,6 @@ typedef struct ref_interface_s // texture management const byte *(*R_GetTextureOriginalBuffer)( unsigned int idx ); // not always available int (*GL_LoadTextureFromBuffer)( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update ); - int (*R_GetBuiltinTexture)( enum ref_shared_texture_e type ); - void (*R_FreeSharedTexture)( enum ref_shared_texture_e type ); void (*GL_ProcessTexture)( int texnum, float gamma, int topColor, int bottomColor ); void (*R_SetupSky)( const char *skyname ); diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index 99de63a0..4710df89 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -47,45 +47,6 @@ static const byte *R_GetTextureOriginalBuffer( unsigned int idx ) return glt->original->buffer; } -static int R_GetBuiltinTexture( enum ref_shared_texture_e type ) -{ - switch( type ) - { - case REF_DEFAULT_TEXTURE: return tr.defaultTexture; - case REF_GRAY_TEXTURE: return tr.grayTexture; - case REF_WHITE_TEXTURE: return tr.whiteTexture; - case REF_SOLIDSKY_TEXTURE: return tr.solidskyTexture; - case REF_ALPHASKY_TEXTURE: return tr.alphaskyTexture; - default: gEngfuncs.Host_Error( "R_GetBuiltinTexture: unsupported type %d\n", type ); - } - - return 0; -} - -static void R_FreeSharedTexture( enum ref_shared_texture_e type ) -{ - int num = 0; - - switch( type ) - { - case REF_SOLIDSKY_TEXTURE: - num = tr.solidskyTexture; - tr.solidskyTexture = 0; - break; - case REF_ALPHASKY_TEXTURE: - num = tr.alphaskyTexture; - tr.alphaskyTexture = 0; - break; - case REF_DEFAULT_TEXTURE: - case REF_GRAY_TEXTURE: - case REF_WHITE_TEXTURE: - gEngfuncs.Host_Error( "R_FreeSharedTexture: invalid type %d\n", type ); - default: gEngfuncs.Host_Error( "R_FreeSharedTexture: unsupported type %d\n", type ); - } - - GL_FreeTexture( num ); -} - /* ============= CL_FillRGBA @@ -413,8 +374,6 @@ ref_interface_t gReffuncs = R_GetTextureOriginalBuffer, GL_LoadTextureFromBuffer, - R_GetBuiltinTexture, - R_FreeSharedTexture, GL_ProcessTexture, R_SetupSky, diff --git a/ref_gl/gl_image.c b/ref_gl/gl_image.c index 3e808881..3fcba776 100644 --- a/ref_gl/gl_image.c +++ b/ref_gl/gl_image.c @@ -1910,7 +1910,7 @@ static void GL_CreateInternalTextures( void ) } } - tr.defaultTexture = GL_LoadTextureInternal( "*default", pic, TF_COLORMAP ); + tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP ); // particle texture from quake1 pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA ); @@ -1934,19 +1934,19 @@ static void GL_CreateInternalTextures( void ) pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) ((uint *)pic->buffer)[x] = 0xFFFFFFFF; - tr.whiteTexture = GL_LoadTextureInternal( "*white", pic, TF_COLORMAP ); + tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP ); // gray texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) ((uint *)pic->buffer)[x] = 0xFF7F7F7F; - tr.grayTexture = GL_LoadTextureInternal( "*gray", pic, TF_COLORMAP ); + tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP ); // black texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); for( x = 0; x < 16; x++ ) ((uint *)pic->buffer)[x] = 0xFF000000; - tr.blackTexture = GL_LoadTextureInternal( "*black", pic, TF_COLORMAP ); + tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP ); // cinematic dummy pic = GL_FakeImage( 640, 100, 1, IMAGE_HAS_COLOR ); diff --git a/ref_gl/gl_warp.c b/ref_gl/gl_warp.c index 4399f3b5..fafcf95f 100644 --- a/ref_gl/gl_warp.c +++ b/ref_gl/gl_warp.c @@ -716,7 +716,7 @@ void R_InitSkyClouds( mip_t *mt, texture_t *tx, qboolean custom_palette ) r_temp.palette = NULL; // load it in - tr.solidskyTexture = GL_LoadTextureInternal( "solid_sky", &r_temp, TF_NOMIPMAP ); + tr.solidskyTexture = GL_LoadTextureInternal( REF_SOLIDSKY_TEXTURE, &r_temp, TF_NOMIPMAP ); for( i = 0; i < r_sky->width >> 1; i++ ) { @@ -739,7 +739,7 @@ void R_InitSkyClouds( mip_t *mt, texture_t *tx, qboolean custom_palette ) r_temp.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA; // load it in - tr.alphaskyTexture = GL_LoadTextureInternal( "alpha_sky", &r_temp, TF_NOMIPMAP ); + tr.alphaskyTexture = GL_LoadTextureInternal( REF_ALPHASKY_TEXTURE, &r_temp, TF_NOMIPMAP ); // clean up gEngfuncs.FS_FreeImage( r_sky );