]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/ishaders.h
Merge branch 'vfs' into 'master'
[xonotic/netradiant.git] / include / ishaders.h
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
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_ISHADERS_H )
23 #define INCLUDED_ISHADERS_H
24
25 #include "generic/constant.h"
26 #include "generic/callback.h"
27
28 enum
29 {
30         QER_TRANS = 1 << 0,
31         QER_NOCARVE = 1 << 1,
32         QER_NODRAW = 1 << 2,
33         QER_NONSOLID = 1 << 3,
34         QER_WATER = 1 << 4,
35         QER_LAVA = 1 << 5,
36         QER_FOG = 1 << 6,
37         QER_ALPHATEST = 1 << 7,
38         QER_CULL = 1 << 8,
39         QER_AREAPORTAL = 1 << 9,
40         QER_CLIP = 1 << 10,
41         QER_BOTCLIP = 1 << 11,
42 };
43
44 struct qtexture_t;
45
46 template<typename Element> class BasicVector3;
47 typedef BasicVector3<float> Vector3;
48 typedef Vector3 Colour3;
49
50 typedef unsigned char BlendFactor;
51 const BlendFactor BLEND_ZERO = 0;
52 const BlendFactor BLEND_ONE = 1;
53 const BlendFactor BLEND_SRC_COLOUR = 2;
54 const BlendFactor BLEND_ONE_MINUS_SRC_COLOUR = 3;
55 const BlendFactor BLEND_SRC_ALPHA = 4;
56 const BlendFactor BLEND_ONE_MINUS_SRC_ALPHA = 5;
57 const BlendFactor BLEND_DST_COLOUR = 6;
58 const BlendFactor BLEND_ONE_MINUS_DST_COLOUR = 7;
59 const BlendFactor BLEND_DST_ALPHA = 8;
60 const BlendFactor BLEND_ONE_MINUS_DST_ALPHA = 9;
61 const BlendFactor BLEND_SRC_ALPHA_SATURATE = 10;
62
63 class BlendFunc
64 {
65 public:
66 BlendFunc( BlendFactor src, BlendFactor dst ) : m_src( src ), m_dst( dst ){
67 }
68 BlendFactor m_src;
69 BlendFactor m_dst;
70 };
71
72 class ShaderLayer
73 {
74 public:
75 virtual qtexture_t* texture() const = 0;
76 virtual BlendFunc blendFunc() const = 0;
77 virtual bool clampToBorder() const = 0;
78 virtual float alphaTest() const = 0;
79 };
80
81 typedef Callback<void(const ShaderLayer&)> ShaderLayerCallback;
82
83 class IShader
84 {
85 public:
86 enum EAlphaFunc
87 {
88         eAlways,
89         eEqual,
90         eLess,
91         eGreater,
92         eLEqual,
93         eGEqual,
94 };
95 enum ECull
96 {
97         eCullNone,
98         eCullBack,
99 };
100 // Increment the number of references to this object
101 virtual void IncRef() = 0;
102 // Decrement the reference count
103 virtual void DecRef() = 0;
104 // get/set the qtexture_t* Radiant uses to represent this shader object
105 virtual qtexture_t* getTexture() const = 0;
106 virtual qtexture_t* getDiffuse() const = 0;
107 virtual qtexture_t* getBump() const = 0;
108 virtual qtexture_t* getSpecular() const = 0;
109 // get shader name
110 virtual const char* getName() const = 0;
111 virtual const char* getWadName() const = 0;
112 virtual void setWadName( const char* name ) = 0;
113 virtual bool IsInUse() const = 0;
114 virtual void SetInUse( bool bInUse ) = 0;
115 // get the editor flags (QER_NOCARVE QER_TRANS)
116 virtual int getFlags() const = 0;
117 // get the transparency value
118 virtual float getTrans() const = 0;
119 // test if it's a true shader, or a default shader created to wrap around a texture
120 virtual bool IsDefault() const = 0;
121 // get the alphaFunc
122 virtual void getAlphaFunc( EAlphaFunc *func, float *ref ) = 0;
123 virtual BlendFunc getBlendFunc() const = 0;
124 // get the cull type
125 virtual ECull getCull() = 0;
126 // get shader file name (ie the file where this one is defined)
127 virtual const char* getShaderFileName() const = 0;
128
129 virtual const ShaderLayer* firstLayer() const = 0;
130 virtual void forEachLayer( const ShaderLayerCallback& layer ) const = 0;
131
132 virtual qtexture_t* lightFalloffImage() const = 0;
133 };
134
135 typedef struct _GSList GSList;
136 typedef Callback<void(const char*)> ShaderNameCallback;
137
138 class ModuleObserver;
139
140 class ShaderSystem
141 {
142 public:
143 INTEGER_CONSTANT( Version, 1 );
144 STRING_CONSTANT( Name, "shaders" );
145 // NOTE: shader and texture names used must be full path.
146 // Shaders usable as textures have prefix equal to getTexturePrefix()
147
148 virtual void realise() = 0;
149 virtual void unrealise() = 0;
150 virtual void refresh() = 0;
151 // activate the shader for a given name and return it
152 // will return the default shader if name is not found
153 virtual IShader* getShaderForName( const char* name ) = 0;
154
155 virtual void foreachShaderName( const ShaderNameCallback& callback ) = 0;
156
157 // iterate over the list of active shaders
158 virtual void beginActiveShadersIterator() = 0;
159 virtual bool endActiveShadersIterator() = 0;
160 virtual IShader* dereferenceActiveShadersIterator() = 0;
161 virtual void incrementActiveShadersIterator() = 0;
162
163 virtual void setActiveShadersChangedNotify( const Callback<void()>& notify ) = 0;
164
165 virtual void attach( ModuleObserver& observer ) = 0;
166 virtual void detach( ModuleObserver& observer ) = 0;
167
168 virtual void setLightingEnabled( bool enabled ) = 0;
169
170 virtual const char* getTexturePrefix() const = 0;
171 };
172
173 #include "modulesystem.h"
174
175 template<typename Type>
176 class GlobalModule;
177 typedef GlobalModule<ShaderSystem> GlobalShadersModule;
178
179 template<typename Type>
180 class GlobalModuleRef;
181 typedef GlobalModuleRef<ShaderSystem> GlobalShadersModuleRef;
182
183 inline ShaderSystem& GlobalShaderSystem(){
184         return GlobalShadersModule::getTable();
185 }
186
187 #define QERApp_Shader_ForName GlobalShaderSystem().getShaderForName
188 #define QERApp_ActiveShaders_IteratorBegin GlobalShaderSystem().beginActiveShadersIterator
189 #define QERApp_ActiveShaders_IteratorAtEnd GlobalShaderSystem().endActiveShadersIterator
190 #define QERApp_ActiveShaders_IteratorCurrent GlobalShaderSystem().dereferenceActiveShadersIterator
191 #define QERApp_ActiveShaders_IteratorIncrement GlobalShaderSystem().incrementActiveShadersIterator
192
193 #endif