Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textures Manager #729

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
09093ae
resman: Implement texture methods stubs
vklachkov Jan 13, 2022
28bd6b9
resman: Minimal implementation of texture loading
vklachkov Jan 13, 2022
406dbe2
resman: Pass ref_interface_t to resource manager, save texture in mem
vklachkov Jan 13, 2022
f25ae90
resman: Check texture name
vklachkov Jan 13, 2022
b55c92a
resman: Implement cache
vklachkov Jan 13, 2022
bcbfb7c
resman: Generate stub entries for internal textures
vklachkov Jan 13, 2022
378aa88
resman: Implement RM_FindTexture
vklachkov Jan 13, 2022
067c534
resman: Set correct names for first six textures
vklachkov Jan 13, 2022
812af16
resman: Restore strange flags code
vklachkov Jan 13, 2022
697f3b3
resman: Stab more methods
vklachkov Jan 13, 2022
c0e7394
refgl: Dirty hack for get backtrace at texture n 121
vklachkov Jan 14, 2022
5074761
Checkout mainui t master branch
vklachkov Jan 14, 2022
1edd2f7
ref_gl: Remove dirty debug hack
vklachkov Jan 15, 2022
ee6669b
ref: Add RM_LoadTexture to ref_api_t
vklachkov Jan 15, 2022
6a1e1c3
ref_gl: Load some textures via engine, fix sprite glitches
vklachkov Jan 15, 2022
3c65550
resman: Implement RM_LoadTextureFromBuffer, fix more glitches
vklachkov Jan 15, 2022
54fc8a0
ref_gl: Load texture for sky via engine
vklachkov Jan 16, 2022
eea92a4
ref_api: Remove part of texture's methods, pass RM_* to RenderAPI
vklachkov Jan 16, 2022
d50edac
ref_soft: Load all textures via engine
vklachkov Jan 16, 2022
bde20c5
engine: Use remaining RM_* methods in render api
vklachkov Jan 16, 2022
61aa8e2
ref_api: Remove remaining texture tools from ref_interface_t
vklachkov Jan 16, 2022
e47c902
ref_gl: Use engine's RM_FreeTexture
vklachkov Jan 18, 2022
bbbc3e0
ref_gl: Remove unused methods
vklachkov Jan 18, 2022
8b2e6f3
Totally rework memory layout everywhere
vklachkov Apr 23, 2022
b14d5d7
resman: Subtract from textures_count on texture remove
vklachkov Apr 23, 2022
f3af112
resman: Restore internal textures
vklachkov Apr 25, 2022
4177fab
resman: Disable very noisy logs in RM_LoadTexture
vklachkov Apr 25, 2022
8648ce6
client: fix random crashes
vklachkov Apr 25, 2022
f72164d
resman: Implement ReuploadTextures, move CreateInternalTextures into …
vklachkov May 3, 2022
35ca0a4
ref_gl: Minor patch
vklachkov May 3, 2022
14bbe5c
ref_gl: Found standard textures in engine during initialization
vklachkov May 3, 2022
01eed00
resman: Rewrite FakeImage without static buffer
vklachkov May 3, 2022
e91d8db
resman: Create dlight textures, fix a lot of glitches
vklachkov May 4, 2022
3e6ade4
Fix ref_soft for new api
vklachkov May 5, 2022
3bb872b
resman: Minor clean up
vklachkov May 5, 2022
2c55163
Merge branch 'master' into resman_texture
vklachkov Jul 12, 2022
57de05c
resman: Implement RM_TextureName
vklachkov Jul 12, 2022
d7f2c47
resman: Minor changes
vklachkov Jul 12, 2022
d515c8a
resman: Implement RM_TextureData
vklachkov Jul 13, 2022
bcdb8b1
resman: Implement RM_CreateTexture and RM_CreateTextureArray
vklachkov Jul 13, 2022
cf5f074
resman: Implement ProcessFlags, replacement for GL_ProcessImage
vklachkov Jul 13, 2022
6aab155
resman: Implement RM_LoadTextureArray
vklachkov Jul 13, 2022
f78d7b3
Rename resman to texturelib and move to common
vklachkov Aug 7, 2022
f466496
texturelib: Code style fixes
vklachkov Aug 7, 2022
7bbc1da
texturelib: Use engine's Mem_Malloc instead of libc's malloc
vklachkov Aug 7, 2022
24c9474
texturelib: Set MAX_TEXTURES to 1024 when XASH_LOW_MEMORY
vklachkov Aug 7, 2022
d564c92
texturelib: Minor methods renames
vklachkov Aug 7, 2022
fd4d218
client: Remove useless macroses GL_*TextureInternal
vklachkov Aug 8, 2022
783538f
texturelib: Use string type from xash instead of chars array
vklachkov Aug 8, 2022
b94a08e
texturelib: Remove noisy logs
vklachkov Aug 8, 2022
269685d
reg_gl: Implement R_ShutdownImages
vklachkov Aug 8, 2022
374fc98
ref_gl: Restore comments
vklachkov Aug 8, 2022
5553d8a
ref_gl: Remove gl_numTextures
vklachkov Aug 8, 2022
1a23dac
ref_gl: Restore R_TextureList_f
vklachkov Aug 8, 2022
8b4562d
ref_gl: Restore some changes after bad merge
vklachkov Aug 8, 2022
d15ab39
texturelib: Remove texture after freeing in render
vklachkov Aug 8, 2022
d981fe7
ref_soft: Minor changes, restore most of comments
vklachkov Aug 8, 2022
4ce3d59
ref_soft: Restore R_TextureList_f
vklachkov Aug 8, 2022
b2d1283
ref_soft: Find standard textures in the engine
vklachkov Aug 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
texturelib: Minor methods renames
Add RM prefix for all static functions
Rename RM_SetRender -> RM_SetRenderer (render is verb, renderer is noun)
  • Loading branch information
