diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index decfcef9..197fc57c 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -501,6 +501,63 @@ static void CL_FillTriAPI( triangleapi_t *dst ) ref.dllFuncs.R_FillTriAPI( dst ); } +static const byte dottexture[8][8] = +{ + { 0, 1, 1, 0, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 }, +}; + +static void R_CreateBuiltinTextures( void ) +{ + uint data4x4[16]; + uint data16x16[256]; + byte particle[8 * 8 * 4]; + int x, y; + + // default checkerboard + for( y = 0; y < 16; y++ ) + { + for( x = 0; x < 16; x++ ) + { + if(( y < 8 ) ^ ( x < 8 )) + data16x16[y * 16 + x] = 0xFFFF00FF; + else + data16x16[y * 16 + x] = 0xFF000000; + } + } + ref.dllFuncs.GL_CreateTexture( REF_DEFAULT_TEXTURE, 16, 16, data16x16, TF_COLORMAP ); + + // particle texture + memset( particle, 0, sizeof( particle )); + for( x = 0; x < 8; x++ ) + { + for( y = 0; y < 8; y++ ) + { + if( dottexture[x][y] ) + particle[( y * 8 + x ) * 4 + 3] = 255; + } + } + ref.dllFuncs.GL_CreateTexture( REF_PARTICLE_TEXTURE, 8, 8, particle, TF_CLAMP ); + + // solid colors + memset( data4x4, 0xFF, sizeof( data4x4 )); + ref.dllFuncs.GL_CreateTexture( REF_WHITE_TEXTURE, 4, 4, data4x4, TF_COLORMAP ); + + for( x = 0; x < 16; x++ ) + data4x4[x] = 0xFF7F7F7F; + ref.dllFuncs.GL_CreateTexture( REF_GRAY_TEXTURE, 4, 4, data4x4, TF_COLORMAP ); + + for( x = 0; x < 16; x++ ) + data4x4[x] = 0xFF000000; + ref.dllFuncs.GL_CreateTexture( REF_BLACK_TEXTURE, 4, 4, data4x4, TF_COLORMAP ); +} + static qboolean R_LoadProgs( const char *name ) { static ref_api_t gpEngfuncs; @@ -544,7 +601,7 @@ static qboolean R_LoadProgs( const char *name ) Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY ); ref.initialized = true; - // initialize TriAPI callbacks + R_CreateBuiltinTextures(); CL_FillTriAPI( &gTriApi ); return true; diff --git a/ref/gl/gl_image.c b/ref/gl/gl_image.c index a44b4c89..66c1ebfc 100644 --- a/ref/gl/gl_image.c +++ b/ref/gl/gl_image.c @@ -23,19 +23,6 @@ static gl_texture_t gl_textures[MAX_TEXTURES]; static gl_texture_t* gl_texturesHashTable[TEXTURES_HASH_SIZE]; static uint gl_numTextures; -static byte dottexture[8][8] = -{ - {0,1,1,0,0,0,0,0}, - {1,1,1,1,0,0,0,0}, - {1,1,1,1,0,0,0,0}, - {0,1,1,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0}, -}; - - #define IsLightMap( tex ) ( FBitSet(( tex )->flags, TF_ATLAS_PAGE )) /* ================= @@ -1699,7 +1686,20 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe r_empty.size *= 6; } - return GL_LoadTextureFromBuffer( name, &r_empty, flags, update ); + int texnum = GL_LoadTextureFromBuffer( name, &r_empty, flags, update ); + + if( !Q_strcmp( name, REF_DEFAULT_TEXTURE )) + tr.defaultTexture = texnum; + else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE )) + tr.particleTexture = texnum; + else if( !Q_strcmp( name, REF_WHITE_TEXTURE )) + tr.whiteTexture = texnum; + else if( !Q_strcmp( name, REF_GRAY_TEXTURE )) + tr.grayTexture = texnum; + else if( !Q_strcmp( name, REF_BLACK_TEXTURE )) + tr.blackTexture = texnum; + + return texnum; } /* @@ -1912,67 +1912,6 @@ void R_InitDlightTexture( void ) tr.dlightTexture = GL_LoadTextureFromBuffer( "*dlight", &r_image, TF_NOMIPMAP|TF_CLAMP|TF_ATLAS_PAGE, update ); } -/* -================== -GL_CreateInternalTextures -================== -*/ -static void GL_CreateInternalTextures( void ) -{ - int dx2, dy, d; - int x, y; - rgbdata_t *pic; - - // emo-texture from quake1 - pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR ); - - for( y = 0; y < 16; y++ ) - { - for( x = 0; x < 16; x++ ) - { - if(( y < 8 ) ^ ( x < 8 )) - ((uint *)pic->buffer)[y*16+x] = 0xFFFF00FF; - else ((uint *)pic->buffer)[y*16+x] = 0xFF000000; - } - } - - tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP ); - - // particle texture from quake1 - pic = GL_FakeImage( 8, 8, 1, IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA ); - - for( x = 0; x < 8; x++ ) - { - for( y = 0; y < 8; y++ ) - { - if( dottexture[x][y] ) - pic->buffer[( y * 8 + x ) * 4 + 3] = 255; - else pic->buffer[( y * 8 + x ) * 4 + 3] = 0; - } - } - - tr.particleTexture = GL_LoadTextureInternal( REF_PARTICLE_TEXTURE, pic, TF_CLAMP ); - - // white texture - pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); - for( x = 0; x < 16; x++ ) - ((uint *)pic->buffer)[x] = 0xFFFFFFFF; - 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( 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( REF_BLACK_TEXTURE, pic, TF_COLORMAP ); - -} - /* =============== R_TextureList_f @@ -2205,7 +2144,6 @@ void R_InitImages( void ) // validate cvars R_SetTextureParameters(); - GL_CreateInternalTextures(); gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" ); } diff --git a/ref/soft/r_image.c b/ref/soft/r_image.c index 4e771854..c3f281f9 100644 --- a/ref/soft/r_image.c +++ b/ref/soft/r_image.c @@ -659,7 +659,20 @@ int GAME_EXPORT GL_CreateTexture( const char *name, int width, int height, const return 0; } - return GL_LoadTextureInternal( name, &r_empty, flags ); + int texnum = GL_LoadTextureInternal( name, &r_empty, flags ); + + if( !Q_strcmp( name, REF_DEFAULT_TEXTURE )) + tr.defaultTexture = texnum; + else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE )) + tr.particleTexture = texnum; + else if( !Q_strcmp( name, REF_WHITE_TEXTURE )) + tr.whiteTexture = texnum; + else if( !Q_strcmp( name, REF_GRAY_TEXTURE )) + tr.grayTexture = texnum; + else if( !Q_strcmp( name, REF_BLACK_TEXTURE )) + tr.blackTexture = texnum; + + return texnum; } /* @@ -838,71 +851,6 @@ void R_InitDlightTexture( void ) tr.dlightTexture = GL_LoadTextureInternal( "*dlight", &r_image, TF_NOMIPMAP | TF_CLAMP | TF_ATLAS_PAGE ); } -/* -================== -GL_CreateInternalTextures -================== -*/ -static void GL_CreateInternalTextures( void ) -{ - int dx2, dy, d; - int x, y; - rgbdata_t *pic; - - // emo-texture from quake1 - pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR ); - - for( y = 0; y < 16; y++ ) - { - for( x = 0; x < 16; x++ ) - { - if(( y < 8 ) ^ ( x < 8 )) - ((uint *)pic->buffer )[y * 16 + x] = 0xFFFF00FF; - else - ((uint *)pic->buffer )[y * 16 + x] = 0xFF000000; - } - } - - 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 ); - - for( x = 0; x < 16; x++ ) - { - dx2 = x - 8; - dx2 = dx2 * dx2; - - for( y = 0; y < 16; y++ ) - { - dy = y - 8; - d = 255 - 35 * sqrt( dx2 + dy * dy ); - pic->buffer[( y * 16 + x ) * 4 + 3] = bound( 0, d, 255 ); - } - } - - tr.particleTexture = GL_LoadTextureInternal( "*particle", pic, TF_CLAMP ); - - // white texture - pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); - for( x = 0; x < 16; x++ ) - ((uint *)pic->buffer )[x] = 0xFFFFFFFF; - 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( 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( REF_BLACK_TEXTURE, pic, TF_COLORMAP ); - -} - /* =============== R_TextureList_f @@ -968,7 +916,6 @@ void R_InitImages( void ) r_numImages = 1; // validate cvars - GL_CreateInternalTextures(); gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" ); }