mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-16 06:00:33 +01:00
materials: enable force-reloading textures
mark such materials as `"force_reload" "1"`
This commit is contained in:
parent
1624f4620a
commit
f0aaa3cd10
@ -34,8 +34,8 @@ static int findTextureNamedLike( const char *texture_name ) {
|
||||
return tex_id ? tex_id : -1;
|
||||
}
|
||||
|
||||
static int loadTexture( const char *filename ) {
|
||||
const int tex_id = VK_LoadTexture( filename, NULL, 0, 0);
|
||||
static int loadTexture( const char *filename, qboolean force_reload ) {
|
||||
const int tex_id = force_reload ? XVK_LoadTextureReplace( filename, NULL, 0, 0 ) : VK_LoadTexture( filename, NULL, 0, 0 );
|
||||
gEngine.Con_Reportf("Loading texture %s => %d\n", filename, tex_id);
|
||||
return tex_id ? tex_id : -1;
|
||||
}
|
||||
@ -53,6 +53,7 @@ static void loadMaterialsFromFile( const char *filename ) {
|
||||
.normalmap = 0,
|
||||
};
|
||||
int current_material_index = -1;
|
||||
qboolean force_reload = false;
|
||||
|
||||
gEngine.Con_Reportf("Loading materials from %s\n", filename);
|
||||
|
||||
@ -80,6 +81,7 @@ static void loadMaterialsFromFile( const char *filename ) {
|
||||
.roughness = tglob.whiteTexture,
|
||||
.normalmap = 0,
|
||||
};
|
||||
force_reload = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -99,10 +101,12 @@ static void loadMaterialsFromFile( const char *filename ) {
|
||||
|
||||
if (Q_stricmp(key, "for") == 0) {
|
||||
current_material_index = findTextureNamedLike(value);
|
||||
} else if (Q_stricmp(key, "force_reload") == 0) {
|
||||
force_reload = Q_atoi(value) != 0;
|
||||
} else {
|
||||
char texture_path[256];
|
||||
int *tex_id_dest;
|
||||
int tex_id = loadTexture(texture_path);
|
||||
int tex_id = -1;
|
||||
if (Q_stricmp(key, "basecolor_map") == 0) {
|
||||
tex_id_dest = ¤t_material.base_color;
|
||||
} else if (Q_stricmp(key, "normal_map") == 0) {
|
||||
@ -124,7 +128,7 @@ static void loadMaterialsFromFile( const char *filename ) {
|
||||
Q_snprintf(texture_path, sizeof(texture_path), "%.*s%s", path_end - path_begin, path_begin, value);
|
||||
}
|
||||
|
||||
tex_id = loadTexture(texture_path);
|
||||
tex_id = loadTexture(texture_path, force_reload);
|
||||
if (tex_id < 0) {
|
||||
gEngine.Con_Printf(S_ERROR "Failed to load texture \"%s\" for key \"%s\"\n", value, key);
|
||||
continue;
|
||||
|
@ -744,6 +744,19 @@ int VK_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
|
||||
return tex - vk_textures;
|
||||
}
|
||||
|
||||
int XVK_LoadTextureReplace( const char *name, const byte *buf, size_t size, int flags ) {
|
||||
vk_texture_t *tex;
|
||||
if( !Common_CheckTexName( name ))
|
||||
return 0;
|
||||
|
||||
// free if already loaded
|
||||
if(( tex = Common_TextureForName( name ))) {
|
||||
VK_FreeTexture( tex - vk_textures );
|
||||
}
|
||||
|
||||
return VK_LoadTexture( name, buf, size, flags );
|
||||
}
|
||||
|
||||
int VK_CreateTexture( const char *name, int width, int height, const void *buffer, texFlags_t flags )
|
||||
{
|
||||
gEngine.Con_Printf("VK FIXME: %s\n", __FUNCTION__);
|
||||
|
@ -66,6 +66,8 @@ int VK_CreateTextureArray( const char *name, int width, int height, int depth,
|
||||
void VK_FreeTexture( unsigned int texnum );
|
||||
int VK_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update );
|
||||
|
||||
int XVK_LoadTextureReplace( const char *name, const byte *buf, size_t size, int flags );
|
||||
|
||||
int XVK_TextureLookupF( const char *fmt, ...);
|
||||
|
||||
#define VK_LoadTextureInternal( name, pic, flags ) VK_LoadTextureFromBuffer( name, pic, flags, false )
|
||||
|
Loading…
Reference in New Issue
Block a user