do not list empty shader dir

This commit is contained in:
Thomas Debesse 2017-08-29 23:56:21 +02:00
parent 69972f9458
commit 41ed9c2ce5
3 changed files with 40 additions and 2 deletions

View File

@ -111,6 +111,9 @@ typedef void ( WINAPI * PFN_RELOADSHADERS )();
// load all shaders in a given directory // load all shaders in a given directory
// this will scan the list of in-memory shaders, and load the related qtexture_t if needed // this will scan the list of in-memory shaders, and load the related qtexture_t if needed
typedef int ( WINAPI * PFN_LOADSHADERSFROMDIR )( const char* path ); typedef int ( WINAPI * PFN_LOADSHADERSFROMDIR )( const char* path );
// count all shaders in a given directory
// this will scan the list of in-memory shaders
typedef bool ( WINAPI * PFN_ISDIRCONTAININGSHADER )( const char* path );
// load a shader file (ie a set of shaders) // load a shader file (ie a set of shaders)
// after LoadShaderFile shaders will be in memory, next step is to load the qtexture_t Radiant uses to represent them // after LoadShaderFile shaders will be in memory, next step is to load the qtexture_t Radiant uses to represent them
// if a shader with the same name exists, new one will not be loaded - don't use this to refresh the shaders! // if a shader with the same name exists, new one will not be loaded - don't use this to refresh the shaders!
@ -178,6 +181,7 @@ struct _QERShadersTable
PFN_FREESHADERS m_pfnFreeShaders; PFN_FREESHADERS m_pfnFreeShaders;
PFN_RELOADSHADERS m_pfnReloadShaders; PFN_RELOADSHADERS m_pfnReloadShaders;
PFN_LOADSHADERSFROMDIR m_pfnLoadShadersFromDir; PFN_LOADSHADERSFROMDIR m_pfnLoadShadersFromDir;
PFN_ISDIRCONTAININGSHADER m_pfnIsDirContainingShaders;
PFN_LOADSHADERFILE m_pfnLoadShaderFile; PFN_LOADSHADERFILE m_pfnLoadShaderFile;
PFN_RELOADSHADERFILE m_pfnReloadShaderFile; PFN_RELOADSHADERFILE m_pfnReloadShaderFile;
PFN_HASSHADER m_pfnHasShader; PFN_HASSHADER m_pfnHasShader;
@ -219,7 +223,7 @@ struct _QERShadersTable
#define QERApp_ColorShader_ForName __SHADERSTABLENAME.m_pfnColorShader_ForName #define QERApp_ColorShader_ForName __SHADERSTABLENAME.m_pfnColorShader_ForName
#define QERApp_Shader_ForName_NoLoad __SHADERSTABLENAME.m_pfnShader_ForName_NoLoad #define QERApp_Shader_ForName_NoLoad __SHADERSTABLENAME.m_pfnShader_ForName_NoLoad
#define QERApp_LoadShadersFromDir __SHADERSTABLENAME.m_pfnLoadShadersFromDir #define QERApp_LoadShadersFromDir __SHADERSTABLENAME.m_pfnLoadShadersFromDir
#define QERApp_LoadShadersFromDir __SHADERSTABLENAME.m_pfnLoadShadersFromDir #define QERApp_IsDirContainingShaders __SHADERSTABLENAME.m_pfnIsDirContainingShaders
#define QERApp_CreateShader_ForTextureName __SHADERSTABLENAME.m_pfnCreateShader_ForTextureName #define QERApp_CreateShader_ForTextureName __SHADERSTABLENAME.m_pfnCreateShader_ForTextureName
#define QERApp_GetActiveShaderCount __SHADERSTABLENAME.m_pfnGetActiveShaderCount #define QERApp_GetActiveShaderCount __SHADERSTABLENAME.m_pfnGetActiveShaderCount
#define QERApp_ActiveShaders_SetDisplayed __SHADERSTABLENAME.m_pfnActiveShaders_SetDisplayed #define QERApp_ActiveShaders_SetDisplayed __SHADERSTABLENAME.m_pfnActiveShaders_SetDisplayed

View File

