1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __GpuProgram_H_
|
---|
26 | #define __GpuProgram_H_
|
---|
27 |
|
---|
28 | // Precompiler options
|
---|
29 | #include "OgrePrerequisites.h"
|
---|
30 | #include "OgreResource.h"
|
---|
31 | #include "OgreSharedPtr.h"
|
---|
32 | #include "OgreIteratorWrappers.h"
|
---|
33 |
|
---|
34 | namespace Ogre {
|
---|
35 |
|
---|
36 | /** Enumerates the types of programs which can run on the GPU. */
|
---|
37 | enum GpuProgramType
|
---|
38 | {
|
---|
39 | GPT_VERTEX_PROGRAM,
|
---|
40 | GPT_FRAGMENT_PROGRAM
|
---|
41 | };
|
---|
42 |
|
---|
43 |
|
---|
44 | /** Collects together the program parameters used for a GpuProgram.
|
---|
45 | @remarks
|
---|
46 | Gpu program state includes constant parameters used by the program, and
|
---|
47 | bindings to render system state which is propagated into the constants
|
---|
48 | by the engine automatically if requested.
|
---|
49 | @par
|
---|
50 | GpuProgramParameters objects should be created through the GpuProgramManager and
|
---|
51 | may be shared between multiple GpuProgram instances. For this reason they
|
---|
52 | are managed using a shared pointer, which will ensure they are automatically
|
---|
53 | deleted when no program is using them anymore.
|
---|
54 | */
|
---|
55 | class _OgreExport GpuProgramParameters
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | /** Defines the types of automatically updated values that may be bound to GpuProgram
|
---|
59 | parameters, or used to modify parameters on a per-object basis.
|
---|
60 | */
|
---|
61 | enum AutoConstantType
|
---|
62 | {
|
---|
63 | /// The current world matrix
|
---|
64 | ACT_WORLD_MATRIX,
|
---|
65 | /// The current array of world matrices, as a 3x4 matrix, used for blending
|
---|
66 | ACT_WORLD_MATRIX_ARRAY_3x4,
|
---|
67 | /// The current array of world matrices, used for blending
|
---|
68 | ACT_WORLD_MATRIX_ARRAY,
|
---|
69 | /// The current view matrix
|
---|
70 | ACT_VIEW_MATRIX,
|
---|
71 | /// The current projection matrix
|
---|
72 | ACT_PROJECTION_MATRIX,
|
---|
73 | /// The current view & projection matrices concatenated
|
---|
74 | ACT_VIEWPROJ_MATRIX,
|
---|
75 | /// The current world & view matrices concatenated
|
---|
76 | ACT_WORLDVIEW_MATRIX,
|
---|
77 | /// The current world, view & projection matrices concatenated
|
---|
78 | ACT_WORLDVIEWPROJ_MATRIX,
|
---|
79 | /// The current world matrix, inverted
|
---|
80 | ACT_INVERSE_WORLD_MATRIX,
|
---|
81 | /// The current view matrix, inverted
|
---|
82 | ACT_INVERSE_VIEW_MATRIX,
|
---|
83 | /// The current world & view matrices concatenated, then inverted
|
---|
84 | ACT_INVERSE_WORLDVIEW_MATRIX,
|
---|
85 | /// The current world matrix, inverted & transposed
|
---|
86 | ACT_INVERSETRANSPOSE_WORLD_MATRIX,
|
---|
87 | /// The current world & view matrices concatenated, then inverted & tranposed
|
---|
88 | ACT_INVERSETRANSPOSE_WORLDVIEW_MATRIX,
|
---|
89 | /// Light diffuse colour (index determined by setAutoConstant call)
|
---|
90 | ACT_LIGHT_DIFFUSE_COLOUR,
|
---|
91 | /// Light diffuse colour (index determined by setAutoConstant call)
|
---|
92 | ACT_LIGHT_SPECULAR_COLOUR,
|
---|
93 | /// Light attenuation parameters, Vector4(range, constant, linear, quadric)
|
---|
94 | ACT_LIGHT_ATTENUATION,
|
---|
95 | /// A light position in world space (index determined by setAutoConstant call)
|
---|
96 | ACT_LIGHT_POSITION,
|
---|
97 | /// A light direction in world space (index determined by setAutoConstant call)
|
---|
98 | ACT_LIGHT_DIRECTION,
|
---|
99 | /// A light position in object space (index determined by setAutoConstant call)
|
---|
100 | ACT_LIGHT_POSITION_OBJECT_SPACE,
|
---|
101 | /// A light direction in object space (index determined by setAutoConstant call)
|
---|
102 | ACT_LIGHT_DIRECTION_OBJECT_SPACE,
|
---|
103 | /** The distance of the light from the center of the object
|
---|
104 | a useful approximation as an alternative to per-vertex distance
|
---|
105 | calculations.
|
---|
106 | */
|
---|
107 | ACT_LIGHT_DISTANCE_OBJECT_SPACE,
|
---|
108 | /** The distance a shadow volume should be extruded when using
|
---|
109 | finite extrusion programs.
|
---|
110 | */
|
---|
111 | ACT_SHADOW_EXTRUSION_DISTANCE,
|
---|
112 | /// The current camera's position in object space
|
---|
113 | ACT_CAMERA_POSITION_OBJECT_SPACE,
|
---|
114 | /// The ambient light colour set in the scene
|
---|
115 | ACT_AMBIENT_LIGHT_COLOUR,
|
---|
116 | /// The view/projection matrix of the assigned texture projection frustum
|
---|
117 | ACT_TEXTURE_VIEWPROJ_MATRIX,
|
---|
118 | /// A custom parameter which will come from the renderable, using 'data' as the identifier
|
---|
119 | ACT_CUSTOM,
|
---|
120 | /// The current camera's position in world space
|
---|
121 | ACT_CAMERA_POSITION,
|
---|
122 | ACT_TIME,
|
---|
123 | /** Single float value, which repeats itself based on given as
|
---|
124 | parameter "cycle time". Equivalent to RenderMonkey's "Time0_X".
|
---|
125 | */
|
---|
126 | ACT_TIME_0_X,
|
---|
127 | /// Cosine of "Time0_X". Equivalent to RenderMonkey's "CosTime0_X".
|
---|
128 | ACT_COSTIME_0_X,
|
---|
129 | /// Sine of "Time0_X". Equivalent to RenderMonkey's "SinTime0_X".
|
---|
130 | ACT_SINTIME_0_X,
|
---|
131 | /// Tangent of "Time0_X". Equivalent to RenderMonkey's "TanTime0_X".
|
---|
132 | ACT_TANTIME_0_X,
|
---|
133 | /** Vector of "Time0_X", "SinTime0_X", "CosTime0_X",
|
---|
134 | "TanTime0_X". Equivalent to RenderMonkey's "Time0_X_Packed".
|
---|
135 | */
|
---|
136 | ACT_TIME_0_X_PACKED,
|
---|
137 | /** Single float value, which represents scaled time value [0..1],
|
---|
138 | which repeats itself based on given as parameter "cycle time".
|
---|
139 | Equivalent to RenderMonkey's "Time0_1".
|
---|
140 | */
|
---|
141 | ACT_TIME_0_1,
|
---|
142 | /// Cosine of "Time0_1". Equivalent to RenderMonkey's "CosTime0_1".
|
---|
143 | ACT_COSTIME_0_1,
|
---|
144 | /// Sine of "Time0_1". Equivalent to RenderMonkey's "SinTime0_1".
|
---|
145 | ACT_SINTIME_0_1,
|
---|
146 | /// Tangent of "Time0_1". Equivalent to RenderMonkey's "TanTime0_1".
|
---|
147 | ACT_TANTIME_0_1,
|
---|
148 | /** Vector of "Time0_1", "SinTime0_1", "CosTime0_1",
|
---|
149 | "TanTime0_1". Equivalent to RenderMonkey's "Time0_1_Packed".
|
---|
150 | */
|
---|
151 | ACT_TIME_0_1_PACKED,
|
---|
152 | /** Single float value, which represents scaled time value [0..2*Pi],
|
---|
153 | which repeats itself based on given as parameter "cycle time".
|
---|
154 | Equivalent to RenderMonkey's "Time0_2PI".
|
---|
155 | */
|
---|
156 | ACT_TIME_0_2PI,
|
---|
157 | /// Cosine of "Time0_2PI". Equivalent to RenderMonkey's "CosTime0_2PI".
|
---|
158 | ACT_COSTIME_0_2PI,
|
---|
159 | /// Sine of "Time0_2PI". Equivalent to RenderMonkey's "SinTime0_2PI".
|
---|
160 | ACT_SINTIME_0_2PI,
|
---|
161 | /// Tangent of "Time0_2PI". Equivalent to RenderMonkey's "TanTime0_2PI".
|
---|
162 | ACT_TANTIME_0_2PI,
|
---|
163 | /** Vector of "Time0_2PI", "SinTime0_2PI", "CosTime0_2PI",
|
---|
164 | "TanTime0_2PI". Equivalent to RenderMonkey's "Time0_2PI_Packed".
|
---|
165 | */
|
---|
166 | ACT_TIME_0_2PI_PACKED,
|
---|
167 | /// provides the calculated frames per second, returned as a floating point value.
|
---|
168 | ACT_FPS,
|
---|
169 | /// viewport-related values
|
---|
170 | /** Current viewport width (in pixels) as floating point value.
|
---|
171 | Equivalent to RenderMonkey's "ViewportWidth".
|
---|
172 | */
|
---|
173 | ACT_VIEWPORT_WIDTH,
|
---|
174 | /** Current viewport height (in pixels) as floating point value.
|
---|
175 | Equivalent to RenderMonkey's "ViewportHeight".
|
---|
176 | */
|
---|
177 | ACT_VIEWPORT_HEIGHT,
|
---|
178 | /** This variable represents 1.0/ViewportWidth.
|
---|
179 | Equivalent to RenderMonkey's "ViewportWidthInverse".
|
---|
180 | */
|
---|
181 | ACT_INVERSE_VIEWPORT_WIDTH,
|
---|
182 | /** This variable represents 1.0/ViewportHeight.
|
---|
183 | Equivalent to RenderMonkey's "ViewportHeightInverse".
|
---|
184 | */
|
---|
185 | ACT_INVERSE_VIEWPORT_HEIGHT,
|
---|
186 |
|
---|
187 | /// view parameters
|
---|
188 | /** This variable provides the view direction vector (world space).
|
---|
189 | Equivalent to RenderMonkey's "ViewDirection".
|
---|
190 | */
|
---|
191 | ACT_VIEW_DIRECTION,
|
---|
192 | /** This variable provides the view side vector (world space).
|
---|
193 | Equivalent to RenderMonkey's "ViewSideVector".
|
---|
194 | */
|
---|
195 | ACT_VIEW_SIDE_VECTOR,
|
---|
196 | /** This variable provides the view up vector (world space).
|
---|
197 | Equivalent to RenderMonkey's "ViewUpVector".
|
---|
198 | */
|
---|
199 | ACT_VIEW_UP_VECTOR,
|
---|
200 | /** This variable provides the field of view as a floating point value.
|
---|
201 | Equivalent to RenderMonkey's "FOV".
|
---|
202 | */
|
---|
203 | ACT_FOV,
|
---|
204 | /** This variable provides the near clip distance as a floating point value.
|
---|
205 | Equivalent to RenderMonkey's "NearClipPlane".
|
---|
206 | */
|
---|
207 | ACT_NEAR_CLIP_DISTANCE,
|
---|
208 | /** This variable provides the far clip distance as a floating point value.
|
---|
209 | Equivalent to RenderMonkey's "FarClipPlane".
|
---|
210 | */
|
---|
211 | ACT_FAR_CLIP_DISTANCE,
|
---|
212 |
|
---|
213 | /// view matrices.
|
---|
214 | /** Provides inverse of concatenated view and projection matrices.
|
---|
215 | Equivalent to RenderMonkey's "ViewProjectionInverse".
|
---|
216 | */
|
---|
217 | ACT_INVERSE_VIEWPROJ_MATRIX,
|
---|
218 | /** Provides inverse transpose of concatenated view and projection matrices.
|
---|
219 | Equivalent to RenderMonkey's "ViewProjectionInverseTranspose".
|
---|
220 | */
|
---|
221 | ACT_INVERSETRANSPOSE_VIEWPROJ_MATRIX,
|
---|
222 | /** Provides transpose of concatenated view and projection matrices.
|
---|
223 | Equivalent to RenderMonkey's "ViewProjectionTranspose".
|
---|
224 | */
|
---|
225 | ACT_TRANSPOSE_VIEWPROJ_MATRIX,
|
---|
226 |
|
---|
227 | /** Provides transpose of view matrix.
|
---|
228 | Equivalent to RenderMonkey's "ViewTranspose".
|
---|
229 | */
|
---|
230 | ACT_TRANSPOSE_VIEW_MATRIX,
|
---|
231 | /** Provides inverse transpose of view matrix.
|
---|
232 | Equivalent to RenderMonkey's "ViewInverseTranspose".
|
---|
233 | */
|
---|
234 | ACT_INVERSETRANSPOSE_VIEW_MATRIX,
|
---|
235 |
|
---|
236 | /** Provides transpose of projection matrix.
|
---|
237 | Equivalent to RenderMonkey's "ProjectionTranspose".
|
---|
238 | */
|
---|
239 | ACT_TRANSPOSE_PROJECTION_MATRIX,
|
---|
240 | /** Provides inverse of projection matrix.
|
---|
241 | Equivalent to RenderMonkey's "ProjectionInverse".
|
---|
242 | */
|
---|
243 | ACT_INVERSE_PROJECTION_MATRIX,
|
---|
244 | /** Provides inverse transpose of projection matrix.
|
---|
245 | Equivalent to RenderMonkey's "ProjectionInverseTranspose".
|
---|
246 | */
|
---|
247 | ACT_INVERSETRANSPOSE_PROJECTION_MATRIX,
|
---|
248 |
|
---|
249 | /** Provides transpose of concatenated world, view and projection matrices.
|
---|
250 | Equivalent to RenderMonkey's "WorldViewProjectionTranspose".
|
---|
251 | */
|
---|
252 | ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
|
---|
253 | /** Provides inverse of concatenated world, view and projection matrices.
|
---|
254 | Equivalent to RenderMonkey's "WorldViewProjectionInverse".
|
---|
255 | */
|
---|
256 | ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
|
---|
257 | /** Provides inverse transpose of concatenated world, view and projection
|
---|
258 | matrices. Equivalent to RenderMonkey's "WorldViewProjectionInverseTranspose".
|
---|
259 | */
|
---|
260 | ACT_INVERSETRANSPOSE_WORLDVIEWPROJ_MATRIX,
|
---|
261 |
|
---|
262 | /** Provides transpose of concatenated world and view matrices.
|
---|
263 | Equivalent to RenderMonkey's "WorldViewTranspose".
|
---|
264 | */
|
---|
265 | ACT_TRANSPOSE_WORLDVIEW_MATRIX,
|
---|
266 | /** Provides inverse transpose of concatenate world and view matrices.
|
---|
267 | Equivalent to RenderMonkey's "WorldViewInverseTranspose".
|
---|
268 | */
|
---|
269 | ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
|
---|
270 |
|
---|
271 | /** Provides transpose of world matrix.
|
---|
272 | Equivalent to RenderMonkey's "WorldTranspose".
|
---|
273 | */
|
---|
274 | ACT_TRANSPOSE_WORLD_MATRIX,
|
---|
275 | /** Provides inverse transpose of world matrix.
|
---|
276 | Equivalent to RenderMonkey's "WorldInverseTranspose".
|
---|
277 | */
|
---|
278 | ACT_INVERSE_TRANSPOSE_WORLD_MATRIX
|
---|
279 |
|
---|
280 | };
|
---|
281 | /** Structure recording the use of an automatic parameter. */
|
---|
282 | class _OgrePrivate AutoConstantEntry
|
---|
283 | {
|
---|
284 | public:
|
---|
285 | /// The type of parameter
|
---|
286 | AutoConstantType paramType;
|
---|
287 | /// The target constant index
|
---|
288 | size_t index;
|
---|
289 | /// Additional information to go with the parameter
|
---|
290 | union{
|
---|
291 | size_t data;
|
---|
292 | Real fData;
|
---|
293 | };
|
---|
294 |
|
---|
295 | AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData)
|
---|
296 | : paramType(theType), index(theIndex), data(theData) {}
|
---|
297 |
|
---|
298 | AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData)
|
---|
299 | : paramType(theType), index(theIndex), fData(theData) {}
|
---|
300 |
|
---|
301 | };
|
---|
302 | /** Real parameter entry; contains both a group of 4 values and
|
---|
303 | an indicator to say if it's been set or not. This allows us to
|
---|
304 | filter out constant entries which have not been set by the renderer
|
---|
305 | and may actually be being used internally by the program. */
|
---|
306 | struct RealConstantEntry
|
---|
307 | {
|
---|
308 | float val[4];
|
---|
309 | bool isSet;
|
---|
310 | RealConstantEntry() : isSet(false) {}
|
---|
311 | };
|
---|
312 | /** Int parameter entry; contains both a group of 4 values and
|
---|
313 | an indicator to say if it's been set or not. This allows us to
|
---|
314 | filter out constant entries which have not been set by the renderer
|
---|
315 | and may actually be being used internally by the program. */
|
---|
316 | struct IntConstantEntry
|
---|
317 | {
|
---|
318 | int val[4];
|
---|
319 | bool isSet;
|
---|
320 | IntConstantEntry() : isSet(false) {}
|
---|
321 | };
|
---|
322 | protected:
|
---|
323 | // Constant lists
|
---|
324 | typedef std::vector<RealConstantEntry> RealConstantList;
|
---|
325 | typedef std::vector<IntConstantEntry> IntConstantList;
|
---|
326 | // Auto parameter storage
|
---|
327 | typedef std::vector<AutoConstantEntry> AutoConstantList;
|
---|
328 | /// Packed list of floating-point constants
|
---|
329 | RealConstantList mRealConstants;
|
---|
330 | /// Packed list of integer constants
|
---|
331 | IntConstantList mIntConstants;
|
---|
332 | /// List of automatically updated parameters
|
---|
333 | AutoConstantList mAutoConstants;
|
---|
334 | /// Mapping from parameter names to indexes - high-level programs are expected to populate this
|
---|
335 | typedef std::map<String, size_t> ParamNameMap;
|
---|
336 | ParamNameMap mParamNameMap;
|
---|
337 | /// Do we need to transpose matrices?
|
---|
338 | bool mTransposeMatrices;
|
---|
339 | /// flag to indicate if names not found will be automatically added
|
---|
340 | bool mAutoAddParamName;
|
---|
341 |
|
---|
342 | public:
|
---|
343 | GpuProgramParameters();
|
---|
344 | ~GpuProgramParameters() {}
|
---|
345 |
|
---|
346 | /** Sets a 4-element floating-point parameter to the program.
|
---|
347 | @param index The constant index at which to place the parameter (each constant is
|
---|
348 | a 4D float)
|
---|
349 | @param vec The value to set
|
---|
350 | */
|
---|
351 | void setConstant(size_t index, const Vector4& vec);
|
---|
352 | /** Sets a single floating-point parameter to the program.
|
---|
353 | @note This is actually equivalent to calling
|
---|
354 | setConstant(index Vector4(val, 0, 0, 0)) since all constants are 4D.
|
---|
355 | @param index The constant index at which to place the parameter (each constant is
|
---|
356 | a 4D float)
|
---|
357 | @param val The value to set
|
---|
358 | */
|
---|
359 | void setConstant(size_t index, Real val);
|
---|
360 | /** Sets a 4-element floating-point parameter to the program via Vector3.
|
---|
361 | @param index The constant index at which to place the parameter (each constant is
|
---|
362 | a 4D float).
|
---|
363 | Note that since you're passing a Vector3, the last element of the 4-element
|
---|
364 | value will be set to 1 (a homogenous vector)
|
---|
365 | @param vec The value to set
|
---|
366 | */
|
---|
367 | void setConstant(size_t index, const Vector3& vec);
|
---|
368 | /** Sets a Matrix4 parameter to the program.
|
---|
369 | @param index The constant index at which to place the parameter (each constant is
|
---|
370 | a 4D float).
|
---|
371 | NB since a Matrix4 is 16 floats long, this parameter will take up 4 indexes.
|
---|
372 | @param m The value to set
|
---|
373 | */
|
---|
374 | void setConstant(size_t index, const Matrix4& m);
|
---|
375 | /** Sets a list of Matrix4 parameters to the program.
|
---|
376 | @param index The constant index at which to start placing the parameter (each constant is
|
---|
377 | a 4D float).
|
---|
378 | NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
|
---|
379 | @param m Pointer to an array of matrices to set
|
---|
380 | @param numEntries Number of Matrix4 entries
|
---|
381 | */
|
---|
382 | void setConstant(size_t index, const Matrix4* m, size_t numEntries);
|
---|
383 | /** Sets a multiple value constant floating-point parameter to the program.
|
---|
384 | @param index The constant index at which to start placing parameters (each constant is
|
---|
385 | a 4D float)
|
---|
386 | @param val Pointer to the values to write, must contain 4*count floats
|
---|
387 | @param count The number of groups of 4 floats to write
|
---|
388 | */
|
---|
389 | void setConstant(size_t index, const float *val, size_t count);
|
---|
390 | /** Sets a multiple value constant floating-point parameter to the program.
|
---|
391 | @param index The constant index at which to start placing parameters (each constant is
|
---|
392 | a 4D float)
|
---|
393 | @param val Pointer to the values to write, must contain 4*count floats
|
---|
394 | @param count The number of groups of 4 floats to write
|
---|
395 | */
|
---|
396 | void setConstant(size_t index, const double *val, size_t count);
|
---|
397 | /** Sets a ColourValue parameter to the program.
|
---|
398 | @param index The constant index at which to place the parameter (each constant is
|
---|
399 | a 4D float)
|
---|
400 | @param colour The value to set
|
---|
401 | */
|
---|
402 | void setConstant(size_t index, const ColourValue& colour);
|
---|
403 |
|
---|
404 | /** Sets a multiple value constant integer parameter to the program.
|
---|
405 | @remarks
|
---|
406 | Different types of GPU programs support different types of constant parameters.
|
---|
407 | For example, it's relatively common to find that vertex programs only support
|
---|
408 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
409 | parameters. This can vary depending on the program version supported by the
|
---|
410 | graphics card being used. You should consult the documentation for the type of
|
---|
411 | low level program you are using, or alternatively use the methods
|
---|
412 | provided on RenderSystemCapabilities to determine the options.
|
---|
413 | @param index The constant index at which to place the parameter (each constant is
|
---|
414 | a 4D integer)
|
---|
415 | @param val Pointer to the values to write, must contain 4*count ints
|
---|
416 | @param count The number of groups of 4 ints to write
|
---|
417 | */
|
---|
418 | void setConstant(size_t index, const int *val, size_t count);
|
---|
419 |
|
---|
420 | /** Deletes the contents of the Real constants registers. */
|
---|
421 | void resetRealConstants(void) { mRealConstants.clear(); }
|
---|
422 | /** Deletes the contents of the int constants registers. */
|
---|
423 | void resetIntConstants(void) { mIntConstants.clear(); }
|
---|
424 |
|
---|
425 | typedef ConstVectorIterator<RealConstantList> RealConstantIterator;
|
---|
426 | typedef ConstVectorIterator<IntConstantList> IntConstantIterator;
|
---|
427 | /// Gets an iterator over the Real constant parameters
|
---|
428 | RealConstantIterator getRealConstantIterator(void) const;
|
---|
429 | /// Gets an iterator over the integer constant parameters
|
---|
430 | IntConstantIterator getIntConstantIterator(void) const;
|
---|
431 |
|
---|
432 | /** Gets a specific Real Constant entry if index is in valid range
|
---|
433 | otherwise returns a NULL
|
---|
434 | @parem index which entry is to be retrieved
|
---|
435 | */
|
---|
436 | RealConstantEntry* getRealConstantEntry(const size_t index);
|
---|
437 | /** Gets a specific Int Constant entry if index is in valid range
|
---|
438 | otherwise returns a NULL
|
---|
439 | @parem index which entry is to be retrieved
|
---|
440 | */
|
---|
441 | IntConstantEntry* getIntConstantEntry(const size_t index);
|
---|
442 |
|
---|
443 | /** Gets a Named Real Constant entry if the name is found otherwise returns a NULL
|
---|
444 | @parem name The name of the entry to be retrieved
|
---|
445 | */
|
---|
446 | RealConstantEntry* getNamedRealConstantEntry(const String& name);
|
---|
447 | /** Gets a named Int Constant entry if name is found otherwise returns a NULL
|
---|
448 | @parem name The name of the entry to be retrieved
|
---|
449 | */
|
---|
450 | IntConstantEntry* getNamedIntConstantEntry(const String& name);
|
---|
451 | /// Gets the number of Real constants that have been set
|
---|
452 | size_t getRealConstantCount(void) const { return mRealConstants.size(); }
|
---|
453 | /// Gets the number of int constants that have been set
|
---|
454 | size_t getIntConstantCount(void) const { return mIntConstants.size(); }
|
---|
455 | /// Returns true if there are any Real constants contained here
|
---|
456 | bool hasRealConstantParams(void) const { return !(mRealConstants.empty()); }
|
---|
457 | /// Returns true if there are any int constants contained here
|
---|
458 | bool hasIntConstantParams(void) const { return !(mIntConstants.empty()); }
|
---|
459 |
|
---|
460 | /** Sets up a constant which will automatically be updated by the system.
|
---|
461 | @remarks
|
---|
462 | Vertex and fragment programs often need parameters which are to do with the
|
---|
463 | current render state, or particular values which may very well change over time,
|
---|
464 | and often between objects which are being rendered. This feature allows you
|
---|
465 | to set up a certain number of predefined parameter mappings that are kept up to
|
---|
466 | date for you.
|
---|
467 | @param index The location in the constant list to place this updated constant every time
|
---|
468 | it is changed. Note that because of the nature of the types, we know how big the
|
---|
469 | parameter details will be so you don't need to set that like you do for manual constants.
|
---|
470 | @param acType The type of automatic constant to set
|
---|
471 | @param extraInfo If the constant type needs more information (like a light index) put it here.
|
---|
472 | */
|
---|
473 | void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
|
---|
474 | void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
|
---|
475 | /** Sets a named parameter up to track a derivation of the current time.
|
---|
476 | @param index The index of the parameter
|
---|
477 | @param factor The amount by which to scale the time value
|
---|
478 | */
|
---|
479 | void setConstantFromTime(size_t index, Real factor);
|
---|
480 |
|
---|
481 | /** Clears all the existing automatic constants. */
|
---|
482 | void clearAutoConstants(void);
|
---|
483 | typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
|
---|
484 | /** Gets an iterator over the automatic constant bindings currently in place. */
|
---|
485 | AutoConstantIterator getAutoConstantIterator(void) const;
|
---|
486 | /** Returns true if this instance has any automatic constants. */
|
---|
487 | bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
|
---|
488 | /** Updates the automatic parameters (except lights) based on the details provided. */
|
---|
489 | void _updateAutoParamsNoLights(const AutoParamDataSource& source);
|
---|
490 | /** Updates the automatic parameters for lights based on the details provided. */
|
---|
491 | void _updateAutoParamsLightsOnly(const AutoParamDataSource& source);
|
---|
492 |
|
---|
493 | /** Sets the auto add parameter name flag
|
---|
494 | @remarks
|
---|
495 | Not all GPU programs make named parameters available after the high level
|
---|
496 | source is compiled. GLSL is one such case. If parameter names are not loaded
|
---|
497 | prior to the material serializer reading in parameter names in a script then
|
---|
498 | an exception is generated. Set AutoAddParamName to true to have names not found
|
---|
499 | in the map added to the map.
|
---|
500 | @note
|
---|
501 | The index of the parameter name will be set to the end of the Real Constant List.
|
---|
502 | @param state true to enable automatic name
|
---|
503 | */
|
---|
504 | void setAutoAddParamName(bool state) { mAutoAddParamName = state; }
|
---|
505 |
|
---|
506 | /** Sets a single value constant floating-point parameter to the program.
|
---|
507 | @remarks
|
---|
508 | Different types of GPU programs support different types of constant parameters.
|
---|
509 | For example, it's relatively common to find that vertex programs only support
|
---|
510 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
511 | parameters. This can vary depending on the program version supported by the
|
---|
512 | graphics card being used. You should consult the documentation for the type of
|
---|
513 | low level program you are using, or alternatively use the methods
|
---|
514 | provided on RenderSystemCapabilities to determine the options.
|
---|
515 | @par
|
---|
516 | Another possible limitation is that some systems only allow constants to be set
|
---|
517 | on certain boundaries, e.g. in sets of 4 values for example. Again, see
|
---|
518 | RenderSystemCapabilities for full details.
|
---|
519 | @note
|
---|
520 | This named option will only work if you are using a parameters object created
|
---|
521 | from a high-level program (HighLevelGpuProgram).
|
---|
522 | @param name The name of the parameter
|
---|
523 | @param val The value to set
|
---|
524 | */
|
---|
525 | void setNamedConstant(const String& name, Real val);
|
---|
526 | /** Sets a single value constant integer parameter to the program.
|
---|
527 | @remarks
|
---|
528 | Different types of GPU programs support different types of constant parameters.
|
---|
529 | For example, it's relatively common to find that vertex programs only support
|
---|
530 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
531 | parameters. This can vary depending on the program version supported by the
|
---|
532 | graphics card being used. You should consult the documentation for the type of
|
---|
533 | low level program you are using, or alternatively use the methods
|
---|
534 | provided on RenderSystemCapabilities to determine the options.
|
---|
535 | @par
|
---|
536 | Another possible limitation is that some systems only allow constants to be set
|
---|
537 | on certain boundaries, e.g. in sets of 4 values for example. Again, see
|
---|
538 | RenderSystemCapabilities for full details.
|
---|
539 | @note
|
---|
540 | This named option will only work if you are using a parameters object created
|
---|
541 | from a high-level program (HighLevelGpuProgram).
|
---|
542 | @param name The name of the parameter
|
---|
543 | @param val The value to set
|
---|
544 | */
|
---|
545 | void setNamedConstant(const String& name, int val);
|
---|
546 | /** Sets a Vector4 parameter to the program.
|
---|
547 | @param name The name of the parameter
|
---|
548 | @param vec The value to set
|
---|
549 | */
|
---|
550 | void setNamedConstant(const String& name, const Vector4& vec);
|
---|
551 | /** Sets a Vector3 parameter to the program.
|
---|
552 | @note
|
---|
553 | This named option will only work if you are using a parameters object created
|
---|
554 | from a high-level program (HighLevelGpuProgram).
|
---|
555 | @param index The index at which to place the parameter
|
---|
556 | NB this index refers to the number of floats, so a Vector3 is 3. Note that many
|
---|
557 | rendersystems & programs assume that every floating point parameter is passed in
|
---|
558 | as a vector of 4 items, so you are strongly advised to check with
|
---|
559 | RenderSystemCapabilities before using this version - if in doubt use Vector4
|
---|
560 | or ColourValue instead (both are 4D).
|
---|
561 | @param vec The value to set
|
---|
562 | */
|
---|
563 | void setNamedConstant(const String& name, const Vector3& vec);
|
---|
564 | /** Sets a Matrix4 parameter to the program.
|
---|
565 | @param name The name of the parameter
|
---|
566 | @param m The value to set
|
---|
567 | */
|
---|
568 | void setNamedConstant(const String& name, const Matrix4& m);
|
---|
569 | /** Sets a list of Matrix4 parameters to the program.
|
---|
570 | @param name The name of the parameter; this must be the first index of an array,
|
---|
571 | for examples 'matrices[0]'
|
---|
572 | NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
|
---|
573 | @param m Pointer to an array of matrices to set
|
---|
574 | @param numEntries Number of Matrix4 entries
|
---|
575 | */
|
---|
576 | void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
|
---|
577 | /** Sets a multiple value constant floating-point parameter to the program.
|
---|
578 | @remarks
|
---|
579 | Different types of GPU programs support different types of constant parameters.
|
---|
580 | For example, it's relatively common to find that vertex programs only support
|
---|
581 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
582 | parameters. This can vary depending on the program version supported by the
|
---|
583 | graphics card being used. You should consult the documentation for the type of
|
---|
584 | low level program you are using, or alternatively use the methods
|
---|
585 | provided on RenderSystemCapabilities to determine the options.
|
---|
586 | @par
|
---|
587 | Another possible limitation is that some systems only allow constants to be set
|
---|
588 | on certain boundaries, e.g. in sets of 4 values for example. Again, see
|
---|
589 | RenderSystemCapabilities for full details.
|
---|
590 | @note
|
---|
591 | This named option will only work if you are using a parameters object created
|
---|
592 | from a high-level program (HighLevelGpuProgram).
|
---|
593 | @param name The name of the parameter
|
---|
594 | @param val Pointer to the values to write
|
---|
595 | @param count The number of floats to write
|
---|
596 | */
|
---|
597 | void setNamedConstant(const String& name, const float *val, size_t count);
|
---|
598 | /** Sets a multiple value constant floating-point parameter to the program.
|
---|
599 | @remarks
|
---|
600 | Different types of GPU programs support different types of constant parameters.
|
---|
601 | For example, it's relatively common to find that vertex programs only support
|
---|
602 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
603 | parameters. This can vary depending on the program version supported by the
|
---|
604 | graphics card being used. You should consult the documentation for the type of
|
---|
605 | low level program you are using, or alternatively use the methods
|
---|
606 | provided on RenderSystemCapabilities to determine the options.
|
---|
607 | @par
|
---|
608 | Another possible limitation is that some systems only allow constants to be set
|
---|
609 | on certain boundaries, e.g. in sets of 4 values for example. Again, see
|
---|
610 | RenderSystemCapabilities for full details.
|
---|
611 | @note
|
---|
612 | This named option will only work if you are using a parameters object created
|
---|
613 | from a high-level program (HighLevelGpuProgram).
|
---|
614 | @param name The name of the parameter
|
---|
615 | @param val Pointer to the values to write
|
---|
616 | @param count The number of floats to write
|
---|
617 | */
|
---|
618 | void setNamedConstant(const String& name, const double *val, size_t count);
|
---|
619 | /** Sets a ColourValue parameter to the program.
|
---|
620 | @param name The name of the parameter
|
---|
621 | @param colour The value to set
|
---|
622 | */
|
---|
623 | void setNamedConstant(const String& name, const ColourValue& colour);
|
---|
624 |
|
---|
625 | /** Sets a multiple value constant integer parameter to the program.
|
---|
626 | @remarks
|
---|
627 | Different types of GPU programs support different types of constant parameters.
|
---|
628 | For example, it's relatively common to find that vertex programs only support
|
---|
629 | floating point constants, and that fragment programs only support integer (fixed point)
|
---|
630 | parameters. This can vary depending on the program version supported by the
|
---|
631 | graphics card being used. You should consult the documentation for the type of
|
---|
632 | low level program you are using, or alternatively use the methods
|
---|
633 | provided on RenderSystemCapabilities to determine the options.
|
---|
634 | @par
|
---|
635 | Another possible limitation is that some systems only allow constants to be set
|
---|
636 | on certain boundaries, e.g. in sets of 4 values for example. Again, see
|
---|
637 | RenderSystemCapabilities for full details.
|
---|
638 | @note
|
---|
639 | This named option will only work if you are using a parameters object created
|
---|
640 | from a high-level program (HighLevelGpuProgram).
|
---|
641 | @param name The name of the parameter
|
---|
642 | @param val Pointer to the values to write
|
---|
643 | @param count The number of integers to write
|
---|
644 | */
|
---|
645 | void setNamedConstant(const String& name, const int *val, size_t count);
|
---|
646 |
|
---|
647 | /** Sets up a constant which will automatically be updated by the system.
|
---|
648 | @remarks
|
---|
649 | Vertex and fragment programs often need parameters which are to do with the
|
---|
650 | current render state, or particular values which may very well change over time,
|
---|
651 | and often between objects which are being rendered. This feature allows you
|
---|
652 | to set up a certain number of predefined parameter mappings that are kept up to
|
---|
653 | date for you.
|
---|
654 | @note
|
---|
655 | This named option will only work if you are using a parameters object created
|
---|
656 | from a high-level program (HighLevelGpuProgram).
|
---|
657 | @param name The name of the parameter
|
---|
658 | @param acType The type of automatic constant to set
|
---|
659 | @param extraInfo If the constant type needs more information (like a light index) put it here.
|
---|
660 | */
|
---|
661 | void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
|
---|
662 |
|
---|
663 | /** Sets a named parameter up to track a derivation of the current time.
|
---|
664 | @note
|
---|
665 | This named option will only work if you are using a parameters object created
|
---|
666 | from a high-level program (HighLevelGpuProgram).
|
---|
667 | @param name The name of the parameter
|
---|
668 | @param factor The amount by which to scale the time value
|
---|
669 | */
|
---|
670 | void setNamedConstantFromTime(const String& name, Real factor);
|
---|
671 | /// Internal method for associating a parameter name with an index
|
---|
672 | void _mapParameterNameToIndex(const String& name, size_t index);
|
---|
673 |
|
---|
674 | /** Gets the constant index associated with a named parameter. */
|
---|
675 | size_t getParamIndex(const String& name);
|
---|
676 |
|
---|
677 |
|
---|
678 | /** Sets whether or not we need to transpose the matrices passed in from the rest of OGRE.
|
---|
679 | @remarks
|
---|
680 | D3D uses transposed matrices compared to GL and OGRE; this is not important when you
|
---|
681 | use programs which are written to process row-major matrices, such as those generated
|
---|
682 | by Cg, but if you use a program written to D3D's matrix layout you will need to enable
|
---|
683 | this flag.
|
---|
684 | */
|
---|
685 | void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
|
---|
686 | /// Gets whether or not matrices are to be transposed when set
|
---|
687 | bool getTransposeMatrices(void) const { return mTransposeMatrices; }
|
---|
688 |
|
---|
689 | /** Copies the values of all constants (including auto constants) from another
|
---|
690 | GpuProgramParameters object.
|
---|
691 | */
|
---|
692 | void copyConstantsFrom(const GpuProgramParameters& source);
|
---|
693 |
|
---|
694 | };
|
---|
695 |
|
---|
696 | /// Shared pointer used to hold references to GpuProgramParameters instances
|
---|
697 | typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
|
---|
698 |
|
---|
699 | // Forward declaration
|
---|
700 | class GpuProgramPtr;
|
---|
701 |
|
---|
702 | /** Defines a program which runs on the GPU such as a vertex or fragment program.
|
---|
703 | @remarks
|
---|
704 | This class defines the low-level program in assembler code, the sort used to
|
---|
705 | directly assemble into machine instructions for the GPU to execute. By nature,
|
---|
706 | this means that the assembler source is rendersystem specific, which is why this
|
---|
707 | is an abstract class - real instances are created through the RenderSystem.
|
---|
708 | If you wish to use higher level shading languages like HLSL and Cg, you need to
|
---|
709 | use the HighLevelGpuProgram class instead.
|
---|
710 | */
|
---|
711 | class _OgreExport GpuProgram : public Resource
|
---|
712 | {
|
---|
713 | protected:
|
---|
714 | /// Command object - see ParamCommand
|
---|
715 | class _OgreExport CmdType : public ParamCommand
|
---|
716 | {
|
---|
717 | public:
|
---|
718 | String doGet(const void* target) const;
|
---|
719 | void doSet(void* target, const String& val);
|
---|
720 | };
|
---|
721 | class _OgreExport CmdSyntax : public ParamCommand
|
---|
722 | {
|
---|
723 | public:
|
---|
724 | String doGet(const void* target) const;
|
---|
725 | void doSet(void* target, const String& val);
|
---|
726 | };
|
---|
727 | class _OgreExport CmdSkeletal : public ParamCommand
|
---|
728 | {
|
---|
729 | public:
|
---|
730 | String doGet(const void* target) const;
|
---|
731 | void doSet(void* target, const String& val);
|
---|
732 | };
|
---|
733 | // Command object for setting / getting parameters
|
---|
734 | static CmdType msTypeCmd;
|
---|
735 | static CmdSyntax msSyntaxCmd;
|
---|
736 | static CmdSkeletal msSkeletalCmd;
|
---|
737 |
|
---|
738 | /// The type of the program
|
---|
739 | GpuProgramType mType;
|
---|
740 | /// The name of the file to load source from (may be blank)
|
---|
741 | String mFilename;
|
---|
742 | /// The assembler source of the program (may be blank until file loaded)
|
---|
743 | String mSource;
|
---|
744 | /// Whether we need to load source from file or not
|
---|
745 | bool mLoadFromFile;
|
---|
746 | /// Syntax code eg arbvp1, vs_2_0 etc
|
---|
747 | String mSyntaxCode;
|
---|
748 | /// Does this (vertex) program include skeletal animation?
|
---|
749 | bool mSkeletalAnimation;
|
---|
750 | /// The default parameters for use with this object
|
---|
751 | GpuProgramParametersSharedPtr mDefaultParams;
|
---|
752 | /// Does this program want light states passed through fixed pipeline
|
---|
753 | bool mPassSurfaceAndLightStates;
|
---|
754 |
|
---|
755 | /** Internal method for setting up the basic parameter definitions for a subclass.
|
---|
756 | @remarks
|
---|
757 | Because StringInterface holds a dictionary of parameters per class, subclasses need to
|
---|
758 | call this to ask the base class to add it's parameters to their dictionary as well.
|
---|
759 | Can't do this in the constructor because that runs in a non-virtual context.
|
---|
760 | @par
|
---|
761 | The subclass must have called it's own createParamDictionary before calling this method.
|
---|
762 | */
|
---|
763 | void setupBaseParamDictionary(void);
|
---|
764 |
|
---|
765 | /// @copydoc Resource::calculateSize
|
---|
766 | size_t calculateSize(void) const { return 0; } // TODO
|
---|
767 |
|
---|
768 | /// @copydoc Resource::loadImpl
|
---|
769 | void loadImpl(void);
|
---|
770 | public:
|
---|
771 |
|
---|
772 | GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
773 | const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
|
---|
774 |
|
---|
775 | virtual ~GpuProgram() {}
|
---|
776 |
|
---|
777 | /** Sets the filename of the source assembly for this program.
|
---|
778 | @remarks
|
---|
779 | Setting this will have no effect until you (re)load the program.
|
---|
780 | */
|
---|
781 | virtual void setSourceFile(const String& filename);
|
---|
782 |
|
---|
783 | /** Sets the source assembly for this program from an in-memory string.
|
---|
784 | @remarks
|
---|
785 | Setting this will have no effect until you (re)load the program.
|
---|
786 | */
|
---|
787 | virtual void setSource(const String& source);
|
---|
788 |
|
---|
789 | /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
|
---|
790 | virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
|
---|
791 |
|
---|
792 | /** Sets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
|
---|
793 | virtual void setSyntaxCode(const String& syntax);
|
---|
794 |
|
---|
795 | /** Gets the name of the file used as source for this program. */
|
---|
796 | virtual const String& getSourceFile(void) const { return mFilename; }
|
---|
797 | /** Gets the assembler source for this program. */
|
---|
798 | virtual const String& getSource(void) const { return mSource; }
|
---|
799 | /// Set the program type (only valid before load)
|
---|
800 | virtual void setType(GpuProgramType t);
|
---|
801 | /// Get the program type
|
---|
802 | virtual GpuProgramType getType(void) const { return mType; }
|
---|
803 |
|
---|
804 | /** Returns the GpuProgram which should be bound to the pipeline.
|
---|
805 | @remarks
|
---|
806 | This method is simply to allow some subclasses of GpuProgram to delegate
|
---|
807 | the program which is bound to the pipeline to a delegate, if required. */
|
---|
808 | virtual GpuProgram* _getBindingDelegate(void) { return this; }
|
---|
809 |
|
---|
810 | /** Returns whether this program can be supported on the current renderer and hardware. */
|
---|
811 | virtual bool isSupported(void) const;
|
---|
812 |
|
---|
813 | /** Creates a new parameters object compatible with this program definition.
|
---|
814 | @remarks
|
---|
815 | It is recommended that you use this method of creating parameters objects
|
---|
816 | rather than going direct to GpuProgramManager, because this method will
|
---|
817 | populate any implementation-specific extras (like named parameters) where
|
---|
818 | they are appropriate.
|
---|
819 | */
|
---|
820 | virtual GpuProgramParametersSharedPtr createParameters(void);
|
---|
821 |
|
---|
822 | /** Sets whether a vertex program includes the required instructions
|
---|
823 | to perform skeletal animation.
|
---|
824 | @remarks
|
---|
825 | If this is set to true, OGRE will not blend the geometry according to
|
---|
826 | skeletal animation, it will expect the vertex program to do it.
|
---|
827 | */
|
---|
828 | virtual void setSkeletalAnimationIncluded(bool included)
|
---|
829 | { mSkeletalAnimation = included; }
|
---|
830 |
|
---|
831 | /** Returns whether a vertex program includes the required instructions
|
---|
832 | to perform skeletal animation.
|
---|
833 | @remarks
|
---|
834 | If this returns true, OGRE will not blend the geometry according to
|
---|
835 | skeletal animation, it will expect the vertex program to do it.
|
---|
836 | */
|
---|
837 | virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
|
---|
838 |
|
---|
839 | /** Get a reference to the default parameters which are to be used for all
|
---|
840 | uses of this program.
|
---|
841 | @remarks
|
---|
842 | A program can be set up with a list of default parameters, which can save time when
|
---|
843 | using a program many times in a material with roughly the same settings. By
|
---|
844 | retrieving the default parameters and populating it with the most used options,
|
---|
845 | any new parameter objects created from this program afterwards will automatically include
|
---|
846 | the default parameters; thus users of the program need only change the parameters
|
---|
847 | which are unique to their own usage of the program.
|
---|
848 | */
|
---|
849 | virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
|
---|
850 |
|
---|
851 | /** Sets whether a vertex program requires light and material states to be passed
|
---|
852 | to through fixed pipeline low level API rendering calls.
|
---|
853 | @remarks
|
---|
854 | If this is set to true, OGRE will pass all active light states to the fixed function
|
---|
855 | pipeline. This is useful for high level shaders like GLSL that can read the OpenGL
|
---|
856 | light and material states. This way the user does not have to use autoparameters to
|
---|
857 | pass light position, color etc.
|
---|
858 | */
|
---|
859 | virtual void setSurfaceAndPassLightStates(bool state)
|
---|
860 | { mPassSurfaceAndLightStates = state; }
|
---|
861 |
|
---|
862 | /** Returns whether a vertex program wants light and material states to be passed
|
---|
863 | through fixed pipeline low level API rendering calls
|
---|
864 | */
|
---|
865 | virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
|
---|
866 |
|
---|
867 | protected:
|
---|
868 | /// Virtual method which must be implemented by subclasses, load from mSource
|
---|
869 | virtual void loadFromSource(void) = 0;
|
---|
870 |
|
---|
871 | };
|
---|
872 |
|
---|
873 |
|
---|
874 | /** Specialisation of SharedPtr to allow SharedPtr to be assigned to GpuProgramPtr
|
---|
875 | @note Has to be a subclass since we need operator=.
|
---|
876 | We could templatise this instead of repeating per Resource subclass,
|
---|
877 | except to do so requires a form VC6 does not support i.e.
|
---|
878 | ResourceSubclassPtr<T> : public SharedPtr<T>
|
---|
879 | */
|
---|
880 | class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram>
|
---|
881 | {
|
---|
882 | public:
|
---|
883 | GpuProgramPtr() : SharedPtr<GpuProgram>() {}
|
---|
884 | explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
|
---|
885 | GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {}
|
---|
886 | GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
|
---|
887 | {
|
---|
888 | // lock & copy other mutex pointer
|
---|
889 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
890 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
891 | pRep = static_cast<GpuProgram*>(r.getPointer());
|
---|
892 | pUseCount = r.useCountPointer();
|
---|
893 | if (pUseCount)
|
---|
894 | {
|
---|
895 | ++(*pUseCount);
|
---|
896 | }
|
---|
897 | }
|
---|
898 |
|
---|
899 | /// Operator used to convert a ResourcePtr to a GpuProgramPtr
|
---|
900 | GpuProgramPtr& operator=(const ResourcePtr& r)
|
---|
901 | {
|
---|
902 | if (pRep == static_cast<GpuProgram*>(r.getPointer()))
|
---|
903 | return *this;
|
---|
904 | release();
|
---|
905 | // lock & copy other mutex pointer
|
---|
906 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
907 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
908 | pRep = static_cast<GpuProgram*>(r.getPointer());
|
---|
909 | pUseCount = r.useCountPointer();
|
---|
910 | if (pUseCount)
|
---|
911 | {
|
---|
912 | ++(*pUseCount);
|
---|
913 | }
|
---|
914 | return *this;
|
---|
915 | }
|
---|
916 | /// Operator used to convert a HighLevelGpuProgramPtr to a GpuProgramPtr
|
---|
917 | GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
|
---|
918 | };
|
---|
919 | }
|
---|
920 |
|
---|
921 | #endif
|
---|