2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
22 #if !defined( INCLUDED_ISHADERS_H )
23 #define INCLUDED_ISHADERS_H
25 #include "generic/constant.h"
26 #include "generic/callback.h"
33 QER_NONSOLID = 1 << 3,
36 QER_ALPHATEST = 1 << 6,
38 QER_AREAPORTAL = 1 << 8,
40 QER_BOTCLIP = 1 << 10,
45 template<typename Element> class BasicVector3;
46 typedef BasicVector3<float> Vector3;
47 typedef Vector3 Colour3;
49 typedef unsigned char BlendFactor;
50 const BlendFactor BLEND_ZERO = 0;
51 const BlendFactor BLEND_ONE = 1;
52 const BlendFactor BLEND_SRC_COLOUR = 2;
53 const BlendFactor BLEND_ONE_MINUS_SRC_COLOUR = 3;
54 const BlendFactor BLEND_SRC_ALPHA = 4;
55 const BlendFactor BLEND_ONE_MINUS_SRC_ALPHA = 5;
56 const BlendFactor BLEND_DST_COLOUR = 6;
57 const BlendFactor BLEND_ONE_MINUS_DST_COLOUR = 7;
58 const BlendFactor BLEND_DST_ALPHA = 8;
59 const BlendFactor BLEND_ONE_MINUS_DST_ALPHA = 9;
60 const BlendFactor BLEND_SRC_ALPHA_SATURATE = 10;
65 BlendFunc( BlendFactor src, BlendFactor dst ) : m_src( src ), m_dst( dst ){
74 virtual qtexture_t* texture() const = 0;
75 virtual BlendFunc blendFunc() const = 0;
76 virtual bool clampToBorder() const = 0;
77 virtual float alphaTest() const = 0;
80 typedef Callback<void(const ShaderLayer&)> ShaderLayerCallback;
99 // Increment the number of references to this object
100 virtual void IncRef() = 0;
101 // Decrement the reference count
102 virtual void DecRef() = 0;
103 // get/set the qtexture_t* Radiant uses to represent this shader object
104 virtual qtexture_t* getTexture() const = 0;
105 virtual qtexture_t* getDiffuse() const = 0;
106 virtual qtexture_t* getBump() const = 0;
107 virtual qtexture_t* getSpecular() const = 0;
109 virtual const char* getName() const = 0;
110 virtual const char* getWadName() const = 0;
111 virtual void setWadName( const char* name ) = 0;
112 virtual bool IsInUse() const = 0;
113 virtual void SetInUse( bool bInUse ) = 0;
114 // get the editor flags (QER_NOCARVE QER_TRANS)
115 virtual int getFlags() const = 0;
116 // get the transparency value
117 virtual float getTrans() const = 0;
118 // test if it's a true shader, or a default shader created to wrap around a texture
119 virtual bool IsDefault() const = 0;
121 virtual void getAlphaFunc( EAlphaFunc *func, float *ref ) = 0;
122 virtual BlendFunc getBlendFunc() const = 0;
124 virtual ECull getCull() = 0;
125 // get shader file name (ie the file where this one is defined)
126 virtual const char* getShaderFileName() const = 0;
128 virtual const ShaderLayer* firstLayer() const = 0;
130 virtual qtexture_t* lightFalloffImage() const = 0;
133 typedef struct _GSList GSList;
134 typedef Callback<void(const char*)> ShaderNameCallback;
136 class ModuleObserver;
141 INTEGER_CONSTANT( Version, 1 );
142 STRING_CONSTANT( Name, "shaders" );
143 // NOTE: shader and texture names used must be full path.
144 // Shaders usable as textures have prefix equal to getTexturePrefix()
146 virtual void realise() = 0;
147 virtual void unrealise() = 0;
148 virtual void refresh() = 0;
149 // activate the shader for a given name and return it
150 // will return the default shader if name is not found
151 virtual IShader* getShaderForName( const char* name ) = 0;
153 virtual void foreachShaderName( const ShaderNameCallback& callback ) = 0;
155 // iterate over the list of active shaders
156 virtual void beginActiveShadersIterator() = 0;
157 virtual bool endActiveShadersIterator() = 0;
158 virtual IShader* dereferenceActiveShadersIterator() = 0;
159 virtual void incrementActiveShadersIterator() = 0;
161 virtual void setActiveShadersChangedNotify( const Callback<void()>& notify ) = 0;
163 virtual void attach( ModuleObserver& observer ) = 0;
164 virtual void detach( ModuleObserver& observer ) = 0;
166 virtual void setLightingEnabled( bool enabled ) = 0;
168 virtual const char* getTexturePrefix() const = 0;
171 #include "modulesystem.h"
173 template<typename Type>
175 typedef GlobalModule<ShaderSystem> GlobalShadersModule;
177 template<typename Type>
178 class GlobalModuleRef;
179 typedef GlobalModuleRef<ShaderSystem> GlobalShadersModuleRef;
181 inline ShaderSystem& GlobalShaderSystem(){
182 return GlobalShadersModule::getTable();
185 #define QERApp_Shader_ForName GlobalShaderSystem().getShaderForName
186 #define QERApp_ActiveShaders_IteratorBegin GlobalShaderSystem().beginActiveShadersIterator
187 #define QERApp_ActiveShaders_IteratorAtEnd GlobalShaderSystem().endActiveShadersIterator
188 #define QERApp_ActiveShaders_IteratorCurrent GlobalShaderSystem().dereferenceActiveShadersIterator
189 #define QERApp_ActiveShaders_IteratorIncrement GlobalShaderSystem().incrementActiveShadersIterator