1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
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.
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.
28 #ifndef INCLUDED_RENDERMODIFIERS
29 #define INCLUDED_RENDERMODIFIERS
31 #include "ModelRenderer.h"
32 #include "graphics/ShaderProgram.h"
33 #include "graphics/ShaderTechnique.h"
34 #include "graphics/Texture.h"
42 * Class RenderModifier: Some ModelRenderer implementations provide vertex
43 * management behaviour but allow fragment stages to be modified by a plugged in
46 * You should use RenderModifierPtr when referencing RenderModifiers.
52 virtual ~RenderModifier() { }
55 * BeginPass: Setup OpenGL for the given rendering pass.
57 * Must be implemented by derived classes.
59 * @param pass The current pass number (pass == 0 is the first pass)
61 * @return The streamflags that indicate which vertex components
62 * are required by the fragment stages (see STREAM_XYZ constants).
64 virtual void BeginPass(const CShaderProgramPtr
& shader
) = 0;
67 * PrepareModel: Called before rendering the given model.
69 * Default behaviour does nothing.
71 * @param pass The current pass number (pass == 0 is the first pass)
72 * @param model The model that is about to be rendered.
74 virtual void PrepareModel(const CShaderProgramPtr
& shader
, CModel
* model
) = 0;
79 * Class LitRenderModifier: Abstract base class for RenderModifiers that apply
81 * LitRenderModifiers expect the diffuse brightness in the primary color (instead of ambient + diffuse).
83 class LitRenderModifier
: public RenderModifier
90 * SetShadowMap: Set the shadow map that will be used for rendering.
91 * Must be called by the user of the RenderModifier.
93 * The shadow map must be non-null and use depth texturing, or subsequent rendering
94 * using this RenderModifier will fail.
96 * @param shadow the shadow map
98 void SetShadowMap(const ShadowMap
* shadow
);
101 * SetLightEnv: Set the light environment that will be used for rendering.
102 * Must be called by the user of the RenderModifier.
104 * @param lightenv the light environment (must be non-null)
106 void SetLightEnv(const CLightEnv
* lightenv
);
108 const ShadowMap
* GetShadowMap() const { return m_Shadow
; }
109 const CLightEnv
* GetLightEnv() const { return m_LightEnv
; }
112 const ShadowMap
* m_Shadow
;
113 const CLightEnv
* m_LightEnv
;
117 * A RenderModifier that sets uniforms and textures appropriately for rendering models.
119 class ShaderRenderModifier
: public LitRenderModifier
122 ShaderRenderModifier();
125 void BeginPass(const CShaderProgramPtr
& shader
);
126 void PrepareModel(const CShaderProgramPtr
& shader
, CModel
* model
);
129 CShaderProgram::Binding m_BindingInstancingTransform
;
130 CShaderProgram::Binding m_BindingShadingColor
;
131 CShaderProgram::Binding m_BindingPlayerColor
;
134 #endif // INCLUDED_RENDERMODIFIERS