]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/shaderlib.h
Merge branch 'SiPlus/tga-grey-rle' into 'master'
[xonotic/netradiant.git] / libs / shaderlib.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined ( INCLUDED_SHADERLIB_H )
23 #define INCLUDED_SHADERLIB_H
24
25 #include "string/string.h"
26 #include "character.h"
27 #include "ishaders.h"
28
29 inline bool shader_equal( const char* shader, const char* other ){
30         return string_equal_nocase( shader, other );
31 }
32
33 inline bool shader_equal_n( const char* shader, const char* other, std::size_t n ){
34         return string_equal_nocase_n( shader, other, n );
35 }
36
37 inline bool shader_less( const char* shader, const char* other ){
38         return string_less_nocase( shader, other );
39 }
40
41 inline bool shader_equal_prefix( const char* string, const char* prefix ){
42         return shader_equal_n( string, prefix, string_length( prefix ) );
43 }
44
45 class shader_less_t
46 {
47 public:
48 bool operator()( const CopiedString& shader, const CopiedString& other ) const {
49         return shader_less( shader.c_str(), other.c_str() );
50 }
51 };
52
53 static inline bool shader_is_diffuse( const char *shader ){
54         return
55                 /* Quake2World */
56                 !string_equal_suffix( shader, "_bump" )
57                 && !string_equal_suffix( shader, "_glow" )
58                 && !string_equal_suffix( shader, "_h" )
59                 && !string_equal_suffix( shader, "_local" )
60                 && !string_equal_suffix( shader, "_luma" )
61                 && !string_equal_suffix( shader, "_nm" )
62                 && !string_equal_suffix( shader, "_s" )
63                 /* DarkPlaces */
64                 && !string_equal_suffix( shader, "_norm" )
65                 // (already in Quake2World) && !string_equal_suffix( shader, "_bump" )
66                 // (already in Quake2World) && !string_equal_suffix( shader, "_glow" )
67                 && !string_equal_suffix( shader, "_gloss" )
68                 && !string_equal_suffix( shader, "_pants" )
69                 && !string_equal_suffix( shader, "_shirt" )
70                 && !string_equal_suffix( shader, "_reflect" )
71                 ;
72 }
73
74 inline bool shader_valid( const char* shader ){
75         return string_is_ascii( shader )
76                    && strchr( shader, ' ' ) == 0
77                    && strchr( shader, '\n' ) == 0
78                    && strchr( shader, '\r' ) == 0
79                    && strchr( shader, '\t' ) == 0
80                    && strchr( shader, '\v' ) == 0
81                    && strchr( shader, '\\' ) == 0
82                    && shader_is_diffuse( shader );
83 }
84
85 inline const char* GlobalTexturePrefix_get(){
86         return GlobalShaderSystem().getTexturePrefix();
87 }
88
89 inline bool shader_is_texture( const char* name ){
90         return shader_equal_prefix( name, GlobalTexturePrefix_get() );
91 }
92
93 inline const char* shader_get_textureName( const char* name ){
94         return name + string_length( GlobalTexturePrefix_get() );
95 }
96
97 inline bool texdef_name_valid( const char* name ){
98         return shader_valid( name ) && shader_is_texture( name );
99 }
100
101 inline const char* texdef_name_default(){
102         return GlobalTexturePrefix_get();
103 }
104
105
106 #endif