]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant/image: load fallback images with png loader even if game does not support...
authorThomas Debesse <dev@illwieckz.net>
Thu, 21 May 2020 22:43:20 +0000 (00:43 +0200)
committerThomas Debesse <dev@illwieckz.net>
Fri, 22 May 2020 08:36:57 +0000 (10:36 +0200)
Current implementation has a minor issue, when "Hide Fallback" option is
disabled, the fallback image does not appear in texture browser before radiant
makes use of it (for example creating a brush before selecting a texture).

Since "Hide Fallback" option is enabled by default and it never makes sense
to apply those fallback intentionally, I don't care for the moment.

I would like to see a better implementation that would work for all
editor images (like the one set with `qer_editorImage` shader keyword).

radiant/image.cpp
radiant/textures.cpp

index c81b3617ab7fe5527d9c8c45ac2fc6c83623db2b..c9014294f639c0dc07c762355b414b0a87b310cc 100644 (file)
@@ -30,9 +30,9 @@
 #include "os/path.h"
 #include "stream/stringstream.h"
 
-
 typedef Modules<_QERPlugImageTable> ImageModules;
 ImageModules& Textures_getImageModules();
+ImageModules& Textures_getFallbackImageModules();
 
 /// \brief Returns a new image for the first file matching \p name in one of the available texture formats, or 0 if no file is found.
 Image* QERApp_LoadImage( void* environment, const char* name ){
@@ -60,5 +60,12 @@ public:
 
        Textures_getImageModules().foreachModule( LoadImageVisitor( name, image ) );
 
+       // Games can provide their own fallback, so only do this when previous
+       // loading attempt did not work.
+       if ( image == 0 && !!string_compare_nocase( name, "textures/radiant" ) )
+       {
+               Textures_getFallbackImageModules().foreachModule( LoadImageVisitor( name, image ) );
+       }
+
        return image;
 }
index 02f706b90e0629d6df7808ea62f3f88067abcba7..afa8d4e05c1d180b5c3f9b2e48d0e365edc60c67 100644 (file)
@@ -815,13 +815,18 @@ class TexturesDependencies :
        public GlobalPreferenceSystemModuleRef
 {
 ImageModulesRef m_image_modules;
+ImageModulesRef m_fallback_image_modules;
 public:
 TexturesDependencies() :
-       m_image_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "texturetypes" ) ){
+       m_image_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "texturetypes" ) ),
+       m_fallback_image_modules( "png" ){
 }
 ImageModules& getImageModules(){
        return m_image_modules.get();
 }
+ImageModules& getFallbackImageModules(){
+       return m_fallback_image_modules.get();
+}
 };
 
 class TexturesAPI
@@ -851,3 +856,6 @@ StaticRegisterModule staticRegisterTextures( StaticTexturesModule::instance() );
 ImageModules& Textures_getImageModules(){
        return StaticTexturesModule::instance().getDependencies().getImageModules();
 }
+ImageModules& Textures_getFallbackImageModules(){
+       return StaticTexturesModule::instance().getDependencies().getFallbackImageModules();
+}