]> git.xonotic.org Git - xonotic/netradiant.git/blob - include/irender.h
282fb031f9c083b10709a0060a45013159b314cd
[xonotic/netradiant.git] / include / irender.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_IRENDER_H )
23 #define INCLUDED_IRENDER_H
24
25 #include "generic/constant.h"
26 #include "generic/callbackfwd.h"
27
28
29 // Rendering states to sort by.
30 // Higher bits have the most effect - slowest state changes should be highest.
31
32 const unsigned int RENDER_DEFAULT = 0;
33 const unsigned int RENDER_LINESTIPPLE = 1 << 0; // glEnable(GL_LINE_STIPPLE)
34 const unsigned int RENDER_LINESMOOTH = 1 << 1; // glEnable(GL_LINE_SMOOTH)
35 const unsigned int RENDER_POLYGONSTIPPLE = 1 << 2; // glEnable(GL_POLYGON_STIPPLE)
36 const unsigned int RENDER_POLYGONSMOOTH = 1 << 3; // glEnable(GL_POLYGON_SMOOTH)
37 const unsigned int RENDER_ALPHATEST = 1 << 4; // glEnable(GL_ALPHA_TEST)
38 const unsigned int RENDER_DEPTHTEST = 1 << 5; // glEnable(GL_DEPTH_TEST)
39 const unsigned int RENDER_DEPTHWRITE = 1 << 6; // glDepthMask(GL_TRUE)
40 const unsigned int RENDER_COLOURWRITE = 1 << 7; // glColorMask(GL_TRUE; GL_TRUE; GL_TRUE; GL_TRUE)
41 const unsigned int RENDER_CULLFACE = 1 << 8; // glglEnable(GL_CULL_FACE)
42 const unsigned int RENDER_SCALED = 1 << 9; // glEnable(GL_NORMALIZE)
43 const unsigned int RENDER_SMOOTH = 1 << 10; // glShadeModel
44 const unsigned int RENDER_FOG = 1 << 11; // glEnable(GL_FOG)
45 const unsigned int RENDER_LIGHTING = 1 << 12; // glEnable(GL_LIGHTING)
46 const unsigned int RENDER_BLEND = 1 << 13; // glEnable(GL_BLEND)
47 const unsigned int RENDER_OFFSETLINE = 1 << 14; // glEnable(GL_POLYGON_OFFSET_LINE)
48 const unsigned int RENDER_FILL = 1 << 15; // glPolygonMode
49 const unsigned int RENDER_COLOURARRAY = 1 << 16; // glEnableClientState(GL_COLOR_ARRAY)
50 const unsigned int RENDER_COLOURCHANGE = 1 << 17; // render() is allowed to call glColor*()
51 const unsigned int RENDER_TEXTURE = 1 << 18; // glEnable(GL_TEXTURE_2D)
52 const unsigned int RENDER_BUMP = 1 << 19;
53 const unsigned int RENDER_PROGRAM = 1 << 20;
54 const unsigned int RENDER_SCREEN = 1 << 21;
55 const unsigned int RENDER_OVERRIDE = 1 << 22;
56 typedef unsigned int RenderStateFlags;
57
58
59 class AABB;
60 class Matrix4;
61
62 template<typename Element> class BasicVector3;
63 typedef BasicVector3<float> Vector3;
64
65 class Shader;
66
67 class RendererLight
68 {
69 public:
70 virtual ~RendererLight(){}
71 virtual Shader* getShader() const = 0;
72 virtual const AABB& aabb() const = 0;
73 virtual bool testAABB( const AABB& other ) const = 0;
74 virtual const Matrix4& rotation() const = 0;
75 virtual const Vector3& offset() const = 0;
76 virtual const Vector3& colour() const = 0;
77 virtual bool isProjected() const = 0;
78 virtual const Matrix4& projection() const = 0;
79 };
80
81 class LightCullable
82 {
83 public:
84 virtual ~LightCullable(){}
85 virtual bool testLight( const RendererLight& light ) const = 0;
86 virtual void insertLight( const RendererLight& light ){
87 }
88 virtual void clearLights(){
89 }
90 };
91
92 class Renderable;
93 typedef Callback1<const Renderable&> RenderableCallback;
94
95 typedef Callback1<const RendererLight&> RendererLightCallback;
96
97 class LightList
98 {
99 public:
100 virtual ~LightList(){}
101 virtual void evaluateLights() const = 0;
102 virtual void lightsChanged() const = 0;
103 virtual void forEachLight( const RendererLightCallback& callback ) const = 0;
104 };
105
106 const int c_attr_TexCoord0 = 1;
107 const int c_attr_Tangent = 3;
108 const int c_attr_Binormal = 4;
109
110 class OpenGLRenderable
111 {
112 public:
113 virtual ~OpenGLRenderable(){}
114 virtual void render( RenderStateFlags state ) const = 0;
115 };
116
117 class Matrix4;
118 struct qtexture_t;
119 class ModuleObserver;
120
121 #include "generic/vector.h"
122
123 class Shader
124 {
125 public:
126 virtual ~Shader(){}
127 virtual void addRenderable( const OpenGLRenderable& renderable, const Matrix4& modelview, const LightList* lights = 0 ) = 0;
128 virtual void incrementUsed() = 0;
129 virtual void decrementUsed() = 0;
130 virtual void attach( ModuleObserver& observer ) = 0;
131 virtual void detach( ModuleObserver& observer ) = 0;
132 virtual qtexture_t& getTexture() const = 0;
133 virtual unsigned int getFlags() const = 0;
134 };
135
136 class ShaderCache
137 {
138 public:
139 INTEGER_CONSTANT( Version, 1 );
140 STRING_CONSTANT( Name, "renderstate" );
141
142 virtual ~ShaderCache(){}
143 virtual Shader* capture( const char* name ) = 0;
144 virtual void release( const char* name ) = 0;
145 /*! Render all Shader objects. */
146 virtual void render( RenderStateFlags globalstate, const Matrix4& modelview, const Matrix4& projection, const Vector3& viewer = Vector3( 0, 0, 0 ) ) = 0;
147
148 virtual void realise() = 0;
149 virtual void unrealise() = 0;
150
151 virtual bool lightingSupported() const = 0;
152 virtual bool useShaderLanguage() const = 0;
153
154 virtual const LightList& attach( LightCullable& cullable ) = 0;
155 virtual void detach( LightCullable& cullable ) = 0;
156 virtual void changed( LightCullable& cullable ) = 0;
157 virtual void attach( RendererLight& light ) = 0;
158 virtual void detach( RendererLight& light ) = 0;
159 virtual void changed( RendererLight& light ) = 0;
160
161 virtual void attachRenderable( const Renderable& renderable ) = 0;
162 virtual void detachRenderable( const Renderable& renderable ) = 0;
163 virtual void forEachRenderable( const RenderableCallback& callback ) const = 0;
164 };
165
166 #include "modulesystem.h"
167
168 template<typename Type>
169 class GlobalModule;
170 typedef GlobalModule<ShaderCache> GlobalShaderCacheModule;
171
172 template<typename Type>
173 class GlobalModuleRef;
174 typedef GlobalModuleRef<ShaderCache> GlobalShaderCacheModuleRef;
175
176 inline ShaderCache& GlobalShaderCache(){
177         return GlobalShaderCacheModule::getTable();
178 }
179
180 #endif