vklachkov committed Aug 7, 2022
commit d564c923c6632558b835ca36ea55fc67b53fe7fa
2 changes: 1 addition & 1 deletion engine/client/ref_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ qboolean R_Init( void )
}
}

RM_SetRender(&ref.dllFuncs);
RM_SetRenderer(&ref.dllFuncs);

if( !success )
{
Expand Down
122 changes: 61 additions & 61 deletions engine/common/texturelib/texturelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ static byte dot_texture[8][8] =
{0,0,0,0,0,0,0,0},
};

static size_t CalcImageSize( pixformat_t format, int width, int height, int depth );
static qboolean IsValidTextureName( const char *name );
static rm_texture_t *GetTextureByName( const char *name );
static rm_texture_t *AppendTexture( const char *name, int flags );
static void ProcessImage( rm_texture_t *tex, rgbdata_t *pic );
static qboolean UploadTexture( rm_texture_t *tex, qboolean update );
static void RemoveTexture( const char *name );
static size_t RM_CalcImageSize( pixformat_t format, int width, int height, int depth );
static qboolean RM_IsValidTextureName( const char *name );
static rm_texture_t *RM_GetTextureByName( const char *name );
static rm_texture_t *RM_AppendTexture( const char *name, int flags );
static void RM_ProcessImage( rm_texture_t *tex, rgbdata_t *pic );
static qboolean RM_UploadTexture( rm_texture_t *tex, qboolean update );
static void RM_RemoveTexture( const char *name );

static void CreateUnusedEntry( void );
static void RM_CreateUnusedEntry( void );

static void CreateInternalTextures( void );
static void RM_CreateInternalTextures( void );

static rgbdata_t *FakeImage( int width, int height, int depth, int flags );
static int CreateEmoTexture( void );
static int CreateParticleTexture( void );
static int CreateStaticColoredTexture( const char *name, uint32_t color );
static int CreateCinematicDummyTexture( void );
static int CreateDlightTexture( void );
static rgbdata_t *RM_FakeImage( int width, int height, int depth, int flags );
static int RM_CreateEmoTexture( void );
static int RM_CreateParticleTexture( void );
static int RM_CreateStaticColoredTexture( const char *name, uint32_t color );
static int RM_CreateCinematicDummyTexture( void );
static int RM_CreateDlightTexture( void );


