]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/shaderlib.h
netradiant: strip 16-bit png to 8-bit, fix #153
[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 "defaults.h"
26 #include "string/string.h"
27 #include "character.h"
28 #include "ishaders.h"
29
30 inline bool shader_equal( const char* shader, const char* other ){
31         return string_equal_nocase( shader, other );
32 }
33
34 inline bool shader_equal_n( const char* shader, const char* other, std::size_t n ){
35         return string_equal_nocase_n( shader, other, n );
36 }
37
38 inline bool shader_less( const char* shader, const char* other ){
39         return string_less_nocase( shader, other );
40 }
41
42 inline bool shader_equal_prefix( const char* string, const char* prefix ){
43         return shader_equal_n( string, prefix, string_length( prefix ) );
44 }
45
46 class shader_less_t
47 {
48 public:
49 bool operator()( const CopiedString& shader, const CopiedString& other ) const {
50         return shader_less( shader.c_str(), other.c_str() );
51 }
52 };
53
54 inline bool shader_valid( const char* shader ){
55         return string_is_ascii( shader )
56                    && strchr( shader, ' ' ) == 0
57                    && strchr( shader, '\n' ) == 0
58                    && strchr( shader, '\r' ) == 0
59                    && strchr( shader, '\t' ) == 0
60                    && strchr( shader, '\v' ) == 0
61                    && strchr( shader, '\\' ) == 0;
62 }
63
64 inline const char* GlobalTexturePrefix_get(){
65         return GlobalShaderSystem().getTexturePrefix();
66 }
67
68 inline bool shader_is_texture( const char* name ){
69         return shader_equal_prefix( name, GlobalTexturePrefix_get() );
70 }
71
72 inline const char* shader_get_textureName( const char* name ){
73         return name + string_length( GlobalTexturePrefix_get() );
74 }
75
76 inline bool texdef_name_valid( const char* name ){
77         return shader_valid( name ) && shader_is_texture( name );
78 }
79
80 inline const char* texdef_name_default(){
81         const char* notex = DEFAULT_NOTEX_NAME;
82         return notex;
83 }
84
85 #endif