# OgreGpuProgramParams.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __GpuProgramParams_H_
    00029 #define __GpuProgramParams_H_
    00030
    00031 // Precompiler options
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreSharedPtr.h"
    00034 #include "OgreIteratorWrappers.h"
    00035 #include "OgreSerializer.h"
    00036 #include "OgreRenderOperation.h"
    00037 #include "OgreAny.h"
    00038
    00039 namespace Ogre {
    00040
    00052     enum GpuConstantType
    00053     {
    00054         GCT_FLOAT1 = 1,
    00055         GCT_FLOAT2 = 2,
    00056         GCT_FLOAT3 = 3,
    00057         GCT_FLOAT4 = 4,
    00058         GCT_SAMPLER1D = 5,
    00059         GCT_SAMPLER2D = 6,
    00060         GCT_SAMPLER3D = 7,
    00061         GCT_SAMPLERCUBE = 8,
    00062         GCT_SAMPLER1DSHADOW = 9,
    00063         GCT_SAMPLER2DSHADOW = 10,
    00064         GCT_MATRIX_2X2 = 11,
    00065         GCT_MATRIX_2X3 = 12,
    00066         GCT_MATRIX_2X4 = 13,
    00067         GCT_MATRIX_3X2 = 14,
    00068         GCT_MATRIX_3X3 = 15,
    00069         GCT_MATRIX_3X4 = 16,
    00070         GCT_MATRIX_4X2 = 17,
    00071         GCT_MATRIX_4X3 = 18,
    00072         GCT_MATRIX_4X4 = 19,
    00073         GCT_INT1 = 20,
    00074         GCT_INT2 = 21,
    00075         GCT_INT3 = 22,
    00076         GCT_INT4 = 23,
    00077         GCT_UNKNOWN = 99
    00078     };
    00079
    00083     enum GpuParamVariability
    00084     {
    00086         GPV_GLOBAL = 1,
    00088         GPV_PER_OBJECT = 2,
    00090         GPV_LIGHTS = 4,
    00092         GPV_PASS_ITERATION_NUMBER = 8,
    00093
    00094
    00096         GPV_ALL = 0xFFFF
    00097
    00098     };
    00099
    00104     struct _OgreExport GpuConstantDefinition
    00105     {
    00107         GpuConstantType constType;
    00109         size_t physicalIndex;
    00111         size_t logicalIndex;
    00114         size_t elementSize;
    00116         size_t arraySize;
    00118         mutable uint16 variability;
    00119
    00120         bool isFloat() const
    00121         {
    00122             return isFloat(constType);
    00123         }
    00124
    00125         static bool isFloat(GpuConstantType c)
    00126         {
    00127             switch(c)
    00128             {
    00129             case GCT_INT1:
    00130             case GCT_INT2:
    00131             case GCT_INT3:
    00132             case GCT_INT4:
    00133             case GCT_SAMPLER1D:
    00134             case GCT_SAMPLER2D:
    00135             case GCT_SAMPLER3D:
    00136             case GCT_SAMPLERCUBE:
    00137             case GCT_SAMPLER1DSHADOW:
    00138             case GCT_SAMPLER2DSHADOW:
    00139                 return false;
    00140             default:
    00141                 return true;
    00142             };
    00143
    00144         }
    00145
    00146         bool isSampler() const
    00147         {
    00148             return isSampler(constType);
    00149         }
    00150
    00151         static bool isSampler(GpuConstantType c)
    00152         {
    00153             switch(c)
    00154             {
    00155             case GCT_SAMPLER1D:
    00156             case GCT_SAMPLER2D:
    00157             case GCT_SAMPLER3D:
    00158             case GCT_SAMPLERCUBE:
    00159             case GCT_SAMPLER1DSHADOW:
    00160             case GCT_SAMPLER2DSHADOW:
    00161                 return true;
    00162             default:
    00163                 return false;
    00164             };
    00165
    00166         }
    00167
    00168
    00172         static size_t getElementSize(GpuConstantType ctype, bool padToMultiplesOf4)
    00173         {
    00174             if (padToMultiplesOf4)
    00175             {
    00176                 switch(ctype)
    00177                 {
    00178                 case GCT_FLOAT1:
    00179                 case GCT_INT1:
    00180                 case GCT_SAMPLER1D:
    00181                 case GCT_SAMPLER2D:
    00182                 case GCT_SAMPLER3D:
    00183                 case GCT_SAMPLERCUBE:
    00184                 case GCT_SAMPLER1DSHADOW:
    00185                 case GCT_SAMPLER2DSHADOW:
    00186                 case GCT_FLOAT2:
    00187                 case GCT_INT2:
    00188                 case GCT_FLOAT3:
    00189                 case GCT_INT3:
    00190                 case GCT_FLOAT4:
    00191                 case GCT_INT4:
    00192                     return 4;
    00193                 case GCT_MATRIX_2X2:
    00194                 case GCT_MATRIX_2X3:
    00195                 case GCT_MATRIX_2X4:
    00196                     return 8; // 2 float4s
    00197                 case GCT_MATRIX_3X2:
    00198                 case GCT_MATRIX_3X3:
    00199                 case GCT_MATRIX_3X4:
    00200                     return 12; // 3 float4s
    00201                 case GCT_MATRIX_4X2:
    00202                 case GCT_MATRIX_4X3:
    00203                 case GCT_MATRIX_4X4:
    00204                     return 16; // 4 float4s
    00205                 default:
    00206                     return 4;
    00207                 };
    00208             }
    00209             else
    00210             {
    00211                 switch(ctype)
    00212                 {
    00213                 case GCT_FLOAT1:
    00214                 case GCT_INT1:
    00215                 case GCT_SAMPLER1D:
    00216                 case GCT_SAMPLER2D:
    00217                 case GCT_SAMPLER3D:
    00218                 case GCT_SAMPLERCUBE:
    00219                 case GCT_SAMPLER1DSHADOW:
    00220                 case GCT_SAMPLER2DSHADOW:
    00221                     return 1;
    00222                 case GCT_FLOAT2:
    00223                 case GCT_INT2:
    00224                     return 2;
    00225                 case GCT_FLOAT3:
    00226                 case GCT_INT3:
    00227                     return 3;
    00228                 case GCT_FLOAT4:
    00229                 case GCT_INT4:
    00230                     return 4;
    00231                 case GCT_MATRIX_2X2:
    00232                     return 4;
    00233                 case GCT_MATRIX_2X3:
    00234                 case GCT_MATRIX_3X2:
    00235                     return 6;
    00236                 case GCT_MATRIX_2X4:
    00237                 case GCT_MATRIX_4X2:
    00238                     return 8;
    00239                 case GCT_MATRIX_3X3:
    00240                     return 9;
    00241                 case GCT_MATRIX_3X4:
    00242                 case GCT_MATRIX_4X3:
    00243                     return 12;
    00244                 case GCT_MATRIX_4X4:
    00245                     return 16;
    00246                 default:
    00247                     return 4;
    00248                 };
    00249
    00250             }
    00251         }
    00252
    00253         GpuConstantDefinition()
    00254             : constType(GCT_UNKNOWN)
    00255             , physicalIndex((std::numeric_limits<size_t>::max)())
    00256             , elementSize(0)
    00257             , arraySize(1)
    00258             , variability(GPV_GLOBAL) {}
    00259     };
    00260     typedef map<String, GpuConstantDefinition>::type GpuConstantDefinitionMap;
    00261     typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
    00262
    00264     struct _OgreExport GpuNamedConstants : public GpuParamsAlloc
    00265     {
    00267         size_t floatBufferSize;
    00269         size_t intBufferSize;
    00271         GpuConstantDefinitionMap map;
    00272
    00273         GpuNamedConstants() : floatBufferSize(0), intBufferSize(0) {}
    00274
    00286         void generateConstantDefinitionArrayEntries(const String& paramName,
    00287             const GpuConstantDefinition& baseDef);
    00288
    00290         static bool getGenerateAllConstantDefinitionArrayEntries();
    00291
    00298         static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
    00299
    00303         void save(const String& filename) const;
    00307         void load(DataStreamPtr& stream);
    00308
    00309     protected:
    00316         static bool msGenerateAllConstantDefinitionArrayEntries;
    00317     };
    00318     typedef SharedPtr<GpuNamedConstants> GpuNamedConstantsPtr;
    00319
    00321     class _OgreExport GpuNamedConstantsSerializer : public Serializer
    00322     {
    00323     public:
    00324         GpuNamedConstantsSerializer();
    00325         virtual ~GpuNamedConstantsSerializer();
    00326         void exportNamedConstants(const GpuNamedConstants* pConsts, const String& filename,
    00327             Endian endianMode = ENDIAN_NATIVE);
    00328         void importNamedConstants(DataStreamPtr& stream, GpuNamedConstants* pDest);
    00329     };
    00330
    00334     struct _OgreExport GpuLogicalIndexUse
    00335     {
    00337         size_t physicalIndex;
    00339         size_t currentSize;
    00341         mutable uint16 variability;
    00342
    00343         GpuLogicalIndexUse()
    00344             : physicalIndex(99999), currentSize(0), variability(GPV_GLOBAL) {}
    00345         GpuLogicalIndexUse(size_t bufIdx, size_t curSz, uint16 v)
    00346             : physicalIndex(bufIdx), currentSize(curSz), variability(v) {}
    00347     };
    00348     typedef map<size_t, GpuLogicalIndexUse>::type GpuLogicalIndexUseMap;
    00350     struct _OgreExport GpuLogicalBufferStruct : public GpuParamsAlloc
    00351     {
    00352         OGRE_MUTEX(mutex)
    00354             GpuLogicalIndexUseMap map;
    00356         size_t bufferSize;
    00357         GpuLogicalBufferStruct() : bufferSize(0) {}
    00358     };
    00359     typedef SharedPtr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
    00360
    00365     typedef vector<float>::type FloatConstantList;
    00370     typedef vector<int>::type IntConstantList;
    00371
    00387     class _OgreExport GpuSharedParameters : public GpuParamsAlloc
    00388     {
    00389     protected:
    00390         GpuNamedConstants mNamedConstants;
    00391         FloatConstantList mFloatConstants;
    00392         IntConstantList mIntConstants;
    00393         String mName;
    00394
    00395         // Optional data the rendersystem might want to store
    00396         mutable Any mRenderSystemData;
    00397
    00399         size_t mFrameLastUpdated;
    00400
    00402         unsigned long mVersion;
    00403
    00404     public:
    00405         GpuSharedParameters(const String& name);
    00406         virtual ~GpuSharedParameters();
    00407
    00409         const String& getName() { return mName; }
    00410
    00418         void addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize = 1);
    00419
    00422         void removeConstantDefinition(const String& name);
    00423
    00426         void removeAllConstantDefinitions();
    00427
    00431         unsigned long getVersion() const { return mVersion; }
    00432
    00438         void _markDirty();
    00440         size_t getFrameLastUpdated() const { return mFrameLastUpdated; }
    00441
    00445         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    00446
    00449         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    00450
    00453         const GpuNamedConstants& getConstantDefinitions() const;
    00454
    00456         void setNamedConstant(const String& name, Real val);
    00458         void setNamedConstant(const String& name, int val);
    00460         void setNamedConstant(const String& name, const Vector4& vec);
    00462         void setNamedConstant(const String& name, const Vector3& vec);
    00464         void setNamedConstant(const String& name, const Matrix4& m);
    00466         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    00468         void setNamedConstant(const String& name, const float *val, size_t count);
    00470         void setNamedConstant(const String& name, const double *val, size_t count);
    00472         void setNamedConstant(const String& name, const ColourValue& colour);
    00474         void setNamedConstant(const String& name, const int *val, size_t count);
    00475
    00477         float* getFloatPointer(size_t pos) { _markDirty(); return &mFloatConstants[pos]; }
    00479         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    00481         int* getIntPointer(size_t pos) { _markDirty(); return &mIntConstants[pos]; }
    00483         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    00484
    00485
    00487         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    00489         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    00490
    00491     };
    00492
    00494     typedef SharedPtr<GpuSharedParameters> GpuSharedParametersPtr;
    00495
    00496     class GpuProgramParameters;
    00497
    00501     class _OgreExport GpuSharedParametersUsage : public GpuParamsAlloc
    00502     {
    00503     protected:
    00504         GpuSharedParametersPtr mSharedParams;
    00505         // Not a shared pointer since this is also parent
    00506         GpuProgramParameters* mParams;
    00507         // list of physical mappings that we are going to bring in
    00508         struct CopyDataEntry
    00509         {
    00510             const GpuConstantDefinition* srcDefinition;
    00511             const GpuConstantDefinition* dstDefinition;
    00512         };
    00513         typedef vector<CopyDataEntry>::type CopyDataList;
    00514
    00515         CopyDataList mCopyDataList;
    00516
    00517         // Optional data the rendersystem might want to store
    00518         mutable Any mRenderSystemData;
    00519
    00521         unsigned long mCopyDataVersion;
    00522
    00523         void initCopyData();
    00524
    00525
    00526     public:
    00528         GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams,
    00529             GpuProgramParameters* params);
    00530
    00538         void _copySharedParamsToTargetParams();
    00539
    00541         const String& getName() const { return mSharedParams->getName(); }
    00542
    00543         GpuSharedParametersPtr getSharedParams() const { return mSharedParams; }
    00544         GpuProgramParameters* getTargetParams() const { return mParams; }
    00545
    00547         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    00549         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    00550
    00551
    00552     };
    00553
    00584     class _OgreExport GpuProgramParameters : public GpuParamsAlloc
    00585     {
    00586     public:
    00590         enum AutoConstantType
    00591         {
    00593             ACT_WORLD_MATRIX,
    00595             ACT_INVERSE_WORLD_MATRIX,
    00599             ACT_TRANSPOSE_WORLD_MATRIX,
    00601             ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
    00602
    00603
    00605             ACT_WORLD_MATRIX_ARRAY_3x4,
    00607             ACT_WORLD_MATRIX_ARRAY,
    00608
    00610             ACT_VIEW_MATRIX,
    00612             ACT_INVERSE_VIEW_MATRIX,
    00616             ACT_TRANSPOSE_VIEW_MATRIX,
    00620             ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
    00621
    00622
    00624             ACT_PROJECTION_MATRIX,
    00628             ACT_INVERSE_PROJECTION_MATRIX,
    00632             ACT_TRANSPOSE_PROJECTION_MATRIX,
    00636             ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
    00637
    00638
    00640             ACT_VIEWPROJ_MATRIX,
    00644             ACT_INVERSE_VIEWPROJ_MATRIX,
    00648             ACT_TRANSPOSE_VIEWPROJ_MATRIX,
    00652             ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
    00653
    00654
    00656             ACT_WORLDVIEW_MATRIX,
    00658             ACT_INVERSE_WORLDVIEW_MATRIX,
    00662             ACT_TRANSPOSE_WORLDVIEW_MATRIX,
    00664             ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
    00666
    00667
    00669             ACT_WORLDVIEWPROJ_MATRIX,
    00673             ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
    00677             ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00681             ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00682
    00683
    00685
    00688             ACT_RENDER_TARGET_FLIPPING,
    00689
    00692             ACT_VERTEX_WINDING,
    00693
    00695             ACT_FOG_COLOUR,
    00697             ACT_FOG_PARAMS,
    00698
    00699
    00701             ACT_SURFACE_AMBIENT_COLOUR,
    00703             ACT_SURFACE_DIFFUSE_COLOUR,
    00705             ACT_SURFACE_SPECULAR_COLOUR,
    00707             ACT_SURFACE_EMISSIVE_COLOUR,
    00709             ACT_SURFACE_SHININESS,
    00710
    00711
    00713             ACT_LIGHT_COUNT,
    00714
    00715
    00717             ACT_AMBIENT_LIGHT_COLOUR,
    00718
    00720             ACT_LIGHT_DIFFUSE_COLOUR,
    00722             ACT_LIGHT_SPECULAR_COLOUR,
    00724             ACT_LIGHT_ATTENUATION,
    00730             ACT_SPOTLIGHT_PARAMS,
    00732             ACT_LIGHT_POSITION,
    00734             ACT_LIGHT_POSITION_OBJECT_SPACE,
    00736             ACT_LIGHT_POSITION_VIEW_SPACE,
    00738             ACT_LIGHT_DIRECTION,
    00740             ACT_LIGHT_DIRECTION_OBJECT_SPACE,
    00742             ACT_LIGHT_DIRECTION_VIEW_SPACE,
    00747             ACT_LIGHT_DISTANCE_OBJECT_SPACE,
    00749             ACT_LIGHT_POWER_SCALE,
    00751             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
    00753             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
    00755             ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00757             ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
    00759             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
    00761             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
    00763             ACT_LIGHT_ATTENUATION_ARRAY,
    00765             ACT_LIGHT_POSITION_ARRAY,
    00767             ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
    00769             ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
    00771             ACT_LIGHT_DIRECTION_ARRAY,
    00773             ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
    00775             ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
    00780             ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
    00784             ACT_LIGHT_POWER_SCALE_ARRAY,
    00791             ACT_SPOTLIGHT_PARAMS_ARRAY,
    00792
    00797             ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
    00802             ACT_DERIVED_SCENE_COLOUR,
    00803
    00809             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
    00815             ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
    00816
    00818             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00820             ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
    00827             ACT_LIGHT_NUMBER,
    00829             ACT_LIGHT_CASTS_SHADOWS,
    00830
    00831
    00835             ACT_SHADOW_EXTRUSION_DISTANCE,
    00837             ACT_CAMERA_POSITION,
    00839             ACT_CAMERA_POSITION_OBJECT_SPACE,
    00841             ACT_TEXTURE_VIEWPROJ_MATRIX,
    00843             ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
    00847             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
    00849             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
    00851             ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
    00855             ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
    00857             ACT_CUSTOM,
    00860             ACT_TIME,
    00864             ACT_TIME_0_X,
    00866             ACT_COSTIME_0_X,
    00868             ACT_SINTIME_0_X,
    00870             ACT_TANTIME_0_X,
    00874             ACT_TIME_0_X_PACKED,
    00879             ACT_TIME_0_1,
    00881             ACT_COSTIME_0_1,
    00883             ACT_SINTIME_0_1,
    00885             ACT_TANTIME_0_1,
    00889             ACT_TIME_0_1_PACKED,
    00894             ACT_TIME_0_2PI,
    00896             ACT_COSTIME_0_2PI,
    00898             ACT_SINTIME_0_2PI,
    00900             ACT_TANTIME_0_2PI,
    00904             ACT_TIME_0_2PI_PACKED,
    00906             ACT_FRAME_TIME,
    00908             ACT_FPS,
    00910
    00913             ACT_VIEWPORT_WIDTH,
    00917             ACT_VIEWPORT_HEIGHT,
    00921             ACT_INVERSE_VIEWPORT_WIDTH,
    00925             ACT_INVERSE_VIEWPORT_HEIGHT,
    00929             ACT_VIEWPORT_SIZE,
    00930
    00932
    00935             ACT_VIEW_DIRECTION,
    00939             ACT_VIEW_SIDE_VECTOR,
    00943             ACT_VIEW_UP_VECTOR,
    00947             ACT_FOV,
    00951             ACT_NEAR_CLIP_DISTANCE,
    00955             ACT_FAR_CLIP_DISTANCE,
    00956
    00960             ACT_PASS_NUMBER,
    00961
    00966             ACT_PASS_ITERATION_NUMBER,
    00967
    00968
    00972             ACT_ANIMATION_PARAMETRIC,
    00973
    00979             ACT_TEXEL_OFFSETS,
    00980
    00985             ACT_SCENE_DEPTH_RANGE,
    00986
    00992             ACT_SHADOW_SCENE_DEPTH_RANGE,
    00993
    00997             ACT_SHADOW_COLOUR,
    01001             ACT_TEXTURE_SIZE,
    01005             ACT_INVERSE_TEXTURE_SIZE,
    01009             ACT_PACKED_TEXTURE_SIZE,
    01010
    01014             ACT_TEXTURE_MATRIX,
    01015
    01021             ACT_LOD_CAMERA_POSITION,
    01027             ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,
    01029             ACT_LIGHT_CUSTOM
    01030         };
    01031
    01035         enum ACDataType {
    01037             ACDT_NONE,
    01039             ACDT_INT,
    01041             ACDT_REAL
    01042         };
    01043
    01046         enum ElementType {
    01047             ET_INT,
    01048             ET_REAL
    01049         };
    01050
    01054         struct AutoConstantDefinition
    01055         {
    01056             AutoConstantType acType;
    01057             String name;
    01058             size_t elementCount;
    01060             ElementType elementType;
    01062             ACDataType dataType;
    01063
    01064             AutoConstantDefinition(AutoConstantType _acType, const String& _name,
    01065                 size_t _elementCount, ElementType _elementType,
    01066                 ACDataType _dataType)
    01067                 :acType(_acType), name(_name), elementCount(_elementCount),
    01068                 elementType(_elementType), dataType(_dataType)
    01069             {
    01070
    01071             }
    01072         };
    01073
    01075         class AutoConstantEntry
    01076         {
    01077         public:
    01079             AutoConstantType paramType;
    01081             size_t physicalIndex;
    01085             size_t elementCount;
    01087             union{
    01088                 size_t data;
    01089                 Real fData;
    01090             };
    01092             uint16 variability;
    01093
    01094             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
    01095                 uint16 theVariability, size_t theElemCount = 4)
    01096                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01097                 data(theData), variability(theVariability) {}
    01098
    01099             AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
    01100                 uint16 theVariability, size_t theElemCount = 4)
    01101                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01102                 fData(theData), variability(theVariability) {}
    01103
    01104         };
    01105         // Auto parameter storage
    01106         typedef vector<AutoConstantEntry>::type AutoConstantList;
    01107
    01108         typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
    01109
    01110     protected:
    01111         static AutoConstantDefinition AutoConstantDictionary[];
    01113         FloatConstantList mFloatConstants;
    01115         IntConstantList mIntConstants;
    01118         GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
    01121         GpuLogicalBufferStructPtr mIntLogicalToPhysical;
    01123         GpuNamedConstantsPtr mNamedConstants;
    01125         AutoConstantList mAutoConstants;
    01127         uint16 mCombinedVariability;
    01129         bool mTransposeMatrices;
    01131         bool mIgnoreMissingParams;
    01133         size_t mActivePassIterationIndex;
    01134
    01137         GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01140         GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01141
    01143         uint16 deriveVariability(AutoConstantType act);
    01144
    01145         void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
    01146
    01147         GpuSharedParamUsageList mSharedParamSets;
    01148
    01149         // Optional data the rendersystem might want to store
    01150         mutable Any mRenderSystemData;
    01151
    01152
    01153
    01154     public:
    01155         GpuProgramParameters();
    01156         ~GpuProgramParameters() {}
    01157
    01159         GpuProgramParameters(const GpuProgramParameters& oth);
    01161         GpuProgramParameters& operator=(const GpuProgramParameters& oth);
    01162
    01164         void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
    01165
    01167         void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap,
    01168             const GpuLogicalBufferStructPtr&  intIndexMap);
    01169
    01170
    01172         bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
    01178         bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
    01179
    01185         void setConstant(size_t index, const Vector4& vec);
    01193         void setConstant(size_t index, Real val);
    01201         void setConstant(size_t index, const Vector3& vec);
    01208         void setConstant(size_t index, const Matrix4& m);
    01216         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    01223         void setConstant(size_t index, const float *val, size_t count);
    01230         void setConstant(size_t index, const double *val, size_t count);
    01236         void setConstant(size_t index, const ColourValue& colour);
    01237
    01252         void setConstant(size_t index, const int *val, size_t count);
    01253
    01260         void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
    01267         void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
    01274         void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
    01281         void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
    01288         void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
    01289
    01300         void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
    01301             size_t count = 4);
    01309         void _writeRawConstant(size_t physicalIndex, Real val);
    01317         void _writeRawConstant(size_t physicalIndex, int val);
    01325         void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
    01334         void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
    01342         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    01352         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    01353             size_t count = 4);
    01354
    01355
    01361         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    01362
    01367         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    01368
    01373         const GpuNamedConstants& getConstantDefinitions() const;
    01374
    01380         const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    01381
    01387         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01393         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01394
    01400         const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    01402         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    01404         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    01406         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    01408         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    01410         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    01412         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    01414         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    01415
    01429         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    01430         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    01431
    01446         void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01447
    01451         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    01452             uint16 variability, size_t elementSize = 4);
    01456         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01457             uint16 variability, size_t elementSize = 4);
    01458
    01459
    01461         void clearAutoConstant(size_t index);
    01462
    01467         void setConstantFromTime(size_t index, Real factor);
    01468
    01470         void clearAutoConstants(void);
    01471         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01473         AutoConstantIterator getAutoConstantIterator(void) const;
    01475         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01480         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01482         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01487         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01492         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01496         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01500         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01504         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01505
    01510         void _updateAutoParams(const AutoParamDataSource* source, uint16 variabilityMask);
    01511
    01514         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01515
    01535         void setNamedConstant(const String& name, Real val);
    01555         void setNamedConstant(const String& name, int val);
    01560         void setNamedConstant(const String& name, const Vector4& vec);
    01573         void setNamedConstant(const String& name, const Vector3& vec);
    01578         void setNamedConstant(const String& name, const Matrix4& m);
    01586         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01603         void setNamedConstant(const String& name, const float *val, size_t count,
    01604             size_t multiple = 4);
    01621         void setNamedConstant(const String& name, const double *val, size_t count,
    01622             size_t multiple = 4);
    01627         void setNamedConstant(const String& name, const ColourValue& colour);
    01628
    01645         void setNamedConstant(const String& name, const int *val, size_t count,
    01646             size_t multiple = 4);
    01647
    01662         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01663         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01664
    01680         void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01681
    01689         void setNamedConstantFromTime(const String& name, Real factor);
    01690
    01692         void clearNamedAutoConstant(const String& name);
    01693
    01703         const GpuConstantDefinition* _findNamedConstantDefinition(
    01704             const String& name, bool throwExceptionIfMissing = false) const;
    01711         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01718         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01719
    01727         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01729         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01730
    01737         void copyConstantsFrom(const GpuProgramParameters& source);
    01738
    01747         void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
    01748
    01752         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01757         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01760         static size_t getNumAutoConstantDefinitions(void);
    01761
    01762
    01765         void incPassIterationNumber(void);
    01767         bool hasPassIterationNumber() const
    01768         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01770         size_t getPassIterationNumberIndex() const
    01771         { return mActivePassIterationIndex; }
    01772
    01773
    01779         void addSharedParameters(GpuSharedParametersPtr sharedParams);
    01780
    01788         void addSharedParameters(const String& sharedParamsName);
    01789
    01791         bool isUsingSharedParameters(const String& sharedParamsName) const;
    01792
    01794         void removeSharedParameters(const String& sharedParamsName);
    01795
    01797         void removeAllSharedParameters();
    01798
    01800         const GpuSharedParamUsageList& getSharedParameters() const;
    01801
    01803         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    01805         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    01806
    01814         void _copySharedParams();
    01815
    01816
    01817
    01818     };
    01819
    01821     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01822
    01825 }
    01826 #endif
    01827

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51