////////////////////////////////////////////////////////////////////////////////
Expand All @@ -112,12 +112,12 @@ void RM_Init()

g_textures.mempool = Mem_AllocPool( "Textures" );

CreateUnusedEntry();
RM_CreateUnusedEntry();

CreateInternalTextures();
RM_CreateInternalTextures();
}

void RM_SetRender( ref_interface_t *ref )
void RM_SetRenderer( ref_interface_t *ref )
{
g_textures.ref = ref;

Expand All @@ -143,7 +143,7 @@ void RM_ReuploadTextures()
continue;

if( tex->picture != NULL )
UploadTexture( tex, false );
RM_UploadTexture( tex, false );
else
Con_Reportf( S_ERROR "Reupload without early saved picture is not supported now\n" );
}
Expand All @@ -158,14 +158,14 @@ int RM_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
Con_Reportf( "RM_LoadTexture. Name %s\n", name );

// Check name
if( !IsValidTextureName( name ))
if( !RM_IsValidTextureName( name ))
{
Con_Reportf( "Invalid texture name %s\n", name );
return 0;
}

// Check cache
if(( tex = GetTextureByName( name )))
if(( tex = RM_GetTextureByName( name )))
{
//Con_Reportf( "Texture %s is already loaded with number %d\n", name, texture->number );
return tex->number;
Expand All @@ -189,16 +189,16 @@ int RM_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
}

// Allocate texture
tex = AppendTexture( name, flags );
tex = RM_AppendTexture( name, flags );
tex->picture = picture;
tex->width = picture->width;
tex->height = picture->height;

ProcessImage( tex, picture );
RM_ProcessImage( tex, picture );

// And upload texture
// FIXME: Handle error
UploadTexture( tex, false );
RM_UploadTexture( tex, false );

return tex->number;
}
Expand Down Expand Up @@ -238,14 +238,14 @@ int RM_LoadTextureArray( const char **names, int flags )
Q_strncat( &name, va( "[%i]", layers_count ), MAX_NAME_LEN );

// Validate texture name
if( !IsValidTextureName( name ))
if( !RM_IsValidTextureName( name ))
{
//Con_Reportf( "Invalid texture name %s\n", name );
return 0;
}

