]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Filter non-diffuse textures (bump, glow, local, spec, etc) from texture browser.
authorJay Dolan <jay@jaydolan.com>
Tue, 17 Feb 2015 14:34:32 +0000 (09:34 -0500)
committerJay Dolan <jay@jaydolan.com>
Tue, 17 Feb 2015 14:34:32 +0000 (09:34 -0500)
libs/shaderlib.h
libs/string/string.h

index ee972437befeb934fbfb06c11862af6873d6329b..c4e5ba3b2f20309c5e83c847ebcfcfba1f2318a8 100644 (file)
@@ -50,6 +50,16 @@ bool operator()( const CopiedString& shader, const CopiedString& other ) const {
 }
 };
 
+static inline bool shader_is_diffuse( const char *shader ){
+       return !string_equal_suffix( shader, "_bump" )
+                  && !string_equal_suffix( shader, "_glow" )
+                  && !string_equal_suffix( shader, "_h" )
+                  && !string_equal_suffix( shader, "_local" )
+                  && !string_equal_suffix( shader, "_luma" )
+                  && !string_equal_suffix( shader, "_nm" )
+                  && !string_equal_suffix( shader, "_s" );
+}
+
 inline bool shader_valid( const char* shader ){
        return string_is_ascii( shader )
                   && strchr( shader, ' ' ) == 0
@@ -57,7 +67,8 @@ inline bool shader_valid( const char* shader ){
                   && strchr( shader, '\r' ) == 0
                   && strchr( shader, '\t' ) == 0
                   && strchr( shader, '\v' ) == 0
-                  && strchr( shader, '\\' ) == 0;
+                  && strchr( shader, '\\' ) == 0
+                  && shader_is_diffuse( shader );
 }
 
 inline const char* GlobalTexturePrefix_get(){
index a6de0673913009b899cead876a192372223128b6..826d4a938392209ba847facc52f353ae5341d16d 100644 (file)
@@ -141,6 +141,13 @@ inline bool string_equal_prefix( const char* string, const char* prefix ){
        return string_equal_n( string, prefix, string_length( prefix ) );
 }
 
+/// \brief Returns true if the ending of \p string is equal to \p suffix.
+/// O(n)
+inline bool string_equal_suffix( const char* string, const char* suffix){
+       const char *s = string + string_length( string ) - string_length( suffix );
+       return string_equal_n( s , suffix, string_length( suffix ) );
+}
+
 /// \brief Copies \p other into \p string and returns \p string.
 /// Assumes that the space allocated for \p string is at least string_length(other) + 1.
 /// O(n)