From 41ed9c2ce57a4fae6ad4e28d6ef704012ba9483c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 29 Aug 2017 23:56:21 +0200 Subject: [PATCH] do not list empty shader dir --- include/ishaders.h | 6 +++++- plugins/shaders/shaders.cpp | 30 ++++++++++++++++++++++++++++++ radiant/texwindow.cpp | 6 +++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/ishaders.h b/include/ishaders.h index 5ade5956..bd35b593 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -111,6 +111,9 @@ typedef void ( WINAPI * PFN_RELOADSHADERS )(); // load all shaders in a given directory // 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 ); +// 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) // 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! @@ -178,6 +181,7 @@ struct _QERShadersTable PFN_FREESHADERS m_pfnFreeShaders; PFN_RELOADSHADERS m_pfnReloadShaders; PFN_LOADSHADERSFROMDIR m_pfnLoadShadersFromDir; + PFN_ISDIRCONTAININGSHADER m_pfnIsDirContainingShaders; PFN_LOADSHADERFILE m_pfnLoadShaderFile; PFN_RELOADSHADERFILE m_pfnReloadShaderFile; PFN_HASSHADER m_pfnHasShader; @@ -219,7 +223,7 @@ struct _QERShadersTable #define QERApp_ColorShader_ForName __SHADERSTABLENAME.m_pfnColorShader_ForName #define QERApp_Shader_ForName_NoLoad __SHADERSTABLENAME.m_pfnShader_ForName_NoLoad #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_GetActiveShaderCount __SHADERSTABLENAME.m_pfnGetActiveShaderCount #define QERApp_ActiveShaders_SetDisplayed __SHADERSTABLENAME.m_pfnActiveShaders_SetDisplayed diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index 792b2ad0..1c75f4d0 100644 --- a/plugins/shaders/shaders.cpp +++ b/plugins/shaders/shaders.cpp @@ -410,6 +410,16 @@ int WINAPI QERApp_LoadShadersFromDir( const char *path ){ for ( int i = 0; i < nSize; 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 ) ) { count++; // 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; } +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(){ char *token = g_ScripLibTable.m_pfnToken(); @@ -924,6 +953,7 @@ bool CSynapseClientShaders::RequestAPI( APIDescriptor_t *pAPI ){ pTable->m_pfnFreeShaders = QERApp_FreeShaders; pTable->m_pfnReloadShaders = QERApp_ReloadShaders; pTable->m_pfnLoadShadersFromDir = QERApp_LoadShadersFromDir; + pTable->m_pfnIsDirContainingShaders = QERApp_IsDirContainingShaders; pTable->m_pfnReloadShaderFile = QERApp_ReloadShaderFile; pTable->m_pfnLoadShaderFile = QERApp_LoadShaderFile; pTable->m_pfnHasShader = QERApp_HasShader; diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index d91842a7..344dc942 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -591,7 +591,10 @@ void FillTextureList( GSList** pArray ) } if ( !found ) { - texdirs = g_slist_prepend( texdirs, g_strdup( shaderfile ) ); + if( QERApp_IsDirContainingShaders( shaderfile ) ) + { + texdirs = g_slist_prepend( texdirs, g_strdup( shaderfile ) ); + } } free( l_shaderfiles->data ); @@ -784,6 +787,7 @@ void Texture_ShowDirectory_by_path( const char* pPath ) ( the GL textures are not flushed though) ============== */ + void Texture_ShowDirectory(){ char name[1024]; char dirstring[1024];