Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/include/OgreGpuProgram.h @ 17

Last change on this file since 17 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 70.2 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __GpuProgram_H_
30#define __GpuProgram_H_
31
32// Precompiler options
33#include "OgrePrerequisites.h"
34#include "OgreResource.h"
35#include "OgreSharedPtr.h"
36#include "OgreIteratorWrappers.h"
37
38namespace Ogre {
39
40        /** Enumerates the types of programs which can run on the GPU. */
41        enum GpuProgramType
42        {
43                GPT_VERTEX_PROGRAM,
44                GPT_FRAGMENT_PROGRAM
45        };
46
47        /** Enumeration of the types of constant we may encounter in programs.
48        @note Low-level programs, by definition, will always use either
49        float4 or int4 constant types since that is the fundamental underlying
50        type in assembler.
51        */
52        enum GpuConstantType
53        {
54                GCT_FLOAT1,
55                GCT_FLOAT2,
56                GCT_FLOAT3,
57                GCT_FLOAT4,
58                GCT_SAMPLER1D,
59                GCT_SAMPLER2D,
60                GCT_SAMPLER3D,
61                GCT_SAMPLERCUBE,
62                GCT_SAMPLER1DSHADOW,
63                GCT_SAMPLER2DSHADOW,
64                GCT_MATRIX_2X2,
65                GCT_MATRIX_2X3,
66                GCT_MATRIX_2X4,
67                GCT_MATRIX_3X2,
68                GCT_MATRIX_3X3,
69                GCT_MATRIX_3X4,
70                GCT_MATRIX_4X2,
71                GCT_MATRIX_4X3,
72                GCT_MATRIX_4X4,
73                GCT_INT1,
74                GCT_INT2,
75                GCT_INT3,
76                GCT_INT4,
77                GCT_UNKNOWN
78        };
79
80        /** Information about predefined program constants.
81        @note Only available for high-level programs but is referenced generically
82                by GpuProgramParameters.
83        */
84        struct _OgreExport GpuConstantDefinition
85        {
86                /// Data type
87                GpuConstantType constType;
88                /// Physical start index in buffer (either float or int buffer)
89                size_t physicalIndex;
90                /** Number of raw buffer slots per element
91                (some programs pack each array element to float4, some do not) */
92                size_t elementSize;
93                /// Length of array
94                size_t arraySize;
95
96                bool isFloat() const
97                {
98                        switch(constType)
99                        {
100                        case GCT_INT1:
101                        case GCT_INT2:
102                        case GCT_INT3:
103                        case GCT_INT4:
104                        case GCT_SAMPLER1D:
105                        case GCT_SAMPLER2D:
106                        case GCT_SAMPLER3D:
107                        case GCT_SAMPLERCUBE:
108                        case GCT_SAMPLER1DSHADOW:
109                        case GCT_SAMPLER2DSHADOW:
110                                return false;
111                        default:
112                                return true;
113                        };
114
115                }
116
117                bool isSampler() const
118                {
119                        switch(constType)
120                        {
121                        case GCT_SAMPLER1D:
122                        case GCT_SAMPLER2D:
123                        case GCT_SAMPLER3D:
124                        case GCT_SAMPLERCUBE:
125                        case GCT_SAMPLER1DSHADOW:
126                        case GCT_SAMPLER2DSHADOW:
127                                return true;
128                        default:
129                                return false;
130                        };
131
132                }
133
134                GpuConstantDefinition()
135                        : constType(GCT_UNKNOWN)
136                        , physicalIndex((std::numeric_limits<size_t>::max)())
137                        , elementSize(0)
138                        , arraySize(1) {}
139        };
140        typedef std::map<String, GpuConstantDefinition> GpuConstantDefinitionMap;
141        typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
142
143        /// Struct collecting together the information for named constants.
144        struct _OgreExport GpuNamedConstants
145        {
146                /// Total size of the float buffer required
147                size_t floatBufferSize;
148                /// Total size of the int buffer required
149                size_t intBufferSize;
150                /// Map of parameter names to GpuConstantDefinition
151                GpuConstantDefinitionMap map;
152
153                /** Generate additional constant entries for arrays based on a base definition.
154                @remarks
155                        Array uniforms will be added just with their base name with no array
156                        suffix. This method will add named entries for array suffixes too
157                        so individual array entries can be addressed. Note that we only
158                        individually index array elements if the array size is up to 16
159                        entries in size. Anything larger than that only gets a [0] entry
160                        as well as the main entry, to save cluttering up the name map. After
161                        all, you can address the larger arrays in a bulk fashion much more
162                        easily anyway.
163                */
164                void generateConstantDefinitionArrayEntries(const String& paramName, 
165                        const GpuConstantDefinition& baseDef);
166
167        };
168
169        /** Structure recording the use of a physical buffer by a logical parameter
170                index. Only used for low-level programs.
171        */
172        struct _OgreExport GpuLogicalIndexUse
173        {
174                /// Physical buffer index
175                size_t physicalIndex;
176                /// Current physical size allocation
177                size_t currentSize;
178
179                GpuLogicalIndexUse(size_t bufIdx, size_t curSz) 
180                        : physicalIndex(bufIdx), currentSize(curSz) {}
181        };
182        typedef std::map<size_t, GpuLogicalIndexUse> GpuLogicalIndexUseMap;
183        /// Container struct to allow params to safely & update shared list of logical buffer assignments
184        struct _OgreExport GpuLogicalBufferStruct
185        {
186                OGRE_MUTEX(mutex)
187                /// Map from logical index to physical buffer location
188                GpuLogicalIndexUseMap map;
189                /// Shortcut to know the buffer size needs
190                size_t bufferSize;
191                GpuLogicalBufferStruct() : bufferSize(0) {}
192        };
193
194    /** Collects together the program parameters used for a GpuProgram.
195    @remarks
196        Gpu program state includes constant parameters used by the program, and
197        bindings to render system state which is propagated into the constants
198        by the engine automatically if requested.
199    @par
200        GpuProgramParameters objects should be created through the GpuProgram and
201        may be shared between multiple Pass instances. For this reason they
202        are managed using a shared pointer, which will ensure they are automatically
203        deleted when no Pass is using them anymore.
204        @par
205                High-level programs use named parameters (uniforms), low-level programs
206                use indexed constants. This class supports both, but you can tell whether
207                named constants are supported by calling hasNamedParameters(). There are
208                references in the documentation below to 'logical' and 'physical' indexes;
209                logical indexes are the indexes used by low-level programs and represent
210                indexes into an array of float4's, some of which may be settable, some of
211                which may be predefined constants in the program. We only store those
212                constants which have actually been set, therefore our buffer could have
213                gaps if we used the logical indexes in our own buffers. So instead we map
214                these logical indexes to physical indexes in our buffer. When using
215                high-level programs, logical indexes don't necessarily exist, although they
216                might if the high-level program has a direct, exposed mapping from parameter
217                names to logical indexes. In addition, high-level languages may or may not pack
218                arrays of elements that are smaller than float4 (e.g. float2/vec2) contiguously.
219                This kind of information is held in the ConstantDefinition structure which
220                is only populated for high-level programs. You don't have to worry about
221                any of this unless you intend to read parameters back from this structure
222                rather than just setting them.
223    */
224    class _OgreExport GpuProgramParameters
225    {
226    public:
227        /** Defines the types of automatically updated values that may be bound to GpuProgram
228        parameters, or used to modify parameters on a per-object basis.
229        */
230        enum AutoConstantType
231        {
232            /// The current world matrix
233            ACT_WORLD_MATRIX,
234            /// The current world matrix, inverted
235            ACT_INVERSE_WORLD_MATRIX,
236                        /** Provides transpose of world matrix.
237                        Equivalent to RenderMonkey's "WorldTranspose".
238                        */
239                        ACT_TRANSPOSE_WORLD_MATRIX,
240            /// The current world matrix, inverted & transposed
241            ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
242
243
244            /// The current array of world matrices, as a 3x4 matrix, used for blending
245            ACT_WORLD_MATRIX_ARRAY_3x4,
246            /// The current array of world matrices, used for blending
247            ACT_WORLD_MATRIX_ARRAY,
248
249            /// The current view matrix
250            ACT_VIEW_MATRIX,
251                        /// The current view matrix, inverted
252                        ACT_INVERSE_VIEW_MATRIX,
253                        /** Provides transpose of view matrix.
254                        Equivalent to RenderMonkey's "ViewTranspose".
255                        */
256                        ACT_TRANSPOSE_VIEW_MATRIX,
257                        /** Provides inverse transpose of view matrix.
258                        Equivalent to RenderMonkey's "ViewInverseTranspose".
259                        */
260                        ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
261
262
263            /// The current projection matrix
264            ACT_PROJECTION_MATRIX,
265                        /** Provides inverse of projection matrix.
266                        Equivalent to RenderMonkey's "ProjectionInverse".
267                        */
268                        ACT_INVERSE_PROJECTION_MATRIX,
269                        /** Provides transpose of projection matrix.
270                        Equivalent to RenderMonkey's "ProjectionTranspose".
271                        */
272                        ACT_TRANSPOSE_PROJECTION_MATRIX,
273                        /** Provides inverse transpose of projection matrix.
274                        Equivalent to RenderMonkey's "ProjectionInverseTranspose".
275                        */
276                        ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
277
278
279            /// The current view & projection matrices concatenated
280            ACT_VIEWPROJ_MATRIX,
281                        /** Provides inverse of concatenated view and projection matrices.
282                        Equivalent to RenderMonkey's "ViewProjectionInverse".
283                        */
284                        ACT_INVERSE_VIEWPROJ_MATRIX,
285                        /** Provides transpose of concatenated view and projection matrices.
286                        Equivalent to RenderMonkey's "ViewProjectionTranspose".
287                        */
288                        ACT_TRANSPOSE_VIEWPROJ_MATRIX,
289                        /** Provides inverse transpose of concatenated view and projection matrices.
290                        Equivalent to RenderMonkey's "ViewProjectionInverseTranspose".
291                        */
292                        ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
293
294
295            /// The current world & view matrices concatenated
296            ACT_WORLDVIEW_MATRIX,
297            /// The current world & view matrices concatenated, then inverted
298            ACT_INVERSE_WORLDVIEW_MATRIX,
299                        /** Provides transpose of concatenated world and view matrices.
300                                Equivalent to RenderMonkey's "WorldViewTranspose".
301                        */
302                        ACT_TRANSPOSE_WORLDVIEW_MATRIX,
303            /// The current world & view matrices concatenated, then inverted & tranposed
304            ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
305                        /// view matrices.
306
307
308            /// The current world, view & projection matrices concatenated
309            ACT_WORLDVIEWPROJ_MATRIX,
310                        /** Provides inverse of concatenated world, view and projection matrices.
311                        Equivalent to RenderMonkey's "WorldViewProjectionInverse".
312                        */
313                        ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
314                        /** Provides transpose of concatenated world, view and projection matrices.
315                        Equivalent to RenderMonkey's "WorldViewProjectionTranspose".
316                        */
317                        ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
318                        /** Provides inverse transpose of concatenated world, view and projection
319                        matrices. Equivalent to RenderMonkey's "WorldViewProjectionInverseTranspose".
320                        */
321                        ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
322
323
324            /// render target related values
325            /** -1 if requires texture flipping, +1 otherwise. It's useful when you bypassed
326            projection matrix transform, still able use this value to adjust transformed y position.
327            */
328            ACT_RENDER_TARGET_FLIPPING,
329
330
331            /// Fog colour
332            ACT_FOG_COLOUR,
333            /// Fog params: density, linear start, linear end, 1/(end-start)
334            ACT_FOG_PARAMS,
335
336
337            /// Surface ambient colour, as set in Pass::setAmbient
338            ACT_SURFACE_AMBIENT_COLOUR,
339            /// Surface diffuse colour, as set in Pass::setDiffuse
340            ACT_SURFACE_DIFFUSE_COLOUR,
341            /// Surface specular colour, as set in Pass::setSpecular
342            ACT_SURFACE_SPECULAR_COLOUR,
343            /// Surface emissive colour, as set in Pass::setSelfIllumination
344            ACT_SURFACE_EMISSIVE_COLOUR,
345            /// Surface shininess, as set in Pass::setShininess
346            ACT_SURFACE_SHININESS,
347
348
349                        /// The ambient light colour set in the scene
350                        ACT_AMBIENT_LIGHT_COLOUR, 
351
352            /// Light diffuse colour (index determined by setAutoConstant call)
353            ACT_LIGHT_DIFFUSE_COLOUR,
354            /// Light specular colour (index determined by setAutoConstant call)
355            ACT_LIGHT_SPECULAR_COLOUR,
356            /// Light attenuation parameters, Vector4(range, constant, linear, quadric)
357            ACT_LIGHT_ATTENUATION,
358                        /** Spotlight parameters, Vector4(innerFactor, outerFactor, falloff, isSpot)
359                                innerFactor and outerFactor are cos(angle/2)
360                                The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
361                                Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively
362                        */ 
363                        ACT_SPOTLIGHT_PARAMS,
364            /// A light position in world space (index determined by setAutoConstant call)
365            ACT_LIGHT_POSITION,
366            /// A light position in object space (index determined by setAutoConstant call)
367            ACT_LIGHT_POSITION_OBJECT_SPACE,
368                        /// A light position in view space (index determined by setAutoConstant call)
369            ACT_LIGHT_POSITION_VIEW_SPACE,
370            /// A light direction in world space (index determined by setAutoConstant call)
371            ACT_LIGHT_DIRECTION,
372            /// A light direction in object space (index determined by setAutoConstant call)
373            ACT_LIGHT_DIRECTION_OBJECT_SPACE,
374                        /// A light direction in view space (index determined by setAutoConstant call)
375                        ACT_LIGHT_DIRECTION_VIEW_SPACE,
376                        /** The distance of the light from the center of the object
377                                a useful approximation as an alternative to per-vertex distance
378                                calculations.
379                        */
380                        ACT_LIGHT_DISTANCE_OBJECT_SPACE,
381                        /** Light power level, a single scalar as set in Light::setPowerScale  (index determined by setAutoConstant call) */
382                        ACT_LIGHT_POWER_SCALE,
383                        /// Array of light diffuse colours (count set by extra param)
384                        ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
385                        /// Array of light specular colours (count set by extra param)
386                        ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
387                        /// Array of light attenuation parameters, Vector4(range, constant, linear, quadric) (count set by extra param)
388                        ACT_LIGHT_ATTENUATION_ARRAY,
389                        /// Array of light positions in world space (count set by extra param)
390                        ACT_LIGHT_POSITION_ARRAY,
391                        /// Array of light positions in object space (count set by extra param)
392                        ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
393                        /// Array of light positions in view space (count set by extra param)
394                        ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
395                        /// Array of light directions in world space (count set by extra param)
396                        ACT_LIGHT_DIRECTION_ARRAY,
397                        /// Array of light directions in object space (count set by extra param)
398                        ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
399                        /// Array of light directions in view space (count set by extra param)
400                        ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
401                        /** Array of distances of the lights from the center of the object
402                        a useful approximation as an alternative to per-vertex distance
403                        calculations. (count set by extra param)
404                        */
405                        ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
406                        /** Array of light power levels, a single scalar as set in Light::setPowerScale
407                         (count set by extra param)
408                        */
409                        ACT_LIGHT_POWER_SCALE_ARRAY,
410                        /** Spotlight parameters array of Vector4(innerFactor, outerFactor, falloff, isSpot)
411                        innerFactor and outerFactor are cos(angle/2)
412                        The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
413                        Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively.
414                        (count set by extra param)
415                        */ 
416                        ACT_SPOTLIGHT_PARAMS_ARRAY,
417
418            /** The derived ambient light colour, with 'r', 'g', 'b' components filled with
419                product of surface ambient colour and ambient light colour, respectively,
420                and 'a' component filled with surface ambient alpha component.
421            */
422            ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
423            /** The derived scene colour, with 'r', 'g' and 'b' components filled with sum
424                of derived ambient light colour and surface emissive colour, respectively,
425                and 'a' component filled with surface diffuse alpha component.
426            */
427            ACT_DERIVED_SCENE_COLOUR,
428
429            /** The derived light diffuse colour (index determined by setAutoConstant call),
430                with 'r', 'g' and 'b' components filled with product of surface diffuse colour
431                and light diffuse colour, respectively, and 'a' component filled with surface
432                diffuse alpha component.
433            */
434            ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
435            /** The derived light specular colour (index determined by setAutoConstant call),
436                with 'r', 'g' and 'b' components filled with product of surface specular colour
437                and light specular colour, respectively, and 'a' component filled with surface
438                specular alpha component.
439            */
440            ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
441
442                        /// Array of derived light diffuse colours (count set by extra param)
443            ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
444                        /// Array of derived light specular colours (count set by extra param)
445            ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
446
447
448                        /** The distance a shadow volume should be extruded when using
449                            finite extrusion programs.
450                        */
451                        ACT_SHADOW_EXTRUSION_DISTANCE,
452            /// The current camera's position in world space
453            ACT_CAMERA_POSITION,
454            /// The current camera's position in object space
455            ACT_CAMERA_POSITION_OBJECT_SPACE,
456            /// The view/projection matrix of the assigned texture projection frustum
457            ACT_TEXTURE_VIEWPROJ_MATRIX,
458            /// A custom parameter which will come from the renderable, using 'data' as the identifier
459            ACT_CUSTOM,
460            /** provides current elapsed time
461            */
462            ACT_TIME,
463                        /** Single float value, which repeats itself based on given as
464                        parameter "cycle time". Equivalent to RenderMonkey's "Time0_X".
465                        */
466                        ACT_TIME_0_X,
467                        /// Cosine of "Time0_X". Equivalent to RenderMonkey's "CosTime0_X".
468                        ACT_COSTIME_0_X,
469                        /// Sine of "Time0_X". Equivalent to RenderMonkey's "SinTime0_X".
470                        ACT_SINTIME_0_X,
471                        /// Tangent of "Time0_X". Equivalent to RenderMonkey's "TanTime0_X".
472                        ACT_TANTIME_0_X,
473                        /** Vector of "Time0_X", "SinTime0_X", "CosTime0_X",
474                        "TanTime0_X". Equivalent to RenderMonkey's "Time0_X_Packed".
475                        */
476                        ACT_TIME_0_X_PACKED,
477                        /** Single float value, which represents scaled time value [0..1],
478                        which repeats itself based on given as parameter "cycle time".
479                        Equivalent to RenderMonkey's "Time0_1".
480                        */
481                        ACT_TIME_0_1,
482                        /// Cosine of "Time0_1". Equivalent to RenderMonkey's "CosTime0_1".
483                        ACT_COSTIME_0_1,
484                        /// Sine of "Time0_1". Equivalent to RenderMonkey's "SinTime0_1".
485                        ACT_SINTIME_0_1,
486                        /// Tangent of "Time0_1". Equivalent to RenderMonkey's "TanTime0_1".
487                        ACT_TANTIME_0_1,
488                        /** Vector of "Time0_1", "SinTime0_1", "CosTime0_1",
489                        "TanTime0_1". Equivalent to RenderMonkey's "Time0_1_Packed".
490                        */
491                        ACT_TIME_0_1_PACKED,
492                        /**     Single float value, which represents scaled time value [0..2*Pi],
493                        which repeats itself based on given as parameter "cycle time".
494                        Equivalent to RenderMonkey's "Time0_2PI".
495                        */
496                        ACT_TIME_0_2PI,
497                        /// Cosine of "Time0_2PI". Equivalent to RenderMonkey's "CosTime0_2PI".
498                        ACT_COSTIME_0_2PI,
499                        /// Sine of "Time0_2PI". Equivalent to RenderMonkey's "SinTime0_2PI".
500                        ACT_SINTIME_0_2PI,
501                        /// Tangent of "Time0_2PI". Equivalent to RenderMonkey's "TanTime0_2PI".
502                        ACT_TANTIME_0_2PI,
503                        /** Vector of "Time0_2PI", "SinTime0_2PI", "CosTime0_2PI",
504                        "TanTime0_2PI". Equivalent to RenderMonkey's "Time0_2PI_Packed".
505                        */
506                        ACT_TIME_0_2PI_PACKED,
507                        /// provides the scaled frame time, returned as a floating point value.
508            ACT_FRAME_TIME,
509                        /// provides the calculated frames per second, returned as a floating point value.
510                        ACT_FPS,
511                        /// viewport-related values
512                        /** Current viewport width (in pixels) as floating point value.
513                        Equivalent to RenderMonkey's "ViewportWidth".
514                        */
515                        ACT_VIEWPORT_WIDTH,
516                        /** Current viewport height (in pixels) as floating point value.
517                        Equivalent to RenderMonkey's "ViewportHeight".
518                        */
519                        ACT_VIEWPORT_HEIGHT,
520                        /** This variable represents 1.0/ViewportWidth.
521                        Equivalent to RenderMonkey's "ViewportWidthInverse".
522                        */
523                        ACT_INVERSE_VIEWPORT_WIDTH,
524                        /** This variable represents 1.0/ViewportHeight.
525                        Equivalent to RenderMonkey's "ViewportHeightInverse".
526                        */
527                        ACT_INVERSE_VIEWPORT_HEIGHT,
528            /** Packed of "ViewportWidth", "ViewportHeight", "ViewportWidthInverse",
529            "ViewportHeightInverse".
530            */
531            ACT_VIEWPORT_SIZE,
532
533                        /// view parameters
534                        /** This variable provides the view direction vector (world space).
535                        Equivalent to RenderMonkey's "ViewDirection".
536                        */
537                        ACT_VIEW_DIRECTION,
538                        /** This variable provides the view side vector (world space).
539                        Equivalent to RenderMonkey's "ViewSideVector".
540                        */
541                        ACT_VIEW_SIDE_VECTOR,
542                        /** This variable provides the view up vector (world space).
543                        Equivalent to RenderMonkey's "ViewUpVector".
544                        */
545                        ACT_VIEW_UP_VECTOR,
546                        /** This variable provides the field of view as a floating point value.
547                        Equivalent to RenderMonkey's "FOV".
548                        */
549                        ACT_FOV,
550                        /**     This variable provides the near clip distance as a floating point value.
551                        Equivalent to RenderMonkey's "NearClipPlane".
552                        */
553                        ACT_NEAR_CLIP_DISTANCE,
554                        /**     This variable provides the far clip distance as a floating point value.
555                        Equivalent to RenderMonkey's "FarClipPlane".
556                        */
557                        ACT_FAR_CLIP_DISTANCE,
558
559            /** provides the pass index number within the technique
560                of the active materil.
561            */
562            ACT_PASS_NUMBER,
563
564            /** provides the current iteration number of the pass. The iteration
565                number is the number of times the current render operation has
566                been drawn for the acitve pass.
567            */
568            ACT_PASS_ITERATION_NUMBER,
569
570
571                        /** Provides a parametric animation value [0..1], only available
572                                where the renderable specifically implements it.
573                        */
574                        ACT_ANIMATION_PARAMETRIC,
575
576                        /** Provides the texel offsets required by this rendersystem to map
577                                texels to pixels. Packed as
578                                float4(absoluteHorizontalOffset, absoluteVerticalOffset,
579                                        horizontalOffset / viewportWidth, verticalOffset / viewportHeight)
580                        */
581                        ACT_TEXEL_OFFSETS,
582
583                        /** Provides information about the depth range of the scene as viewed
584                                from the current camera.
585                                Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
586                        */
587                        ACT_SCENE_DEPTH_RANGE,
588
589                        /** Provides information about the depth range of the scene as viewed
590                        from a given shadow camera. Requires an index parameter which maps
591                        to a light index relative to the current light list.
592                        Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
593                        */
594                        ACT_SHADOW_SCENE_DEPTH_RANGE,
595
596            /** Provides texture size of the texture unit (index determined by setAutoConstant
597                call). Packed as float4(width, height, depth, 1)
598            */
599            ACT_TEXTURE_SIZE,
600            /** Provides inverse texture size of the texture unit (index determined by setAutoConstant
601                call). Packed as float4(1 / width, 1 / height, 1 / depth, 1)
602            */
603            ACT_INVERSE_TEXTURE_SIZE,
604            /** Provides packed texture size of the texture unit (index determined by setAutoConstant
605                call). Packed as float4(width, height, 1 / width, 1 / height)
606            */
607            ACT_PACKED_TEXTURE_SIZE,
608
609
610        };
611
612        /** Defines the type of the extra data item used by the auto constant.
613
614        */
615        enum ACDataType {
616            /// no data is required
617            ACDT_NONE,
618            /// the auto constant requires data of type int
619            ACDT_INT,
620            /// the auto constant requires data of type real
621            ACDT_REAL
622        };
623
624        /** Defines the base element type of the auto constant
625        */
626        enum ElementType {
627            ET_INT,
628            ET_REAL
629        };
630
631        /** Structure defining an auto constant that's available for use in
632                        a parameters object.
633                */
634                struct AutoConstantDefinition
635        {
636            AutoConstantType acType;
637            String name;
638            size_t elementCount;
639                        /// The type of the constant in the program
640            ElementType elementType;
641                        /// The type of any extra data
642            ACDataType dataType;
643
644                        AutoConstantDefinition(AutoConstantType _acType, const String& _name, 
645                                size_t _elementCount, ElementType _elementType, 
646                                ACDataType _dataType)
647                                :acType(_acType), name(_name), elementCount(_elementCount), 
648                                elementType(_elementType), dataType(_dataType)
649                        {
650                               
651                        }
652        };
653
654        /** Structure recording the use of an automatic parameter. */
655        class AutoConstantEntry
656        {
657        public:
658            /// The type of parameter
659            AutoConstantType paramType;
660                        /// The target (physical) constant index
661            size_t physicalIndex;
662                        /** The number of elements per individual entry in this constant
663                                Used in case people used packed elements smaller than 4 (e.g. GLSL)
664                                and bind an auto which is 4-element packed to it */
665                        size_t elementCount;
666            /// Additional information to go with the parameter
667                        union{
668                                size_t data;
669                                Real fData;
670                        };
671
672            AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData, 
673                                size_t theElemCount = 4)
674                : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), data(theData) {}
675
676                        AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData, 
677                                size_t theElemCount = 4)
678                                : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), fData(theData) {}
679
680        };
681                // Auto parameter storage
682                typedef std::vector<AutoConstantEntry> AutoConstantList;
683
684                /** Definition of container that holds the current float constants.
685                @note Not necessarily in direct index order to constant indexes, logical
686                        to physical index map is derived from GpuProgram
687                */
688                typedef std::vector<float> FloatConstantList;
689                /** Definition of container that holds the current float constants.
690                @note Not necessarily in direct index order to constant indexes, logical
691                        to physical index map is derived from GpuProgram
692                */
693                typedef std::vector<int> IntConstantList;
694
695        protected:
696        static AutoConstantDefinition AutoConstantDictionary[];
697                /// Packed list of floating-point constants (physical indexing)
698        FloatConstantList mFloatConstants;
699        /// Packed list of integer constants (physical indexing)
700        IntConstantList mIntConstants;
701                /** Logical index to physical index map - for low-level programs
702                        or high-level programs which pass params this way. */
703                GpuLogicalBufferStruct* mFloatLogicalToPhysical;
704                /** Logical index to physical index map - for low-level programs
705                or high-level programs which pass params this way. */
706                GpuLogicalBufferStruct* mIntLogicalToPhysical;
707                /// Mapping from parameter names to def - high-level programs are expected to populate this
708                const GpuNamedConstants* mNamedConstants;
709        /// List of automatically updated parameters
710        AutoConstantList mAutoConstants;
711        /// Do we need to transpose matrices?
712        bool mTransposeMatrices;
713                /// flag to indicate if names not found will be ignored
714                bool mIgnoreMissingParams;
715        /// physical index for active pass iteration parameter real constant entry;
716        size_t mActivePassIterationIndex;
717
718    public:
719                GpuProgramParameters();
720                ~GpuProgramParameters() {}
721
722        /// Copy constructor
723        GpuProgramParameters(const GpuProgramParameters& oth);
724        /// Operator = overload
725        GpuProgramParameters& operator=(const GpuProgramParameters& oth);
726
727                /** Internal method for providing a link to a name->definition map for parameters. */
728                void _setNamedConstants(const GpuNamedConstants* constantmap);
729
730                /** Internal method for providing a link to a logical index->physical index map for parameters. */
731                void _setLogicalIndexes(GpuLogicalBufferStruct* floatIndexMap, 
732                        GpuLogicalBufferStruct* intIndexMap);
733
734
735                /// Does this parameter set include named parameters?
736                bool hasNamedParameters() const { return mNamedConstants != 0;}
737                /** Does this parameter set include logically indexed parameters?
738                @note Not mutually exclusive with hasNamedParameters since some high-level
739                        programs still use logical indexes to set the parameters on the
740                        rendersystem.
741                */
742                bool hasLogicalIndexedParameters() const { return mFloatLogicalToPhysical != 0;}
743
744                /** Sets a 4-element floating-point parameter to the program.
745                @param index The logical constant index at which to place the parameter
746                        (each constant is a 4D float)
747                @param vec The value to set
748                */
749                void setConstant(size_t index, const Vector4& vec);
750                /** Sets a single floating-point parameter to the program.
751                @note This is actually equivalent to calling
752                setConstant(index Vector4(val, 0, 0, 0)) since all constants are 4D.
753                @param index The logical constant index at which to place the parameter (each constant is
754                a 4D float)
755                @param val The value to set
756                */
757                void setConstant(size_t index, Real val);
758                /** Sets a 4-element floating-point parameter to the program via Vector3.
759                @param index The logical constant index at which to place the parameter (each constant is
760            a 4D float).
761            Note that since you're passing a Vector3, the last element of the 4-element
762            value will be set to 1 (a homogenous vector)
763                @param vec The value to set
764                */
765                void setConstant(size_t index, const Vector3& vec);
766                /** Sets a Matrix4 parameter to the program.
767                @param index The logical constant index at which to place the parameter (each constant is
768            a 4D float).
769            NB since a Matrix4 is 16 floats long, this parameter will take up 4 indexes.
770                @param m The value to set
771                */
772                void setConstant(size_t index, const Matrix4& m);
773        /** Sets a list of Matrix4 parameters to the program.
774        @param index The logical constant index at which to start placing the parameter (each constant is
775        a 4D float).
776        NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
777        @param m Pointer to an array of matrices to set
778        @param numEntries Number of Matrix4 entries
779        */
780        void setConstant(size_t index, const Matrix4* m, size_t numEntries);
781                /** Sets a multiple value constant floating-point parameter to the program.
782                @param index The logical constant index at which to start placing parameters (each constant is
783            a 4D float)
784                @param val Pointer to the values to write, must contain 4*count floats
785                @param count The number of groups of 4 floats to write
786                */
787                void setConstant(size_t index, const float *val, size_t count);
788                /** Sets a multiple value constant floating-point parameter to the program.
789                @param index The logical constant index at which to start placing parameters (each constant is
790            a 4D float)
791                @param val Pointer to the values to write, must contain 4*count floats
792                @param count The number of groups of 4 floats to write
793                */
794                void setConstant(size_t index, const double *val, size_t count);
795                /** Sets a ColourValue parameter to the program.
796                @param index The logical constant index at which to place the parameter (each constant is
797            a 4D float)
798                @param colour The value to set
799                */
800        void setConstant(size_t index, const ColourValue& colour);
801               
802                /** Sets a multiple value constant integer parameter to the program.
803        @remarks
804            Different types of GPU programs support different types of constant parameters.
805            For example, it's relatively common to find that vertex programs only support
806            floating point constants, and that fragment programs only support integer (fixed point)
807            parameters. This can vary depending on the program version supported by the
808            graphics card being used. You should consult the documentation for the type of
809            low level program you are using, or alternatively use the methods
810            provided on RenderSystemCapabilities to determine the options.
811                @param index The logical constant index at which to place the parameter (each constant is
812            a 4D integer)
813                @param val Pointer to the values to write, must contain 4*count ints
814                @param count The number of groups of 4 ints to write
815                */
816                void setConstant(size_t index, const int *val, size_t count);
817
818                /** Write a series of floating point values into the underlying float
819                        constant buffer at the given physical index.
820                @param physicalIndex The buffer position to start writing
821                @param val Pointer to a list of values to write
822                @param count The number of floats to write
823                */
824                void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
825                /** Write a series of floating point values into the underlying float
826                constant buffer at the given physical index.
827                @param physicalIndex The buffer position to start writing
828                @param val Pointer to a list of values to write
829                @param count The number of floats to write
830                */
831                void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
832                /** Write a series of integer values into the underlying integer
833                        constant buffer at the given physical index.
834                @param physicalIndex The buffer position to start writing
835                @param val Pointer to a list of values to write
836                @param count The number of ints to write
837                */
838                void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
839                /** Read a series of floating point values from the underlying float
840                        constant buffer at the given physical index.
841                @param physicalIndex The buffer position to start reading
842                @param count The number of floats to read
843                @param dest Pointer to a buffer to receive the values
844                */
845                void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
846                /** Read a series of integer values from the underlying integer
847                constant buffer at the given physical index.
848                @param physicalIndex The buffer position to start reading
849                @param count The number of ints to read
850                @param dest Pointer to a buffer to receive the values
851                */
852                void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
853
854                /** Write a 4-element floating-point parameter to the program directly to
855                        the underlying constants buffer.
856                @note You can use these methods if you have already derived the physical
857                        constant buffer location, for a slight speed improvement over using
858                        the named / logical index versions.
859                @param physicalIndex The physical buffer index at which to place the parameter
860                @param vec The value to set
861                @param count The number of floats to write; if for example
862                        the uniform constant 'slot' is smaller than a Vector4
863                */
864                void _writeRawConstant(size_t physicalIndex, const Vector4& vec, 
865                        size_t count = 4);
866                /** Write a single floating-point parameter to the program.
867                @note You can use these methods if you have already derived the physical
868                constant buffer location, for a slight speed improvement over using
869                the named / logical index versions.
870                @param physicalIndex The physical buffer index at which to place the parameter
871                @param val The value to set
872                */
873                void _writeRawConstant(size_t physicalIndex, Real val);
874                /** Write a single integer parameter to the program.
875                @note You can use these methods if you have already derived the physical
876                constant buffer location, for a slight speed improvement over using
877                the named / logical index versions.
878                @param physicalIndex The physical buffer index at which to place the parameter
879                @param val The value to set
880                */
881                void _writeRawConstant(size_t physicalIndex, int val);
882                /** Write a 3-element floating-point parameter to the program via Vector3.
883                @note You can use these methods if you have already derived the physical
884                constant buffer location, for a slight speed improvement over using
885                the named / logical index versions.
886                @param physicalIndex The physical buffer index at which to place the parameter
887                @param vec The value to set
888                */
889                void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
890                /** Write a Matrix4 parameter to the program.
891                @note You can use these methods if you have already derived the physical
892                constant buffer location, for a slight speed improvement over using
893                the named / logical index versions.
894                @param physicalIndex The physical buffer index at which to place the parameter
895                @param m The value to set
896                */
897                void _writeRawConstant(size_t physicalIndex, const Matrix4& m);
898        /** Write a list of Matrix4 parameters to the program.
899                @note You can use these methods if you have already derived the physical
900                constant buffer location, for a slight speed improvement over using
901                the named / logical index versions.
902                @param physicalIndex The physical buffer index at which to place the parameter
903        @param numEntries Number of Matrix4 entries
904        */
905        void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
906                /** Write a ColourValue parameter to the program.
907                @note You can use these methods if you have already derived the physical
908                constant buffer location, for a slight speed improvement over using
909                the named / logical index versions.
910                @param physicalIndex The physical buffer index at which to place the parameter
911                @param colour The value to set
912                @param count The number of floats to write; if for example
913                        the uniform constant 'slot' is smaller than a Vector4
914                */
915        void _writeRawConstant(size_t physicalIndex, const ColourValue& colour, 
916                        size_t count = 4);
917               
918
919        /** Gets an iterator over the named GpuConstantDefinition instances as defined
920                        by the program for which these parameters exist.
921                @note
922                        Only available if this parameters object has named parameters.
923                */
924        GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
925
926                /** Get a specific GpuConstantDefinition for a named parameter.
927                @note
928                        Only available if this parameters object has named parameters.
929                */
930                const GpuConstantDefinition& getConstantDefinition(const String& name) const;
931
932                /** Get the full list of GpuConstantDefinition instances.
933                @note
934                Only available if this parameters object has named parameters.
935                */
936                const GpuNamedConstants& getConstantDefinitions() const;
937
938                /** Get the current list of mappings from low-level logical param indexes
939                        to physical buffer locations in the float buffer.
940                @note
941                        Only applicable to low-level programs.
942                */
943                const GpuLogicalBufferStruct* getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
944
945                /** Retrieves the logical index relating to a physical index in the float
946                        buffer, for programs which support that (low-level programs and
947                        high-level programs which use logical parameter indexes).
948                        @returns std::numeric_limits<size_t>::max() if not found
949                */
950                size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
951                /** Retrieves the logical index relating to a physical index in the int
952                buffer, for programs which support that (low-level programs and
953                high-level programs which use logical parameter indexes).
954                @returns std::numeric_limits<size_t>::max() if not found
955                */
956                size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
957
958                /** Get the current list of mappings from low-level logical param indexes
959                        to physical buffer locations in the integer buffer.
960                @note
961                        Only applicable to low-level programs.
962                */
963                const GpuLogicalBufferStruct* getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
964                /// Get a reference to the list of float constants
965                const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
966                /// Get a pointer to the 'nth' item in the float buffer
967                float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
968                /// Get a pointer to the 'nth' item in the float buffer
969                const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
970                /// Get a reference to the list of int constants
971                const IntConstantList& getIntConstantList() const { return mIntConstants; }
972                /// Get a pointer to the 'nth' item in the int buffer
973                int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
974                /// Get a pointer to the 'nth' item in the int buffer
975                const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
976                /// Get a reference to the list of auto constant bindings
977                const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
978
979        /** Sets up a constant which will automatically be updated by the system.
980        @remarks
981            Vertex and fragment programs often need parameters which are to do with the
982            current render state, or particular values which may very well change over time,
983            and often between objects which are being rendered. This feature allows you
984            to set up a certain number of predefined parameter mappings that are kept up to
985            date for you.
986        @param index The location in the constant list to place this updated constant every time
987            it is changed. Note that because of the nature of the types, we know how big the
988            parameter details will be so you don't need to set that like you do for manual constants.
989        @param acType The type of automatic constant to set
990        @param extraInfo If the constant type needs more information (like a light index) put it here.
991        */
992        void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
993                void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
994
995                /** As setAutoConstant, but sets up the auto constant directly against a
996                        physical buffer index.
997                */
998                void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo, 
999                        size_t elementSize = 4);
1000                /** As setAutoConstantReal, but sets up the auto constant directly against a
1001                physical buffer index.
1002                */
1003                void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData, 
1004                        size_t elementSize = 4);
1005
1006
1007                /** Unbind an auto constant so that the constant is manually controlled again. */
1008                void clearAutoConstant(size_t index);
1009
1010        /** Sets a named parameter up to track a derivation of the current time.
1011        @param index The index of the parameter
1012        @param factor The amount by which to scale the time value
1013        */ 
1014        void setConstantFromTime(size_t index, Real factor);
1015
1016        /** Clears all the existing automatic constants. */
1017        void clearAutoConstants(void);
1018        typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
1019        /** Gets an iterator over the automatic constant bindings currently in place. */
1020        AutoConstantIterator getAutoConstantIterator(void) const;
1021        /// Gets the number of int constants that have been set
1022        size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
1023                /** Gets a specific Auto Constant entry if index is in valid range
1024                        otherwise returns a NULL
1025                @parem index which entry is to be retrieved
1026                */
1027                AutoConstantEntry* getAutoConstantEntry(const size_t index);
1028        /** Returns true if this instance has any automatic constants. */
1029        bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
1030                /** Finds an auto constant that's affecting a given logical parameter
1031                        index for floating-point values.
1032                @note Only applicable for low-level programs.
1033                */
1034                const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
1035                /** Finds an auto constant that's affecting a given logical parameter
1036                index for integer values.
1037                @note Only applicable for low-level programs.
1038                */
1039                const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
1040                /** Finds an auto constant that's affecting a given named parameter index.
1041                @note Only applicable to high-level programs.
1042                */
1043                const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
1044                /** Finds an auto constant that's affecting a given physical position in
1045                        the floating-point buffer
1046                */
1047                const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
1048                /** Finds an auto constant that's affecting a given physical position in
1049                the integer buffer
1050                */
1051                const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
1052
1053        /** Updates the automatic parameters (except lights) based on the details provided. */
1054        void _updateAutoParamsNoLights(const AutoParamDataSource& source);
1055        /** Updates the automatic parameters for lights based on the details provided. */
1056        void _updateAutoParamsLightsOnly(const AutoParamDataSource& source);
1057
1058                /** Tells the program whether to ignore missing parameters or not.
1059                */
1060                void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
1061
1062                /** Sets a single value constant floating-point parameter to the program.
1063        @remarks
1064            Different types of GPU programs support different types of constant parameters.
1065            For example, it's relatively common to find that vertex programs only support
1066            floating point constants, and that fragment programs only support integer (fixed point)
1067            parameters. This can vary depending on the program version supported by the
1068            graphics card being used. You should consult the documentation for the type of
1069            low level program you are using, or alternatively use the methods
1070            provided on RenderSystemCapabilities to determine the options.
1071        @par
1072            Another possible limitation is that some systems only allow constants to be set
1073            on certain boundaries, e.g. in sets of 4 values for example. Again, see
1074            RenderSystemCapabilities for full details.
1075        @note
1076            This named option will only work if you are using a parameters object created
1077            from a high-level program (HighLevelGpuProgram).
1078                @param name The name of the parameter
1079                @param val The value to set
1080                */
1081                void setNamedConstant(const String& name, Real val);
1082                /** Sets a single value constant integer parameter to the program.
1083        @remarks
1084            Different types of GPU programs support different types of constant parameters.
1085            For example, it's relatively common to find that vertex programs only support
1086            floating point constants, and that fragment programs only support integer (fixed point)
1087            parameters. This can vary depending on the program version supported by the
1088            graphics card being used. You should consult the documentation for the type of
1089            low level program you are using, or alternatively use the methods
1090            provided on RenderSystemCapabilities to determine the options.
1091        @par
1092            Another possible limitation is that some systems only allow constants to be set
1093            on certain boundaries, e.g. in sets of 4 values for example. Again, see
1094            RenderSystemCapabilities for full details.
1095        @note
1096            This named option will only work if you are using a parameters object created
1097            from a high-level program (HighLevelGpuProgram).
1098        @param name The name of the parameter
1099                @param val The value to set
1100                */
1101                void setNamedConstant(const String& name, int val);
1102                /** Sets a Vector4 parameter to the program.
1103        @param name The name of the parameter
1104                @param vec The value to set
1105                */
1106                void setNamedConstant(const String& name, const Vector4& vec);
1107                /** Sets a Vector3 parameter to the program.
1108        @note
1109            This named option will only work if you are using a parameters object created
1110            from a high-level program (HighLevelGpuProgram).
1111                @param index The index at which to place the parameter
1112                        NB this index refers to the number of floats, so a Vector3 is 3. Note that many
1113            rendersystems & programs assume that every floating point parameter is passed in
1114            as a vector of 4 items, so you are strongly advised to check with
1115            RenderSystemCapabilities before using this version - if in doubt use Vector4
1116            or ColourValue instead (both are 4D).
1117                @param vec The value to set
1118                */
1119                void setNamedConstant(const String& name, const Vector3& vec);
1120                /** Sets a Matrix4 parameter to the program.
1121        @param name The name of the parameter
1122                @param m The value to set
1123                */
1124                void setNamedConstant(const String& name, const Matrix4& m);
1125        /** Sets a list of Matrix4 parameters to the program.
1126        @param name The name of the parameter; this must be the first index of an array,
1127            for examples 'matrices[0]'
1128        NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
1129        @param m Pointer to an array of matrices to set
1130        @param numEntries Number of Matrix4 entries
1131        */
1132        void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
1133                /** Sets a multiple value constant floating-point parameter to the program.
1134        @par
1135            Some systems only allow constants to be set on certain boundaries,
1136                        e.g. in sets of 4 values for example. The 'multiple' parameter allows
1137                        you to control that although you should only change it if you know
1138                        your chosen language supports that (at the time of writing, only
1139                        GLSL allows constants which are not a multiple of 4).
1140        @note
1141            This named option will only work if you are using a parameters object created
1142            from a high-level program (HighLevelGpuProgram).
1143        @param name The name of the parameter
1144                @param val Pointer to the values to write
1145                @param count The number of 'multiples' of floats to write
1146                @param multiple The number of raw entries in each element to write,
1147                        the default is 4 so count = 1 would write 4 floats.
1148                */
1149                void setNamedConstant(const String& name, const float *val, size_t count, 
1150                        size_t multiple = 4);
1151                /** Sets a multiple value constant floating-point parameter to the program.
1152        @par
1153            Some systems only allow constants to be set on certain boundaries,
1154                        e.g. in sets of 4 values for example. The 'multiple' parameter allows
1155                        you to control that although you should only change it if you know
1156                        your chosen language supports that (at the time of writing, only
1157                        GLSL allows constants which are not a multiple of 4).
1158        @note
1159            This named option will only work if you are using a parameters object created
1160            from a high-level program (HighLevelGpuProgram).
1161        @param name The name of the parameter
1162                @param val Pointer to the values to write
1163                @param count The number of 'multiples' of floats to write
1164                @param multiple The number of raw entries in each element to write,
1165                        the default is 4 so count = 1 would write 4 floats.
1166                */
1167                void setNamedConstant(const String& name, const double *val, size_t count, 
1168                        size_t multiple = 4);
1169                /** Sets a ColourValue parameter to the program.
1170        @param name The name of the parameter
1171                @param colour The value to set
1172                */
1173        void setNamedConstant(const String& name, const ColourValue& colour);
1174               
1175                /** Sets a multiple value constant floating-point parameter to the program.
1176        @par
1177            Some systems only allow constants to be set on certain boundaries,
1178                        e.g. in sets of 4 values for example. The 'multiple' parameter allows
1179                        you to control that although you should only change it if you know
1180                        your chosen language supports that (at the time of writing, only
1181                        GLSL allows constants which are not a multiple of 4).
1182        @note
1183            This named option will only work if you are using a parameters object created
1184            from a high-level program (HighLevelGpuProgram).
1185        @param name The name of the parameter
1186                @param val Pointer to the values to write
1187                @param count The number of 'multiples' of floats to write
1188                @param multiple The number of raw entries in each element to write,
1189                        the default is 4 so count = 1 would write 4 floats.
1190                */
1191                void setNamedConstant(const String& name, const int *val, size_t count, 
1192                        size_t multiple = 4);
1193
1194        /** Sets up a constant which will automatically be updated by the system.
1195        @remarks
1196            Vertex and fragment programs often need parameters which are to do with the
1197            current render state, or particular values which may very well change over time,
1198            and often between objects which are being rendered. This feature allows you
1199            to set up a certain number of predefined parameter mappings that are kept up to
1200            date for you.
1201        @note
1202            This named option will only work if you are using a parameters object created
1203            from a high-level program (HighLevelGpuProgram).
1204        @param name The name of the parameter
1205        @param acType The type of automatic constant to set
1206        @param extraInfo If the constant type needs more information (like a light index) put it here.
1207        */
1208        void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
1209                void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
1210
1211        /** Sets a named parameter up to track a derivation of the current time.
1212        @note
1213            This named option will only work if you are using a parameters object created
1214            from a high-level program (HighLevelGpuProgram).
1215        @param name The name of the parameter
1216        @param factor The amount by which to scale the time value
1217        */ 
1218        void setNamedConstantFromTime(const String& name, Real factor);
1219
1220                /** Unbind an auto constant so that the constant is manually controlled again. */
1221                void clearNamedAutoConstant(const String& name);
1222
1223        /** Find a constant definition for a named parameter.
1224                @remarks
1225                        This method returns null if the named parameter did not exist, unlike
1226                        getConstantDefinition which is more strict; unless you set the
1227                        last parameter to true.
1228                @param name The name to look up
1229                @param throwExceptionIfMissing If set to true, failure to find an entry
1230                        will throw an exception.
1231                */
1232        const GpuConstantDefinition* _findNamedConstantDefinition(
1233                        const String& name, bool throwExceptionIfMissing = false) const;
1234                /** Gets the physical buffer index associated with a logical float constant index.
1235                @note Only applicable to low-level programs.
1236                @param logicalIndex The logical parameter index
1237                @param requestedSize The requested size - pass 0 to ignore missing entries
1238                        and return std::numeric_limits<size_t>::max()
1239                */
1240                size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
1241                /** Gets the physical buffer index associated with a logical int constant index.
1242                @note Only applicable to low-level programs.
1243                @param logicalIndex The logical parameter index
1244                @param requestedSize The requested size - pass 0 to ignore missing entries
1245                        and return std::numeric_limits<size_t>::max()
1246                */
1247                size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
1248
1249
1250        /** Sets whether or not we need to transpose the matrices passed in from the rest of OGRE.
1251        @remarks
1252            D3D uses transposed matrices compared to GL and OGRE; this is not important when you
1253            use programs which are written to process row-major matrices, such as those generated
1254            by Cg, but if you use a program written to D3D's matrix layout you will need to enable
1255            this flag.
1256        */
1257        void setTransposeMatrices(bool val) { mTransposeMatrices = val; } 
1258        /// Gets whether or not matrices are to be transposed when set
1259        bool getTransposeMatrices(void) const { return mTransposeMatrices; } 
1260
1261                /** Copies the values of all constants (including auto constants) from another
1262                        GpuProgramParameters object.
1263                */
1264                void copyConstantsFrom(const GpuProgramParameters& source);
1265
1266        /** gets the auto constant definition associated with name if found else returns NULL
1267        @param name The name of the auto constant
1268        */
1269        static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
1270        /** gets the auto constant definition using an index into the auto constant definition array.
1271            If the index is out of bounds then NULL is returned;
1272        @param idx The auto constant index
1273        */
1274        static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
1275        /** Returns the number of auto constant definitions
1276        */
1277        static size_t getNumAutoConstantDefinitions(void);
1278
1279
1280        /** increments the multipass number entry by 1 if it exists
1281        */
1282        void incPassIterationNumber(void);
1283                /** Does this parameters object have a pass iteration number constant? */
1284                bool hasPassIterationNumber() const 
1285                { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
1286                /** Get the physical buffer index of the pass iteration number constant */
1287                size_t getPassIterationNumberIndex() const 
1288                { return mActivePassIterationIndex; }
1289
1290
1291    };
1292
1293    /// Shared pointer used to hold references to GpuProgramParameters instances
1294    typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
1295
1296    // Forward declaration
1297    class GpuProgramPtr;
1298
1299        /** Defines a program which runs on the GPU such as a vertex or fragment program.
1300        @remarks
1301                This class defines the low-level program in assembler code, the sort used to
1302                directly assemble into machine instructions for the GPU to execute. By nature,
1303                this means that the assembler source is rendersystem specific, which is why this
1304                is an abstract class - real instances are created through the RenderSystem.
1305                If you wish to use higher level shading languages like HLSL and Cg, you need to
1306                use the HighLevelGpuProgram class instead.
1307        */
1308        class _OgreExport GpuProgram : public Resource
1309        {
1310        protected:
1311                /// Command object - see ParamCommand
1312                class _OgreExport CmdType : public ParamCommand
1313                {
1314                public:
1315                        String doGet(const void* target) const;
1316                        void doSet(void* target, const String& val);
1317                };
1318                class _OgreExport CmdSyntax : public ParamCommand
1319                {
1320                public:
1321                        String doGet(const void* target) const;
1322                        void doSet(void* target, const String& val);
1323                };
1324                class _OgreExport CmdSkeletal : public ParamCommand
1325                {
1326                public:
1327                        String doGet(const void* target) const;
1328                        void doSet(void* target, const String& val);
1329                };
1330                class _OgreExport CmdMorph : public ParamCommand
1331                {
1332                public:
1333                        String doGet(const void* target) const;
1334                        void doSet(void* target, const String& val);
1335                };
1336                class _OgreExport CmdPose : public ParamCommand
1337                {
1338                public:
1339                        String doGet(const void* target) const;
1340                        void doSet(void* target, const String& val);
1341                };
1342                class _OgreExport CmdVTF : public ParamCommand
1343                {
1344                public:
1345                        String doGet(const void* target) const;
1346                        void doSet(void* target, const String& val);
1347                };
1348                // Command object for setting / getting parameters
1349                static CmdType msTypeCmd;
1350                static CmdSyntax msSyntaxCmd;
1351                static CmdSkeletal msSkeletalCmd;
1352                static CmdMorph msMorphCmd;
1353                static CmdPose msPoseCmd;
1354                static CmdVTF msVTFCmd;
1355       
1356                /// The type of the program
1357                GpuProgramType mType;
1358                /// The name of the file to load source from (may be blank)
1359                String mFilename;
1360        /// The assembler source of the program (may be blank until file loaded)
1361        String mSource;
1362        /// Whether we need to load source from file or not
1363        bool mLoadFromFile;
1364        /// Syntax code eg arbvp1, vs_2_0 etc
1365        String mSyntaxCode;
1366        /// Does this (vertex) program include skeletal animation?
1367        bool mSkeletalAnimation;
1368                /// Does this (vertex) program include morph animation?
1369                bool mMorphAnimation;
1370                /// Does this (vertex) program include pose animation (count of number of poses supported)
1371                ushort mPoseAnimation;
1372                /// Does this (vertex) program require support for vertex texture fetch?
1373                bool mVertexTextureFetch;
1374                /// The default parameters for use with this object
1375                GpuProgramParametersSharedPtr mDefaultParams;
1376                /// Does this program want light states passed through fixed pipeline
1377                bool mPassSurfaceAndLightStates;
1378                /// Did we encounter a compilation error?
1379                bool mCompileError;
1380                /** Record of logical to physical buffer maps. Mandatory for low-level
1381                        programs or high-level programs which set their params the same way. */
1382                mutable GpuLogicalBufferStruct mFloatLogicalToPhysical;
1383                /** Record of logical to physical buffer maps. Mandatory for low-level
1384                        programs or high-level programs which set their params the same way. */
1385                mutable GpuLogicalBufferStruct mIntLogicalToPhysical;
1386
1387                /** Internal method for setting up the basic parameter definitions for a subclass.
1388                @remarks
1389                Because StringInterface holds a dictionary of parameters per class, subclasses need to
1390                call this to ask the base class to add it's parameters to their dictionary as well.
1391                Can't do this in the constructor because that runs in a non-virtual context.
1392                @par
1393                The subclass must have called it's own createParamDictionary before calling this method.
1394                */
1395                void setupBaseParamDictionary(void);
1396
1397        /** Internal method returns whether required capabilities for this program is supported.
1398        */
1399        bool isRequiredCapabilitiesSupported(void) const;
1400
1401                /// @copydoc Resource::calculateSize
1402                size_t calculateSize(void) const { return 0; } // TODO
1403
1404                /// @copydoc Resource::loadImpl
1405                void loadImpl(void);
1406        public:
1407
1408                GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
1409                        const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
1410
1411                virtual ~GpuProgram() {}
1412
1413        /** Sets the filename of the source assembly for this program.
1414        @remarks
1415            Setting this will have no effect until you (re)load the program.
1416        */
1417        virtual void setSourceFile(const String& filename);
1418
1419                /** Sets the source assembly for this program from an in-memory string.
1420        @remarks
1421            Setting this will have no effect until you (re)load the program.
1422        */
1423        virtual void setSource(const String& source);
1424
1425        /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
1426        virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
1427
1428                /** Sets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
1429                virtual void setSyntaxCode(const String& syntax);
1430
1431                /** Gets the name of the file used as source for this program. */
1432                virtual const String& getSourceFile(void) const { return mFilename; }
1433        /** Gets the assembler source for this program. */
1434        virtual const String& getSource(void) const { return mSource; }
1435                /// Set the program type (only valid before load)
1436                virtual void setType(GpuProgramType t);
1437        /// Get the program type
1438        virtual GpuProgramType getType(void) const { return mType; }
1439
1440        /** Returns the GpuProgram which should be bound to the pipeline.
1441        @remarks
1442            This method is simply to allow some subclasses of GpuProgram to delegate
1443            the program which is bound to the pipeline to a delegate, if required. */
1444        virtual GpuProgram* _getBindingDelegate(void) { return this; }
1445
1446        /** Returns whether this program can be supported on the current renderer and hardware. */
1447        virtual bool isSupported(void) const;
1448
1449        /** Creates a new parameters object compatible with this program definition.
1450        @remarks
1451            It is recommended that you use this method of creating parameters objects
1452            rather than going direct to GpuProgramManager, because this method will
1453            populate any implementation-specific extras (like named parameters) where
1454            they are appropriate.
1455        */
1456        virtual GpuProgramParametersSharedPtr createParameters(void);
1457
1458        /** Sets whether a vertex program includes the required instructions
1459        to perform skeletal animation.
1460        @remarks
1461        If this is set to true, OGRE will not blend the geometry according to
1462        skeletal animation, it will expect the vertex program to do it.
1463        */
1464        virtual void setSkeletalAnimationIncluded(bool included) 
1465        { mSkeletalAnimation = included; }
1466
1467        /** Returns whether a vertex program includes the required instructions
1468            to perform skeletal animation.
1469        @remarks
1470            If this returns true, OGRE will not blend the geometry according to
1471            skeletal animation, it will expect the vertex program to do it.
1472        */
1473        virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
1474
1475        /** Sets whether a vertex program includes the required instructions
1476        to perform morph animation.
1477        @remarks
1478        If this is set to true, OGRE will not blend the geometry according to
1479        morph animation, it will expect the vertex program to do it.
1480        */
1481        virtual void setMorphAnimationIncluded(bool included) 
1482                { mMorphAnimation = included; }
1483
1484        /** Sets whether a vertex program includes the required instructions
1485        to perform pose animation.
1486        @remarks
1487        If this is set to true, OGRE will not blend the geometry according to
1488        pose animation, it will expect the vertex program to do it.
1489                @param poseCount The number of simultaneous poses the program can blend
1490        */
1491        virtual void setPoseAnimationIncluded(ushort poseCount) 
1492                { mPoseAnimation = poseCount; }
1493
1494                /** Returns whether a vertex program includes the required instructions
1495            to perform morph animation.
1496        @remarks
1497            If this returns true, OGRE will not blend the geometry according to
1498            morph animation, it will expect the vertex program to do it.
1499        */
1500        virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
1501
1502                /** Returns whether a vertex program includes the required instructions
1503            to perform pose animation.
1504        @remarks
1505            If this returns true, OGRE will not blend the geometry according to
1506            pose animation, it will expect the vertex program to do it.
1507        */
1508        virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
1509                /** Returns the number of simultaneous poses the vertex program can
1510                        blend, for use in pose animation.
1511        */
1512        virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
1513                /** Sets whether this vertex program requires support for vertex
1514                        texture fetch from the hardware.
1515                */
1516                virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
1517                /** Returns whether this vertex program requires support for vertex
1518                        texture fetch from the hardware.
1519                */
1520                virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
1521
1522                /** Get a reference to the default parameters which are to be used for all
1523                        uses of this program.
1524                @remarks
1525                        A program can be set up with a list of default parameters, which can save time when
1526                        using a program many times in a material with roughly the same settings. By
1527                        retrieving the default parameters and populating it with the most used options,
1528                        any new parameter objects created from this program afterwards will automatically include
1529                        the default parameters; thus users of the program need only change the parameters
1530                        which are unique to their own usage of the program.
1531                */
1532                virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
1533
1534        /** Returns true if default parameters have been set up. 
1535        */
1536        virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
1537
1538                /** Sets whether a vertex program requires light and material states to be passed
1539                to through fixed pipeline low level API rendering calls.
1540                @remarks
1541                If this is set to true, OGRE will pass all active light states to the fixed function
1542                pipeline.  This is useful for high level shaders like GLSL that can read the OpenGL
1543                light and material states.  This way the user does not have to use autoparameters to
1544                pass light position, color etc.
1545                */
1546                virtual void setSurfaceAndPassLightStates(bool state)
1547                        { mPassSurfaceAndLightStates = state; }
1548
1549                /** Returns whether a vertex program wants light and material states to be passed
1550                through fixed pipeline low level API rendering calls
1551                */
1552                virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
1553
1554        /** Returns a string that specifies the language of the gpu programs as specified
1555        in a material script. ie: asm, cg, hlsl, glsl
1556        */
1557        virtual const String& getLanguage(void) const;
1558
1559                /** Did this program encounter a compile error when loading?
1560                */
1561                virtual bool hasCompileError(void) const { return mCompileError; }
1562
1563                /** Reset a compile error if it occurred, allowing the load to be retried
1564                */
1565                virtual void resetCompileError(void) { mCompileError = false; }
1566    protected:
1567        /// Virtual method which must be implemented by subclasses, load from mSource
1568        virtual void loadFromSource(void) = 0;
1569
1570        };
1571
1572
1573        /** Specialisation of SharedPtr to allow SharedPtr to be assigned to GpuProgramPtr
1574        @note Has to be a subclass since we need operator=.
1575        We could templatise this instead of repeating per Resource subclass,
1576        except to do so requires a form VC6 does not support i.e.
1577        ResourceSubclassPtr<T> : public SharedPtr<T>
1578        */
1579        class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram> 
1580        {
1581        public:
1582                GpuProgramPtr() : SharedPtr<GpuProgram>() {}
1583                explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
1584                GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {} 
1585                GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
1586                {
1587                        // lock & copy other mutex pointer
1588            OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
1589            {
1590                            OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
1591                            OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
1592                            pRep = static_cast<GpuProgram*>(r.getPointer());
1593                            pUseCount = r.useCountPointer();
1594                            if (pUseCount)
1595                            {
1596                                    ++(*pUseCount);
1597                            }
1598            }
1599                }
1600
1601                /// Operator used to convert a ResourcePtr to a GpuProgramPtr
1602                GpuProgramPtr& operator=(const ResourcePtr& r)
1603                {
1604                        if (pRep == static_cast<GpuProgram*>(r.getPointer()))
1605                                return *this;
1606                        release();
1607                        // lock & copy other mutex pointer
1608            OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
1609            {
1610                OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
1611                            OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
1612                            pRep = static_cast<GpuProgram*>(r.getPointer());
1613                            pUseCount = r.useCountPointer();
1614                            if (pUseCount)
1615                            {
1616                                    ++(*pUseCount);
1617                            }
1618            }
1619                        else
1620                        {
1621                                // RHS must be a null pointer
1622                                assert(r.isNull() && "RHS must be null if it has no mutex!");
1623                                setNull();
1624                        }
1625                        return *this;
1626                }
1627        /// Operator used to convert a HighLevelGpuProgramPtr to a GpuProgramPtr
1628        GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
1629        };
1630}
1631
1632#endif
Note: See TracBrowser for help on using the repository browser.