/src/ogre/Components/RTShaderSystem/include/OgreShaderRenderState.h
Line | Count | Source |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | | of this software and associated documentation files (the "Software"), to deal |
10 | | in the Software without restriction, including without limitation the rights |
11 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 | | copies of the Software, and to permit persons to whom the Software is |
13 | | furnished to do so, subject to the following conditions: |
14 | | |
15 | | The above copyright notice and this permission notice shall be included in |
16 | | all copies or substantial portions of the Software. |
17 | | |
18 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 | | THE SOFTWARE. |
25 | | ----------------------------------------------------------------------------- |
26 | | */ |
27 | | #ifndef _ShaderRenderState_ |
28 | | #define _ShaderRenderState_ |
29 | | |
30 | | #include "OgreShaderPrerequisites.h" |
31 | | #include "OgreShaderSubRenderState.h" |
32 | | #include "OgreShaderProgramSet.h" |
33 | | |
34 | | namespace Ogre { |
35 | | namespace RTShader { |
36 | | |
37 | | /** \addtogroup Optional |
38 | | * @{ |
39 | | */ |
40 | | /** \addtogroup RTShader |
41 | | * @{ |
42 | | */ |
43 | | |
44 | | /** This is a container class for sub render state class. |
45 | | A render state is defined by the sub render states that compose it. |
46 | | The user should use this interface to define global or per material custom behavior. |
47 | | I.E In order to apply per pixel to a specific material one should implement a sub class of SubRenderState that |
48 | | perform a per pixel lighting model, get the render state of the target material and add the custom sub class to it. |
49 | | */ |
50 | | class _OgreRTSSExport RenderState : public RTShaderSystemAlloc |
51 | | { |
52 | | |
53 | | // Interface. |
54 | | public: |
55 | | |
56 | | /** Class default constructor. */ |
57 | | RenderState(); |
58 | | |
59 | | /** Class destructor */ |
60 | | virtual ~RenderState(); |
61 | | |
62 | | /** Reset this render state */ |
63 | | void resetToBuiltinSubRenderStates(); |
64 | | |
65 | | /** Add a template sub render state to this render state. |
66 | | @param subRenderState The sub render state template to add. |
67 | | */ |
68 | | void addTemplateSubRenderState(SubRenderState* subRenderState); |
69 | | |
70 | | /// Add multiple template sub render states by SRS type |
71 | | void addTemplateSubRenderStates(const StringVector& srsTypes); |
72 | | |
73 | | /** Remove a sub render state from this render state. |
74 | | @param subRenderState The sub render state to remove. |
75 | | */ |
76 | | void removeSubRenderState(SubRenderState* subRenderState); |
77 | | |
78 | | /** Get the list of the sub render states composing this render state. */ |
79 | 0 | const SubRenderStateList& getSubRenderStates() const { return mSubRenderStateList; } |
80 | | |
81 | | /// get sub render state by type (uniquely identified) or NULL if not found |
82 | | SubRenderState* getSubRenderState(const String& type) const; |
83 | | |
84 | | /** |
85 | | Set the maximal light count to consider |
86 | | */ |
87 | 0 | void setLightCount(int32 lightCount) { mLightCount = lightCount;} |
88 | | |
89 | | /** |
90 | | Get the maximal light count to consider |
91 | | */ |
92 | 0 | int32 getLightCount() const { return mLightCount; } |
93 | | |
94 | | /** |
95 | | Set the light count auto update state. |
96 | | If the value is false the light count will remain static for the values that were set by the user. |
97 | | If the value is true the light count will be updated from the owner shader generator scheme based on current scene lights. |
98 | | The default is true. |
99 | | */ |
100 | 0 | void setLightCountAutoUpdate(bool autoUpdate) { mLightCountAutoUpdate = autoUpdate; } |
101 | | |
102 | | /** |
103 | | Return true if this render state override the light count. |
104 | | If light count is not overridden it will be updated from the shader generator based on current scene lights. |
105 | | */ |
106 | 0 | bool getLightCountAutoUpdate() const { return mLightCountAutoUpdate; } |
107 | | |
108 | 0 | bool haveAreaLights() const { return mHaveAreaLights; } |
109 | 0 | void setHaveAreaLights(bool val) { mHaveAreaLights = val; } |
110 | | |
111 | | |
112 | | // Attributes. |
113 | | protected: |
114 | | // The sub render states list. |
115 | | SubRenderStateList mSubRenderStateList; |
116 | | // The light count per light type definition. |
117 | | int32 mLightCount; |
118 | | // True if light count was explicitly set. |
119 | | bool mLightCountAutoUpdate; |
120 | | bool mHaveAreaLights; |
121 | | |
122 | | private: |
123 | | void clear(); |
124 | | friend class ProgramManager; |
125 | | }; |
126 | | |
127 | | /** This is the target render state. This class will hold the actual generated CPU/GPU programs. |
128 | | It will be initially build from the FFP state of a given Pass by the FFP builder and then will be linked |
129 | | with the custom pass render state and the global scheme render state. See ShaderGenerator::SGPass::buildTargetRenderState(). |
130 | | */ |
131 | | class _OgreRTSSExport TargetRenderState : public RenderState |
132 | | { |
133 | | |
134 | | // Interface. |
135 | | public: |
136 | | |
137 | | /** Class default constructor. */ |
138 | | TargetRenderState(); |
139 | | ~TargetRenderState(); |
140 | | |
141 | | /** Add the SubRenderStates of the given render state as templates to this render state. |
142 | | @note Only sub render states with non FFP execution order will be added. |
143 | | @param templateRS The other render state to use as a template. |
144 | | @param srcPass The source pass that this render state is constructed from. |
145 | | @param dstPass The destination pass that constructed from this render state. |
146 | | */ |
147 | | void link(const RenderState& templateRS, Pass* srcPass, Pass* dstPass); |
148 | | |
149 | | /** Add the SubRenderStates to this render state. |
150 | | */ |
151 | | void link(const StringVector& srsTypes, Pass* srcPass, Pass* dstPass); |
152 | | |
153 | | /** Update the GPU programs constant parameters before a renderable is rendered. |
154 | | @param rend The renderable object that is going to be rendered. |
155 | | @param pass The pass that is used to do the rendering operation. |
156 | | @param source The auto parameter auto source instance. |
157 | | @param pLightList The light list used for the current rendering operation. |
158 | | */ |
159 | | void updateGpuProgramsParams(Renderable* rend, const Pass* pass, const AutoParamDataSource* source, const LightList* pLightList); |
160 | | |
161 | | /** Add sub render state to this render state. |
162 | | @param subRenderState The sub render state to add. |
163 | | */ |
164 | | void addSubRenderStateInstance(SubRenderState* subRenderState); |
165 | | |
166 | | /** Acquire CPU/GPU programs set associated with the given render state and bind them to the pass. |
167 | | @param pass The pass to bind the programs to. |
168 | | */ |
169 | | void acquirePrograms(Pass* pass); |
170 | | |
171 | | /** Release CPU/GPU programs set associated with the given render state and pass. |
172 | | @param pass The pass to release the programs from. |
173 | | */ |
174 | | void releasePrograms(Pass* pass); |
175 | | |
176 | | /// Key name for associating with a Pass instance. |
177 | | static const char* UserKey; |
178 | | private: |
179 | | /** Bind the uniform parameters of a given CPU and GPU program set. */ |
180 | | static void bindUniformParameters(Program* pCpuProgram, const GpuProgramParametersSharedPtr& passParams); |
181 | | |
182 | | /** Sort the sub render states composing this render state. */ |
183 | | void sortSubRenderStates(); |
184 | | |
185 | | /** Create CPU programs that represent this render state. |
186 | | */ |
187 | | void createCpuPrograms(); |
188 | | |
189 | | /** Create the program set of this render state. |
190 | | */ |
191 | | ProgramSet* createProgramSet(); |
192 | | |
193 | | /** Return the program set of this render state. |
194 | | */ |
195 | 0 | ProgramSet* getProgramSet() { return mProgramSet.get(); } |
196 | | |
197 | | // Tells if the list of the sub render states is sorted. |
198 | | bool mSubRenderStateSortValid; |
199 | | // The program set of this RenderState. |
200 | | std::unique_ptr<ProgramSet> mProgramSet; |
201 | | Pass* mParent; |
202 | | |
203 | | private: |
204 | | friend class ProgramManager; |
205 | | }; |
206 | | |
207 | | typedef std::shared_ptr<TargetRenderState> TargetRenderStatePtr; |
208 | | |
209 | | /** @} */ |
210 | | /** @} */ |
211 | | |
212 | | } |
213 | | } |
214 | | |
215 | | #endif |
216 | | |