@ -410,6 +410,16 @@ int WINAPI QERApp_LoadShadersFromDir( const char *path ){
for ( int i = 0; i < nSize; i++ ) for ( int i = 0; i < nSize; i++ )
{ {
CShader *pShader = reinterpret_cast < CShader * >( g_Shaders[i] ); CShader *pShader = reinterpret_cast < CShader * >( g_Shaders[i] );
// does not uselessly load shader with path not starting with "textures/"
// they will not be displayed by texture browser, because they can't be
// applied to a surface
if ( !g_str_has_prefix( pShader->getName(), "textures/" ) ) {
continue;
}
// this is basically doing:
// if path in ["scripts/eerie.shader", "textures/eerie/blackness"]
if ( strstr( pShader->getShaderFileName(), path ) || strstr( pShader->getName(), path ) ) { if ( strstr( pShader->getShaderFileName(), path ) || strstr( pShader->getName(), path ) ) {
count++; count++;
// request the shader, this will load the texture if needed and set "inuse" // request the shader, this will load the texture if needed and set "inuse"
@ -430,6 +440,25 @@ int WINAPI QERApp_LoadShadersFromDir( const char *path ){
return count; return count;
} }
bool WINAPI QERApp_IsDirContainingShaders( const char *path ){
int nSize = g_Shaders.GetSize();
// exclude shaders that are not starting with "textures/"
// they will not be displayed and are not applicable to surfaces
// exclude shaders from other paths,
// they are not the ones we are looking for
gchar* prefix = g_strconcat("textures/", path, NULL);
for ( int i = 0; i < nSize; i++ )
{
CShader *pShader = reinterpret_cast < CShader * >( g_Shaders[i] );
if ( g_str_has_prefix( pShader->getName(), prefix ) ) {
g_free(prefix);
return true;
}
}
g_free(prefix);
return false;
}
bool CShader::Parse(){ bool CShader::Parse(){
char *token = g_ScripLibTable.m_pfnToken(); char *token = g_ScripLibTable.m_pfnToken();
@ -924,6 +953,7 @@ bool CSynapseClientShaders::RequestAPI( APIDescriptor_t *pAPI ){
pTable->m_pfnFreeShaders = QERApp_FreeShaders; pTable->m_pfnFreeShaders = QERApp_FreeShaders;
pTable->m_pfnReloadShaders = QERApp_ReloadShaders; pTable->m_pfnReloadShaders = QERApp_ReloadShaders;
pTable->m_pfnLoadShadersFromDir = QERApp_LoadShadersFromDir; pTable->m_pfnLoadShadersFromDir = QERApp_LoadShadersFromDir;
pTable->m_pfnIsDirContainingShaders = QERApp_IsDirContainingShaders;
pTable->m_pfnReloadShaderFile = QERApp_ReloadShaderFile; pTable->m_pfnReloadShaderFile = QERApp_ReloadShaderFile;
pTable->m_pfnLoadShaderFile = QERApp_LoadShaderFile; pTable->m_pfnLoadShaderFile = QERApp_LoadShaderFile;
pTable->m_pfnHasShader = QERApp_HasShader; pTable->m_pfnHasShader = QERApp_HasShader;

View File

@ -591,8 +591,11 @@ void FillTextureList( GSList** pArray )
} }
if ( !found ) { if ( !found ) {
if( QERApp_IsDirContainingShaders( shaderfile ) )
{
texdirs = g_slist_prepend( texdirs, g_strdup( shaderfile ) ); texdirs = g_slist_prepend( texdirs, g_strdup( shaderfile ) );
} }
}
free( l_shaderfiles->data ); free( l_shaderfiles->data );
l_shaderfiles = g_slist_remove( l_shaderfiles, l_shaderfiles->data ); l_shaderfiles = g_slist_remove( l_shaderfiles, l_shaderfiles->data );
@ -784,6 +787,7 @@ void Texture_ShowDirectory_by_path( const char* pPath )
( the GL textures are not flushed though) ( the GL textures are not flushed though)
============== ==============
*/ */
void Texture_ShowDirectory(){ void Texture_ShowDirectory(){
char name[1024]; char name[1024];
char dirstring[1024]; char dirstring[1024];