Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreGpuProgramParams.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 84.8 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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __GpuProgramParams_H_
29#define __GpuProgramParams_H_
30
31// Precompiler options
32#include "OgrePrerequisites.h"
33#include "OgreSharedPtr.h"
34#include "OgreIteratorWrappers.h"
35#include "OgreSerializer.h"
36#include "OgreRenderOperation.h"
37#include "OgreAny.h"
38#include "Threading/OgreThreadHeaders.h"
39#include "OgreHeaderPrefix.h"
40
41namespace Ogre {
42
43        /** \addtogroup Core
44        *  @{
45        */
46        /** \addtogroup Materials
47        *  @{
48        */
49        /** Enumeration of the types of constant we may encounter in programs.
50        @note Low-level programs, by definition, will always use either
51        float4 or int4 constant types since that is the fundamental underlying
52        type in assembler.
53        */
54        enum GpuConstantType
55        {
56                GCT_FLOAT1 = 1,
57                GCT_FLOAT2 = 2,
58                GCT_FLOAT3 = 3,
59                GCT_FLOAT4 = 4,
60                GCT_SAMPLER1D = 5,
61                GCT_SAMPLER2D = 6,
62                GCT_SAMPLER3D = 7,
63                GCT_SAMPLERCUBE = 8,
64                GCT_SAMPLERRECT = 9,
65                GCT_SAMPLER1DSHADOW = 10,
66                GCT_SAMPLER2DSHADOW = 11,
67                GCT_SAMPLER2DARRAY = 12,
68                GCT_MATRIX_2X2 = 13,
69                GCT_MATRIX_2X3 = 14,
70                GCT_MATRIX_2X4 = 15,
71                GCT_MATRIX_3X2 = 16,
72                GCT_MATRIX_3X3 = 17,
73                GCT_MATRIX_3X4 = 18,
74                GCT_MATRIX_4X2 = 19,
75                GCT_MATRIX_4X3 = 20,
76                GCT_MATRIX_4X4 = 21,
77                GCT_INT1 = 22,
78                GCT_INT2 = 23,
79                GCT_INT3 = 24,
80                GCT_INT4 = 25,
81                GCT_SUBROUTINE = 26,
82                GCT_DOUBLE1 = 27,
83                GCT_DOUBLE2 = 28,
84                GCT_DOUBLE3 = 29,
85                GCT_DOUBLE4 = 30,
86                GCT_MATRIX_DOUBLE_2X2 = 31,
87                GCT_MATRIX_DOUBLE_2X3 = 32,
88                GCT_MATRIX_DOUBLE_2X4 = 33,
89                GCT_MATRIX_DOUBLE_3X2 = 34,
90                GCT_MATRIX_DOUBLE_3X3 = 35,
91                GCT_MATRIX_DOUBLE_3X4 = 36,
92                GCT_MATRIX_DOUBLE_4X2 = 37,
93                GCT_MATRIX_DOUBLE_4X3 = 38,
94                GCT_MATRIX_DOUBLE_4X4 = 39,
95                GCT_UNKNOWN = 99
96        };
97
98        /** The variability of a GPU parameter, as derived from auto-params targeting it.
99        These values must be powers of two since they are used in masks.
100        */
101        enum GpuParamVariability
102        {
103                /// No variation except by manual setting - the default
104                GPV_GLOBAL = 1, 
105                /// Varies per object (based on an auto param usually), but not per light setup
106                GPV_PER_OBJECT = 2, 
107                /// Varies with light setup
108                GPV_LIGHTS = 4, 
109                /// Varies with pass iteration number
110                GPV_PASS_ITERATION_NUMBER = 8,
111
112
113                /// Full mask (16-bit)
114                GPV_ALL = 0xFFFF
115
116        };
117
118        /** Information about predefined program constants.
119        @note Only available for high-level programs but is referenced generically
120        by GpuProgramParameters.
121        */
122        struct _OgreExport GpuConstantDefinition
123        {
124                /// Data type
125                GpuConstantType constType;
126                /// Physical start index in buffer (either float, double or int buffer)
127                size_t physicalIndex;
128                /// Logical index - used to communicate this constant to the rendersystem
129                size_t logicalIndex;
130                /** Number of raw buffer slots per element
131                (some programs pack each array element to float4, some do not) */
132                size_t elementSize;
133                /// Length of array
134                size_t arraySize;
135                /// How this parameter varies (bitwise combination of GpuProgramVariability)
136                mutable uint16 variability;
137
138                bool isFloat() const
139                {
140                        return isFloat(constType);
141                }
142
143                static bool isFloat(GpuConstantType c)
144                {
145                        switch(c)
146                        {
147                        case GCT_INT1:
148                        case GCT_INT2:
149                        case GCT_INT3:
150                        case GCT_INT4:
151                        case GCT_SAMPLER1D:
152                        case GCT_SAMPLER2D:
153            case GCT_SAMPLER2DARRAY:
154                        case GCT_SAMPLER3D:
155                        case GCT_SAMPLERCUBE:
156                        case GCT_SAMPLER1DSHADOW:
157                        case GCT_SAMPLER2DSHADOW:
158                                return false;
159                        default:
160                                return true;
161                        };
162
163                }
164
165        bool isDouble() const
166                {
167                        return isDouble(constType);
168                }
169
170                static bool isDouble(GpuConstantType c)
171                {
172                        switch(c)
173                        {
174                case GCT_INT1:
175                case GCT_INT2:
176                case GCT_INT3:
177                case GCT_INT4:
178                case GCT_FLOAT1:
179                case GCT_FLOAT2:
180                case GCT_FLOAT3:
181                case GCT_FLOAT4:
182                case GCT_SAMPLER1D:
183                case GCT_SAMPLER2D:
184                case GCT_SAMPLER2DARRAY:
185                case GCT_SAMPLER3D:
186                case GCT_SAMPLERCUBE:
187                case GCT_SAMPLER1DSHADOW:
188                case GCT_SAMPLER2DSHADOW:
189                    return false;
190                default:
191                    return true;
192                        };
193           
194                }
195
196                bool isSampler() const
197                {
198                        return isSampler(constType);
199                }
200
201                static bool isSampler(GpuConstantType c)
202                {
203                        switch(c)
204                        {
205                        case GCT_SAMPLER1D:
206                        case GCT_SAMPLER2D:
207            case GCT_SAMPLER2DARRAY:
208                        case GCT_SAMPLER3D:
209                        case GCT_SAMPLERCUBE:
210                        case GCT_SAMPLER1DSHADOW:
211                        case GCT_SAMPLER2DSHADOW:
212                                return true;
213                        default:
214                                return false;
215                        };
216
217                }
218
219                bool isSubroutine() const
220                {
221                        return isSubroutine(constType);
222                }
223
224                static bool isSubroutine(GpuConstantType c)
225                {
226                        return c == GCT_SUBROUTINE;
227                }
228
229                /** Get the element size of a given type, including whether to pad the
230                        elements into multiples of 4 (e.g. SM1 and D3D does, GLSL doesn't)
231                */
232                static size_t getElementSize(GpuConstantType ctype, bool padToMultiplesOf4)
233                {
234                        if (padToMultiplesOf4)
235                        {
236                                switch(ctype)
237                                {
238                                case GCT_FLOAT1:
239                                case GCT_INT1:
240                                case GCT_SAMPLER1D:
241                                case GCT_SAMPLER2D:
242                case GCT_SAMPLER2DARRAY:
243                                case GCT_SAMPLER3D:
244                                case GCT_SAMPLERCUBE:
245                                case GCT_SAMPLER1DSHADOW:
246                                case GCT_SAMPLER2DSHADOW:
247                                case GCT_FLOAT2:
248                                case GCT_INT2:
249                                case GCT_FLOAT3:
250                                case GCT_INT3:
251                                case GCT_FLOAT4:
252                                case GCT_INT4:
253                                        return 4;
254                                case GCT_MATRIX_2X2:
255                                case GCT_MATRIX_2X3:
256                                case GCT_MATRIX_2X4:
257                case GCT_DOUBLE1:
258                case GCT_DOUBLE2:
259                case GCT_DOUBLE3:
260                case GCT_DOUBLE4:
261                                        return 8; // 2 float4s
262                                case GCT_MATRIX_3X2:
263                                case GCT_MATRIX_3X3:
264                                case GCT_MATRIX_3X4:
265                                        return 12; // 3 float4s
266                                case GCT_MATRIX_4X2:
267                                case GCT_MATRIX_4X3:
268                                case GCT_MATRIX_4X4:
269                case GCT_MATRIX_DOUBLE_2X2:
270                case GCT_MATRIX_DOUBLE_2X3:
271                case GCT_MATRIX_DOUBLE_2X4:
272                                        return 16; // 4 float4s
273                case GCT_MATRIX_DOUBLE_3X2:
274                case GCT_MATRIX_DOUBLE_3X3:
275                case GCT_MATRIX_DOUBLE_3X4:
276                    return 24;
277                case GCT_MATRIX_DOUBLE_4X2:
278                case GCT_MATRIX_DOUBLE_4X3:
279                case GCT_MATRIX_DOUBLE_4X4:
280                    return 32;
281                                default:
282                                        return 4;
283                                };
284                        }
285                        else
286                        {
287                                switch(ctype)
288                                {
289                                case GCT_FLOAT1:
290                case GCT_DOUBLE1:
291                                case GCT_INT1:
292                                case GCT_SAMPLER1D:
293                                case GCT_SAMPLER2D:
294                case GCT_SAMPLER2DARRAY:
295                                case GCT_SAMPLER3D:
296                                case GCT_SAMPLERCUBE:
297                                case GCT_SAMPLER1DSHADOW:
298                                case GCT_SAMPLER2DSHADOW:
299                                        return 1;
300                                case GCT_FLOAT2:
301                                case GCT_INT2:
302                case GCT_DOUBLE2:
303                                        return 2;
304                                case GCT_FLOAT3:
305                                case GCT_INT3:
306                case GCT_DOUBLE3:
307                                        return 3;
308                                case GCT_FLOAT4:
309                                case GCT_INT4:
310                case GCT_DOUBLE4:
311                                        return 4;
312                                case GCT_MATRIX_2X2:
313                case GCT_MATRIX_DOUBLE_2X2:
314                                        return 4;
315                                case GCT_MATRIX_2X3:
316                                case GCT_MATRIX_3X2:
317                case GCT_MATRIX_DOUBLE_2X3:
318                case GCT_MATRIX_DOUBLE_3X2:
319                                        return 6;
320                                case GCT_MATRIX_2X4:
321                                case GCT_MATRIX_4X2:
322                case GCT_MATRIX_DOUBLE_2X4:
323                case GCT_MATRIX_DOUBLE_4X2:
324                                        return 8;
325                                case GCT_MATRIX_3X3:
326                case GCT_MATRIX_DOUBLE_3X3:
327                                        return 9;
328                                case GCT_MATRIX_3X4:
329                                case GCT_MATRIX_4X3:
330                case GCT_MATRIX_DOUBLE_3X4:
331                case GCT_MATRIX_DOUBLE_4X3:
332                                        return 12;
333                                case GCT_MATRIX_4X4:
334                case GCT_MATRIX_DOUBLE_4X4:
335                                        return 16;
336                                default:
337                                        return 4;
338                                };
339
340                        }
341                }
342
343                GpuConstantDefinition()
344                        : constType(GCT_UNKNOWN)
345                        , physicalIndex((std::numeric_limits<size_t>::max)())
346            , logicalIndex(0)
347                        , elementSize(0)
348                        , arraySize(1)
349                        , variability(GPV_GLOBAL) {}
350        };
351        typedef map<String, GpuConstantDefinition>::type GpuConstantDefinitionMap;
352        typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
353
354        /// Struct collecting together the information for named constants.
355        struct _OgreExport GpuNamedConstants : public GpuParamsAlloc
356        {
357                /// Total size of the float buffer required
358                size_t floatBufferSize;
359                /// Total size of the double buffer required
360                size_t doubleBufferSize;
361                /// Total size of the int buffer required
362                size_t intBufferSize;
363                /// Map of parameter names to GpuConstantDefinition
364                GpuConstantDefinitionMap map;
365
366                GpuNamedConstants() : floatBufferSize(0), doubleBufferSize(0), intBufferSize(0) {}
367
368                /** Generate additional constant entries for arrays based on a base definition.
369                @remarks
370                Array uniforms will be added just with their base name with no array
371                suffix. This method will add named entries for array suffixes too
372                so individual array entries can be addressed. Note that we only
373                individually index array elements if the array size is up to 16
374                entries in size. Anything larger than that only gets a [0] entry
375                as well as the main entry, to save cluttering up the name map. After
376                all, you can address the larger arrays in a bulk fashion much more
377                easily anyway.
378                */
379                void generateConstantDefinitionArrayEntries(const String& paramName, 
380                        const GpuConstantDefinition& baseDef);
381
382                /// Indicates whether all array entries will be generated and added to the definitions map
383                static bool getGenerateAllConstantDefinitionArrayEntries();
384
385                /** Sets whether all array entries will be generated and added to the definitions map.
386                @remarks
387                Usually, array entries can only be individually indexed if they're up to 16 entries long,
388                to save memory - arrays larger than that can be set but only via the bulk setting
389                methods. This option allows you to choose to individually index every array entry.
390                */
391                static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
392
393                /** Saves constant definitions to a file, compatible with GpuProgram::setManualNamedConstantsFile.
394                @see GpuProgram::setManualNamedConstantsFile
395                */
396                void save(const String& filename) const;
397                /** Loads constant definitions from a stream, compatible with GpuProgram::setManualNamedConstantsFile.
398                @see GpuProgram::setManualNamedConstantsFile
399                */
400                void load(DataStreamPtr& stream);
401
402        size_t calculateSize(void) const;
403
404        protected:
405                /** Indicates whether all array entries will be generated and added to the definitions map
406                @remarks
407                Normally, the number of array entries added to the definitions map is capped at 16
408                to save memory. Setting this value to <code>true</code> allows all of the entries
409                to be generated and added to the map.
410                */
411                static bool msGenerateAllConstantDefinitionArrayEntries;
412        };
413        typedef SharedPtr<GpuNamedConstants> GpuNamedConstantsPtr;
414
415        /// Simple class for loading / saving GpuNamedConstants
416        class _OgreExport GpuNamedConstantsSerializer : public Serializer
417        {
418        public:
419                GpuNamedConstantsSerializer();
420                virtual ~GpuNamedConstantsSerializer();
421                void exportNamedConstants(const GpuNamedConstants* pConsts, const String& filename,
422                        Endian endianMode = ENDIAN_NATIVE);
423                void exportNamedConstants(const GpuNamedConstants* pConsts, DataStreamPtr stream,
424                        Endian endianMode = ENDIAN_NATIVE);
425                void importNamedConstants(DataStreamPtr& stream, GpuNamedConstants* pDest);
426        };
427
428        /** Structure recording the use of a physical buffer by a logical parameter
429        index. Only used for low-level programs.
430        */
431        struct _OgreExport GpuLogicalIndexUse
432        {
433                /// Physical buffer index
434                size_t physicalIndex;
435                /// Current physical size allocation
436                size_t currentSize;
437                /// How the contents of this slot vary
438                mutable uint16 variability;
439
440                GpuLogicalIndexUse() 
441                        : physicalIndex(99999), currentSize(0), variability(GPV_GLOBAL) {}
442                GpuLogicalIndexUse(size_t bufIdx, size_t curSz, uint16 v) 
443                        : physicalIndex(bufIdx), currentSize(curSz), variability(v) {}
444        };
445        typedef map<size_t, GpuLogicalIndexUse>::type GpuLogicalIndexUseMap;
446        /// Container struct to allow params to safely & update shared list of logical buffer assignments
447        struct _OgreExport GpuLogicalBufferStruct : public GpuParamsAlloc
448        {
449            OGRE_MUTEX(mutex);
450           
451            /// Map from logical index to physical buffer location
452            GpuLogicalIndexUseMap map;
453            /// Shortcut to know the buffer size needs
454            size_t bufferSize;
455            GpuLogicalBufferStruct() : bufferSize(0) {}
456        };
457        typedef SharedPtr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
458
459        /** Definition of container that holds the current float constants.
460        @note Not necessarily in direct index order to constant indexes, logical
461        to physical index map is derived from GpuProgram
462        */
463        typedef vector<float>::type FloatConstantList;
464        /** Definition of container that holds the current double constants.
465     @note Not necessarily in direct index order to constant indexes, logical
466     to physical index map is derived from GpuProgram
467     */
468        typedef vector<double>::type DoubleConstantList;
469        /** Definition of container that holds the current float constants.
470        @note Not necessarily in direct index order to constant indexes, logical
471        to physical index map is derived from GpuProgram
472        */
473        typedef vector<int>::type IntConstantList;
474
475        /** A group of manually updated parameters that are shared between many parameter sets.
476        @remarks
477                Sometimes you want to set some common parameters across many otherwise
478                different parameter sets, and keep them all in sync together. This class
479                allows you to define a set of parameters that you can share across many
480                parameter sets and have the parameters that match automatically be pulled
481                from the shared set, rather than you having to set them on all the parameter
482                sets individually.
483        @par
484                Parameters in a shared set are matched up with instances in a GpuProgramParameters
485                structure by matching names. It is up to you to define the named parameters
486                that a shared set contains, and ensuring the definition matches.
487        @note
488                Shared parameter sets can be named, and looked up using the GpuProgramManager.
489        */
490        class _OgreExport GpuSharedParameters : public GpuParamsAlloc
491        {
492        protected:
493                GpuNamedConstants mNamedConstants;
494                FloatConstantList mFloatConstants;
495                DoubleConstantList mDoubleConstants;
496                IntConstantList mIntConstants;
497                String mName;
498
499                // Optional data the rendersystem might want to store
500                mutable Any mRenderSystemData;
501
502                /// Not used when copying data, but might be useful to RS using shared buffers
503                size_t mFrameLastUpdated;
504
505                /// Version number of the definitions in this buffer
506                unsigned long mVersion; 
507
508        public:
509                GpuSharedParameters(const String& name);
510                virtual ~GpuSharedParameters();
511
512                /// Get the name of this shared parameter set
513                const String& getName() { return mName; }
514
515                /** Add a new constant definition to this shared set of parameters.
516                @remarks
517                        Unlike GpuProgramParameters, where the parameter list is defined by the
518                        program being compiled, this shared parameter set is defined by the
519                        user. Only parameters which have been predefined here may be later
520                        updated.
521                */
522                void addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize = 1);
523
524                /** Remove a constant definition from this shared set of parameters.
525                */
526                void removeConstantDefinition(const String& name);
527
528                /** Remove a constant definition from this shared set of parameters.
529                */
530                void removeAllConstantDefinitions();
531
532                /** Get the version number of this shared parameter set, can be used to identify when
533                        changes have occurred.
534                */
535                unsigned long getVersion() const { return mVersion; }
536
537        size_t calculateSize(void) const;
538
539                /** Mark the shared set as being dirty (values modified).
540                @remarks
541                You do not need to call this yourself, set is marked as dirty whenever
542                setNamedConstant or (non const) getFloatPointer et al are called.
543                */
544                void _markDirty();
545                /// Get the frame in which this shared parameter set was last updated
546                size_t getFrameLastUpdated() const { return mFrameLastUpdated; }
547
548                /** Gets an iterator over the named GpuConstantDefinition instances as defined
549                        by the user.
550                */
551                GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
552
553                /** Get a specific GpuConstantDefinition for a named parameter.
554                */
555                const GpuConstantDefinition& getConstantDefinition(const String& name) const;
556
557                /** Get the full list of GpuConstantDefinition instances.
558                */
559                const GpuNamedConstants& getConstantDefinitions() const;
560       
561                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, Real val) */
562                void setNamedConstant(const String& name, Real val);
563                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, int val) */
564                void setNamedConstant(const String& name, int val);
565                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const Vector4& vec) */
566                void setNamedConstant(const String& name, const Vector4& vec);
567                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const Vector3& vec) */
568                void setNamedConstant(const String& name, const Vector3& vec);
569                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const Vector2& vec) */
570                void setNamedConstant(const String& name, const Vector2& vec);
571                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const Matrix4& m) */
572                void setNamedConstant(const String& name, const Matrix4& m);
573                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const Matrix4* m, size_t numEntries) */
574                void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
575                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const float *val, size_t count) */
576                void setNamedConstant(const String& name, const float *val, size_t count);
577                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const double *val, size_t count) */
578                void setNamedConstant(const String& name, const double *val, size_t count);
579                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const ColourValue& colour) */
580                void setNamedConstant(const String& name, const ColourValue& colour);
581                /** @copydoc GpuProgramParameters::setNamedConstant(const String& name, const int *val, size_t count) */
582                void setNamedConstant(const String& name, const int *val, size_t count);
583
584                /// Get a pointer to the 'nth' item in the float buffer
585                float* getFloatPointer(size_t pos) { _markDirty(); return &mFloatConstants[pos]; }
586                /// Get a pointer to the 'nth' item in the float buffer
587                const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
588                /// Get a pointer to the 'nth' item in the double buffer
589                double* getDoublePointer(size_t pos) { _markDirty(); return &mDoubleConstants[pos]; }
590                /// Get a pointer to the 'nth' item in the double buffer
591                const double* getDoublePointer(size_t pos) const { return &mDoubleConstants[pos]; }
592                /// Get a pointer to the 'nth' item in the int buffer
593                int* getIntPointer(size_t pos) { _markDirty(); return &mIntConstants[pos]; }
594                /// Get a pointer to the 'nth' item in the int buffer
595                const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
596
597                /// Get a reference to the list of float constants
598                const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
599                /// Get a reference to the list of double constants
600                const DoubleConstantList& getDoubleConstantList() const { return mDoubleConstants; }
601                /// Get a reference to the list of int constants
602                const IntConstantList& getIntConstantList() const { return mIntConstants; }
603
604                /** Internal method that the RenderSystem might use to store optional data. */
605                void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
606                /** Internal method that the RenderSystem might use to store optional data. */
607                const Any& _getRenderSystemData() const { return mRenderSystemData; }
608
609        };
610
611        /// Shared pointer used to hold references to GpuProgramParameters instances
612        typedef SharedPtr<GpuSharedParameters> GpuSharedParametersPtr;
613
614        class GpuProgramParameters;
615
616        /** This class records the usage of a set of shared parameters in a concrete
617                set of GpuProgramParameters.
618        */
619        class _OgreExport GpuSharedParametersUsage : public GpuParamsAlloc
620        {
621        protected:
622                GpuSharedParametersPtr mSharedParams;
623                // Not a shared pointer since this is also parent
624                GpuProgramParameters* mParams;
625                // list of physical mappings that we are going to bring in
626                struct CopyDataEntry
627                {
628                        const GpuConstantDefinition* srcDefinition;
629                        const GpuConstantDefinition* dstDefinition;
630                };
631                typedef vector<CopyDataEntry>::type CopyDataList;
632
633                CopyDataList mCopyDataList;
634
635                // Optional data the rendersystem might want to store
636                mutable Any mRenderSystemData;
637
638                /// Version of shared params we based the copydata on
639                unsigned long mCopyDataVersion;
640
641                void initCopyData();
642
643
644        public:
645                /// Construct usage
646                GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams, 
647                        GpuProgramParameters* params);
648
649                /** Update the target parameters by copying the data from the shared
650                        parameters.
651                @note This method  may not actually be called if the RenderSystem
652                        supports using shared parameters directly in their own shared buffer; in
653                        which case the values should not be copied out of the shared area
654                        into the individual parameter set, but bound separately.
655                */
656                void _copySharedParamsToTargetParams();
657
658                /// Get the name of the shared parameter set
659                const String& getName() const { return mSharedParams->getName(); }
660
661                GpuSharedParametersPtr getSharedParams() const { return mSharedParams; }
662                GpuProgramParameters* getTargetParams() const { return mParams; }
663
664                /** Internal method that the RenderSystem might use to store optional data. */
665                void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
666                /** Internal method that the RenderSystem might use to store optional data. */
667                const Any& _getRenderSystemData() const { return mRenderSystemData; }
668
669
670        };
671
672        /** Collects together the program parameters used for a GpuProgram.
673        @remarks
674        Gpu program state includes constant parameters used by the program, and
675        bindings to render system state which is propagated into the constants
676        by the engine automatically if requested.
677        @par
678        GpuProgramParameters objects should be created through the GpuProgram and
679        may be shared between multiple Pass instances. For this reason they
680        are managed using a shared pointer, which will ensure they are automatically
681        deleted when no Pass is using them anymore.
682        @par
683        High-level programs use named parameters (uniforms), low-level programs
684        use indexed constants. This class supports both, but you can tell whether
685        named constants are supported by calling hasNamedParameters(). There are
686        references in the documentation below to 'logical' and 'physical' indexes;
687        logical indexes are the indexes used by low-level programs and represent
688        indexes into an array of float4's, some of which may be settable, some of
689        which may be predefined constants in the program. We only store those
690        constants which have actually been set, therefore our buffer could have
691        gaps if we used the logical indexes in our own buffers. So instead we map
692        these logical indexes to physical indexes in our buffer. When using
693        high-level programs, logical indexes don't necessarily exist, although they
694        might if the high-level program has a direct, exposed mapping from parameter
695        names to logical indexes. In addition, high-level languages may or may not pack
696        arrays of elements that are smaller than float4 (e.g. float2/vec2) contiguously.
697        This kind of information is held in the ConstantDefinition structure which
698        is only populated for high-level programs. You don't have to worry about
699        any of this unless you intend to read parameters back from this structure
700        rather than just setting them.
701        */
702        class _OgreExport GpuProgramParameters : public GpuParamsAlloc
703        {
704        public:
705                /** Defines the types of automatically updated values that may be bound to GpuProgram
706                parameters, or used to modify parameters on a per-object basis.
707                */
708                enum AutoConstantType
709                {
710                        /// The current world matrix
711                        ACT_WORLD_MATRIX,
712                        /// The current world matrix, inverted
713                        ACT_INVERSE_WORLD_MATRIX,
714                        /** Provides transpose of world matrix.
715                        Equivalent to RenderMonkey's "WorldTranspose".
716                        */
717                        ACT_TRANSPOSE_WORLD_MATRIX,
718                        /// The current world matrix, inverted & transposed
719                        ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
720
721                        /// The current array of world matrices, as a 3x4 matrix, used for blending
722                        ACT_WORLD_MATRIX_ARRAY_3x4,
723                        /// The current array of world matrices, used for blending
724                        ACT_WORLD_MATRIX_ARRAY,
725                        /// The current array of world matrices transformed to an array of dual quaternions, represented as a 2x4 matrix
726                        ACT_WORLD_DUALQUATERNION_ARRAY_2x4,
727                        /// The scale and shear components of the current array of world matrices
728                        ACT_WORLD_SCALE_SHEAR_MATRIX_ARRAY_3x4,
729                       
730                        /// The current view matrix
731                        ACT_VIEW_MATRIX,
732                        /// The current view matrix, inverted
733                        ACT_INVERSE_VIEW_MATRIX,
734                        /** Provides transpose of view matrix.
735                        Equivalent to RenderMonkey's "ViewTranspose".
736                        */
737                        ACT_TRANSPOSE_VIEW_MATRIX,
738                        /** Provides inverse transpose of view matrix.
739                        Equivalent to RenderMonkey's "ViewInverseTranspose".
740                        */
741                        ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
742
743
744                        /// The current projection matrix
745                        ACT_PROJECTION_MATRIX,
746                        /** Provides inverse of projection matrix.
747                        Equivalent to RenderMonkey's "ProjectionInverse".
748                        */
749                        ACT_INVERSE_PROJECTION_MATRIX,
750                        /** Provides transpose of projection matrix.
751                        Equivalent to RenderMonkey's "ProjectionTranspose".
752                        */
753                        ACT_TRANSPOSE_PROJECTION_MATRIX,
754                        /** Provides inverse transpose of projection matrix.
755                        Equivalent to RenderMonkey's "ProjectionInverseTranspose".
756                        */
757                        ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
758
759
760                        /// The current view & projection matrices concatenated
761                        ACT_VIEWPROJ_MATRIX,
762                        /** Provides inverse of concatenated view and projection matrices.
763                        Equivalent to RenderMonkey's "ViewProjectionInverse".
764                        */
765                        ACT_INVERSE_VIEWPROJ_MATRIX,
766                        /** Provides transpose of concatenated view and projection matrices.
767                        Equivalent to RenderMonkey's "ViewProjectionTranspose".
768                        */
769                        ACT_TRANSPOSE_VIEWPROJ_MATRIX,
770                        /** Provides inverse transpose of concatenated view and projection matrices.
771                        Equivalent to RenderMonkey's "ViewProjectionInverseTranspose".
772                        */
773                        ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
774
775
776                        /// The current world & view matrices concatenated
777                        ACT_WORLDVIEW_MATRIX,
778                        /// The current world & view matrices concatenated, then inverted
779                        ACT_INVERSE_WORLDVIEW_MATRIX,
780                        /** Provides transpose of concatenated world and view matrices.
781                        Equivalent to RenderMonkey's "WorldViewTranspose".
782                        */
783                        ACT_TRANSPOSE_WORLDVIEW_MATRIX,
784                        /// The current world & view matrices concatenated, then inverted & transposed
785                        ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
786                        /// view matrices.
787
788
789                        /// The current world, view & projection matrices concatenated
790                        ACT_WORLDVIEWPROJ_MATRIX,
791                        /** Provides inverse of concatenated world, view and projection matrices.
792                        Equivalent to RenderMonkey's "WorldViewProjectionInverse".
793                        */
794                        ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
795                        /** Provides transpose of concatenated world, view and projection matrices.
796                        Equivalent to RenderMonkey's "WorldViewProjectionTranspose".
797                        */
798                        ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
799                        /** Provides inverse transpose of concatenated world, view and projection
800                        matrices. Equivalent to RenderMonkey's "WorldViewProjectionInverseTranspose".
801                        */
802                        ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
803
804
805                        /// render target related values
806                        /** -1 if requires texture flipping, +1 otherwise. It's useful when you bypassed
807                        projection matrix transform, still able use this value to adjust transformed y position.
808                        */
809                        ACT_RENDER_TARGET_FLIPPING,
810
811                        /** -1 if the winding has been inverted (e.g. for reflections), +1 otherwise.
812                        */
813                        ACT_VERTEX_WINDING,
814
815                        /// Fog colour
816                        ACT_FOG_COLOUR,
817                        /// Fog params: density, linear start, linear end, 1/(end-start)
818                        ACT_FOG_PARAMS,
819
820
821                        /// Surface ambient colour, as set in Pass::setAmbient
822                        ACT_SURFACE_AMBIENT_COLOUR,
823                        /// Surface diffuse colour, as set in Pass::setDiffuse
824                        ACT_SURFACE_DIFFUSE_COLOUR,
825                        /// Surface specular colour, as set in Pass::setSpecular
826                        ACT_SURFACE_SPECULAR_COLOUR,
827                        /// Surface emissive colour, as set in Pass::setSelfIllumination
828                        ACT_SURFACE_EMISSIVE_COLOUR,
829                        /// Surface shininess, as set in Pass::setShininess
830                        ACT_SURFACE_SHININESS,
831                        /// Surface alpha rejection value, not as set in Pass::setAlphaRejectionValue, but a floating number between 0.0f and 1.0f instead (255.0f / Pass::getAlphaRejectionValue())
832                        ACT_SURFACE_ALPHA_REJECTION_VALUE,
833
834
835                        /// The number of active light sources (better than gl_MaxLights)
836                        ACT_LIGHT_COUNT,
837
838
839                        /// The ambient light colour set in the scene
840                        ACT_AMBIENT_LIGHT_COLOUR, 
841
842                        /// Light diffuse colour (index determined by setAutoConstant call)
843                        ACT_LIGHT_DIFFUSE_COLOUR,
844                        /// Light specular colour (index determined by setAutoConstant call)
845                        ACT_LIGHT_SPECULAR_COLOUR,
846                        /// Light attenuation parameters, Vector4(range, constant, linear, quadric)
847                        ACT_LIGHT_ATTENUATION,
848                        /** Spotlight parameters, Vector4(innerFactor, outerFactor, falloff, isSpot)
849                        innerFactor and outerFactor are cos(angle/2)
850                        The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
851                        Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively
852                        */ 
853                        ACT_SPOTLIGHT_PARAMS,
854                        /// A light position in world space (index determined by setAutoConstant call)
855                        ACT_LIGHT_POSITION,
856                        /// A light position in object space (index determined by setAutoConstant call)
857                        ACT_LIGHT_POSITION_OBJECT_SPACE,
858                        /// A light position in view space (index determined by setAutoConstant call)
859                        ACT_LIGHT_POSITION_VIEW_SPACE,
860                        /// A light direction in world space (index determined by setAutoConstant call)
861                        ACT_LIGHT_DIRECTION,
862                        /// A light direction in object space (index determined by setAutoConstant call)
863                        ACT_LIGHT_DIRECTION_OBJECT_SPACE,
864                        /// A light direction in view space (index determined by setAutoConstant call)
865                        ACT_LIGHT_DIRECTION_VIEW_SPACE,
866                        /** The distance of the light from the center of the object
867                        a useful approximation as an alternative to per-vertex distance
868                        calculations.
869                        */
870                        ACT_LIGHT_DISTANCE_OBJECT_SPACE,
871                        /** Light power level, a single scalar as set in Light::setPowerScale  (index determined by setAutoConstant call) */
872                        ACT_LIGHT_POWER_SCALE,
873                        /// Light diffuse colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
874                        ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
875                        /// Light specular colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
876                        ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
877                        /// Array of light diffuse colours (count set by extra param)
878                        ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
879                        /// Array of light specular colours (count set by extra param)
880                        ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
881                        /// Array of light diffuse colours scaled by light power (count set by extra param)
882                        ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
883                        /// Array of light specular colours scaled by light power (count set by extra param)
884                        ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
885                        /// Array of light attenuation parameters, Vector4(range, constant, linear, quadric) (count set by extra param)
886                        ACT_LIGHT_ATTENUATION_ARRAY,
887                        /// Array of light positions in world space (count set by extra param)
888                        ACT_LIGHT_POSITION_ARRAY,
889                        /// Array of light positions in object space (count set by extra param)
890                        ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
891                        /// Array of light positions in view space (count set by extra param)
892                        ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
893                        /// Array of light directions in world space (count set by extra param)
894                        ACT_LIGHT_DIRECTION_ARRAY,
895                        /// Array of light directions in object space (count set by extra param)
896                        ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
897                        /// Array of light directions in view space (count set by extra param)
898                        ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
899                        /** Array of distances of the lights from the center of the object
900                        a useful approximation as an alternative to per-vertex distance
901                        calculations. (count set by extra param)
902                        */
903                        ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
904                        /** Array of light power levels, a single scalar as set in Light::setPowerScale
905                        (count set by extra param)
906                        */
907                        ACT_LIGHT_POWER_SCALE_ARRAY,
908                        /** Spotlight parameters array of Vector4(innerFactor, outerFactor, falloff, isSpot)
909                        innerFactor and outerFactor are cos(angle/2)
910                        The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
911                        Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively.
912                        (count set by extra param)
913                        */ 
914                        ACT_SPOTLIGHT_PARAMS_ARRAY,
915
916                        /** The derived ambient light colour, with 'r', 'g', 'b' components filled with
917                        product of surface ambient colour and ambient light colour, respectively,
918                        and 'a' component filled with surface ambient alpha component.
919                        */
920                        ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
921                        /** The derived scene colour, with 'r', 'g' and 'b' components filled with sum
922                        of derived ambient light colour and surface emissive colour, respectively,
923                        and 'a' component filled with surface diffuse alpha component.
924                        */
925                        ACT_DERIVED_SCENE_COLOUR,
926
927                        /** The derived light diffuse colour (index determined by setAutoConstant call),
928                        with 'r', 'g' and 'b' components filled with product of surface diffuse colour,
929                        light power scale and light diffuse colour, respectively, and 'a' component filled with surface
930                        diffuse alpha component.
931                        */
932                        ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
933                        /** The derived light specular colour (index determined by setAutoConstant call),
934                        with 'r', 'g' and 'b' components filled with product of surface specular colour
935                        and light specular colour, respectively, and 'a' component filled with surface
936                        specular alpha component.
937                        */
938                        ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
939
940                        /// Array of derived light diffuse colours (count set by extra param)
941                        ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
942                        /// Array of derived light specular colours (count set by extra param)
943                        ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
944                        /** The absolute light number of a local light index. Each pass may have
945                        a number of lights passed to it, and each of these lights will have
946                        an index in the overall light list, which will differ from the local
947                        light index due to factors like setStartLight and setIteratePerLight.
948                        This binding provides the global light index for a local index.
949                        */
950                        ACT_LIGHT_NUMBER,
951                        /// Returns (int) 1 if the  given light casts shadows, 0 otherwise (index set in extra param)
952                        ACT_LIGHT_CASTS_SHADOWS,
953                        /// Returns (int) 1 if the  given light casts shadows, 0 otherwise (index set in extra param)
954                        ACT_LIGHT_CASTS_SHADOWS_ARRAY,
955
956
957                        /** The distance a shadow volume should be extruded when using
958                        finite extrusion programs.
959                        */
960                        ACT_SHADOW_EXTRUSION_DISTANCE,
961                        /// The current camera's position in world space
962                        ACT_CAMERA_POSITION,
963                        /// The current camera's position in object space
964                        ACT_CAMERA_POSITION_OBJECT_SPACE,
965                        /// The view/projection matrix of the assigned texture projection frustum
966                        ACT_TEXTURE_VIEWPROJ_MATRIX,
967                        /// Array of view/projection matrices of the first n texture projection frustums
968                        ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
969                        /** The view/projection matrix of the assigned texture projection frustum,
970                        combined with the current world matrix
971                        */
972                        ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
973                        /// Array of world/view/projection matrices of the first n texture projection frustums
974                        ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
975                        /// The view/projection matrix of a given spotlight
976                        ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
977                        /// Array of view/projection matrix of a given spotlight
978                        ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY,
979                        /** The view/projection matrix of a given spotlight projection frustum,
980                        combined with the current world matrix
981                        */
982                        ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
983                        /** An array of the view/projection matrix of a given spotlight projection frustum,
984             combined with the current world matrix
985             */
986                        ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX_ARRAY,
987                        /// A custom parameter which will come from the renderable, using 'data' as the identifier
988                        ACT_CUSTOM,
989                        /** provides current elapsed time
990                        */
991                        ACT_TIME,
992                        /** Single float value, which repeats itself based on given as
993                        parameter "cycle time". Equivalent to RenderMonkey's "Time0_X".
994                        */
995                        ACT_TIME_0_X,
996                        /// Cosine of "Time0_X". Equivalent to RenderMonkey's "CosTime0_X".
997                        ACT_COSTIME_0_X,
998                        /// Sine of "Time0_X". Equivalent to RenderMonkey's "SinTime0_X".
999                        ACT_SINTIME_0_X,
1000                        /// Tangent of "Time0_X". Equivalent to RenderMonkey's "TanTime0_X".
1001                        ACT_TANTIME_0_X,
1002                        /** Vector of "Time0_X", "SinTime0_X", "CosTime0_X",
1003                        "TanTime0_X". Equivalent to RenderMonkey's "Time0_X_Packed".
1004                        */
1005                        ACT_TIME_0_X_PACKED,
1006                        /** Single float value, which represents scaled time value [0..1],
1007                        which repeats itself based on given as parameter "cycle time".
1008                        Equivalent to RenderMonkey's "Time0_1".
1009                        */
1010                        ACT_TIME_0_1,
1011                        /// Cosine of "Time0_1". Equivalent to RenderMonkey's "CosTime0_1".
1012                        ACT_COSTIME_0_1,
1013                        /// Sine of "Time0_1". Equivalent to RenderMonkey's "SinTime0_1".
1014                        ACT_SINTIME_0_1,
1015                        /// Tangent of "Time0_1". Equivalent to RenderMonkey's "TanTime0_1".
1016                        ACT_TANTIME_0_1,
1017                        /** Vector of "Time0_1", "SinTime0_1", "CosTime0_1",
1018                        "TanTime0_1". Equivalent to RenderMonkey's "Time0_1_Packed".
1019                        */
1020                        ACT_TIME_0_1_PACKED,
1021                        /**     Single float value, which represents scaled time value [0..2*Pi],
1022                        which repeats itself based on given as parameter "cycle time".
1023                        Equivalent to RenderMonkey's "Time0_2PI".
1024                        */
1025                        ACT_TIME_0_2PI,
1026                        /// Cosine of "Time0_2PI". Equivalent to RenderMonkey's "CosTime0_2PI".
1027                        ACT_COSTIME_0_2PI,
1028                        /// Sine of "Time0_2PI". Equivalent to RenderMonkey's "SinTime0_2PI".
1029                        ACT_SINTIME_0_2PI,
1030                        /// Tangent of "Time0_2PI". Equivalent to RenderMonkey's "TanTime0_2PI".
1031                        ACT_TANTIME_0_2PI,
1032                        /** Vector of "Time0_2PI", "SinTime0_2PI", "CosTime0_2PI",
1033                        "TanTime0_2PI". Equivalent to RenderMonkey's "Time0_2PI_Packed".
1034                        */
1035                        ACT_TIME_0_2PI_PACKED,
1036                        /// provides the scaled frame time, returned as a floating point value.
1037                        ACT_FRAME_TIME,
1038                        /// provides the calculated frames per second, returned as a floating point value.
1039                        ACT_FPS,
1040                        /// viewport-related values
1041                        /** Current viewport width (in pixels) as floating point value.
1042                        Equivalent to RenderMonkey's "ViewportWidth".
1043                        */
1044                        ACT_VIEWPORT_WIDTH,
1045                        /** Current viewport height (in pixels) as floating point value.
1046                        Equivalent to RenderMonkey's "ViewportHeight".
1047                        */
1048                        ACT_VIEWPORT_HEIGHT,
1049                        /** This variable represents 1.0/ViewportWidth.
1050                        Equivalent to RenderMonkey's "ViewportWidthInverse".
1051                        */
1052                        ACT_INVERSE_VIEWPORT_WIDTH,
1053                        /** This variable represents 1.0/ViewportHeight.
1054                        Equivalent to RenderMonkey's "ViewportHeightInverse".
1055                        */
1056                        ACT_INVERSE_VIEWPORT_HEIGHT,
1057                        /** Packed of "ViewportWidth", "ViewportHeight", "ViewportWidthInverse",
1058                        "ViewportHeightInverse".
1059                        */
1060                        ACT_VIEWPORT_SIZE,
1061
1062                        /// view parameters
1063                        /** This variable provides the view direction vector (world space).
1064                        Equivalent to RenderMonkey's "ViewDirection".
1065                        */
1066                        ACT_VIEW_DIRECTION,
1067                        /** This variable provides the view side vector (world space).
1068                        Equivalent to RenderMonkey's "ViewSideVector".
1069                        */
1070                        ACT_VIEW_SIDE_VECTOR,
1071                        /** This variable provides the view up vector (world space).
1072                        Equivalent to RenderMonkey's "ViewUpVector".
1073                        */
1074                        ACT_VIEW_UP_VECTOR,
1075                        /** This variable provides the field of view as a floating point value.
1076                        Equivalent to RenderMonkey's "FOV".
1077                        */
1078                        ACT_FOV,
1079                        /**     This variable provides the near clip distance as a floating point value.
1080                        Equivalent to RenderMonkey's "NearClipPlane".
1081                        */
1082                        ACT_NEAR_CLIP_DISTANCE,
1083                        /**     This variable provides the far clip distance as a floating point value.
1084                        Equivalent to RenderMonkey's "FarClipPlane".
1085                        */
1086                        ACT_FAR_CLIP_DISTANCE,
1087
1088                        /** provides the pass index number within the technique
1089                        of the active materil.
1090                        */
1091                        ACT_PASS_NUMBER,
1092
1093                        /** provides the current iteration number of the pass. The iteration
1094                        number is the number of times the current render operation has
1095                        been drawn for the active pass.
1096                        */
1097                        ACT_PASS_ITERATION_NUMBER,
1098
1099
1100                        /** Provides a parametric animation value [0..1], only available
1101                        where the renderable specifically implements it.
1102                        */
1103                        ACT_ANIMATION_PARAMETRIC,
1104
1105                        /** Provides the texel offsets required by this rendersystem to map
1106                        texels to pixels. Packed as
1107                        float4(absoluteHorizontalOffset, absoluteVerticalOffset,
1108                        horizontalOffset / viewportWidth, verticalOffset / viewportHeight)
1109                        */
1110                        ACT_TEXEL_OFFSETS,
1111
1112                        /** Provides information about the depth range of the scene as viewed
1113                        from the current camera.
1114                        Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
1115                        */
1116                        ACT_SCENE_DEPTH_RANGE,
1117
1118                        /** Provides information about the depth range of the scene as viewed
1119                        from a given shadow camera. Requires an index parameter which maps
1120                        to a light index relative to the current light list.
1121                        Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
1122                        */
1123                        ACT_SHADOW_SCENE_DEPTH_RANGE,
1124
1125            /** Provides an array of information about the depth range of the scene as viewed
1126             from a given shadow camera. Requires an index parameter which maps
1127             to a light index relative to the current light list.
1128             Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
1129            */
1130                        ACT_SHADOW_SCENE_DEPTH_RANGE_ARRAY,
1131
1132                        /** Provides the fixed shadow colour as configured via SceneManager::setShadowColour;
1133                        useful for integrated modulative shadows.
1134                        */
1135                        ACT_SHADOW_COLOUR,
1136                        /** Provides texture size of the texture unit (index determined by setAutoConstant
1137                        call). Packed as float4(width, height, depth, 1)
1138                        */
1139                        ACT_TEXTURE_SIZE,
1140                        /** Provides inverse texture size of the texture unit (index determined by setAutoConstant
1141                        call). Packed as float4(1 / width, 1 / height, 1 / depth, 1)
1142                        */
1143                        ACT_INVERSE_TEXTURE_SIZE,
1144                        /** Provides packed texture size of the texture unit (index determined by setAutoConstant
1145                        call). Packed as float4(width, height, 1 / width, 1 / height)
1146                        */
1147                        ACT_PACKED_TEXTURE_SIZE,
1148
1149                        /** Provides the current transform matrix of the texture unit (index determined by setAutoConstant
1150                        call), as seen by the fixed-function pipeline.
1151                        */
1152                        ACT_TEXTURE_MATRIX, 
1153
1154                        /** Provides the position of the LOD camera in world space, allowing you
1155                        to perform separate LOD calculations in shaders independent of the rendering
1156                        camera. If there is no separate LOD camera then this is the real camera
1157                        position. See Camera::setLodCamera.
1158                        */
1159                        ACT_LOD_CAMERA_POSITION, 
1160                        /** Provides the position of the LOD camera in object space, allowing you
1161                        to perform separate LOD calculations in shaders independent of the rendering
1162                        camera. If there is no separate LOD camera then this is the real camera
1163                        position. See Camera::setLodCamera.
1164                        */
1165                        ACT_LOD_CAMERA_POSITION_OBJECT_SPACE, 
1166                        /** Binds custom per-light constants to the shaders. */
1167                        ACT_LIGHT_CUSTOM,
1168
1169            ACT_UNKNOWN = 999
1170                };
1171
1172                /** Defines the type of the extra data item used by the auto constant.
1173
1174                */
1175                enum ACDataType {
1176                        /// no data is required
1177                        ACDT_NONE,
1178                        /// the auto constant requires data of type int
1179                        ACDT_INT,
1180                        /// the auto constant requires data of type real
1181                        ACDT_REAL
1182                };
1183
1184                /** Defines the base element type of the auto constant
1185                */
1186                enum ElementType {
1187                        ET_INT,
1188                        ET_REAL
1189                };
1190
1191                /** Structure defining an auto constant that's available for use in
1192                a parameters object.
1193                */
1194                struct AutoConstantDefinition
1195                {
1196                        AutoConstantType acType;
1197                        String name;
1198                        size_t elementCount;
1199                        /// The type of the constant in the program
1200                        ElementType elementType;
1201                        /// The type of any extra data
1202                        ACDataType dataType;
1203
1204                        AutoConstantDefinition(AutoConstantType _acType, const String& _name, 
1205                                size_t _elementCount, ElementType _elementType, 
1206                                ACDataType _dataType)
1207                                :acType(_acType), name(_name), elementCount(_elementCount), 
1208                                elementType(_elementType), dataType(_dataType)
1209                        {
1210
1211                        }
1212                };
1213
1214                /** Structure recording the use of an automatic parameter. */
1215                class AutoConstantEntry
1216                {
1217                public:
1218                        /// The type of parameter
1219                        AutoConstantType paramType;
1220                        /// The target (physical) constant index
1221                        size_t physicalIndex;
1222                        /** The number of elements per individual entry in this constant
1223                        Used in case people used packed elements smaller than 4 (e.g. GLSL)
1224                        and bind an auto which is 4-element packed to it */
1225                        size_t elementCount;
1226                        /// Additional information to go with the parameter
1227                        union{
1228                                size_t data;
1229                                Real fData;
1230                        };
1231                        /// The variability of this parameter (see GpuParamVariability)
1232                        uint16 variability;
1233
1234                        AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData, 
1235                                uint16 theVariability, size_t theElemCount = 4)
1236                                : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), 
1237                                data(theData), variability(theVariability) {}
1238
1239                        AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData, 
1240                                uint16 theVariability, size_t theElemCount = 4)
1241                                : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), 
1242                                fData(theData), variability(theVariability) {}
1243
1244                };
1245                // Auto parameter storage
1246                typedef vector<AutoConstantEntry>::type AutoConstantList;
1247
1248                typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
1249
1250                // Map that store subroutines associated with slots
1251                typedef HashMap<unsigned int, String> SubroutineMap;
1252                typedef HashMap<unsigned int, String>::const_iterator SubroutineIterator;
1253
1254        protected:
1255                SubroutineMap mSubroutineMap;
1256
1257                static AutoConstantDefinition AutoConstantDictionary[];
1258                /// Packed list of floating-point constants (physical indexing)
1259                FloatConstantList mFloatConstants;
1260                /// Packed list of double-point constants (physical indexing)
1261                DoubleConstantList mDoubleConstants;
1262                /// Packed list of integer constants (physical indexing)
1263                IntConstantList mIntConstants;
1264                /** Logical index to physical index map - for low-level programs
1265         or high-level programs which pass params this way. */
1266                GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
1267                /** Logical index to physical index map - for low-level programs
1268                or high-level programs which pass params this way. */
1269                GpuLogicalBufferStructPtr mDoubleLogicalToPhysical;
1270                /** Logical index to physical index map - for low-level programs
1271                or high-level programs which pass params this way. */
1272                GpuLogicalBufferStructPtr mIntLogicalToPhysical;
1273                /// Mapping from parameter names to def - high-level programs are expected to populate this
1274                GpuNamedConstantsPtr mNamedConstants;
1275                /// List of automatically updated parameters
1276                AutoConstantList mAutoConstants;
1277                /// The combined variability masks of all parameters
1278                uint16 mCombinedVariability;
1279                /// Do we need to transpose matrices?
1280                bool mTransposeMatrices;
1281                /// flag to indicate if names not found will be ignored
1282                bool mIgnoreMissingParams;
1283                /// physical index for active pass iteration parameter real constant entry;
1284                size_t mActivePassIterationIndex;
1285
1286                /** Gets the low-level structure for a logical index.
1287                */
1288                GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
1289                /** Gets the low-level structure for a logical index.
1290         */
1291                GpuLogicalIndexUse* _getDoubleConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
1292                /** Gets the physical buffer index associated with a logical int constant index.
1293                */
1294                GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
1295
1296                /// Return the variability for an auto constant
1297                uint16 deriveVariability(AutoConstantType act);
1298
1299                void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
1300
1301                GpuSharedParamUsageList mSharedParamSets;
1302
1303                // Optional data the rendersystem might want to store
1304                mutable Any mRenderSystemData;
1305
1306
1307
1308        public:
1309                GpuProgramParameters();
1310                ~GpuProgramParameters() {}
1311
1312                /// Copy constructor
1313                GpuProgramParameters(const GpuProgramParameters& oth);
1314                /// Operator = overload
1315                GpuProgramParameters& operator=(const GpuProgramParameters& oth);
1316
1317                /** Internal method for providing a link to a name->definition map for parameters. */
1318                void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
1319
1320                /** Internal method for providing a link to a logical index->physical index map for parameters. */
1321                void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap, const GpuLogicalBufferStructPtr& doubleIndexMap,
1322                        const GpuLogicalBufferStructPtr&  intIndexMap);
1323
1324
1325                /// Does this parameter set include named parameters?
1326                bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
1327                /** Does this parameter set include logically indexed parameters?
1328                @note Not mutually exclusive with hasNamedParameters since some high-level
1329                programs still use logical indexes to set the parameters on the
1330                rendersystem.
1331                */
1332                bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
1333
1334                /** Sets a 4-element floating-point parameter to the program.
1335                @param index The logical constant index at which to place the parameter
1336                (each constant is a 4D float)
1337                @param vec The value to set
1338                */
1339                void setConstant(size_t index, const Vector4& vec);
1340                /** Sets a single floating-point parameter to the program.
1341                @note This is actually equivalent to calling
1342                setConstant(index Vector4(val, 0, 0, 0)) since all constants are 4D.
1343                @param index The logical constant index at which to place the parameter (each constant is
1344                a 4D float)
1345                @param val The value to set
1346                */
1347                void setConstant(size_t index, Real val);
1348                /** Sets a 4-element floating-point parameter to the program via Vector3.
1349                @param index The logical constant index at which to place the parameter (each constant is
1350                a 4D float).
1351                Note that since you're passing a Vector3, the last element of the 4-element
1352                value will be set to 1 (a homogeneous vector)
1353                @param vec The value to set
1354                */
1355                void setConstant(size_t index, const Vector3& vec);
1356                /** Sets a 4-element floating-point parameter to the program via Vector2.
1357         @param index The logical constant index at which to place the parameter (each constant is
1358         a 4D float).
1359         Note that since you're passing a Vector2, the last 2 elements of the 4-element
1360         value will be set to 1 (a homogeneous vector)
1361         @param vec The value to set
1362         */
1363                void setConstant(size_t index, const Vector2& vec);
1364                /** Sets a Matrix4 parameter to the program.
1365                @param index The logical constant index at which to place the parameter (each constant is
1366                a 4D float).
1367                NB since a Matrix4 is 16 floats long, this parameter will take up 4 indexes.
1368                @param m The value to set
1369                */
1370                void setConstant(size_t index, const Matrix4& m);
1371                /** Sets a list of Matrix4 parameters to the program.
1372                @param index The logical constant index at which to start placing the parameter (each constant is
1373                a 4D float).
1374                NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
1375                @param m Pointer to an array of matrices to set
1376                @param numEntries Number of Matrix4 entries
1377                */
1378                void setConstant(size_t index, const Matrix4* m, size_t numEntries);
1379                /** Sets a multiple value constant floating-point parameter to the program.
1380                @param index The logical constant index at which to start placing parameters (each constant is
1381                a 4D float)
1382                @param val Pointer to the values to write, must contain 4*count floats
1383                @param count The number of groups of 4 floats to write
1384                */
1385                void setConstant(size_t index, const float *val, size_t count);
1386                /** Sets a multiple value constant floating-point parameter to the program.
1387                @param index The logical constant index at which to start placing parameters (each constant is
1388                a 4D float)
1389                @param val Pointer to the values to write, must contain 4*count floats
1390                @param count The number of groups of 4 floats to write
1391                */
1392                void setConstant(size_t index, const double *val, size_t count);
1393                /** Sets a ColourValue parameter to the program.
1394                @param index The logical constant index at which to place the parameter (each constant is
1395                a 4D float)
1396                @param colour The value to set
1397                */
1398                void setConstant(size_t index, const ColourValue& colour);
1399
1400                /** Sets a multiple value constant integer parameter to the program.
1401                @remarks
1402                Different types of GPU programs support different types of constant parameters.
1403                For example, it's relatively common to find that vertex programs only support
1404                floating point constants, and that fragment programs only support integer (fixed point)
1405                parameters. This can vary depending on the program version supported by the
1406                graphics card being used. You should consult the documentation for the type of
1407                low level program you are using, or alternatively use the methods
1408                provided on RenderSystemCapabilities to determine the options.
1409                @param index The logical constant index at which to place the parameter (each constant is
1410                a 4D integer)
1411                @param val Pointer to the values to write, must contain 4*count ints
1412                @param count The number of groups of 4 ints to write
1413                */
1414                void setConstant(size_t index, const int *val, size_t count);
1415
1416                /** Write a series of floating point values into the underlying float
1417                constant buffer at the given physical index.
1418                @param physicalIndex The buffer position to start writing
1419                @param val Pointer to a list of values to write
1420                @param count The number of floats to write
1421                */
1422                void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
1423                /** Write a series of floating point values into the underlying float
1424                constant buffer at the given physical index.
1425                @param physicalIndex The buffer position to start writing
1426                @param val Pointer to a list of values to write
1427                @param count The number of floats to write
1428                */
1429                void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
1430                /** Write a series of integer values into the underlying integer
1431                constant buffer at the given physical index.
1432                @param physicalIndex The buffer position to start writing
1433                @param val Pointer to a list of values to write
1434                @param count The number of ints to write
1435                */
1436                void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
1437                /** Read a series of floating point values from the underlying float
1438                constant buffer at the given physical index.
1439                @param physicalIndex The buffer position to start reading
1440                @param count The number of floats to read
1441                @param dest Pointer to a buffer to receive the values
1442                */
1443                void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
1444                /** Read a series of integer values from the underlying integer
1445                constant buffer at the given physical index.
1446                @param physicalIndex The buffer position to start reading
1447                @param count The number of ints to read
1448                @param dest Pointer to a buffer to receive the values
1449                */
1450                void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
1451
1452                /** Write a 4-element floating-point parameter to the program directly to
1453                the underlying constants buffer.
1454                @note You can use these methods if you have already derived the physical
1455                constant buffer location, for a slight speed improvement over using
1456                the named / logical index versions.
1457                @param physicalIndex The physical buffer index at which to place the parameter
1458                @param vec The value to set
1459                @param count The number of floats to write; if for example
1460                the uniform constant 'slot' is smaller than a Vector4
1461                */
1462                void _writeRawConstant(size_t physicalIndex, const Vector4& vec, 
1463                        size_t count = 4);
1464                /** Write a single floating-point parameter to the program.
1465                @note You can use these methods if you have already derived the physical
1466                constant buffer location, for a slight speed improvement over using
1467                the named / logical index versions.
1468                @param physicalIndex The physical buffer index at which to place the parameter
1469                @param val The value to set
1470                */
1471                void _writeRawConstant(size_t physicalIndex, Real val);
1472                /** Write a variable number of floating-point parameters to the program.
1473         @note You can use these methods if you have already derived the physical
1474         constant buffer location, for a slight speed improvement over using
1475         the named / logical index versions.
1476         @param physicalIndex The physical buffer index at which to place the parameter
1477         @param val The value to set
1478         */
1479                void _writeRawConstant(size_t physicalIndex, Real val, size_t count);
1480                /** Write a single integer parameter to the program.
1481                @note You can use these methods if you have already derived the physical
1482                constant buffer location, for a slight speed improvement over using
1483                the named / logical index versions.
1484                @param physicalIndex The physical buffer index at which to place the parameter
1485                @param val The value to set
1486                */
1487                void _writeRawConstant(size_t physicalIndex, int val);
1488                /** Write a 3-element floating-point parameter to the program via Vector3.
1489                @note You can use these methods if you have already derived the physical
1490                constant buffer location, for a slight speed improvement over using
1491                the named / logical index versions.
1492                @param physicalIndex The physical buffer index at which to place the parameter
1493                @param vec The value to set
1494                */
1495                void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
1496                /** Write a 2-element floating-point parameter to the program via Vector2.
1497         @note You can use these methods if you have already derived the physical
1498         constant buffer location, for a slight speed improvement over using
1499         the named / logical index versions.
1500         @param physicalIndex The physical buffer index at which to place the parameter
1501         @param vec The value to set
1502         */
1503                void _writeRawConstant(size_t physicalIndex, const Vector2& vec);
1504                /** Write a Matrix4 parameter to the program.
1505                @note You can use these methods if you have already derived the physical
1506                constant buffer location, for a slight speed improvement over using
1507                the named / logical index versions.
1508                @param physicalIndex The physical buffer index at which to place the parameter
1509                @param m The value to set
1510                @param elementCount actual element count used with shader
1511                */
1512                void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
1513                /** Write a list of Matrix4 parameters to the program.
1514                @note You can use these methods if you have already derived the physical
1515                constant buffer location, for a slight speed improvement over using
1516                the named / logical index versions.
1517                @param physicalIndex The physical buffer index at which to place the parameter
1518                @param numEntries Number of Matrix4 entries
1519                */
1520                void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
1521                /** Write a ColourValue parameter to the program.
1522                @note You can use these methods if you have already derived the physical
1523                constant buffer location, for a slight speed improvement over using
1524                the named / logical index versions.
1525                @param physicalIndex The physical buffer index at which to place the parameter
1526                @param colour The value to set
1527                @param count The number of floats to write; if for example
1528                the uniform constant 'slot' is smaller than a Vector4
1529                */
1530                void _writeRawConstant(size_t physicalIndex, const ColourValue& colour, 
1531                        size_t count = 4);
1532
1533
1534                /** Gets an iterator over the named GpuConstantDefinition instances as defined
1535                by the program for which these parameters exist.
1536                @note
1537                Only available if this parameters object has named parameters.
1538                */
1539                GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
1540
1541                /** Get a specific GpuConstantDefinition for a named parameter.
1542                @note
1543                Only available if this parameters object has named parameters.
1544                */
1545                const GpuConstantDefinition& getConstantDefinition(const String& name) const;
1546
1547                /** Get the full list of GpuConstantDefinition instances.
1548                @note
1549                Only available if this parameters object has named parameters.
1550                */
1551                const GpuNamedConstants& getConstantDefinitions() const;
1552
1553                /** Get the current list of mappings from low-level logical param indexes
1554                to physical buffer locations in the float buffer.
1555                @note
1556                Only applicable to low-level programs.
1557                */
1558                const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
1559
1560                /** Retrieves the logical index relating to a physical index in the float
1561                buffer, for programs which support that (low-level programs and
1562                high-level programs which use logical parameter indexes).
1563                @return std::numeric_limits<size_t>::max() if not found
1564                */
1565                size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
1566                /** Retrieves the logical index relating to a physical index in the int
1567                buffer, for programs which support that (low-level programs and
1568                high-level programs which use logical parameter indexes).
1569                @return std::numeric_limits<size_t>::max() if not found
1570                */
1571                /** Get the current list of mappings from low-level logical param indexes
1572         to physical buffer locations in the double buffer.
1573         @note
1574         Only applicable to low-level programs.
1575         */
1576                const GpuLogicalBufferStructPtr& getDoubleLogicalBufferStruct() const { return mDoubleLogicalToPhysical; }
1577
1578                /** Retrieves the logical index relating to a physical index in the double
1579         buffer, for programs which support that (low-level programs and
1580         high-level programs which use logical parameter indexes).
1581         @return std::numeric_limits<size_t>::max() if not found
1582         */
1583                size_t getDoubleLogicalIndexForPhysicalIndex(size_t physicalIndex);
1584                /** Retrieves the logical index relating to a physical index in the int
1585         buffer, for programs which support that (low-level programs and
1586         high-level programs which use logical parameter indexes).
1587         @return std::numeric_limits<size_t>::max() if not found
1588         */
1589                size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
1590
1591                /** Get the current list of mappings from low-level logical param indexes
1592                to physical buffer locations in the integer buffer.
1593                @note
1594                Only applicable to low-level programs.
1595                */
1596                const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
1597                /// Get a reference to the list of float constants
1598                const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
1599                /// Get a pointer to the 'nth' item in the float buffer
1600                float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
1601                /// Get a pointer to the 'nth' item in the float buffer
1602                const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
1603                /// Get a reference to the list of double constants
1604                const DoubleConstantList& getDoubleConstantList() const { return mDoubleConstants; }
1605                /// Get a pointer to the 'nth' item in the double buffer
1606                double* getDoublePointer(size_t pos) { return &mDoubleConstants[pos]; }
1607                /// Get a pointer to the 'nth' item in the double buffer
1608                const double* getDoublePointer(size_t pos) const { return &mDoubleConstants[pos]; }
1609                /// Get a reference to the list of int constants
1610                const IntConstantList& getIntConstantList() const { return mIntConstants; }
1611                /// Get a pointer to the 'nth' item in the int buffer
1612                int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
1613                /// Get a pointer to the 'nth' item in the int buffer
1614                const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
1615                /// Get a reference to the list of auto constant bindings
1616                const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
1617
1618                /** Sets up a constant which will automatically be updated by the system.
1619                @remarks
1620                Vertex and fragment programs often need parameters which are to do with the
1621                current render state, or particular values which may very well change over time,
1622                and often between objects which are being rendered. This feature allows you
1623                to set up a certain number of predefined parameter mappings that are kept up to
1624                date for you.
1625                @param index The location in the constant list to place this updated constant every time
1626                it is changed. Note that because of the nature of the types, we know how big the
1627                parameter details will be so you don't need to set that like you do for manual constants.
1628                @param acType The type of automatic constant to set
1629                @param extraInfo If the constant type needs more information (like a light index) put it here.
1630                */
1631                void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
1632                void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
1633
1634                /** Sets up a constant which will automatically be updated by the system.
1635                @remarks
1636                Vertex and fragment programs often need parameters which are to do with the
1637                current render state, or particular values which may very well change over time,
1638                and often between objects which are being rendered. This feature allows you
1639                to set up a certain number of predefined parameter mappings that are kept up to
1640                date for you.
1641                @param index The location in the constant list to place this updated constant every time
1642                it is changed. Note that because of the nature of the types, we know how big the
1643                parameter details will be so you don't need to set that like you do for manual constants.
1644                @param acType The type of automatic constant to set
1645                @param extraInfo1 The first extra parameter required by the auto constant type
1646                @param extraInfo2 The first extra parameter required by the auto constant type
1647                */
1648                void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
1649
1650                /** As setAutoConstant, but sets up the auto constant directly against a
1651                physical buffer index.
1652                */
1653                void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo, 
1654                        uint16 variability, size_t elementSize = 4);
1655                /** As setAutoConstantReal, but sets up the auto constant directly against a
1656                physical buffer index.
1657                */
1658                void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData, 
1659                        uint16 variability, size_t elementSize = 4);
1660
1661
1662                /** Unbind an auto constant so that the constant is manually controlled again. */
1663                void clearAutoConstant(size_t index);
1664
1665                /** Sets a named parameter up to track a derivation of the current time.
1666                @param index The index of the parameter
1667                @param factor The amount by which to scale the time value
1668                */ 
1669                void setConstantFromTime(size_t index, Real factor);
1670
1671                /** Clears all the existing automatic constants. */
1672                void clearAutoConstants(void);
1673                typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
1674                /** Gets an iterator over the automatic constant bindings currently in place. */
1675                AutoConstantIterator getAutoConstantIterator(void) const;
1676                /// Gets the number of int constants that have been set
1677                size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
1678                /** Gets a specific Auto Constant entry if index is in valid range
1679                otherwise returns a NULL
1680                @param index which entry is to be retrieved
1681                */
1682                AutoConstantEntry* getAutoConstantEntry(const size_t index);
1683                /** Returns true if this instance has any automatic constants. */
1684                bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
1685                /** Finds an auto constant that's affecting a given logical parameter
1686                index for floating-point values.
1687                @note Only applicable for low-level programs.
1688                */
1689                const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
1690                /** Finds an auto constant that's affecting a given logical parameter
1691         index for double-point values.
1692         @note Only applicable for low-level programs.
1693         */
1694                const AutoConstantEntry* findDoubleAutoConstantEntry(size_t logicalIndex);
1695                /** Finds an auto constant that's affecting a given logical parameter
1696                index for integer values.
1697                @note Only applicable for low-level programs.
1698                */
1699                const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
1700                /** Finds an auto constant that's affecting a given named parameter index.
1701                @note Only applicable to high-level programs.
1702                */
1703                const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
1704                /** Finds an auto constant that's affecting a given physical position in
1705                the floating-point buffer
1706                */
1707                const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
1708                /** Finds an auto constant that's affecting a given physical position in
1709         the double-point buffer
1710         */
1711                const AutoConstantEntry* _findRawAutoConstantEntryDouble(size_t physicalIndex);
1712                /** Finds an auto constant that's affecting a given physical position in
1713                the integer buffer
1714                */
1715                const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
1716
1717                /** Update automatic parameters.
1718                @param source The source of the parameters
1719                @param variabilityMask A mask of GpuParamVariability which identifies which autos will need updating
1720                */
1721                void _updateAutoParams(const AutoParamDataSource* source, uint16 variabilityMask);
1722
1723                /** Tells the program whether to ignore missing parameters or not.
1724                */
1725                void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
1726
1727                /** Sets a single value constant floating-point parameter to the program.
1728                @remarks
1729                Different types of GPU programs support different types of constant parameters.
1730                For example, it's relatively common to find that vertex programs only support
1731                floating point constants, and that fragment programs only support integer (fixed point)
1732                parameters. This can vary depending on the program version supported by the
1733                graphics card being used. You should consult the documentation for the type of
1734                low level program you are using, or alternatively use the methods
1735                provided on RenderSystemCapabilities to determine the options.
1736                @par
1737                Another possible limitation is that some systems only allow constants to be set
1738                on certain boundaries, e.g. in sets of 4 values for example. Again, see
1739                RenderSystemCapabilities for full details.
1740                @note
1741                This named option will only work if you are using a parameters object created
1742                from a high-level program (HighLevelGpuProgram).
1743                @param name The name of the parameter
1744                @param val The value to set
1745                */
1746                void setNamedConstant(const String& name, Real val);
1747                /** Sets a single value constant integer parameter to the program.
1748                @remarks
1749                Different types of GPU programs support different types of constant parameters.
1750                For example, it's relatively common to find that vertex programs only support
1751                floating point constants, and that fragment programs only support integer (fixed point)
1752                parameters. This can vary depending on the program version supported by the
1753                graphics card being used. You should consult the documentation for the type of
1754                low level program you are using, or alternatively use the methods
1755                provided on RenderSystemCapabilities to determine the options.
1756                @par
1757                Another possible limitation is that some systems only allow constants to be set
1758                on certain boundaries, e.g. in sets of 4 values for example. Again, see
1759                RenderSystemCapabilities for full details.
1760                @note
1761                This named option will only work if you are using a parameters object created
1762                from a high-level program (HighLevelGpuProgram).
1763                @param name The name of the parameter
1764                @param val The value to set
1765                */
1766                void setNamedConstant(const String& name, int val);
1767                /** Sets a Vector4 parameter to the program.
1768                @param name The name of the parameter
1769                @param vec The value to set
1770                */
1771                void setNamedConstant(const String& name, const Vector4& vec);
1772                /** Sets a Vector3 parameter to the program.
1773                @note
1774                This named option will only work if you are using a parameters object created
1775                from a high-level program (HighLevelGpuProgram).
1776        @param name The name of the parameter
1777                @param vec The value to set
1778                */
1779                void setNamedConstant(const String& name, const Vector3& vec);
1780                /** Sets a Vector2 parameter to the program.
1781         @param name The name of the parameter
1782         @param vec The value to set
1783         */
1784                void setNamedConstant(const String& name, const Vector2& vec);
1785                /** Sets a Matrix4 parameter to the program.
1786                @param name The name of the parameter
1787                @param m The value to set
1788                */
1789                void setNamedConstant(const String& name, const Matrix4& m);
1790                /** Sets a list of Matrix4 parameters to the program.
1791                @param name The name of the parameter; this must be the first index of an array,
1792                for examples 'matrices[0]'
1793                NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
1794                @param m Pointer to an array of matrices to set
1795                @param numEntries Number of Matrix4 entries
1796                */
1797                void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
1798                /** Sets a multiple value constant floating-point parameter to the program.
1799                @par
1800                Some systems only allow constants to be set on certain boundaries,
1801                e.g. in sets of 4 values for example. The 'multiple' parameter allows
1802                you to control that although you should only change it if you know
1803                your chosen language supports that (at the time of writing, only
1804                GLSL allows constants which are not a multiple of 4).
1805                @note
1806                This named option will only work if you are using a parameters object created
1807                from a high-level program (HighLevelGpuProgram).
1808                @param name The name of the parameter
1809                @param val Pointer to the values to write
1810                @param count The number of 'multiples' of floats to write
1811                @param multiple The number of raw entries in each element to write,
1812                the default is 4 so count = 1 would write 4 floats.
1813                */
1814                void setNamedConstant(const String& name, const float *val, size_t count, 
1815                        size_t multiple = 4);
1816                /** Sets a multiple value constant floating-point parameter to the program.
1817                @par
1818                Some systems only allow constants to be set on certain boundaries,
1819                e.g. in sets of 4 values for example. The 'multiple' parameter allows
1820                you to control that although you should only change it if you know
1821                your chosen language supports that (at the time of writing, only
1822                GLSL allows constants which are not a multiple of 4).
1823                @note
1824                This named option will only work if you are using a parameters object created
1825                from a high-level program (HighLevelGpuProgram).
1826                @param name The name of the parameter
1827                @param val Pointer to the values to write
1828                @param count The number of 'multiples' of floats to write
1829                @param multiple The number of raw entries in each element to write,
1830                the default is 4 so count = 1 would write 4 floats.
1831                */
1832                void setNamedConstant(const String& name, const double *val, size_t count, 
1833                        size_t multiple = 4);
1834                /** Sets a ColourValue parameter to the program.
1835                @param name The name of the parameter
1836                @param colour The value to set
1837                */
1838                void setNamedConstant(const String& name, const ColourValue& colour);
1839
1840                /** Sets a multiple value constant floating-point parameter to the program.
1841                @par
1842                Some systems only allow constants to be set on certain boundaries,
1843                e.g. in sets of 4 values for example. The 'multiple' parameter allows
1844                you to control that although you should only change it if you know
1845                your chosen language supports that (at the time of writing, only
1846                GLSL allows constants which are not a multiple of 4).
1847                @note
1848                This named option will only work if you are using a parameters object created
1849                from a high-level program (HighLevelGpuProgram).
1850                @param name The name of the parameter
1851                @param val Pointer to the values to write
1852                @param count The number of 'multiples' of floats to write
1853                @param multiple The number of raw entries in each element to write,
1854                the default is 4 so count = 1 would write 4 floats.
1855                */
1856                void setNamedConstant(const String& name, const int *val, size_t count, 
1857                        size_t multiple = 4);
1858
1859                /** Sets up a constant which will automatically be updated by the system.
1860                @remarks
1861                Vertex and fragment programs often need parameters which are to do with the
1862                current render state, or particular values which may very well change over time,
1863                and often between objects which are being rendered. This feature allows you
1864                to set up a certain number of predefined parameter mappings that are kept up to
1865                date for you.
1866                @note
1867                This named option will only work if you are using a parameters object created
1868                from a high-level program (HighLevelGpuProgram).
1869                @param name The name of the parameter
1870                @param acType The type of automatic constant to set
1871                @param extraInfo If the constant type needs more information (like a light index) put it here.
1872                */
1873                void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
1874                void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
1875
1876                /** Sets up a constant which will automatically be updated by the system.
1877                @remarks
1878                Vertex and fragment programs often need parameters which are to do with the
1879                current render state, or particular values which may very well change over time,
1880                and often between objects which are being rendered. This feature allows you
1881                to set up a certain number of predefined parameter mappings that are kept up to
1882                date for you.
1883                @note
1884                This named option will only work if you are using a parameters object created
1885                from a high-level program (HighLevelGpuProgram).
1886                @param name The name of the parameter
1887                @param acType The type of automatic constant to set
1888                @param extraInfo1 The first extra info required by this auto constant type
1889                @param extraInfo2 The first extra info required by this auto constant type
1890                */
1891                void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
1892
1893                /** Sets a named parameter up to track a derivation of the current time.
1894                @note
1895                This named option will only work if you are using a parameters object created
1896                from a high-level program (HighLevelGpuProgram).
1897                @param name The name of the parameter
1898                @param factor The amount by which to scale the time value
1899                */ 
1900                void setNamedConstantFromTime(const String& name, Real factor);
1901
1902                /** Unbind an auto constant so that the constant is manually controlled again. */
1903                void clearNamedAutoConstant(const String& name);
1904
1905                /** Find a constant definition for a named parameter.
1906                @remarks
1907                This method returns null if the named parameter did not exist, unlike
1908                getConstantDefinition which is more strict; unless you set the
1909                last parameter to true.
1910                @param name The name to look up
1911                @param throwExceptionIfMissing If set to true, failure to find an entry
1912                will throw an exception.
1913                */
1914                const GpuConstantDefinition* _findNamedConstantDefinition(
1915                        const String& name, bool throwExceptionIfMissing = false) const;
1916                /** Gets the physical buffer index associated with a logical float constant index.
1917                @note Only applicable to low-level programs.
1918                @param logicalIndex The logical parameter index
1919                @param requestedSize The requested size - pass 0 to ignore missing entries
1920                and return std::numeric_limits<size_t>::max()
1921                */
1922                size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
1923                /** Gets the physical buffer index associated with a logical double constant index.
1924         @note Only applicable to low-level programs.
1925         @param logicalIndex The logical parameter index
1926         @param requestedSize The requested size - pass 0 to ignore missing entries
1927         and return std::numeric_limits<size_t>::max()
1928         */
1929                size_t _getDoubleConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
1930                /** Gets the physical buffer index associated with a logical int constant index.
1931                @note Only applicable to low-level programs.
1932                @param logicalIndex The logical parameter index
1933                @param requestedSize The requested size - pass 0 to ignore missing entries
1934                and return std::numeric_limits<size_t>::max()
1935                */
1936                size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
1937
1938                /** Sets whether or not we need to transpose the matrices passed in from the rest of OGRE.
1939                @remarks
1940                D3D uses transposed matrices compared to GL and OGRE; this is not important when you
1941                use programs which are written to process row-major matrices, such as those generated
1942                by Cg, but if you use a program written to D3D's matrix layout you will need to enable
1943                this flag.
1944                */
1945                void setTransposeMatrices(bool val) { mTransposeMatrices = val; } 
1946                /// Gets whether or not matrices are to be transposed when set
1947                bool getTransposeMatrices(void) const { return mTransposeMatrices; } 
1948
1949                /** Copies the values of all constants (including auto constants) from another
1950                GpuProgramParameters object.
1951                @note This copes the internal storage of the paarameters object and therefore
1952                can only be used for parameters objects created from the same GpuProgram.
1953                To merge parameters that match from different programs, use copyMatchingNamedConstantsFrom.
1954                */
1955                void copyConstantsFrom(const GpuProgramParameters& source);
1956
1957                /** Copies the values of all matching named constants (including auto constants) from
1958                another GpuProgramParameters object.
1959                @remarks
1960                This method iterates over the named constants in another parameters object
1961                and copies across the values where they match. This method is safe to
1962                use when the 2 parameters objects came from different programs, but only
1963                works for named parameters.
1964                */
1965                void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
1966
1967                /** gets the auto constant definition associated with name if found else returns NULL
1968                @param name The name of the auto constant
1969                */
1970                static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
1971                /** gets the auto constant definition using an index into the auto constant definition array.
1972                If the index is out of bounds then NULL is returned;
1973                @param idx The auto constant index
1974                */
1975                static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
1976                /** Returns the number of auto constant definitions
1977                */
1978                static size_t getNumAutoConstantDefinitions(void);
1979
1980
1981                /** increments the multipass number entry by 1 if it exists
1982                */
1983                void incPassIterationNumber(void);
1984                /** Does this parameters object have a pass iteration number constant? */
1985                bool hasPassIterationNumber() const 
1986                { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
1987                /** Get the physical buffer index of the pass iteration number constant */
1988                size_t getPassIterationNumberIndex() const 
1989                { return mActivePassIterationIndex; }
1990
1991
1992                /** Use a set of shared parameters in this parameters object.
1993                @remarks
1994                        Allows you to use a set of shared parameters to automatically update
1995                        this parameter set.
1996                */
1997                void addSharedParameters(GpuSharedParametersPtr sharedParams);
1998
1999                /** Use a set of shared parameters in this parameters object.
2000                @remarks
2001                        Allows you to use a set of shared parameters to automatically update
2002                        this parameter set.
2003                @param sharedParamsName The name of a shared parameter set as defined in
2004                        GpuProgramManager
2005                */
2006                void addSharedParameters(const String& sharedParamsName);
2007
2008                /** Returns whether this parameter set is using the named shared parameter set. */
2009                bool isUsingSharedParameters(const String& sharedParamsName) const;
2010
2011                /** Stop using the named shared parameter set. */
2012                void removeSharedParameters(const String& sharedParamsName);
2013
2014                /** Stop using all shared parameter sets. */
2015                void removeAllSharedParameters();
2016
2017                /** Get the list of shared parameter sets. */
2018                const GpuSharedParamUsageList& getSharedParameters() const;
2019
2020                /** Internal method that the RenderSystem might use to store optional data. */
2021                void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
2022                /** Internal method that the RenderSystem might use to store optional data. */
2023                const Any& _getRenderSystemData() const { return mRenderSystemData; }
2024
2025                /** Update the parameters by copying the data from the shared
2026                parameters.
2027                @note This method  may not actually be called if the RenderSystem
2028                supports using shared parameters directly in their own shared buffer; in
2029                which case the values should not be copied out of the shared area
2030                into the individual parameter set, but bound separately.
2031                */
2032                void _copySharedParams();
2033
2034                size_t calculateSize(void) const;
2035
2036                /** Set subroutine name by slot name
2037                 */
2038                void setNamedSubroutine(const String& subroutineSlot, const String& subroutine);
2039               
2040                /** Set subroutine name by slot index
2041                 */
2042                void setSubroutine(size_t index, const String& subroutine);
2043
2044                /** Get map with
2045                 */
2046                const SubroutineMap& getSubroutineMap() const { return mSubroutineMap; }
2047        };
2048
2049        /// Shared pointer used to hold references to GpuProgramParameters instances
2050        typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
2051
2052        /** @} */
2053        /** @} */
2054}
2055
2056#include "OgreHeaderSuffix.h"
2057
2058#endif
2059
Note: See TracBrowser for help on using the repository browser.