Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
RenderModifiers.h
Go to the documentation of this file.
1/* Copyright (C) 2022 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"
32#include "graphics/Color.h"
35#include "graphics/Texture.h"
36
37class CLightEnv;
38class CModel;
39class ShadowMap;
40
41/**
42 * Class RenderModifier: Some ModelRenderer implementations provide vertex
43 * management behaviour but allow fragment stages to be modified by a plugged in
44 * RenderModifier.
45 *
46 * You should use RenderModifierPtr when referencing RenderModifiers.
47 */
49{
50public:
52 virtual ~RenderModifier() { }
53
54 /**
55 * BeginPass: Setup OpenGL for the given rendering pass.
56 *
57 * Must be implemented by derived classes.
58 */
59 virtual void BeginPass(
60 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
62
63 /**
64 * PrepareModel: Called before rendering the given model.
65 *
66 * Default behaviour does nothing.
67 *
68 * @param model The model that is about to be rendered.
69 */
70 virtual void PrepareModel(
71 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
72 CModel* model) = 0;
73};
74
75
76/**
77 * Class LitRenderModifier: Abstract base class for RenderModifiers that apply
78 * a shadow map.
79 * LitRenderModifiers expect the diffuse brightness in the primary color (instead of ambient + diffuse).
80 */
82{
83public:
86
87 /**
88 * SetShadowMap: Set the shadow map that will be used for rendering.
89 * Must be called by the user of the RenderModifier.
90 *
91 * The shadow map must be non-null and use depth texturing, or subsequent rendering
92 * using this RenderModifier will fail.
93 *
94 * @param shadow the shadow map
95 */
96 void SetShadowMap(const ShadowMap* shadow);
97
98 /**
99 * SetLightEnv: Set the light environment that will be used for rendering.
100 * Must be called by the user of the RenderModifier.
101 *
102 * @param lightenv the light environment (must be non-null)
103 */
104 void SetLightEnv(const CLightEnv* lightenv);
105
106 const ShadowMap* GetShadowMap() const { return m_Shadow; }
107 const CLightEnv* GetLightEnv() const { return m_LightEnv; }
108
109private:
112};
113
114/**
115 * A RenderModifier that sets uniforms and textures appropriately for rendering models.
116 */
118{
119public:
121
122 // Implementation
123 void BeginPass(
124 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
125 Renderer::Backend::IShaderProgram* shader) override;
126 void PrepareModel(
127 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
128 CModel* model) override;
129
130private:
134
136};
137
138#endif // INCLUDED_RENDERMODIFIERS
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:37
Definition: Model.h:39
Class LitRenderModifier: Abstract base class for RenderModifiers that apply a shadow map.
Definition: RenderModifiers.h:82
const ShadowMap * m_Shadow
Definition: RenderModifiers.h:110
const CLightEnv * m_LightEnv
Definition: RenderModifiers.h:111
void SetLightEnv(const CLightEnv *lightenv)
SetLightEnv: Set the light environment that will be used for rendering.
Definition: RenderModifiers.cpp:55
LitRenderModifier()
Definition: RenderModifiers.cpp:39
const CLightEnv * GetLightEnv() const
Definition: RenderModifiers.h:107
void SetShadowMap(const ShadowMap *shadow)
SetShadowMap: Set the shadow map that will be used for rendering.
Definition: RenderModifiers.cpp:49
const ShadowMap * GetShadowMap() const
Definition: RenderModifiers.h:106
~LitRenderModifier()
Definition: RenderModifiers.cpp:44
Class RenderModifier: Some ModelRenderer implementations provide vertex management behaviour but allo...
Definition: RenderModifiers.h:49
virtual ~RenderModifier()
Definition: RenderModifiers.h:52
RenderModifier()
Definition: RenderModifiers.h:51
virtual void BeginPass(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IShaderProgram *shader)=0
BeginPass: Setup OpenGL for the given rendering pass.
virtual void PrepareModel(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, CModel *model)=0
PrepareModel: Called before rendering the given model.
Definition: IDeviceCommandContext.h:42
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:81
A RenderModifier that sets uniforms and textures appropriately for rendering models.
Definition: RenderModifiers.h:118
CColor m_PlayerColor
Definition: RenderModifiers.h:135
void BeginPass(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IShaderProgram *shader) override
BeginPass: Setup OpenGL for the given rendering pass.
Definition: RenderModifiers.cpp:68
int32_t m_BindingInstancingTransform
Definition: RenderModifiers.h:131
ShaderRenderModifier()
Definition: RenderModifiers.cpp:63
int32_t m_BindingPlayerColor
Definition: RenderModifiers.h:133
int32_t m_BindingShadingColor
Definition: RenderModifiers.h:132
CColor m_ShadingColor
Definition: RenderModifiers.h:135
void PrepareModel(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, CModel *model) override
PrepareModel: Called before rendering the given model.
Definition: RenderModifiers.cpp:133
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup,...
Definition: ShadowMap.h:39
Definition: Color.h:43