From 7e081046310cf8afad3dae924e2b40123f063c06 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 20 Mar 2019 01:20:58 +0300 Subject: [PATCH] ref_gl: fixes for MSVC --- ref_gl/gl_context.c | 76 ++++++++++++++++++++++----------------------- ref_gl/gl_local.h | 2 ++ ref_gl/gl_sprite.c | 22 ++++++------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index cc2a1164..ee00a1c7 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -164,6 +164,43 @@ static void Mod_LoadModel( modtype_t desiredType, model_t *mod, const byte *buf, } } +void Mod_BrushUnloadTextures( model_t *mod ) +{ + int i; + + for( i = 0; i < mod->numtextures; i++ ) + { + texture_t *tx = mod->textures[i]; + if( !tx || tx->gl_texturenum == tr.defaultTexture ) + continue; // free slot + + GL_FreeTexture( tx->gl_texturenum ); // main texture + GL_FreeTexture( tx->fb_texturenum ); // luma texture + } +} + +void Mod_UnloadTextures( model_t *mod ) +{ + Assert( mod != NULL ); + + switch( mod->type ) + { + case mod_studio: + Mod_StudioUnloadTextures( mod->cache.data ); + break; + case mod_alias: + Mod_AliasUnloadTextures( mod->cache.data ); + break; + case mod_brush: + Mod_BrushUnloadTextures( mod ); + break; + case mod_sprite: + Mod_SpriteUnloadTextures( mod->cache.data ); + break; + default: gEngfuncs.Host_Error( "Mod_UnloadModel: unsupported type %d\n", mod->type ); + } +} + qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf ) { qboolean loaded = true; @@ -336,45 +373,6 @@ const byte *GL_TextureData( unsigned int texnum ) return NULL; } -void Mod_BrushUnloadTextures( model_t *mod ) -{ - int i; - - for( i = 0; i < mod->numtextures; i++ ) - { - texture_t *tx = mod->textures[i]; - if( !tx || tx->gl_texturenum == tr.defaultTexture ) - continue; // free slot - - GL_FreeTexture( tx->gl_texturenum ); // main texture - GL_FreeTexture( tx->fb_texturenum ); // luma texture - } -} - -void Mod_UnloadTextures( model_t *mod ) -{ - int i, j; - - Assert( mod != NULL ); - - switch( mod->type ) - { - case mod_studio: - Mod_StudioUnloadTextures( mod->cache.data ); - break; - case mod_alias: - Mod_AliasUnloadTextures( mod->cache.data ); - break; - case mod_brush: - Mod_BrushUnloadTextures( mod ); - break; - case mod_sprite: - Mod_SpriteUnloadTextures( mod->cache.data ); - break; - default: gEngfuncs.Host_Error( "Mod_UnloadModel: unsupported type %d\n", mod->type ); - } -} - void R_ProcessEntData( qboolean allocate ) { if( !allocate ) diff --git a/ref_gl/gl_local.h b/ref_gl/gl_local.h index f6a7972d..88212a74 100644 --- a/ref_gl/gl_local.h +++ b/ref_gl/gl_local.h @@ -34,7 +34,9 @@ GNU General Public License for more details. #include "pm_movevars.h" //#include "cvar.h" +#ifndef offsetof #define offsetof(s,m) (size_t)&(((s *)0)->m) +#endif // offsetof #define ASSERT(x) if(!( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) #define Assert(x) if(!( x )) gEngfuncs.Host_Error( "assert failed at %s:%i\n", __FILE__, __LINE__ ) diff --git a/ref_gl/gl_sprite.c b/ref_gl/gl_sprite.c index 89aac7bb..496f4ac2 100644 --- a/ref_gl/gl_sprite.c +++ b/ref_gl/gl_sprite.c @@ -144,9 +144,9 @@ load sprite model */ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags ) { - dsprite_t *pin; - short *numi = NULL; - dframetype_t *pframetype; + const dsprite_t *pin; + const short *numi = NULL; + const dframetype_t *pframetype; msprite_t *psprite; int i; @@ -156,7 +156,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui if( pin->version == SPRITE_VERSION_Q1 || pin->version == SPRITE_VERSION_32 ) numi = NULL; else if( pin->version == SPRITE_VERSION_HL ) - numi = (short *)(buffer + sizeof( dsprite_hl_t )); + numi = (const short *)((const byte*)buffer + sizeof( dsprite_hl_t )); r_texFlags = texFlags; sprite_version = pin->version; @@ -168,21 +168,21 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui rgbdata_t *pal; pal = gEngfuncs.FS_LoadImage( "#id.pal", (byte *)&i, 768 ); - pframetype = (dframetype_t *)(buffer + sizeof( dsprite_q1_t )); // pinq1 + 1 + pframetype = (const dframetype_t *)((const byte*)buffer + sizeof( dsprite_q1_t )); // pinq1 + 1 gEngfuncs.FS_FreeImage( pal ); // palette installed, no reason to keep this data } else if( *numi == 256 ) - { - byte *src = (byte *)(numi+1); + { + const byte *src = (const byte *)(numi+1); rgbdata_t *pal; - + // install palette switch( psprite->texFormat ) { case SPR_INDEXALPHA: pal = gEngfuncs.FS_LoadImage( "#gradient.pal", src, 768 ); break; - case SPR_ALPHTEST: + case SPR_ALPHTEST: pal = gEngfuncs.FS_LoadImage( "#masked.pal", src, 768 ); break; default: @@ -190,7 +190,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui break; } - pframetype = (dframetype_t *)(src + 768); + pframetype = (const dframetype_t *)(src + 768); gEngfuncs.FS_FreeImage( pal ); // palette installed, no reason to keep this data } else @@ -298,7 +298,7 @@ void Mod_LoadMapSprite( model_t *mod, const void *buffer, size_t size, qboolean temp.width = w; temp.height = h; temp.type = pix->type; - temp.flags = pix->flags; + temp.flags = pix->flags; temp.size = w * h * gEngfuncs.Image_GetPFDesc(temp.type)->bpp; temp.buffer = Mem_Malloc( r_temppool, temp.size ); temp.palette = NULL;