2 Copyright (C) 2001-2006, William Joseph.
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_IRENDER_H)
23 #define INCLUDED_IRENDER_H
25 #include "generic/constant.h"
28 // Rendering states to sort by.
29 // Higher bits have the most effect - slowest state changes should be highest.
31 const unsigned int RENDER_DEFAULT = 0;
32 const unsigned int RENDER_LINESTIPPLE = 1 << 0; // glEnable(GL_LINE_STIPPLE)
33 const unsigned int RENDER_POLYGONSTIPPLE = 1 << 1; // glEnable(GL_POLYGON_STIPPLE)
34 const unsigned int RENDER_ALPHATEST = 1 << 2; // glEnable(GL_ALPHA_TEST)
35 const unsigned int RENDER_DEPTHTEST = 1 << 3; // glEnable(GL_DEPTH_TEST)
36 const unsigned int RENDER_DEPTHWRITE = 1 << 4; // glDepthMask(GL_TRUE)
37 const unsigned int RENDER_COLOURWRITE = 1 << 5; // glColorMask(GL_TRUE; GL_TRUE; GL_TRUE; GL_TRUE)
38 const unsigned int RENDER_CULLFACE = 1 << 6; // glglEnable(GL_CULL_FACE)
39 const unsigned int RENDER_SCALED = 1 << 7; // glEnable(GL_NORMALIZE)
40 const unsigned int RENDER_SMOOTH = 1 << 8; // glShadeModel
41 const unsigned int RENDER_LIGHTING = 1 << 9; // glEnable(GL_LIGHTING)
42 const unsigned int RENDER_BLEND = 1 << 10; // glEnable(GL_BLEND)
43 const unsigned int RENDER_OFFSETLINE = 1 << 11; // glEnable(GL_POLYGON_OFFSET_LINE)
44 const unsigned int RENDER_FILL = 1 << 12; // glPolygonMode
45 const unsigned int RENDER_COLOUR = 1 << 13; // glEnableClientState(GL_COLOR_ARRAY)
46 const unsigned int RENDER_TEXTURE = 1 << 14; // glEnable(GL_TEXTURE_2D)
47 const unsigned int RENDER_BUMP = 1 << 15;
48 const unsigned int RENDER_PROGRAM = 1 << 16;
49 const unsigned int RENDER_SCREEN = 1 << 17;
50 const unsigned int RENDER_OVERRIDE = 1 << 18;
51 typedef unsigned int RenderStateFlags;
57 template<typename Element> class BasicVector3;
58 typedef BasicVector3<float> Vector3;
65 virtual Shader* getShader() const = 0;
66 virtual const AABB& aabb() const = 0;
67 virtual bool testAABB(const AABB& other) const = 0;
68 virtual const Matrix4& rotation() const = 0;
69 virtual const Vector3& offset() const = 0;
70 virtual const Vector3& colour() const = 0;
71 virtual bool isProjected() const = 0;
72 virtual const Matrix4& projection() const = 0;
78 virtual bool testLight(const RendererLight& light) const = 0;
79 virtual void insertLight(const RendererLight& light)
82 virtual void clearLights()
87 template<typename FirstArgument>
91 typedef Callback1<const Renderable&> RenderableCallback;
93 typedef Callback1<const RendererLight&> RendererLightCallback;
98 virtual void evaluateLights() const = 0;
99 virtual void lightsChanged() const = 0;
100 virtual void forEachLight(const RendererLightCallback& callback) const = 0;
103 const int c_attr_TexCoord0 = 1;
104 const int c_attr_Tangent = 3;
105 const int c_attr_Binormal = 4;
107 class OpenGLRenderable
110 virtual void render(RenderStateFlags state) const = 0;
115 class ModuleObserver;
117 #include "math/vector.h"
122 virtual void addRenderable(const OpenGLRenderable& renderable, const Matrix4& modelview, const LightList* lights = 0) = 0;
123 virtual void incrementUsed() = 0;
124 virtual void decrementUsed() = 0;
125 virtual void attach(ModuleObserver& observer) = 0;
126 virtual void detach(ModuleObserver& observer) = 0;
127 virtual qtexture_t& getTexture() const = 0;
128 virtual unsigned int getFlags() const = 0;
134 INTEGER_CONSTANT(Version, 1);
135 STRING_CONSTANT(Name, "renderstate");
137 virtual Shader* capture(const char* name) = 0;
138 virtual void release(const char* name) = 0;
139 /*! Render all Shader objects. */
140 virtual void render(RenderStateFlags globalstate, const Matrix4& modelview, const Matrix4& projection, const Vector3& viewer = Vector3(0, 0, 0)) = 0;
142 virtual void realise() = 0;
143 virtual void unrealise() = 0;
145 virtual bool lightingSupported() const = 0;
146 virtual bool useShaderLanguage() const = 0;
148 virtual const LightList& attach(LightCullable& cullable) = 0;
149 virtual void detach(LightCullable& cullable) = 0;
150 virtual void changed(LightCullable& cullable) = 0;
151 virtual void attach(RendererLight& light) = 0;
152 virtual void detach(RendererLight& light) = 0;
153 virtual void changed(RendererLight& light) = 0;
155 virtual void attachRenderable(const Renderable& renderable) = 0;
156 virtual void detachRenderable(const Renderable& renderable) = 0;
157 virtual void forEachRenderable(const RenderableCallback& callback) const = 0;
160 #include "modulesystem.h"
162 template<typename Type>
164 typedef GlobalModule<ShaderCache> GlobalShaderCacheModule;
166 template<typename Type>
167 class GlobalModuleRef;
168 typedef GlobalModuleRef<ShaderCache> GlobalShaderCacheModuleRef;
170 inline ShaderCache& GlobalShaderCache()
172 return GlobalShaderCacheModule::getTable();