/src/ogre/Components/RTShaderSystem/include/OgreShaderProgram.h
Line | Count | Source (jump to first uncovered line) |
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 _ShaderProgram_ |
28 | | #define _ShaderProgram_ |
29 | | |
30 | | #include "OgreShaderPrerequisites.h" |
31 | | #include "OgreGpuProgram.h" |
32 | | #include "OgreSingleton.h" |
33 | | #include "OgreShaderFunction.h" |
34 | | #include "OgreStringVector.h" |
35 | | |
36 | | namespace Ogre { |
37 | | namespace RTShader { |
38 | | |
39 | | /** \addtogroup Optional |
40 | | * @{ |
41 | | */ |
42 | | /** \addtogroup RTShader |
43 | | * @{ |
44 | | */ |
45 | | |
46 | | /** A class that represents a shader based program. |
47 | | */ |
48 | | class _OgreRTSSExport Program : public RTShaderSystemAlloc |
49 | | { |
50 | | |
51 | | // Interface. |
52 | | public: |
53 | | /** Get the type of this program. */ |
54 | | GpuProgramType getType() const; |
55 | | |
56 | | /** Resolve uniform auto constant parameter with associated real data of this program. |
57 | | @param autoType The auto type of the desired parameter. |
58 | | @param data The data to associate with the auto parameter. |
59 | | @param size number of elements in the parameter. |
60 | | @return parameter instance in case of that resolve operation succeeded. |
61 | | */ |
62 | | UniformParameterPtr resolveAutoParameterReal(GpuProgramParameters::AutoConstantType autoType, Real data, size_t size = 0); |
63 | | |
64 | | /** Resolve uniform auto constant parameter with associated real data of this program. |
65 | | @param autoType The auto type of the desired parameter. |
66 | | @param type The desired data type of the auto parameter. |
67 | | @param data The data to associate with the auto parameter. |
68 | | @param size number of elements in the parameter. |
69 | | @return parameter instance in case of that resolve operation succeeded. |
70 | | */ |
71 | | UniformParameterPtr resolveAutoParameterReal(GpuProgramParameters::AutoConstantType autoType, GpuConstantType type, float data, size_t size = 0); |
72 | | |
73 | | /** Resolve uniform auto constant parameter with associated int data of this program. |
74 | | @param autoType The auto type of the desired parameter. |
75 | | @param type The desired data type of the auto parameter. |
76 | | @param data The data to associate with the auto parameter. |
77 | | @param size number of elements in the parameter. |
78 | | @return parameter instance in case of that resolve operation succeeded. |
79 | | */ |
80 | | UniformParameterPtr resolveAutoParameterInt(GpuProgramParameters::AutoConstantType autoType, GpuConstantType type, uint32 data, size_t size = 0); |
81 | | |
82 | | /** Resolve uniform parameter of this program. |
83 | | @param type The type of the desired parameter. |
84 | | @param index The index of the desired parameter. |
85 | | @param suggestedName The suggested name for the parameter in case new one should be create. |
86 | | @param variability How this parameter varies (bitwise combination of GpuProgramVariability). |
87 | | @param size number of elements in the parameter. |
88 | | @return parameter instance in case of that resolve operation succeeded. |
89 | | @remarks Pass -1 as index parameter to create a new parameter with the desired type and index. |
90 | | */ |
91 | | UniformParameterPtr resolveParameter(GpuConstantType type, int index, uint16 variability, const String& suggestedName, size_t size = 0); |
92 | | |
93 | | /// @overload |
94 | | UniformParameterPtr resolveParameter(GpuConstantType type, const String& name, int index = -1) |
95 | 0 | { |
96 | 0 | return resolveParameter(type, index, GPV_GLOBAL, name); |
97 | 0 | } |
98 | | |
99 | | /** Resolve uniform auto constant parameter |
100 | | @param autoType The auto type of the desired parameter |
101 | | @param data The data to associate with the auto parameter. |
102 | | @return parameter instance in case of that resolve operation succeeded. |
103 | | */ |
104 | | UniformParameterPtr resolveParameter(GpuProgramParameters::AutoConstantType autoType, uint32 data = 0); |
105 | | |
106 | | /** Get parameter by a given name. |
107 | | @param name The name of the parameter to search for. |
108 | | @remarks Return NULL if no matching parameter found. |
109 | | */ |
110 | | UniformParameterPtr getParameterByName(const String& name); |
111 | | |
112 | | /** Get parameter by a given auto constant type. |
113 | | @param autoType The auto type of the parameter to search for. |
114 | | @remarks Return NULL if no matching parameter found. |
115 | | */ |
116 | | UniformParameterPtr getParameterByAutoType(GpuProgramParameters::AutoConstantType autoType); |
117 | | |
118 | | /** Get parameter by a given type and index. |
119 | | @param type The type of the parameter to search for. |
120 | | @param index The index of the parameter to search for. |
121 | | @remarks Return NULL if no matching parameter found. |
122 | | */ |
123 | | UniformParameterPtr getParameterByType(GpuConstantType type, int index); |
124 | | |
125 | | /** Get the list of uniform parameters of this program. |
126 | | */ |
127 | 0 | const UniformParameterList& getParameters() const { return mParameters; }; |
128 | | |
129 | | /// @deprecated use getMain() |
130 | 0 | Function* getEntryPointFunction() { return mEntryPointFunction; } |
131 | | |
132 | 0 | Function* getMain() { return mEntryPointFunction; } |
133 | | |
134 | | /** Add dependency for this program. Basically a filename that will be included in this |
135 | | program and provide predefined shader functions code. |
136 | | One should verify that the given library file he provides can be reached by the resource manager. |
137 | | This step can be achieved using the ResourceGroupManager::addResourceLocation method. |
138 | | */ |
139 | | void addDependency(const String& libFileName); |
140 | | |
141 | | /** Get the number of external libs this program depends on */ |
142 | | size_t getDependencyCount() const; |
143 | | |
144 | | /** Get the library name of the given index dependency. |
145 | | @param index The index of the dependecy. |
146 | | */ |
147 | | const String& getDependency(unsigned int index) const; |
148 | | |
149 | | /// @copydoc GpuProgram::setSkeletalAnimationIncluded |
150 | 0 | void setSkeletalAnimationIncluded(bool value) { mSkeletalAnimation = value; } |
151 | | |
152 | | /// @copydoc GpuProgram::isSkeletalAnimationIncluded |
153 | 0 | bool getSkeletalAnimationIncluded() const { return mSkeletalAnimation; } |
154 | | |
155 | | /// @copydoc GpuProgram::setInstancingIncluded |
156 | 0 | void setInstancingIncluded(bool included) { mInstancing = included; } |
157 | | |
158 | | /// @copydoc GpuProgram::isInstancingIncluded |
159 | 0 | bool getInstancingIncluded(void) const { return mInstancing; } |
160 | | |
161 | | /** Tells Ogre whether auto-bound matrices should be sent in column or row-major order. |
162 | | |
163 | | This method has the same effect as column_major_matrices option used when declaring manually written hlsl program. |
164 | | You want to use this method only when you use float3x4 type in a shader, e.g. for bone matrices. |
165 | | In mentioned case you should call this method with false as parameter. |
166 | | @par |
167 | | For more detail see OGRE Manual, section <b>3.1.6 DirectX9 HLSL</b>. |
168 | | @note |
169 | | This setting has any effect only when the target language is HLSL. |
170 | | @param value Should Ogre pass auto-bound matrices as column-major? The default is true. |
171 | | */ |
172 | 0 | void setUseColumnMajorMatrices(bool value) { mColumnMajorMatrices = value; } |
173 | | |
174 | | /** Returns whether Ogre will pass auto-bound matrices as column-major. |
175 | | @return |
176 | | true, when the matrices will be passed in column-major order, false, when they will be passed as row-major. |
177 | | */ |
178 | 0 | bool getUseColumnMajorMatrices() const { return mColumnMajorMatrices; } |
179 | | |
180 | | void addPreprocessorDefines(const String& defines); |
181 | | |
182 | 0 | const String& getPreprocessorDefines() const { return mPreprocessorDefines; } |
183 | | |
184 | | /** Class destructor */ |
185 | | ~Program(); |
186 | | // Protected methods. |
187 | | private: |
188 | | |
189 | | /** Class constructor. |
190 | | @param type The type of this program. |
191 | | */ |
192 | | Program(GpuProgramType type); |
193 | | |
194 | | /** Destroy all parameters of this program. */ |
195 | | void destroyParameters(); |
196 | | |
197 | | /** Add parameter to this program. */ |
198 | | void addParameter(UniformParameterPtr parameter); |
199 | | |
200 | | /** Remove parameter from this program. */ |
201 | | void removeParameter(UniformParameterPtr parameter); |
202 | | |
203 | | // Program type. (Vertex, Fragment, Geometry). |
204 | | GpuProgramType mType; |
205 | | // Program uniform parameters. |
206 | | UniformParameterList mParameters; |
207 | | // Entry point function for this program. |
208 | | Function* mEntryPointFunction; |
209 | | // Program dependencies. |
210 | | StringVector mDependencies; |
211 | | /// preprocessor definitions |
212 | | String mPreprocessorDefines; |
213 | | // Skeletal animation calculation |
214 | | bool mSkeletalAnimation; |
215 | | // Whether to pass matrices as column-major. |
216 | | bool mColumnMajorMatrices; |
217 | | bool mInstancing; |
218 | | friend class TargetRenderState; |
219 | | }; |
220 | | |
221 | | /** @} */ |
222 | | /** @} */ |
223 | | |
224 | | } |
225 | | } |
226 | | |
227 | | #endif |
228 | | |