# OgreGpuProgram.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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __GpuProgram_H_
    00030 #define __GpuProgram_H_
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreResource.h"
    00035 #include "OgreSharedPtr.h"
    00036 #include "OgreIteratorWrappers.h"
    00037 #include "OgreSerializer.h"
    00038 #include "OgreRenderOperation.h"
    00039
    00040 namespace Ogre {
    00041
    00043     enum GpuProgramType
    00044     {
    00045         GPT_VERTEX_PROGRAM,
    00046         GPT_FRAGMENT_PROGRAM,
    00047         GPT_GEOMETRY_PROGRAM
    00048     };
    00049
    00055     enum GpuConstantType
    00056     {
    00057         GCT_FLOAT1 = 1,
    00058         GCT_FLOAT2 = 2,
    00059         GCT_FLOAT3 = 3,
    00060         GCT_FLOAT4 = 4,
    00061         GCT_SAMPLER1D = 5,
    00062         GCT_SAMPLER2D = 6,
    00063         GCT_SAMPLER3D = 7,
    00064         GCT_SAMPLERCUBE = 8,
    00065         GCT_SAMPLER1DSHADOW = 9,
    00066         GCT_SAMPLER2DSHADOW = 10,
    00067         GCT_MATRIX_2X2 = 11,
    00068         GCT_MATRIX_2X3 = 12,
    00069         GCT_MATRIX_2X4 = 13,
    00070         GCT_MATRIX_3X2 = 14,
    00071         GCT_MATRIX_3X3 = 15,
    00072         GCT_MATRIX_3X4 = 16,
    00073         GCT_MATRIX_4X2 = 17,
    00074         GCT_MATRIX_4X3 = 18,
    00075         GCT_MATRIX_4X4 = 19,
    00076         GCT_INT1 = 20,
    00077         GCT_INT2 = 21,
    00078         GCT_INT3 = 22,
    00079         GCT_INT4 = 23,
    00080         GCT_UNKNOWN = 99
    00081     };
    00082
    00087     struct _OgreExport GpuConstantDefinition
    00088     {
    00090         GpuConstantType constType;
    00092         size_t physicalIndex;
    00094         size_t logicalIndex;
    00097         size_t elementSize;
    00099         size_t arraySize;
    00100
    00101         bool isFloat() const
    00102         {
    00103             switch(constType)
    00104             {
    00105             case GCT_INT1:
    00106             case GCT_INT2:
    00107             case GCT_INT3:
    00108             case GCT_INT4:
    00109             case GCT_SAMPLER1D:
    00110             case GCT_SAMPLER2D:
    00111             case GCT_SAMPLER3D:
    00112             case GCT_SAMPLERCUBE:
    00113             case GCT_SAMPLER1DSHADOW:
    00114             case GCT_SAMPLER2DSHADOW:
    00115                 return false;
    00116             default:
    00117                 return true;
    00118             };
    00119
    00120         }
    00121
    00122         bool isSampler() const
    00123         {
    00124             switch(constType)
    00125             {
    00126             case GCT_SAMPLER1D:
    00127             case GCT_SAMPLER2D:
    00128             case GCT_SAMPLER3D:
    00129             case GCT_SAMPLERCUBE:
    00130             case GCT_SAMPLER1DSHADOW:
    00131             case GCT_SAMPLER2DSHADOW:
    00132                 return true;
    00133             default:
    00134                 return false;
    00135             };
    00136
    00137         }
    00138
    00139         GpuConstantDefinition()
    00140             : constType(GCT_UNKNOWN)
    00141             , physicalIndex((std::numeric_limits<size_t>::max)())
    00142             , elementSize(0)
    00143             , arraySize(1) {}
    00144     };
    00145     typedef std::map<String, GpuConstantDefinition> GpuConstantDefinitionMap;
    00146     typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
    00147
    00149     struct _OgreExport GpuNamedConstants
    00150     {
    00152         size_t floatBufferSize;
    00154         size_t intBufferSize;
    00156         GpuConstantDefinitionMap map;
    00157
    00169         void generateConstantDefinitionArrayEntries(const String& paramName,
    00170             const GpuConstantDefinition& baseDef);
    00171
    00173         static bool getGenerateAllConstantDefinitionArrayEntries();
    00174
    00181         static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
    00182
    00186         void save(const String& filename) const;
    00190         void load(DataStreamPtr& stream);
    00191
    00192     protected:
    00199         static bool msGenerateAllConstantDefinitionArrayEntries;
    00200     };
    00201
    00203     class _OgreExport GpuNamedConstantsSerializer : public Serializer
    00204     {
    00205     public:
    00206         GpuNamedConstantsSerializer();
    00207         virtual ~GpuNamedConstantsSerializer();
    00208         void exportNamedConstants(const GpuNamedConstants* pConsts, const String& filename,
    00209             Endian endianMode = ENDIAN_NATIVE);
    00210         void importNamedConstants(DataStreamPtr& stream, GpuNamedConstants* pDest);
    00211     };
    00212
    00216     struct _OgreExport GpuLogicalIndexUse
    00217     {
    00219         size_t physicalIndex;
    00221         size_t currentSize;
    00222
    00223         GpuLogicalIndexUse(size_t bufIdx, size_t curSz)
    00224             : physicalIndex(bufIdx), currentSize(curSz) {}
    00225     };
    00226     typedef std::map<size_t, GpuLogicalIndexUse> GpuLogicalIndexUseMap;
    00228     struct _OgreExport GpuLogicalBufferStruct
    00229     {
    00230         OGRE_MUTEX(mutex)
    00232         GpuLogicalIndexUseMap map;
    00234         size_t bufferSize;
    00235         GpuLogicalBufferStruct() : bufferSize(0) {}
    00236     };
    00237
    00268     class _OgreExport GpuProgramParameters : public GpuParamsAlloc
    00269     {
    00270     public:
    00274         enum AutoConstantType
    00275         {
    00277             ACT_WORLD_MATRIX,
    00279             ACT_INVERSE_WORLD_MATRIX,
    00283             ACT_TRANSPOSE_WORLD_MATRIX,
    00285             ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
    00286
    00287
    00289             ACT_WORLD_MATRIX_ARRAY_3x4,
    00291             ACT_WORLD_MATRIX_ARRAY,
    00292
    00294             ACT_VIEW_MATRIX,
    00296             ACT_INVERSE_VIEW_MATRIX,
    00300             ACT_TRANSPOSE_VIEW_MATRIX,
    00304             ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
    00305
    00306
    00308             ACT_PROJECTION_MATRIX,
    00312             ACT_INVERSE_PROJECTION_MATRIX,
    00316             ACT_TRANSPOSE_PROJECTION_MATRIX,
    00320             ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
    00321
    00322
    00324             ACT_VIEWPROJ_MATRIX,
    00328             ACT_INVERSE_VIEWPROJ_MATRIX,
    00332             ACT_TRANSPOSE_VIEWPROJ_MATRIX,
    00336             ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
    00337
    00338
    00340             ACT_WORLDVIEW_MATRIX,
    00342             ACT_INVERSE_WORLDVIEW_MATRIX,
    00346             ACT_TRANSPOSE_WORLDVIEW_MATRIX,
    00348             ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
    00350
    00351
    00353             ACT_WORLDVIEWPROJ_MATRIX,
    00357             ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
    00361             ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00365             ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00366
    00367
    00369
    00372             ACT_RENDER_TARGET_FLIPPING,
    00373
    00374
    00376             ACT_FOG_COLOUR,
    00378             ACT_FOG_PARAMS,
    00379
    00380
    00382             ACT_SURFACE_AMBIENT_COLOUR,
    00384             ACT_SURFACE_DIFFUSE_COLOUR,
    00386             ACT_SURFACE_SPECULAR_COLOUR,
    00388             ACT_SURFACE_EMISSIVE_COLOUR,
    00390             ACT_SURFACE_SHININESS,
    00391
    00392
    00394             ACT_LIGHT_COUNT,
    00395
    00396
    00398             ACT_AMBIENT_LIGHT_COLOUR,
    00399
    00401             ACT_LIGHT_DIFFUSE_COLOUR,
    00403             ACT_LIGHT_SPECULAR_COLOUR,
    00405             ACT_LIGHT_ATTENUATION,
    00411             ACT_SPOTLIGHT_PARAMS,
    00413             ACT_LIGHT_POSITION,
    00415             ACT_LIGHT_POSITION_OBJECT_SPACE,
    00417             ACT_LIGHT_POSITION_VIEW_SPACE,
    00419             ACT_LIGHT_DIRECTION,
    00421             ACT_LIGHT_DIRECTION_OBJECT_SPACE,
    00423             ACT_LIGHT_DIRECTION_VIEW_SPACE,
    00428             ACT_LIGHT_DISTANCE_OBJECT_SPACE,
    00430             ACT_LIGHT_POWER_SCALE,
    00432             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
    00434             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
    00436             ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00438             ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
    00440             ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
    00442             ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
    00444             ACT_LIGHT_ATTENUATION_ARRAY,
    00446             ACT_LIGHT_POSITION_ARRAY,
    00448             ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
    00450             ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
    00452             ACT_LIGHT_DIRECTION_ARRAY,
    00454             ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
    00456             ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
    00461             ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
    00465             ACT_LIGHT_POWER_SCALE_ARRAY,
    00472             ACT_SPOTLIGHT_PARAMS_ARRAY,
    00473
    00478             ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
    00483             ACT_DERIVED_SCENE_COLOUR,
    00484
    00490             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
    00496             ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
    00497
    00499             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00501             ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
    00508             ACT_LIGHT_NUMBER,
    00510             ACT_LIGHT_CASTS_SHADOWS,
    00511
    00512
    00516             ACT_SHADOW_EXTRUSION_DISTANCE,
    00518             ACT_CAMERA_POSITION,
    00520             ACT_CAMERA_POSITION_OBJECT_SPACE,
    00522             ACT_TEXTURE_VIEWPROJ_MATRIX,
    00524             ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
    00528             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
    00530             ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
    00532             ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
    00536             ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
    00538             ACT_CUSTOM,
    00541             ACT_TIME,
    00545             ACT_TIME_0_X,
    00547             ACT_COSTIME_0_X,
    00549             ACT_SINTIME_0_X,
    00551             ACT_TANTIME_0_X,
    00555             ACT_TIME_0_X_PACKED,
    00560             ACT_TIME_0_1,
    00562             ACT_COSTIME_0_1,
    00564             ACT_SINTIME_0_1,
    00566             ACT_TANTIME_0_1,
    00570             ACT_TIME_0_1_PACKED,
    00575             ACT_TIME_0_2PI,
    00577             ACT_COSTIME_0_2PI,
    00579             ACT_SINTIME_0_2PI,
    00581             ACT_TANTIME_0_2PI,
    00585             ACT_TIME_0_2PI_PACKED,
    00587             ACT_FRAME_TIME,
    00589             ACT_FPS,
    00591
    00594             ACT_VIEWPORT_WIDTH,
    00598             ACT_VIEWPORT_HEIGHT,
    00602             ACT_INVERSE_VIEWPORT_WIDTH,
    00606             ACT_INVERSE_VIEWPORT_HEIGHT,
    00610             ACT_VIEWPORT_SIZE,
    00611
    00613
    00616             ACT_VIEW_DIRECTION,
    00620             ACT_VIEW_SIDE_VECTOR,
    00624             ACT_VIEW_UP_VECTOR,
    00628             ACT_FOV,
    00632             ACT_NEAR_CLIP_DISTANCE,
    00636             ACT_FAR_CLIP_DISTANCE,
    00637
    00641             ACT_PASS_NUMBER,
    00642
    00647             ACT_PASS_ITERATION_NUMBER,
    00648
    00649
    00653             ACT_ANIMATION_PARAMETRIC,
    00654
    00660             ACT_TEXEL_OFFSETS,
    00661
    00666             ACT_SCENE_DEPTH_RANGE,
    00667
    00673             ACT_SHADOW_SCENE_DEPTH_RANGE,
    00674
    00678             ACT_SHADOW_COLOUR,
    00682             ACT_TEXTURE_SIZE,
    00686             ACT_INVERSE_TEXTURE_SIZE,
    00690             ACT_PACKED_TEXTURE_SIZE,
    00691
    00695             ACT_TEXTURE_MATRIX,
    00696
    00702             ACT_LOD_CAMERA_POSITION,
    00708             ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,
    00709         };
    00710
    00714         enum ACDataType {
    00716             ACDT_NONE,
    00718             ACDT_INT,
    00720             ACDT_REAL
    00721         };
    00722
    00725         enum ElementType {
    00726             ET_INT,
    00727             ET_REAL
    00728         };
    00729
    00733         struct AutoConstantDefinition
    00734         {
    00735             AutoConstantType acType;
    00736             String name;
    00737             size_t elementCount;
    00739             ElementType elementType;
    00741             ACDataType dataType;
    00742
    00743             AutoConstantDefinition(AutoConstantType _acType, const String& _name,
    00744                 size_t _elementCount, ElementType _elementType,
    00745                 ACDataType _dataType)
    00746                 :acType(_acType), name(_name), elementCount(_elementCount),
    00747                 elementType(_elementType), dataType(_dataType)
    00748             {
    00749
    00750             }
    00751         };
    00752
    00754         class AutoConstantEntry
    00755         {
    00756         public:
    00758             AutoConstantType paramType;
    00760             size_t physicalIndex;
    00764             size_t elementCount;
    00766             union{
    00767                 size_t data;
    00768                 Real fData;
    00769             };
    00770
    00771             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
    00772                 size_t theElemCount = 4)
    00773                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), data(theData) {}
    00774
    00775             AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
    00776                 size_t theElemCount = 4)
    00777                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), fData(theData) {}
    00778
    00779         };
    00780         // Auto parameter storage
    00781         typedef std::vector<AutoConstantEntry> AutoConstantList;
    00782
    00787         typedef std::vector<float> FloatConstantList;
    00792         typedef std::vector<int> IntConstantList;
    00793
    00794     protected:
    00795         static AutoConstantDefinition AutoConstantDictionary[];
    00797         FloatConstantList mFloatConstants;
    00799         IntConstantList mIntConstants;
    00802         GpuLogicalBufferStruct* mFloatLogicalToPhysical;
    00805         GpuLogicalBufferStruct* mIntLogicalToPhysical;
    00807         const GpuNamedConstants* mNamedConstants;
    00809         AutoConstantList mAutoConstants;
    00811         bool mTransposeMatrices;
    00813         bool mIgnoreMissingParams;
    00815         size_t mActivePassIterationIndex;
    00816
    00817     public:
    00818         GpuProgramParameters();
    00819         ~GpuProgramParameters() {}
    00820
    00822         GpuProgramParameters(const GpuProgramParameters& oth);
    00824         GpuProgramParameters& operator=(const GpuProgramParameters& oth);
    00825
    00827         void _setNamedConstants(const GpuNamedConstants* constantmap);
    00828
    00830         void _setLogicalIndexes(GpuLogicalBufferStruct* floatIndexMap,
    00831             GpuLogicalBufferStruct* intIndexMap);
    00832
    00833
    00835         bool hasNamedParameters() const { return mNamedConstants != 0;}
    00841         bool hasLogicalIndexedParameters() const { return mFloatLogicalToPhysical != 0;}
    00842
    00848         void setConstant(size_t index, const Vector4& vec);
    00856         void setConstant(size_t index, Real val);
    00864         void setConstant(size_t index, const Vector3& vec);
    00871         void setConstant(size_t index, const Matrix4& m);
    00879         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    00886         void setConstant(size_t index, const float *val, size_t count);
    00893         void setConstant(size_t index, const double *val, size_t count);
    00899         void setConstant(size_t index, const ColourValue& colour);
    00900
    00915         void setConstant(size_t index, const int *val, size_t count);
    00916
    00923         void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
    00930         void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
    00937         void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
    00944         void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
    00951         void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
    00952
    00963         void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
    00964             size_t count = 4);
    00972         void _writeRawConstant(size_t physicalIndex, Real val);
    00980         void _writeRawConstant(size_t physicalIndex, int val);
    00988         void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
    00997         void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount = 16);
    01005         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    01015         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    01016             size_t count = 4);
    01017
    01018
    01024         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    01025
    01030         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    01031
    01036         const GpuNamedConstants& getConstantDefinitions() const;
    01037
    01043         const GpuLogicalBufferStruct* getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    01044
    01050         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01056         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01057
    01063         const GpuLogicalBufferStruct* getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    01065         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    01067         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    01069         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    01071         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    01073         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    01075         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    01077         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    01078
    01092         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    01093         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    01094
    01098         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    01099             size_t elementSize = 4);
    01103         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01104             size_t elementSize = 4);
    01105
    01106
    01108         void clearAutoConstant(size_t index);
    01109
    01114         void setConstantFromTime(size_t index, Real factor);
    01115
    01117         void clearAutoConstants(void);
    01118         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01120         AutoConstantIterator getAutoConstantIterator(void) const;
    01122         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01127         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01129         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01134         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01139         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01143         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01147         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01151         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01152
    01154         void _updateAutoParamsNoLights(const AutoParamDataSource* source);
    01156         void _updateAutoParamsLightsOnly(const AutoParamDataSource* source);
    01157
    01160         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01161
    01181         void setNamedConstant(const String& name, Real val);
    01201         void setNamedConstant(const String& name, int val);
    01206         void setNamedConstant(const String& name, const Vector4& vec);
    01219         void setNamedConstant(const String& name, const Vector3& vec);
    01224         void setNamedConstant(const String& name, const Matrix4& m);
    01232         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01249         void setNamedConstant(const String& name, const float *val, size_t count,
    01250             size_t multiple = 4);
    01267         void setNamedConstant(const String& name, const double *val, size_t count,
    01268             size_t multiple = 4);
    01273         void setNamedConstant(const String& name, const ColourValue& colour);
    01274
    01291         void setNamedConstant(const String& name, const int *val, size_t count,
    01292             size_t multiple = 4);
    01293
    01308         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01309         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01310
    01318         void setNamedConstantFromTime(const String& name, Real factor);
    01319
    01321         void clearNamedAutoConstant(const String& name);
    01322
    01332         const GpuConstantDefinition* _findNamedConstantDefinition(
    01333             const String& name, bool throwExceptionIfMissing = false) const;
    01340         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01347         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01348
    01349
    01357         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01359         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01360
    01364         void copyConstantsFrom(const GpuProgramParameters& source);
    01365
    01369         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01374         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01377         static size_t getNumAutoConstantDefinitions(void);
    01378
    01379
    01382         void incPassIterationNumber(void);
    01384         bool hasPassIterationNumber() const
    01385         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01387         size_t getPassIterationNumberIndex() const
    01388         { return mActivePassIterationIndex; }
    01389
    01390
    01391     };
    01392
    01394     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01395
    01396     // Forward declaration
    01397     class GpuProgramPtr;
    01398
    01408     class _OgreExport GpuProgram : public Resource
    01409     {
    01410     protected:
    01412         class _OgreExport CmdType : public ParamCommand
    01413         {
    01414         public:
    01415             String doGet(const void* target) const;
    01416             void doSet(void* target, const String& val);
    01417         };
    01418         class _OgreExport CmdSyntax : public ParamCommand
    01419         {
    01420         public:
    01421             String doGet(const void* target) const;
    01422             void doSet(void* target, const String& val);
    01423         };
    01424         class _OgreExport CmdSkeletal : public ParamCommand
    01425         {
    01426         public:
    01427             String doGet(const void* target) const;
    01428             void doSet(void* target, const String& val);
    01429         };
    01430         class _OgreExport CmdMorph : public ParamCommand
    01431         {
    01432         public:
    01433             String doGet(const void* target) const;
    01434             void doSet(void* target, const String& val);
    01435         };
    01436         class _OgreExport CmdPose : public ParamCommand
    01437         {
    01438         public:
    01439             String doGet(const void* target) const;
    01440             void doSet(void* target, const String& val);
    01441         };
    01442         class _OgreExport CmdVTF : public ParamCommand
    01443         {
    01444         public:
    01445             String doGet(const void* target) const;
    01446             void doSet(void* target, const String& val);
    01447         };
    01448         class _OgreExport CmdManualNamedConstsFile : public ParamCommand
    01449         {
    01450         public:
    01451             String doGet(const void* target) const;
    01452             void doSet(void* target, const String& val);
    01453         };
    01454         class _OgreExport CmdAdjacency : public ParamCommand
    01455         {
    01456         public:
    01457             String doGet(const void* target) const;
    01458             void doSet(void* target, const String& val);
    01459         };
    01460         // Command object for setting / getting parameters
    01461         static CmdType msTypeCmd;
    01462         static CmdSyntax msSyntaxCmd;
    01463         static CmdSkeletal msSkeletalCmd;
    01464         static CmdMorph msMorphCmd;
    01465         static CmdPose msPoseCmd;
    01466         static CmdVTF msVTFCmd;
    01467         static CmdManualNamedConstsFile msManNamedConstsFileCmd;
    01468         static CmdAdjacency msAdjacencyCmd;
    01470         GpuProgramType mType;
    01472         String mFilename;
    01474         String mSource;
    01476         bool mLoadFromFile;
    01478         String mSyntaxCode;
    01480         bool mSkeletalAnimation;
    01482         bool mMorphAnimation;
    01484         ushort mPoseAnimation;
    01486         bool mVertexTextureFetch;
    01488         bool mNeedsAdjacencyInfo;
    01490         GpuProgramParametersSharedPtr mDefaultParams;
    01492         bool mPassSurfaceAndLightStates;
    01494         bool mCompileError;
    01497         mutable GpuLogicalBufferStruct mFloatLogicalToPhysical;
    01500         mutable GpuLogicalBufferStruct mIntLogicalToPhysical;
    01502         mutable GpuNamedConstants mConstantDefs;
    01504         String mManualNamedConstantsFile;
    01505         bool mLoadedManualNamedConstants;
    01506
    01507
    01516         void setupBaseParamDictionary(void);
    01517
    01520         bool isRequiredCapabilitiesSupported(void) const;
    01521
    01523         size_t calculateSize(void) const { return 0; } // TODO
    01524
    01526         void loadImpl(void);
    01527     public:
    01528
    01529         GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    01530             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    01531
    01532         virtual ~GpuProgram() {}
    01533
    01538         virtual void setSourceFile(const String& filename);
    01539
    01544         virtual void setSource(const String& source);
    01545
    01547         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
    01548
    01550         virtual void setSyntaxCode(const String& syntax);
    01551
    01553         virtual const String& getSourceFile(void) const { return mFilename; }
    01555         virtual const String& getSource(void) const { return mSource; }
    01557         virtual void setType(GpuProgramType t);
    01559         virtual GpuProgramType getType(void) const { return mType; }
    01560
    01565         virtual GpuProgram* _getBindingDelegate(void) { return this; }
    01566
    01568         virtual bool isSupported(void) const;
    01569
    01577         virtual GpuProgramParametersSharedPtr createParameters(void);
    01578
    01585         virtual void setSkeletalAnimationIncluded(bool included)
    01586         { mSkeletalAnimation = included; }
    01587
    01594         virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
    01595
    01602         virtual void setMorphAnimationIncluded(bool included)
    01603         { mMorphAnimation = included; }
    01604
    01612         virtual void setPoseAnimationIncluded(ushort poseCount)
    01613         { mPoseAnimation = poseCount; }
    01614
    01621         virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
    01622
    01629         virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
    01633         virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
    01637         virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
    01641         virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
    01642
    01646         virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
    01650         virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
    01651
    01662         virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
    01663
    01666         virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
    01667
    01676         virtual void setSurfaceAndPassLightStates(bool state)
    01677             { mPassSurfaceAndLightStates = state; }
    01678
    01682         virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
    01683
    01687         virtual const String& getLanguage(void) const;
    01688
    01691         virtual bool hasCompileError(void) const { return mCompileError; }
    01692
    01695         virtual void resetCompileError(void) { mCompileError = false; }
    01696
    01705         virtual void setManualNamedConstants(const GpuNamedConstants& namedConstants);
    01706
    01708         virtual const GpuNamedConstants& getNamedConstants() const { return mConstantDefs; }
    01709
    01720         virtual void setManualNamedConstantsFile(const String& paramDefFile);
    01721
    01725         virtual const String& getManualNamedConstantsFile() const { return mManualNamedConstantsFile; }
    01732         virtual const GpuNamedConstants& getConstantDefinitions() const { return mConstantDefs; }
    01733
    01734
    01735     protected:
    01737         virtual void loadFromSource(void) = 0;
    01738
    01739     };
    01740
    01741
    01748     class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram>
    01749     {
    01750     public:
    01751         GpuProgramPtr() : SharedPtr<GpuProgram>() {}
    01752         explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
    01753         GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {}
    01754         GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
    01755         {
    01756             // lock & copy other mutex pointer
    01757             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01758             {
    01759                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01760                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01761                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01762                 pUseCount = r.useCountPointer();
    01763                 if (pUseCount)
    01764                 {
    01765                     ++(*pUseCount);
    01766                 }
    01767             }
    01768         }
    01769
    01771         GpuProgramPtr& operator=(const ResourcePtr& r)
    01772         {
    01773             if (pRep == static_cast<GpuProgram*>(r.getPointer()))
    01774                 return *this;
    01775             release();
    01776             // lock & copy other mutex pointer
    01777             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01778             {
    01779                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01780                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01781                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01782                 pUseCount = r.useCountPointer();
    01783                 if (pUseCount)
    01784                 {
    01785                     ++(*pUseCount);
    01786                 }
    01787             }
    01788             else
    01789             {
    01790                 // RHS must be a null pointer
    01791                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    01792                 setNull();
    01793             }
    01794             return *this;
    01795         }
    01797         GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
    01798     };
    01799 }
    01800
    01801 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:17 2009