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-2012 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_SAMPLER2DARRAY = 11,
    00065         GCT_MATRIX_2X2 = 12,
    00066         GCT_MATRIX_2X3 = 13,
    00067         GCT_MATRIX_2X4 = 14,
    00068         GCT_MATRIX_3X2 = 15,
    00069         GCT_MATRIX_3X3 = 16,
    00070         GCT_MATRIX_3X4 = 17,
    00071         GCT_MATRIX_4X2 = 18,
    00072         GCT_MATRIX_4X3 = 19,
    00073         GCT_MATRIX_4X4 = 20,
    00074         GCT_INT1 = 21,
    00075         GCT_INT2 = 22,
    00076         GCT_INT3 = 23,
    00077         GCT_INT4 = 24,
    00078         GCT_UNKNOWN = 99
    00079     };
    00080
    00084     enum GpuParamVariability
    00085     {
    00087         GPV_GLOBAL = 1,
    00089         GPV_PER_OBJECT = 2,
    00091         GPV_LIGHTS = 4,
    00093         GPV_PASS_ITERATION_NUMBER = 8,
    00094
    00095
    00097         GPV_ALL = 0xFFFF
    00098
    00099     };
    00100
    00105     struct _OgreExport GpuConstantDefinition
    00106     {
    00108         GpuConstantType constType;
    00110         size_t physicalIndex;
    00112         size_t logicalIndex;
    00115         size_t elementSize;
    00117         size_t arraySize;
    00119         mutable uint16 variability;
    00120
    00121         bool isFloat() const
    00122         {
    00123             return isFloat(constType);
    00124         }
    00125
    00126         static bool isFloat(GpuConstantType c)
    00127         {
    00128             switch(c)
    00129             {
    00130             case GCT_INT1:
    00131             case GCT_INT2:
    00132             case GCT_INT3:
    00133             case GCT_INT4:
    00134             case GCT_SAMPLER1D:
    00135             case GCT_SAMPLER2D:
    00136             case GCT_SAMPLER2DARRAY:
    00137             case GCT_SAMPLER3D:
    00138             case GCT_SAMPLERCUBE:
    00139             case GCT_SAMPLER1DSHADOW:
    00140             case GCT_SAMPLER2DSHADOW:
    00141                 return false;
    00142             default:
    00143                 return true;
    00144             };
    00145
    00146         }
    00147
    00148         bool isSampler() const
    00149         {
    00150             return isSampler(constType);
    00151         }
    00152
    00153         static bool isSampler(GpuConstantType c)
    00154         {
    00155             switch(c)
    00156             {
    00157             case GCT_SAMPLER1D:
    00158             case GCT_SAMPLER2D:
    00159             case GCT_SAMPLER2DARRAY:
    00160             case GCT_SAMPLER3D:
    00161             case GCT_SAMPLERCUBE:
    00162             case GCT_SAMPLER1DSHADOW:
    00163             case GCT_SAMPLER2DSHADOW:
    00164                 return true;
    00165             default:
    00166                 return false;
    00167             };
    00168
    00169         }
    00170
    00171
    00175         static size_t getElementSize(GpuConstantType ctype, bool padToMultiplesOf4)
    00176         {
    00177             if (padToMultiplesOf4)
    00178             {
    00179                 switch(ctype)
    00180                 {
    00181                 case GCT_FLOAT1:
    00182                 case GCT_INT1:
    00183                 case GCT_SAMPLER1D:
    00184                 case GCT_SAMPLER2D:
    00185                 case GCT_SAMPLER2DARRAY:
    00186                 case GCT_SAMPLER3D:
    00187                 case GCT_SAMPLERCUBE:
    00188                 case GCT_SAMPLER1DSHADOW:
    00189                 case GCT_SAMPLER2DSHADOW:
    00190                 case GCT_FLOAT2:
    00191                 case GCT_INT2:
    00192                 case GCT_FLOAT3:
    00193                 case GCT_INT3:
    00194                 case GCT_FLOAT4:
    00195                 case GCT_INT4:
    00196                     return 4;
    00197                 case GCT_MATRIX_2X2:
    00198                 case GCT_MATRIX_2X3:
    00199                 case GCT_MATRIX_2X4:
    00200                     return 8; // 2 float4s
    00201                 case GCT_MATRIX_3X2:
    00202                 case GCT_MATRIX_3X3:
    00203                 case GCT_MATRIX_3X4:
    00204                     return 12; // 3 float4s
    00205                 case GCT_MATRIX_4X2:
    00206                 case GCT_MATRIX_4X3:
    00207                 case GCT_MATRIX_4X4:
    00208                     return 16; // 4 float4s
    00209                 default:
    00210                     return 4;
    00211                 };
    00212             }
    00213             else
    00214             {
    00215                 switch(ctype)
    00216                 {
    00217                 case GCT_FLOAT1:
    00218                 case GCT_INT1:
    00219                 case GCT_SAMPLER1D:
    00220                 case GCT_SAMPLER2D:
    00221                 case GCT_SAMPLER2DARRAY:
    00222                 case GCT_SAMPLER3D:
    00223                 case GCT_SAMPLERCUBE:
    00224                 case GCT_SAMPLER1DSHADOW:
    00225                 case GCT_SAMPLER2DSHADOW:
    00226                     return 1;
    00227                 case GCT_FLOAT2:
    00228                 case GCT_INT2:
    00229                     return 2;
    00230                 case GCT_FLOAT3:
    00231                 case GCT_INT3:
    00232                     return 3;
    00233                 case GCT_FLOAT4:
    00234                 case GCT_INT4:
    00235                     return 4;
    00236                 case GCT_MATRIX_2X2:
    00237                     return 4;
    00238                 case GCT_MATRIX_2X3:
    00239                 case GCT_MATRIX_3X2:
    00240                     return 6;
    00241                 case GCT_MATRIX_2X4:
    00242                 case GCT_MATRIX_4X2:
    00243                     return 8;
    00244                 case GCT_MATRIX_3X3:
    00245                     return 9;
    00246                 case GCT_MATRIX_3X4:
    00247                 case GCT_MATRIX_4X3:
    00248                     return 12;
    00249                 case GCT_MATRIX_4X4:
    00250                     return 16;
    00251                 default:
    00252                     return 4;
    00253                 };
    00254
    00255             }
    00256         }
    00257
    00258         GpuConstantDefinition()
    00259             : constType(GCT_UNKNOWN)
    00260             , physicalIndex((std::numeric_limits<size_t>::max)())
    00261             , logicalIndex(0)
    00262             , elementSize(0)
    00263             , arraySize(1)
    00264             , variability(GPV_GLOBAL) {}
    00265     };
    00266     typedef map<String, GpuConstantDefinition>::type GpuConstantDefinitionMap;
    00267     typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
    00268
    00270     struct _OgreExport GpuNamedConstants : public GpuParamsAlloc
    00271     {
    00273         size_t floatBufferSize;
    00275         size_t intBufferSize;
    00277         GpuConstantDefinitionMap map;
    00278
    00279         GpuNamedConstants() : floatBufferSize(0), intBufferSize(0) {}
    00280
    00292         void generateConstantDefinitionArrayEntries(const String& paramName,
    00293             const GpuConstantDefinition& baseDef);
    00294
    00296         static bool getGenerateAllConstantDefinitionArrayEntries();
    00297
    00304         static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
    00305
    00309         void save(const String& filename) const;
    00313         void load(DataStreamPtr& stream);
    00314
    00315     protected:
    00322         static bool msGenerateAllConstantDefinitionArrayEntries;
    00323     };
    00324     typedef SharedPtr<GpuNamedConstants> GpuNamedConstantsPtr;
    00325
    00327     class _OgreExport GpuNamedConstantsSerializer : public Serializer
    00328     {
    00329     public:
    00330         GpuNamedConstantsSerializer();
    00331         virtual ~GpuNamedConstantsSerializer();
    00332         void exportNamedConstants(const GpuNamedConstants* pConsts, const String& filename,
    00333             Endian endianMode = ENDIAN_NATIVE);
    00334         void exportNamedConstants(const GpuNamedConstants* pConsts, DataStreamPtr stream,
    00335             Endian endianMode = ENDIAN_NATIVE);
    00336         void importNamedConstants(DataStreamPtr& stream, GpuNamedConstants* pDest);
    00337     };
    00338
    00342     struct _OgreExport GpuLogicalIndexUse
    00343     {
    00345         size_t physicalIndex;
    00347         size_t currentSize;
    00349         mutable uint16 variability;
    00350
    00351         GpuLogicalIndexUse()
    00352             : physicalIndex(99999), currentSize(0), variability(GPV_GLOBAL) {}
    00353         GpuLogicalIndexUse(size_t bufIdx, size_t curSz, uint16 v)
    00354             : physicalIndex(bufIdx), currentSize(curSz), variability(v) {}
    00355     };
    00356     typedef map<size_t, GpuLogicalIndexUse>::type GpuLogicalIndexUseMap;
    00358     struct _OgreExport GpuLogicalBufferStruct : public GpuParamsAlloc
    00359     {
    00360         OGRE_MUTEX(mutex)
    00362             GpuLogicalIndexUseMap map;
    00364         size_t bufferSize;
    00365         GpuLogicalBufferStruct() : bufferSize(0) {}
    00366     };
    00367     typedef SharedPtr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
    00368
    00373     typedef vector<float>::type FloatConstantList;
    00378     typedef vector<int>::type IntConstantList;
    00379
    00395     class _OgreExport GpuSharedParameters : public GpuParamsAlloc
    00396     {
    00397     protected:
    00398         GpuNamedConstants mNamedConstants;
    00399         FloatConstantList mFloatConstants;
    00400         IntConstantList mIntConstants;
    00401         String mName;
    00402
    00403         // Optional data the rendersystem might want to store
    00404         mutable Any mRenderSystemData;
    00405
    00407         size_t mFrameLastUpdated;
    00408
    00410         unsigned long mVersion;
    00411
    00412     public:
    00413         GpuSharedParameters(const String& name);
    00414         virtual ~GpuSharedParameters();
    00415
    00417         const String& getName() { return mName; }
    00418
    00426         void addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize = 1);
    00427
    00430         void removeConstantDefinition(const String& name);
    00431
    00434         void removeAllConstantDefinitions();
    00435
    00439         unsigned long getVersion() const { return mVersion; }
    00440
    00446         void _markDirty();
    00448         size_t getFrameLastUpdated() const { return mFrameLastUpdated; }
    00449
    00453         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    00454
    00457         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    00458
    00461         const GpuNamedConstants& getConstantDefinitions() const;
    00462
    00464         void setNamedConstant(const String& name, Real val);
    00466         void setNamedConstant(const String& name, int val);
    00468         void setNamedConstant(const String& name, const Vector4& vec);
    00470         void setNamedConstant(const String& name, const Vector3& vec);
    00472         void setNamedConstant(const String& name, const Matrix4& m);
    00474         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    00476         void setNamedConstant(const String& name, const float *val, size_t count);
    00478         void setNamedConstant(const String& name, const double *val, size_t count);
    00480         void setNamedConstant(const String& name, const ColourValue& colour);
    00482         void setNamedConstant(const String& name, const int *val, size_t count);
    00483
    00485         float* getFloatPointer(size_t pos) { _markDirty(); return &mFloatConstants[pos]; }
    00487         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    00489         int* getIntPointer(size_t pos) { _markDirty(); return &mIntConstants[pos]; }
    00491         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    00492
    00493
    00495         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    00497         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    00498
    00499     };
    00500
    00502     typedef SharedPtr<GpuSharedParameters> GpuSharedParametersPtr;
    00503
    00504     class GpuProgramParameters;
    00505
    00509     class _OgreExport GpuSharedParametersUsage : public GpuParamsAlloc
    00510     {
    00511     protected:
    00512         GpuSharedParametersPtr mSharedParams;
    00513         // Not a shared pointer since this is also parent
    00514         GpuProgramParameters* mParams;
    00515         // list of physical mappings that we are going to bring in
    00516         struct CopyDataEntry
    00517         {
    00518             const GpuConstantDefinition* srcDefinition;
    00519             const GpuConstantDefinition* dstDefinition;
    00520         };
    00521         typedef vector<CopyDataEntry>::type CopyDataList;
    00522
    00523         CopyDataList mCopyDataList;
    00524
    00525         // Optional data the rendersystem might want to store
    00526         mutable Any mRenderSystemData;
    00527
    00529         unsigned long mCopyDataVersion;
    00530
    00531         void initCopyData();
    00532
    00533
    00534     public:
    00536         GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams,
    00537             GpuProgramParameters* params);
    00538
    00546         void _copySharedParamsToTargetParams();
    00547
    00549         const String& getName() const { return mSharedParams->getName(); }
    00550
    00551         GpuSharedParametersPtr getSharedParams() const { return mSharedParams; }
    00552         GpuProgramParameters* getTargetParams() const { return mParams; }
    00553
    00555         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    00557         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    00558
    00559
    00560     };
    00561
    00592     class _OgreExport GpuProgramParameters : public GpuParamsAlloc
    00593     {
    00594     public:
    00598         enum AutoConstantType
    00599         {
    00601             ACT_WORLD_MATRIX,
    00603             ACT_INVERSE_WORLD_MATRIX,
    00607             ACT_TRANSPOSE_WORLD_MATRIX,
    00609             ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
    00610
    00612             ACT_WORLD_MATRIX_ARRAY_3x4,
    00614             ACT_WORLD_MATRIX_ARRAY,
    00616             ACT_WORLD_DUALQUATERNION_ARRAY_2x4,
    00618             ACT_WORLD_SCALE_SHEAR_MATRIX_ARRAY_3x4,
    00619
    00621             ACT_VIEW_MATRIX,
    00623             ACT_INVERSE_VIEW_MATRIX,
    00627             ACT_TRANSPOSE_VIEW_MATRIX,
    00631             ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
    00632
    00633
    00635             ACT_PROJECTION_MATRIX,
    00639             ACT_INVERSE_PROJECTION_MATRIX,
    00643             ACT_TRANSPOSE_PROJECTION_MATRIX,
    00647             ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
    00648
    00649
    00651             ACT_VIEWPROJ_MATRIX,
    00655             ACT_INVERSE_VIEWPROJ_MATRIX,
    00659             ACT_TRANSPOSE_VIEWPROJ_MATRIX,
    00663             ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
    00664
    00665
    00667             ACT_WORLDVIEW_MATRIX,
    00669             ACT_INVERSE_WORLDVIEW_MATRIX,
    00673             ACT_TRANSPOSE_WORLDVIEW_MATRIX,
    00675             ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
    00677
    00678
    00680             ACT_WORLDVIEWPROJ_MATRIX,
    00684             ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
    00688             ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00692             ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00693
    00694
    00696
    00699             ACT_RENDER_TARGET_FLIPPING,
    00700
    00703             ACT_VERTEX_WINDING,
    00704
    00706             ACT_FOG_COLOUR,
    00708             ACT_FOG_PARAMS,
    00709
    00710
    00712             ACT_SURFACE_AMBIENT_COLOUR,
    00714             ACT_SURFACE_DIFFUSE_COLOUR,
    00716             ACT_SURFACE_SPECULAR_COLOUR,
    00718             ACT_SURFACE_EMISSIVE_COLOUR,
    00720             ACT_SURFACE_SHININESS,
    00721
    00722
    00724             ACT_LIGHT_COUNT,
    00725
    00726
    00728             ACT_AMBIENT_LIGHT_COLOUR,
    00729
    00731             ACT_LIGHT_DIFFUSE_COLOUR,
    00733             ACT_LIGHT_SPECULAR_COLOUR,
    00735             ACT_LIGHT_ATTENUATION,
    00741             ACT_SPOTLIGHT_PARAMS,
    00743             ACT_LIGHT_POSITION,
    00745             ACT_LIGHT_POSITION_OBJECT_SPACE,
    00747             ACT_LIGHT_POSITION_VIEW_SPACE,
    00749             ACT_LIGHT_DIRECTION,
    00751             ACT_LIGHT_DIRECTION_OBJECT_SPACE,
    00753             ACT_LIGHT_DIRECTION_VIEW_SPACE,
    00758             ACT_LIGHT_DISTANCE_OBJECT_SPACE,
    00760             ACT_LIGHT_POWER_SCALE,
    00762             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
    00764             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
    00766             ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00768             ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
    00770             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
    00772             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
    00774             ACT_LIGHT_ATTENUATION_ARRAY,
    00776             ACT_LIGHT_POSITION_ARRAY,
    00778             ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
    00780             ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
    00782             ACT_LIGHT_DIRECTION_ARRAY,
    00784             ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
    00786             ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
    00791             ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
    00795             ACT_LIGHT_POWER_SCALE_ARRAY,
    00802             ACT_SPOTLIGHT_PARAMS_ARRAY,
    00803
    00808             ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
    00813             ACT_DERIVED_SCENE_COLOUR,
    00814
    00820             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
    00826             ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
    00827
    00829             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00831             ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
    00838             ACT_LIGHT_NUMBER,
    00840             ACT_LIGHT_CASTS_SHADOWS,
    00841
    00842
    00846             ACT_SHADOW_EXTRUSION_DISTANCE,
    00848             ACT_CAMERA_POSITION,
    00850             ACT_CAMERA_POSITION_OBJECT_SPACE,
    00852             ACT_TEXTURE_VIEWPROJ_MATRIX,
    00854             ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
    00858             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
    00860             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
    00862             ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
    00864             ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY,
    00868             ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
    00870             ACT_CUSTOM,
    00873             ACT_TIME,
    00877             ACT_TIME_0_X,
    00879             ACT_COSTIME_0_X,
    00881             ACT_SINTIME_0_X,
    00883             ACT_TANTIME_0_X,
    00887             ACT_TIME_0_X_PACKED,
    00892             ACT_TIME_0_1,
    00894             ACT_COSTIME_0_1,
    00896             ACT_SINTIME_0_1,
    00898             ACT_TANTIME_0_1,
    00902             ACT_TIME_0_1_PACKED,
    00907             ACT_TIME_0_2PI,
    00909             ACT_COSTIME_0_2PI,
    00911             ACT_SINTIME_0_2PI,
    00913             ACT_TANTIME_0_2PI,
    00917             ACT_TIME_0_2PI_PACKED,
    00919             ACT_FRAME_TIME,
    00921             ACT_FPS,
    00923
    00926             ACT_VIEWPORT_WIDTH,
    00930             ACT_VIEWPORT_HEIGHT,
    00934             ACT_INVERSE_VIEWPORT_WIDTH,
    00938             ACT_INVERSE_VIEWPORT_HEIGHT,
    00942             ACT_VIEWPORT_SIZE,
    00943
    00945
    00948             ACT_VIEW_DIRECTION,
    00952             ACT_VIEW_SIDE_VECTOR,
    00956             ACT_VIEW_UP_VECTOR,
    00960             ACT_FOV,
    00964             ACT_NEAR_CLIP_DISTANCE,
    00968             ACT_FAR_CLIP_DISTANCE,
    00969
    00973             ACT_PASS_NUMBER,
    00974
    00979             ACT_PASS_ITERATION_NUMBER,
    00980
    00981
    00985             ACT_ANIMATION_PARAMETRIC,
    00986
    00992             ACT_TEXEL_OFFSETS,
    00993
    00998             ACT_SCENE_DEPTH_RANGE,
    00999
    01005             ACT_SHADOW_SCENE_DEPTH_RANGE,
    01006
    01010             ACT_SHADOW_COLOUR,
    01014             ACT_TEXTURE_SIZE,
    01018             ACT_INVERSE_TEXTURE_SIZE,
    01022             ACT_PACKED_TEXTURE_SIZE,
    01023
    01027             ACT_TEXTURE_MATRIX,
    01028
    01034             ACT_LOD_CAMERA_POSITION,
    01040             ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,
    01042             ACT_LIGHT_CUSTOM
    01043         };
    01044
    01048         enum ACDataType {
    01050             ACDT_NONE,
    01052             ACDT_INT,
    01054             ACDT_REAL
    01055         };
    01056
    01059         enum ElementType {
    01060             ET_INT,
    01061             ET_REAL
    01062         };
    01063
    01067         struct AutoConstantDefinition
    01068         {
    01069             AutoConstantType acType;
    01070             String name;
    01071             size_t elementCount;
    01073             ElementType elementType;
    01075             ACDataType dataType;
    01076
    01077             AutoConstantDefinition(AutoConstantType _acType, const String& _name,
    01078                 size_t _elementCount, ElementType _elementType,
    01079                 ACDataType _dataType)
    01080                 :acType(_acType), name(_name), elementCount(_elementCount),
    01081                 elementType(_elementType), dataType(_dataType)
    01082             {
    01083
    01084             }
    01085         };
    01086
    01088         class AutoConstantEntry
    01089         {
    01090         public:
    01092             AutoConstantType paramType;
    01094             size_t physicalIndex;
    01098             size_t elementCount;
    01100             union{
    01101                 size_t data;
    01102                 Real fData;
    01103             };
    01105             uint16 variability;
    01106
    01107             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
    01108                 uint16 theVariability, size_t theElemCount = 4)
    01109                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01110                 data(theData), variability(theVariability) {}
    01111
    01112             AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
    01113                 uint16 theVariability, size_t theElemCount = 4)
    01114                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
    01115                 fData(theData), variability(theVariability) {}
    01116
    01117         };
    01118         // Auto parameter storage
    01119         typedef vector<AutoConstantEntry>::type AutoConstantList;
    01120
    01121         typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
    01122
    01123     protected:
    01124         static AutoConstantDefinition AutoConstantDictionary[];
    01126         FloatConstantList mFloatConstants;
    01128         IntConstantList mIntConstants;
    01131         GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
    01134         GpuLogicalBufferStructPtr mIntLogicalToPhysical;
    01136         GpuNamedConstantsPtr mNamedConstants;
    01138         AutoConstantList mAutoConstants;
    01140         uint16 mCombinedVariability;
    01142         bool mTransposeMatrices;
    01144         bool mIgnoreMissingParams;
    01146         size_t mActivePassIterationIndex;
    01147
    01150         GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01153         GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01154
    01156         uint16 deriveVariability(AutoConstantType act);
    01157
    01158         void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
    01159
    01160         GpuSharedParamUsageList mSharedParamSets;
    01161
    01162         // Optional data the rendersystem might want to store
    01163         mutable Any mRenderSystemData;
    01164
    01165
    01166
    01167     public:
    01168         GpuProgramParameters();
    01169         ~GpuProgramParameters() {}
    01170
    01172         GpuProgramParameters(const GpuProgramParameters& oth);
    01174         GpuProgramParameters& operator=(const GpuProgramParameters& oth);
    01175
    01177         void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
    01178
    01180         void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap,
    01181             const GpuLogicalBufferStructPtr&  intIndexMap);
    01182
    01183
    01185         bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
    01191         bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
    01192
    01198         void setConstant(size_t index, const Vector4& vec);
    01206         void setConstant(size_t index, Real val);
    01214         void setConstant(size_t index, const Vector3& vec);
    01221         void setConstant(size_t index, const Matrix4& m);
    01229         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    01236         void setConstant(size_t index, const float *val, size_t count);
    01243         void setConstant(size_t index, const double *val, size_t count);
    01249         void setConstant(size_t index, const ColourValue& colour);
    01250
    01265         void setConstant(size_t index, const int *val, size_t count);
    01266
    01273         void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
    01280         void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
    01287         void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
    01294         void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
    01301         void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
    01302
    01313         void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
    01314             size_t count = 4);
    01322         void _writeRawConstant(size_t physicalIndex, Real val);
    01330         void _writeRawConstant(size_t physicalIndex, int val);
    01338         void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
    01347         void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
    01355         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    01365         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    01366             size_t count = 4);
    01367
    01368
    01374         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    01375
    01380         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    01381
    01386         const GpuNamedConstants& getConstantDefinitions() const;
    01387
    01393         const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    01394
    01400         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01406         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01407
    01413         const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    01415         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    01417         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    01419         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    01421         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    01423         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    01425         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    01427         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    01428
    01442         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    01443         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    01444
    01459         void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01460
    01464         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    01465             uint16 variability, size_t elementSize = 4);
    01469         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01470             uint16 variability, size_t elementSize = 4);
    01471
    01472
    01474         void clearAutoConstant(size_t index);
    01475
    01480         void setConstantFromTime(size_t index, Real factor);
    01481
    01483         void clearAutoConstants(void);
    01484         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01486         AutoConstantIterator getAutoConstantIterator(void) const;
    01488         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01493         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01495         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01500         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01505         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01509         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01513         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01517         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01518
    01523         void _updateAutoParams(const AutoParamDataSource* source, uint16 variabilityMask);
    01524
    01527         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01528
    01548         void setNamedConstant(const String& name, Real val);
    01568         void setNamedConstant(const String& name, int val);
    01573         void setNamedConstant(const String& name, const Vector4& vec);
    01586         void setNamedConstant(const String& name, const Vector3& vec);
    01591         void setNamedConstant(const String& name, const Matrix4& m);
    01599         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01616         void setNamedConstant(const String& name, const float *val, size_t count,
    01617             size_t multiple = 4);
    01634         void setNamedConstant(const String& name, const double *val, size_t count,
    01635             size_t multiple = 4);
    01640         void setNamedConstant(const String& name, const ColourValue& colour);
    01641
    01658         void setNamedConstant(const String& name, const int *val, size_t count,
    01659             size_t multiple = 4);
    01660
    01675         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01676         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01677
    01693         void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
    01694
    01702         void setNamedConstantFromTime(const String& name, Real factor);
    01703
    01705         void clearNamedAutoConstant(const String& name);
    01706
    01716         const GpuConstantDefinition* _findNamedConstantDefinition(
    01717             const String& name, bool throwExceptionIfMissing = false) const;
    01724         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01731         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
    01732
    01740         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01742         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01743
    01750         void copyConstantsFrom(const GpuProgramParameters& source);
    01751
    01760         void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
    01761
    01765         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01770         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01773         static size_t getNumAutoConstantDefinitions(void);
    01774
    01775
    01778         void incPassIterationNumber(void);
    01780         bool hasPassIterationNumber() const
    01781         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01783         size_t getPassIterationNumberIndex() const
    01784         { return mActivePassIterationIndex; }
    01785
    01786
    01792         void addSharedParameters(GpuSharedParametersPtr sharedParams);
    01793
    01801         void addSharedParameters(const String& sharedParamsName);
    01802
    01804         bool isUsingSharedParameters(const String& sharedParamsName) const;
    01805
    01807         void removeSharedParameters(const String& sharedParamsName);
    01808
    01810         void removeAllSharedParameters();
    01811
    01813         const GpuSharedParamUsageList& getSharedParameters() const;
    01814
    01816         void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
    01818         const Any& _getRenderSystemData() const { return mRenderSystemData; }
    01819
    01827         void _copySharedParams();
    01828
    01829
    01830
    01831     };
    01832
    01834     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01835
    01838 }
    01839 #endif
    01840

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22