// Check cache
if(( tex = GetTextureByName( name )))
if(( tex = RM_GetTextureByName( name )))
{
//Con_Reportf( "Texture %s is already loaded with number %d\n", name, texture->number );
return tex->number;
Expand Down Expand Up @@ -314,7 +314,7 @@ int RM_LoadTextureArray( const char **names, int flags )
int width = Q_max( 1, ( picture->width >> j ));
int height = Q_max( 1, ( picture->height >> j ));

mip_size = CalcImageSize( picture->type, width, height, 1 );
mip_size = RM_CalcImageSize( picture->type, width, height, 1 );

memcpy( picture->buffer + dst_size + mip_size * i, src->buffer + src_size, mip_size );
dst_size += mip_size * layers_count;
Expand Down Expand Up @@ -358,14 +358,14 @@ int RM_LoadTextureFromBuffer( const char *name, rgbdata_t *picture, int flags, q
Con_Reportf( "RM_LoadTextureFromBuffer. Name %s\n", name );

// Check name
if( !IsValidTextureName( name ))
if( !RM_IsValidTextureName( name ))
{
Con_Reportf( "Invalid texture name\n" );
return 0;
}

// Check cache
if(( tex = GetTextureByName( name )))
if(( tex = RM_GetTextureByName( name )))
{
Con_Reportf( "Texture is already loaded with number %d\n", tex->number );
return tex->number;
Expand All @@ -379,16 +379,16 @@ int RM_LoadTextureFromBuffer( const char *name, rgbdata_t *picture, int flags, q
}

// Create texture
tex = AppendTexture( name, flags );
tex = RM_AppendTexture( name, flags );
tex->picture = picture;
tex->width = picture->width;
tex->height = picture->height;

ProcessImage( tex, picture );
RM_ProcessImage( tex, picture );

// And upload
// FIXME: Handle error
UploadTexture( tex, update );
RM_UploadTexture( tex, update );

return tex->number;
}
Expand All @@ -410,7 +410,7 @@ void RM_FreeTexture( unsigned int texnum )
return;
}

RemoveTexture( tex->name );
RM_RemoveTexture( tex->name );

g_textures.ref->R_FreeTexture( texnum );
}
Expand Down Expand Up @@ -439,7 +439,7 @@ int RM_FindTexture( const char *name )
{
rm_texture_t *tex;

tex = GetTextureByName( name );
tex = RM_GetTextureByName( name );
if( !tex ) return NULL;
return tex->number;
}
Expand Down Expand Up @@ -533,7 +533,7 @@ int RM_CreateTextureArray( const char *name, int width, int height, int depth, c
////////////////////////////////////////////////////////////////////////////////
// Local implementation

size_t CalcImageSize( pixformat_t format, int width, int height, int depth )
size_t RM_CalcImageSize( pixformat_t format, int width, int height, int depth )
{
size_t size = 0;

Expand Down Expand Up @@ -569,15 +569,15 @@ size_t CalcImageSize( pixformat_t format, int width, int height, int depth )
return size;
}

qboolean IsValidTextureName( const char *name )
qboolean RM_IsValidTextureName( const char *name )
{
if( !COM_CheckString( name ) )
return false;
else
return Q_strlen( name ) < MAX_NAME_LEN;
}

rm_texture_t *GetTextureByName( const char *name )
rm_texture_t *RM_GetTextureByName( const char *name )
{
size_t hash;
rm_texture_t *tex;
Expand All @@ -594,7 +594,7 @@ rm_texture_t *GetTextureByName( const char *name )
return NULL;
}

rm_texture_t *AppendTexture( const char *name, int flags )
rm_texture_t *RM_AppendTexture( const char *name, int flags )
{
size_t i;
size_t hash;
Expand Down Expand Up @@ -655,7 +655,7 @@ rm_texture_t *AppendTexture( const char *name, int flags )
return tex;
}

void ProcessImage( rm_texture_t *tex, rgbdata_t *pic )
void RM_ProcessImage( rm_texture_t *tex, rgbdata_t *pic )
{
uint img_flags = 0;

Expand Down Expand Up @@ -705,7 +705,7 @@ void ProcessImage( rm_texture_t *tex, rgbdata_t *pic )
}
}

qboolean UploadTexture( rm_texture_t *tex, qboolean update )
qboolean RM_UploadTexture( rm_texture_t *tex, qboolean update )
{
qboolean status;

Expand All @@ -731,7 +731,7 @@ qboolean UploadTexture( rm_texture_t *tex, qboolean update )
return status;
}

