Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderModifiers.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * RenderModifiers can affect the fragment stage behaviour of some
20  * ModelRenderers. This file defines some common RenderModifiers in
21  * addition to the base class.
22  *
23  * TODO: See comment in CRendererInternals::Models - we no longer use multiple
24  * subclasses of RenderModifier, so most of the stuff here is unnecessary
25  * abstraction which should probably be cleaned up.
26  */
27 
28 #ifndef INCLUDED_RENDERMODIFIERS
29 #define INCLUDED_RENDERMODIFIERS
30 
31 #include "ModelRenderer.h"
33 #include "graphics/Texture.h"
34 
35 class CLightEnv;
36 class CMatrix3D;
37 class CModel;
38 class ShadowMap;
39 
40 /**
41  * Class RenderModifier: Some ModelRenderer implementations provide vertex
42  * management behaviour but allow fragment stages to be modified by a plugged in
43  * RenderModifier.
44  *
45  * You should use RenderModifierPtr when referencing RenderModifiers.
46  */
48 {
49 public:
51  virtual ~RenderModifier() { }
52 
53  /**
54  * BeginPass: Setup OpenGL for the given rendering pass.
55  *
56  * Must be implemented by derived classes.
57  *
58  * @param pass The current pass number (pass == 0 is the first pass)
59  *
60  * @return The streamflags that indicate which vertex components
61  * are required by the fragment stages (see STREAM_XYZ constants).
62  */
63  virtual void BeginPass(const CShaderProgramPtr& shader) = 0;
64 
65  /**
66  * PrepareModel: Called before rendering the given model.
67  *
68  * Default behaviour does nothing.
69  *
70  * @param pass The current pass number (pass == 0 is the first pass)
71  * @param model The model that is about to be rendered.
72  */
73  virtual void PrepareModel(const CShaderProgramPtr& shader, CModel* model) = 0;
74 };
75 
76 
77 /**
78  * Class LitRenderModifier: Abstract base class for RenderModifiers that apply
79  * a shadow map.
80  * LitRenderModifiers expect the diffuse brightness in the primary color (instead of ambient + diffuse).
81  */
83 {
84 public:
87 
88  /**
89  * SetShadowMap: Set the shadow map that will be used for rendering.
90  * Must be called by the user of the RenderModifier.
91  *
92  * The shadow map must be non-null and use depth texturing, or subsequent rendering
93  * using this RenderModifier will fail.
94  *
95  * @param shadow the shadow map
96  */
97  void SetShadowMap(const ShadowMap* shadow);
98 
99  /**
100  * SetLightEnv: Set the light environment that will be used for rendering.
101  * Must be called by the user of the RenderModifier.
102  *
103  * @param lightenv the light environment (must be non-null)
104  */
105  void SetLightEnv(const CLightEnv* lightenv);
106 
107  const ShadowMap* GetShadowMap() const { return m_Shadow; }
108  const CLightEnv* GetLightEnv() const { return m_LightEnv; }
109 
110 private:
113 };
114 
115 /**
116  * A RenderModifier that sets uniforms and textures appropriately for rendering models.
117  */
119 {
120 public:
122 
123  // Implementation
124  void BeginPass(const CShaderProgramPtr& shader);
125  void PrepareModel(const CShaderProgramPtr& shader, CModel* model);
126 
127 private:
131 };
132 
133 #endif // INCLUDED_RENDERMODIFIERS
CShaderProgram::Binding m_BindingShadingColor
void BeginPass(const CShaderProgramPtr &shader)
BeginPass: Setup OpenGL for the given rendering pass.
virtual ~RenderModifier()
virtual void PrepareModel(const CShaderProgramPtr &shader, CModel *model)=0
PrepareModel: Called before rendering the given model.
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations.
Definition: ShadowMap.h:39
const CLightEnv * GetLightEnv() const
const CLightEnv * m_LightEnv
void PrepareModel(const CShaderProgramPtr &shader, CModel *model)
PrepareModel: Called before rendering the given model.
void SetShadowMap(const ShadowMap *shadow)
SetShadowMap: Set the shadow map that will be used for rendering.
virtual void BeginPass(const CShaderProgramPtr &shader)=0
BeginPass: Setup OpenGL for the given rendering pass.
CShaderProgram::Binding m_BindingInstancingTransform
const ShadowMap * m_Shadow
A RenderModifier that sets uniforms and textures appropriately for rendering models.
Class RenderModifier: Some ModelRenderer implementations provide vertex management behaviour but allo...
void SetLightEnv(const CLightEnv *lightenv)
SetLightEnv: Set the light environment that will be used for rendering.
const ShadowMap * GetShadowMap() const
static size_t model
Definition: x86_x64.cpp:211
Represents a uniform attribute or texture binding.
Definition: Model.h:50
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:36
shared_ptr< CShaderProgram > CShaderProgramPtr
CShaderProgram::Binding m_BindingPlayerColor
Class LitRenderModifier: Abstract base class for RenderModifiers that apply a shadow map...