# 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,
    00853             ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY,
    00857             ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
    00859             ACT_CUSTOM,
    00862             ACT_TIME,
    00866             ACT_TIME_0_X,
    00868             ACT_COSTIME_0_X,
    00870             ACT_SINTIME_0_X,
    00872             ACT_TANTIME_0_X,
    00876             ACT_TIME_0_X_PACKED,
    00881             ACT_TIME_0_1,
    00883             ACT_COSTIME_0_1,
    00885             ACT_SINTIME_0_1,
    00887             ACT_TANTIME_0_1,
    00891             ACT_TIME_0_1_PACKED,
    00896             ACT_TIME_0_2PI,
    00898             ACT_COSTIME_0_2PI,
    00900             ACT_SINTIME_0_2PI,
    00902             ACT_TANTIME_0_2PI,
    00906             ACT_TIME_0_2PI_PACKED,
    00908             ACT_FRAME_TIME,
    00910             ACT_FPS,
    00912
    00915             ACT_VIEWPORT_WIDTH,
    00919             ACT_VIEWPORT_HEIGHT,
    00923             ACT_INVERSE_VIEWPORT_WIDTH,
    00927             ACT_INVERSE_VIEWPORT_HEIGHT,
    00931             ACT_VIEWPORT_SIZE,
    00932
    00934
    00937             ACT_VIEW_DIRECTION,
    00941             ACT_VIEW_SIDE_VECTOR,
    00945             ACT_VIEW_UP_VECTOR,
    00949             ACT_FOV,
    00953             ACT_NEAR_CLIP_DISTANCE,
    00957             ACT_FAR_CLIP_DISTANCE,
    00958
    00962             ACT_PASS_NUMBER,
    00963
    00968             ACT_PASS_ITERATION_NUMBER,
    00969
    00970
    00974             ACT_ANIMATION_PARAMETRIC,
    00975
    00981             ACT_TEXEL_OFFSETS,
    00982
    00987             ACT_SCENE_DEPTH_RANGE,
    00988
    00994             ACT_SHADOW_SCENE_DEPTH_RANGE,
    00995
    00999             ACT_SHADOW_COLOUR,
    01003             ACT_TEXTURE_SIZE,
    01007             ACT_INVERSE_TEXTURE_SIZE,
    01011             ACT_PACKED_TEXTURE_SIZE,
    01012
    01016             ACT_TEXTURE_MATRIX,
    01017
    01023             ACT_LOD_CAMERA_POSITION,
    01029             ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,
    01031             ACT_LIGHT_CUSTOM
    01032         };
    01033
    01037         enum ACDataType {
    01039             ACDT_NONE,
    01041             ACDT_INT,
    01043             ACDT_REAL
    01044         };
    01045
    01048         enum ElementType {
    01049             ET_INT,
    01050             ET_REAL
    01051         };
    01052
    01056         struct AutoConstantDefinition
    01057         {
    01058             AutoConstantType acType;
    01059             String name;
    01060             size_t elementCount;
    01062             ElementType elementType;
    01064             ACDataType dataType;
    01065
    01066             AutoConstantDefinition(AutoConstantType _acType, const String& _name,
    01067                 size_t _elementCount, ElementType _elementType,
    01068                 ACDataType _dataType)
    01069                 :acType(_acType), name(_name), elementCount(_elementCount),
    01070                 elementType(_elementType), dataType(_dataType)
    01071             {
    01072
    01073             }
    01074         };
    01075
    01077         class AutoConstantEntry
    01078         {
    01079         public:
    01081             AutoConstantType paramType;
    01083             size_t physicalIndex;
    01087             size_t elementCount;
    01089             union{
    01090                 size_t data;
    01091                 Real fData;
    01092             };
    01094             uint16 variability;
    01095
    01096             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
    01097                 uint16 theVariability, size_t theElemCount = 4)
    01098                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01099                 data(theData), variability(theVariability) {}
    01100
    01101             AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
    01102                 uint16 theVariability, size_t theElemCount = 4)
    01103                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01104                 fData(theData), variability(theVariability) {}
    01105
    01106         };
    01107         // Auto parameter storage
    01108         typedef vector<AutoConstantEntry>::type AutoConstantList;
    01109
    01110         typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
    01111
    01112     protected:
    01113         static AutoConstantDefinition AutoConstantDictionary[];
    01115         FloatConstantList mFloatConstants;
    01117         IntConstantList mIntConstants;
    01120         GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
    01123         GpuLogicalBufferStructPtr mIntLogicalToPhysical;
    01125         GpuNamedConstantsPtr mNamedConstants;
    01127         AutoConstantList mAutoConstants;
    01129         uint16 mCombinedVariability;
    01131         bool mTransposeMatrices;
    01133         bool mIgnoreMissingParams;
    01135         size_t mActivePassIterationIndex;
    01136
    01139         GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01142         GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01143
    01145         uint16 deriveVariability(AutoConstantType act);
    01146
    01147         void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
    01148
    01149         GpuSharedParamUsageList mSharedParamSets;
    01150
    01151         // Optional data the rendersystem might want to store
    01152         mutable Any mRenderSystemData;
    01153
    01154
    01155
    01156     public:
    01157         GpuProgramParameters();
    01158         ~GpuProgramParameters() {}
    01159
    01161         GpuProgramParameters(const GpuProgramParameters& oth);
    01163         GpuProgramParameters& operator=(const GpuProgramParameters& oth);
    01164
    01166         void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
    01167
    01169         void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap,
    01170             const GpuLogicalBufferStructPtr&  intIndexMap);
    01171
    01172
    01174         bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
    01180         bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
    01181
    01187         void setConstant(size_t index, const Vector4& vec);
    01195         void setConstant(size_t index, Real val);
    01203         void setConstant(size_t index, const Vector3& vec);
    01210         void setConstant(size_t index, const Matrix4& m);
    01218         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    01225         void setConstant(size_t index, const float *val, size_t count);
    01232         void setConstant(size_t index, const double *val, size_t count);
    01238         void setConstant(size_t index, const ColourValue& colour);
    01239
    01254         void setConstant(size_t index, const int *val, size_t count);
    01255
    01262         void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
    01269         void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
    01276         void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
    01283         void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
    01290         void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
    01291
    01302         void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
    01303             size_t count = 4);
    01311         void _writeRawConstant(size_t physicalIndex, Real val);
    01319         void _writeRawConstant(size_t physicalIndex, int val);
    01327         void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
    01336         void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
    01344         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    01354         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    01355             size_t count = 4);
    01356
    01357
    01363         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    01364
    01369         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    01370
    01375         const GpuNamedConstants& getConstantDefinitions() const;
    01376
    01382         const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    01383
    01389         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01395         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01396
    01402         const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    01404         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    01406         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    01408         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    01410         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    01412         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    01414         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    01416         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    01417
    01431         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    01432         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    01433
    01448         void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01449
    01453         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    01454             uint16 variability, size_t elementSize = 4);
    01458         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01459             uint16 variability, size_t elementSize = 4);
    01460
    01461
    01463         void clearAutoConstant(size_t index);
    01464
    01469         void setConstantFromTime(size_t index, Real factor);
    01470
    01472         void clearAutoConstants(void);
    01473         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01475         AutoConstantIterator getAutoConstantIterator(void) const;
    01477         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01482         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01484         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01489         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01494         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01498         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01502         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01506         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01507
    01512         void _updateAutoParams(const AutoParamDataSource* source, uint16 variabilityMask);
    01513
    01516         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01517
    01537         void setNamedConstant(const String& name, Real val);
    01557         void setNamedConstant(const String& name, int val);
    01562         void setNamedConstant(const String& name, const Vector4& vec);
    01575         void setNamedConstant(const String& name, const Vector3& vec);
    01580         void setNamedConstant(const String& name, const Matrix4& m);
    01588         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01605         void setNamedConstant(const String& name, const float *val, size_t count,
    01606             size_t multiple = 4);
    01623         void setNamedConstant(const String& name, const double *val, size_t count,
    01624             size_t multiple = 4);
    01629         void setNamedConstant(const String& name, const ColourValue& colour);
    01630
    01647         void setNamedConstant(const String& name, const int *val, size_t count,
    01648             size_t multiple = 4);
    01649
    01664         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01665         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01666
    01682         void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01683
    01691         void setNamedConstantFromTime(const String& name, Real factor);
    01692
    01694         void clearNamedAutoConstant(const String& name);
    01695
    01705         const GpuConstantDefinition* _findNamedConstantDefinition(
    01706             const String& name, bool throwExceptionIfMissing = false) const;
    01713         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01720         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01721
    01729         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01731         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01732
    01739         void copyConstantsFrom(const GpuProgramParameters& source);
    01740
    01749         void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
    01750
    01754         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01759         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01762         static size_t getNumAutoConstantDefinitions(void);
    01763
    01764
    01767         void incPassIterationNumber(void);
    01769         bool hasPassIterationNumber() const
    01770         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01772         size_t getPassIterationNumberIndex() const
    01773         { return mActivePassIterationIndex; }
    01774
    01775
    01781         void addSharedParameters(GpuSharedParametersPtr sharedParams);
    01782
    01790         void addSharedParameters(const String& sharedParamsName);
    01791
    01793         bool isUsingSharedParameters(const String& sharedParamsName) const;
    01794
    01796         void removeSharedParameters(const String& sharedParamsName);
    01797
    01799         void removeAllSharedParameters();
    01800
    01802         const GpuSharedParamUsageList& getSharedParameters() const;
    01803
    01805         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    01807         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    01808
    01816         void _copySharedParams();
    01817
    01818
    01819
    01820     };
    01821
    01823     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01824
    01827 }
    01828 #endif
    01829

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08