void RemoveTexture( const char *name )
void RM_RemoveTexture( const char *name )
{
size_t hash;
rm_texture_t *tex;
Expand Down Expand Up @@ -769,7 +769,7 @@ void RemoveTexture( const char *name )
////////////////////////////////////////////////////////////////////////////////
// Internal textures

void CreateUnusedEntry( void )
void RM_CreateUnusedEntry( void )
{
const char *name = "*unused*";

Expand All @@ -781,21 +781,21 @@ void CreateUnusedEntry( void )
g_textures.count++;
}

void CreateInternalTextures( void )
void RM_CreateInternalTextures( void )
{
CreateEmoTexture();
CreateParticleTexture();
RM_CreateEmoTexture();
RM_CreateParticleTexture();

CreateStaticColoredTexture( REF_WHITE_TEXTURE, 0xFFFFFFFF );
CreateStaticColoredTexture( REF_GRAY_TEXTURE, 0xFF7F7F7F );
CreateStaticColoredTexture( REF_BLACK_TEXTURE, 0xFF000000 );
RM_CreateStaticColoredTexture( REF_WHITE_TEXTURE, 0xFFFFFFFF );
RM_CreateStaticColoredTexture( REF_GRAY_TEXTURE, 0xFF7F7F7F );
RM_CreateStaticColoredTexture( REF_BLACK_TEXTURE, 0xFF000000 );

CreateCinematicDummyTexture();
RM_CreateCinematicDummyTexture();

CreateDlightTexture();
RM_CreateDlightTexture();
}

rgbdata_t *FakeImage( int width, int height, int depth, int flags )
rgbdata_t *RM_FakeImage( int width, int height, int depth, int flags )
{
rgbdata_t *r_image;

Expand All @@ -822,7 +822,7 @@ rgbdata_t *FakeImage( int width, int height, int depth, int flags )
return r_image;
}

int CreateEmoTexture( void )
int RM_CreateEmoTexture( void )
{
int w, h;
int x, y;
Expand All @@ -831,7 +831,7 @@ int CreateEmoTexture( void )
w = 16;
h = 16;

pic = FakeImage( w, h, 1, IMAGE_HAS_COLOR );
pic = RM_FakeImage( w, h, 1, IMAGE_HAS_COLOR );

for( y = 0; y < h; y++ )
{
Expand All @@ -851,7 +851,7 @@ int CreateEmoTexture( void )
return RM_LoadTextureFromBuffer( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP, false );
}

int CreateParticleTexture( void )
int RM_CreateParticleTexture( void )
{
int w, h;
int x, y;
Expand All @@ -860,7 +860,7 @@ int CreateParticleTexture( void )
w = 8;
h = 8;

pic = FakeImage( w, h, 1, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );
pic = RM_FakeImage( w, h, 1, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );

for( y = 0; y < h; y++ )
{
Expand All @@ -880,7 +880,7 @@ int CreateParticleTexture( void )
return RM_LoadTextureFromBuffer( REF_PARTICLE_TEXTURE, pic, TF_CLAMP, false );
}

int CreateStaticColoredTexture( const char *name, uint32_t color )
int RM_CreateStaticColoredTexture( const char *name, uint32_t color )
{
int w, h;
int x, y;
Expand All @@ -889,7 +889,7 @@ int CreateStaticColoredTexture( const char *name, uint32_t color )
w = 4;
h = 4;

pic = FakeImage( w, h, 1, IMAGE_HAS_COLOR );
pic = RM_FakeImage( w, h, 1, IMAGE_HAS_COLOR );

for( x = 0; x < (w * h); x++ )
{
Expand All @@ -899,28 +899,28 @@ int CreateStaticColoredTexture( const char *name, uint32_t color )
return RM_LoadTextureFromBuffer( name, pic, TF_COLORMAP, false );
}

int CreateCinematicDummyTexture( void )
int RM_CreateCinematicDummyTexture( void )
{
int w, h;
rgbdata_t *pic;

w = 640;
h = 100;

pic = FakeImage( w, h, 1, IMAGE_HAS_COLOR );
pic = RM_FakeImage( w, h, 1, IMAGE_HAS_COLOR );

return RM_LoadTextureFromBuffer( REF_CINEMA_TEXTURE, pic, TF_NOMIPMAP | TF_CLAMP, false );
}

int CreateDlightTexture( void )
int RM_CreateDlightTexture( void )
{
int w, h;
rgbdata_t *pic;

w = 128;
h = 128;

pic = FakeImage( w, h, 1, IMAGE_HAS_COLOR );
pic = RM_FakeImage( w, h, 1, IMAGE_HAS_COLOR );

return RM_LoadTextureFromBuffer( REF_DLIGHT_TEXTURE, pic, TF_NOMIPMAP | TF_CLAMP | TF_ATLAS_PAGE, false );
}
2 changes: 1 addition & 1 deletion engine/common/texturelib/texturelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GNU General Public License for more details.

void RM_Init();

void RM_SetRender( ref_interface_t *ref );
void RM_SetRenderer( ref_interface_t *ref );

void RM_ReuploadTextures();

Expand Down