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
resman: Minimal implementation of texture loading
  • Loading branch information
vklachkov committed Jan 13, 2022
commit 28bd6b9dc658434c1b702aeda3e3ce3b28026330
2 changes: 2 additions & 0 deletions engine/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3071,6 +3071,8 @@ void CL_Init( void )

CL_InitLocal();

RM_Init(); // init resource manager

VID_Init(); // init video
S_Init(); // init sound

Expand Down
6 changes: 0 additions & 6 deletions engine/client/ref_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ convar_t *gl_msaa_samples;
convar_t *gl_clear;
convar_t *r_refdll;

void R_GetTextureParms( int *w, int *h, int texnum )
{
if( w ) *w = REF_GET_PARM( PARM_TEX_WIDTH, texnum );
if( h ) *h = REF_GET_PARM( PARM_TEX_HEIGHT, texnum );
}

/*
================
GL_FreeImage
Expand Down
5 changes: 3 additions & 2 deletions engine/client/ref_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ extern struct ref_state_s ref;
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 R_GetBuiltinTexture( name ) RM_LoadTexture( (name), 0, 0, 0 )

#define R_GetTextureParms( WP, HP, T ) RM_GetTextureParams( WP, HP, T )
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
#define R_GetBuiltinTexture( NAME ) RM_LoadTexture( NAME, 0, 0, 0 )

void GL_RenderFrame( const struct ref_viewpass_s *rvp );

Expand Down
199 changes: 195 additions & 4 deletions engine/resman/texture.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,209 @@
#include <common/system.h>
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
#include <common/common.h>

#include "texture.h"

int RM_FindTexture( const char *name )

////////////////////////////////////////////////////////////////////////////////
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы так обычно не комментируем. И так понятно что такое структура, макрос, глобалка. Публичные функции не имеют static, приватные наоборот с ним.

// Defines, macros

#define MAX_TEXTURES (8096)
#define TEXTURES_HASH_SIZE (MAX_TEXTURES)

#define MAX_LIGHTMAPS (256)


////////////////////////////////////////////////////////////////////////////////
// Structs

typedef struct rm_texture_s {
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
char name[256];
int width;
int height;
int flags;

uint number;

uint hash_value;
struct rm_texture_s *next_hash;
} rm_texture_t;


////////////////////////////////////////////////////////////////////////////////
// Global state

static struct {
rm_texture_t textures[MAX_TEXTURES];
rm_texture_t* textures_hash_table[TEXTURES_HASH_SIZE];
uint textures_count;

int default_texture;
int particle_texture;
int white_texture;
int gray_texture;
int black_texture;
int solidsky_texture;
int alphasky_texture;
int lightmap_textures[MAX_LIGHTMAPS];
int dlight_texture;
int cinematic_texture;
} RM_TextureManager;


////////////////////////////////////////////////////////////////////////////////
// Local

static rm_texture_t* AllocTexture( const char* name, int flags );


////////////////////////////////////////////////////////////////////////////////
// Public methods

void RM_Init()
{
Sys_Error( "Unimplemented RM_FindTexture. Name %s", name );
// Reset texture manager
memset( &RM_TextureManager, 0, sizeof( RM_TextureManager ));

// Create unused 0-entry
const char *name = "*unused*";
Q_strncpy( RM_TextureManager.textures[0].name, name, sizeof( RM_TextureManager.textures[0].name ));

uint hash_value = COM_HashKey( name, TEXTURES_HASH_SIZE );
RM_TextureManager.textures[0].hash_value = hash_value;
RM_TextureManager.textures[0].next_hash = RM_TextureManager.textures_hash_table[hash_value];
RM_TextureManager.textures_hash_table[hash_value] = &(RM_TextureManager.textures[0]);
RM_TextureManager.textures_count = 1;

// TODO: Create internal textures
}

int RM_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
{
Sys_Error( "Unimplemented RM_LoadTexture. Name %s, size %d", name, size );
rgbdata_t *picture;
rm_texture_t *texture;

Con_Reportf( "RM_LoadTexture. Name %s, size %d\n", name, size );

// TODO: Check name
//if( !Common_CheckTexName( name ))
// return 0;

// TODO: Check cache
//if(( tex = Common_TextureForName( name )))
// return (tex - vk_textures);

// TODO: Bit magic
//if( FBitSet( flags, TF_NOFLIP_TGA ))
// SetBits( picFlags, IL_DONTFLIP_TGA );

//if( FBitSet( flags, TF_KEEP_SOURCE ) && !FBitSet( flags, TF_EXPAND_SOURCE ))
// SetBits( picFlags, IL_KEEP_8BIT );

// TODO: Flags magic
//Image_SetForceFlags( picFlags );

// Load image using engine
picture = FS_LoadImage( name, buf, size );
if( !picture ) return 0;

// Allocate texture
texture = AllocTexture( name, flags );
texture->width = picture->width;
texture->height = picture->height;

// TODO: Prepare texture
//VK_ProcessImage( tex, pic );

// TODO: Upload texture
//if( !uploadTexture( tex, &pic, 1, false ))
//{
// memset( tex, 0, sizeof( vk_texture_t ));
// gEngine.FS_FreeImage( pic ); // release source texture
// return 0;
//}

// TODO: Apply texture params
//VK_ApplyTextureParams( tex );

// Release source texture
FS_FreeImage( picture );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты его сначала malloc, а потом FS_FreeImage.

Zone вообще сразу должен ругаться на такое. =/


return texture->number;
}

void RM_FreeTexture( unsigned int texnum )
{
Sys_Error( "Unimplemented RM_FreeTexture. TexNum %d", texnum );
Con_Reportf( "Unimplemented RM_FreeTexture. TexNum %d\n", texnum );
}

int RM_FindTexture( const char *name )
{
Con_Reportf( "RM_FindTexture. Name %s\n", name );

return 0;
}

void RM_GetTextureParams( int* w, int* h, int texnum )
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
{
ASSERT( texnum >= 0 && texnum < MAX_TEXTURES );

Con_Reportf( "RM_GetTextureParams. Texnum %d\n", texnum );
Con_Reportf( "Texnum %d is texture %s\n", RM_TextureManager.textures[texnum].name );

if (w) *w = RM_TextureManager.textures[texnum].width;
if (h) *h = RM_TextureManager.textures[texnum].height;
}

////////////////////////////////////////////////////////////////////////////////
// Local implementation

rm_texture_t* AllocTexture( const char* name, int flags )
{
rm_texture_t* texture;
uint i;

// Find a free rm_texture_t slot
for(
i = 0, texture = &(RM_TextureManager.textures);
i < RM_TextureManager.textures_count;
i++, texture++
)
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
{
if( !texture->name[0] )
{
break;
}
}

// No holes, append to tail
if( i == RM_TextureManager.textures_count )
{
// Check textures
// TODO: Maybe it's worth realloc with increasing max textures?
if( RM_TextureManager.textures_count == MAX_TEXTURES )
{
Host_Error( "ResMan: The textures limit is exhausted\n" );
return NULL;
}

RM_TextureManager.textures_count++;
}

// Setup params
Q_strncpy( texture->name, name, sizeof( texture->name ) );

// Width and height will be set later
texture->width = 0;
texture->height = 0;

texture->number = i;
texture->flags = flags;

// Add to hash table
texture->hash_value = COM_HashKey( name, TEXTURES_HASH_SIZE );

RM_TextureManager.textures_hash_table[texture->hash_value] = texture;
texture->next_hash = RM_TextureManager.textures_hash_table[texture->hash_value];

return texture;
}
6 changes: 5 additions & 1 deletion engine/resman/texture.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#ifndef RM_TEXTURE_H
vklachkov marked this conversation as resolved.
Show resolved Hide resolved
#define RM_TEXTURE_H

int RM_FindTexture( const char *name );
void RM_Init();

int RM_LoadTexture( const char *name, const byte *buf, size_t size, int flags );
void RM_FreeTexture( unsigned int texnum );

int RM_FindTexture( const char *name );
void RM_GetTextureParams( int *w, int *h, int texnum );

#endif // RM_TEXTURE_H