irender.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_IRENDER_H)
00023 #define INCLUDED_IRENDER_H
00024 
00025 #include <string>
00026 #include "generic/constant.h"
00027 #include "generic/callbackfwd.h"
00028 
00029 // Rendering states to sort by.
00030 // Higher bits have the most effect - slowest state changes should be highest.
00031 
00032 const unsigned int RENDER_DEFAULT = 0;
00033 const unsigned int RENDER_LINESTIPPLE = 1 << 0; // glEnable(GL_LINE_STIPPLE)
00034 const unsigned int RENDER_ALPHATEST = 1 << 4; // glEnable(GL_ALPHA_TEST)
00035 const unsigned int RENDER_DEPTHTEST = 1 << 5; // glEnable(GL_DEPTH_TEST)
00036 const unsigned int RENDER_DEPTHWRITE = 1 << 6; // glDepthMask(GL_TRUE)
00037 const unsigned int RENDER_COLOURWRITE = 1 << 7; // glColorMask(GL_TRUE; GL_TRUE; GL_TRUE; GL_TRUE)
00038 const unsigned int RENDER_CULLFACE = 1 << 8; // glglEnable(GL_CULL_FACE)
00039 const unsigned int RENDER_SCALED = 1 << 9; // glEnable(GL_NORMALIZE)
00040 const unsigned int RENDER_SMOOTH = 1 << 10; // glShadeModel
00041 const unsigned int RENDER_LIGHTING = 1 << 12; // glEnable(GL_LIGHTING)
00042 const unsigned int RENDER_BLEND = 1 << 13; // glEnable(GL_BLEND)
00043 const unsigned int RENDER_FILL = 1 << 15; // glPolygonMode
00044 const unsigned int RENDER_COLOURARRAY = 1 << 16; // glEnableClientState(GL_COLOR_ARRAY)
00045 const unsigned int RENDER_COLOURCHANGE = 1 << 17; // render() is allowed to call glColor*()
00046 const unsigned int RENDER_TEXTURE = 1 << 18; // glEnable(GL_TEXTURE_2D)
00047 const unsigned int RENDER_SCREEN = 1 << 21;
00048 const unsigned int RENDER_OVERRIDE = 1 << 22;
00049 typedef unsigned int RenderStateFlags;
00050 
00051 class AABB;
00052 class Matrix4;
00053 
00054 template<typename Element> class BasicVector3;
00055 typedef BasicVector3<float> Vector3;
00056 
00057 class Shader;
00058 
00063 class RendererLight
00064 {
00065     public:
00066         virtual ~RendererLight ()
00067         {
00068         }
00069         virtual Shader* getShader () const = 0;
00070         virtual const Vector3& colour () const = 0;
00071 };
00072 
00089 class LightCullable
00090 {
00091     public:
00092         virtual ~LightCullable ()
00093         {
00094         }
00095         virtual void insertLight (const RendererLight& light)
00096         {
00097         }
00098         virtual void clearLights ()
00099         {
00100         }
00101 };
00102 
00103 class Renderable;
00104 typedef Callback1<const Renderable&> RenderableCallback;
00105 
00106 typedef Callback1<const RendererLight&> RendererLightCallback;
00107 
00108 class LightList
00109 {
00110     public:
00111         virtual ~LightList ()
00112         {
00113         }
00114         virtual void evaluateLights () const = 0;
00115         virtual void lightsChanged () const = 0;
00116         virtual void forEachLight (const RendererLightCallback& callback) const = 0;
00117 };
00118 
00119 const int c_attr_TexCoord0 = 1;
00120 const int c_attr_Tangent = 3;
00121 const int c_attr_Binormal = 4;
00122 
00135 class OpenGLRenderable
00136 {
00137     public:
00138         virtual ~OpenGLRenderable ()
00139         {
00140         }
00145         virtual void render (RenderStateFlags state) const = 0;
00146 };
00147 
00148 class Matrix4;
00149 struct qtexture_t;
00150 class ModuleObserver;
00151 
00152 #include "math/Vector3.h"
00153 
00163 class Shader
00164 {
00165     public:
00166         virtual ~Shader ()
00167         {
00168         }
00169         virtual void addRenderable (const OpenGLRenderable& renderable, const Matrix4& modelview,
00170                 const LightList* lights = 0) = 0;
00171         virtual void incrementUsed () = 0;
00172         virtual void decrementUsed () = 0;
00173         virtual void attach (ModuleObserver& observer) = 0;
00174         virtual void detach (ModuleObserver& observer) = 0;
00175         virtual qtexture_t& getTexture () const = 0;
00176         virtual unsigned int getFlags () const = 0;
00177 };
00178 
00179 class ShaderCache
00180 {
00181     public:
00182         INTEGER_CONSTANT(Version, 1);
00183         STRING_CONSTANT(Name, "renderstate");
00184 
00185         virtual ~ShaderCache ()
00186         {
00187         }
00188 
00200         virtual Shader* capture (const std::string& name) = 0;
00201 
00209         virtual void release (const std::string& name) = 0;
00210 
00212         virtual void render (RenderStateFlags globalstate, const Matrix4& modelview, const Matrix4& projection,
00213                 const Vector3& viewer = Vector3(0, 0, 0)) = 0;
00214 
00215         virtual void realise () = 0;
00216         virtual void unrealise () = 0;
00217 
00218         virtual const LightList& attach (LightCullable& cullable) = 0;
00219         virtual void detach (LightCullable& cullable) = 0;
00220         virtual void changed (LightCullable& cullable) = 0;
00221         virtual void attach (RendererLight& light) = 0;
00222         virtual void detach (RendererLight& light) = 0;
00223         virtual void changed (RendererLight& light) = 0;
00224 
00225         virtual void attachRenderable (const Renderable& renderable) = 0;
00226         virtual void detachRenderable (const Renderable& renderable) = 0;
00227         virtual void forEachRenderable (const RenderableCallback& callback) const = 0;
00228 };
00229 
00230 #include "modulesystem.h"
00231 
00232 template<typename Type>
00233 class GlobalModule;
00234 typedef GlobalModule<ShaderCache> GlobalShaderCacheModule;
00235 
00236 template<typename Type>
00237 class GlobalModuleRef;
00238 typedef GlobalModuleRef<ShaderCache> GlobalShaderCacheModuleRef;
00239 
00240 inline ShaderCache& GlobalShaderCache ()
00241 {
00242     return GlobalShaderCacheModule::getTable();
00243 }
00244 
00245 #endif

Generated by  doxygen 1.6.2