Skip to content

Commit 78a0dca

Browse files
committed
engine: move creation of default textures to the engnie
1 parent a37e553 commit 78a0dca

3 files changed

Lines changed: 86 additions & 144 deletions

File tree

engine/client/ref_common.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,63 @@ static void CL_FillTriAPI( triangleapi_t *dst )
501501
ref.dllFuncs.R_FillTriAPI( dst );
502502
}
503503

504+
static const byte dottexture[8][8] =
505+
{
506+
{ 0, 1, 1, 0, 0, 0, 0, 0 },
507+
{ 1, 1, 1, 1, 0, 0, 0, 0 },
508+
{ 1, 1, 1, 1, 0, 0, 0, 0 },
509+
{ 0, 1, 1, 0, 0, 0, 0, 0 },
510+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
511+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
512+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
513+
{ 0, 0, 0, 0, 0, 0, 0, 0 },
514+
};
515+
516+
static void R_CreateBuiltinTextures( void )
517+
{
518+
uint data4x4[16];
519+
uint data16x16[256];
520+
byte particle[8 * 8 * 4];
521+
int x, y;
522+
523+
// default checkerboard
524+
for( y = 0; y < 16; y++ )
525+
{
526+
for( x = 0; x < 16; x++ )
527+
{
528+
if(( y < 8 ) ^ ( x < 8 ))
529+
data16x16[y * 16 + x] = 0xFFFF00FF;
530+
else
531+
data16x16[y * 16 + x] = 0xFF000000;
532+
}
533+
}
534+
ref.dllFuncs.GL_CreateTexture( REF_DEFAULT_TEXTURE, 16, 16, data16x16, TF_COLORMAP );
535+
536+
// particle texture
537+
memset( particle, 0, sizeof( particle ));
538+
for( x = 0; x < 8; x++ )
539+
{
540+
for( y = 0; y < 8; y++ )
541+
{
542+
if( dottexture[x][y] )
543+
particle[( y * 8 + x ) * 4 + 3] = 255;
544+
}
545+
}
546+
ref.dllFuncs.GL_CreateTexture( REF_PARTICLE_TEXTURE, 8, 8, particle, TF_CLAMP );
547+
548+
// solid colors
549+
memset( data4x4, 0xFF, sizeof( data4x4 ));
550+
ref.dllFuncs.GL_CreateTexture( REF_WHITE_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
551+
552+
for( x = 0; x < 16; x++ )
553+
data4x4[x] = 0xFF7F7F7F;
554+
ref.dllFuncs.GL_CreateTexture( REF_GRAY_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
555+
556+
for( x = 0; x < 16; x++ )
557+
data4x4[x] = 0xFF000000;
558+
ref.dllFuncs.GL_CreateTexture( REF_BLACK_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
559+
}
560+
504561
static qboolean R_LoadProgs( const char *name )
505562
{
506563
static ref_api_t gpEngfuncs;
@@ -544,7 +601,7 @@ static qboolean R_LoadProgs( const char *name )
544601
Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY );
545602
ref.initialized = true;
546603

547-
// initialize TriAPI callbacks
604+
R_CreateBuiltinTextures();
548605
CL_FillTriAPI( &gTriApi );
549606

550607
return true;

ref/gl/gl_image.c

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ static gl_texture_t gl_textures[MAX_TEXTURES];
2323
static gl_texture_t* gl_texturesHashTable[TEXTURES_HASH_SIZE];
2424
static uint gl_numTextures;
2525

26-
static byte dottexture[8][8] =
27-
{
28-
{0,1,1,0,0,0,0,0},
29-
{1,1,1,1,0,0,0,0},
30-
{1,1,1,1,0,0,0,0},
31-
{0,1,1,0,0,0,0,0},
32-
{0,0,0,0,0,0,0,0},
33-
{0,0,0,0,0,0,0,0},
34-
{0,0,0,0,0,0,0,0},
35-
{0,0,0,0,0,0,0,0},
36-
};
37-
38-
3926
#define IsLightMap( tex ) ( FBitSet(( tex )->flags, TF_ATLAS_PAGE ))
4027
/*
4128
=================
@@ -1699,7 +1686,20 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
16991686
r_empty.size *= 6;
17001687
}
17011688

1702-
return GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
1689+
int texnum = GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
1690+
1691+
if( !Q_strcmp( name, REF_DEFAULT_TEXTURE ))
1692+
tr.defaultTexture = texnum;
1693+
else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE ))
1694+
tr.particleTexture = texnum;
1695+
else if( !Q_strcmp( name, REF_WHITE_TEXTURE ))
1696+
tr.whiteTexture = texnum;
1697+
else if( !Q_strcmp( name, REF_GRAY_TEXTURE ))
1698+
tr.grayTexture = texnum;
1699+
else if( !Q_strcmp( name, REF_BLACK_TEXTURE ))
1700+
tr.blackTexture = texnum;
1701+
1702+
return texnum;
17031703
}
17041704

17051705
/*
@@ -1912,67 +1912,6 @@ void R_InitDlightTexture( void )
19121912
tr.dlightTexture = GL_LoadTextureFromBuffer( "*dlight", &r_image, TF_NOMIPMAP|TF_CLAMP|TF_ATLAS_PAGE, update );
19131913
}
19141914

1915-
/*
1916-
==================
1917-
GL_CreateInternalTextures
1918-
==================
1919-
*/
1920-
static void GL_CreateInternalTextures( void )
1921-
{
1922-
int dx2, dy, d;
1923-
int x, y;
1924-
rgbdata_t *pic;
1925-
1926-
// emo-texture from quake1
1927-
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR );
1928-
1929-
for( y = 0; y < 16; y++ )
1930-
{
1931-
for( x = 0; x < 16; x++ )
1932-
{
1933-
if(( y < 8 ) ^ ( x < 8 ))
1934-
((uint *)pic->buffer)[y*16+x] = 0xFFFF00FF;
1935-
else ((uint *)pic->buffer)[y*16+x] = 0xFF000000;
1936-
}
1937-
}
1938-
1939-
tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP );
1940-
1941-
// particle texture from quake1
1942-
pic = GL_FakeImage( 8, 8, 1, IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA );
1943-
1944-
for( x = 0; x < 8; x++ )
1945-
{
1946-
for( y = 0; y < 8; y++ )
1947-
{
1948-
if( dottexture[x][y] )
1949-
pic->buffer[( y * 8 + x ) * 4 + 3] = 255;
1950-
else pic->buffer[( y * 8 + x ) * 4 + 3] = 0;
1951-
}
1952-
}
1953-
1954-
tr.particleTexture = GL_LoadTextureInternal( REF_PARTICLE_TEXTURE, pic, TF_CLAMP );
1955-
1956-
// white texture
1957-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
1958-
for( x = 0; x < 16; x++ )
1959-
((uint *)pic->buffer)[x] = 0xFFFFFFFF;
1960-
tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP );
1961-
1962-
// gray texture
1963-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
1964-
for( x = 0; x < 16; x++ )
1965-
((uint *)pic->buffer)[x] = 0xFF7F7F7F;
1966-
tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP );
1967-
1968-
// black texture
1969-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
1970-
for( x = 0; x < 16; x++ )
1971-
((uint *)pic->buffer)[x] = 0xFF000000;
1972-
tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP );
1973-
1974-
}
1975-
19761915
/*
19771916
===============
19781917
R_TextureList_f
@@ -2205,7 +2144,6 @@ void R_InitImages( void )
22052144

22062145
// validate cvars
22072146
R_SetTextureParameters();
2208-
GL_CreateInternalTextures();
22092147

22102148
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
22112149
}

ref/soft/r_image.c

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,20 @@ int GAME_EXPORT GL_CreateTexture( const char *name, int width, int height, const
659659
return 0;
660660
}
661661

662-
return GL_LoadTextureInternal( name, &r_empty, flags );
662+
int texnum = GL_LoadTextureInternal( name, &r_empty, flags );
663+
664+
if( !Q_strcmp( name, REF_DEFAULT_TEXTURE ))
665+
tr.defaultTexture = texnum;
666+
else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE ))
667+
tr.particleTexture = texnum;
668+
else if( !Q_strcmp( name, REF_WHITE_TEXTURE ))
669+
tr.whiteTexture = texnum;
670+
else if( !Q_strcmp( name, REF_GRAY_TEXTURE ))
671+
tr.grayTexture = texnum;
672+
else if( !Q_strcmp( name, REF_BLACK_TEXTURE ))
673+
tr.blackTexture = texnum;
674+
675+
return texnum;
663676
}
664677

665678
/*
@@ -838,71 +851,6 @@ void R_InitDlightTexture( void )
838851
tr.dlightTexture = GL_LoadTextureInternal( "*dlight", &r_image, TF_NOMIPMAP | TF_CLAMP | TF_ATLAS_PAGE );
839852
}
840853

841-
/*
842-
==================
843-
GL_CreateInternalTextures
844-
==================
845-
*/
846-
static void GL_CreateInternalTextures( void )
847-
{
848-
int dx2, dy, d;
849-
int x, y;
850-
rgbdata_t *pic;
851-
852-
// emo-texture from quake1
853-
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR );
854-
855-
for( y = 0; y < 16; y++ )
856-
{
857-
for( x = 0; x < 16; x++ )
858-
{
859-
if(( y < 8 ) ^ ( x < 8 ))
860-
((uint *)pic->buffer )[y * 16 + x] = 0xFFFF00FF;
861-
else
862-
((uint *)pic->buffer )[y * 16 + x] = 0xFF000000;
863-
}
864-
}
865-
866-
tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP );
867-
868-
// particle texture from quake1
869-
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );
870-
871-
for( x = 0; x < 16; x++ )
872-
{
873-
dx2 = x - 8;
874-
dx2 = dx2 * dx2;
875-
876-
for( y = 0; y < 16; y++ )
877-
{
878-
dy = y - 8;
879-
d = 255 - 35 * sqrt( dx2 + dy * dy );
880-
pic->buffer[( y * 16 + x ) * 4 + 3] = bound( 0, d, 255 );
881-
}
882-
}
883-
884-
tr.particleTexture = GL_LoadTextureInternal( "*particle", pic, TF_CLAMP );
885-
886-
// white texture
887-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
888-
for( x = 0; x < 16; x++ )
889-
((uint *)pic->buffer )[x] = 0xFFFFFFFF;
890-
tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP );
891-
892-
// gray texture
893-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
894-
for( x = 0; x < 16; x++ )
895-
((uint *)pic->buffer )[x] = 0xFF7F7F7F;
896-
tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP );
897-
898-
// black texture
899-
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
900-
for( x = 0; x < 16; x++ )
901-
((uint *)pic->buffer )[x] = 0xFF000000;
902-
tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP );
903-
904-
}
905-
906854
/*
907855
===============
908856
R_TextureList_f
@@ -968,7 +916,6 @@ void R_InitImages( void )
968916
r_numImages = 1;
969917

970918
// validate cvars
971-
GL_CreateInternalTextures();
972919

973920
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
974921
}

0 commit comments

Comments
 (0)