# 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);
    00996         void _writeRawConstant(size_t physicalIndex, const Matrix4& m);
    01004         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    01014         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    01015             size_t count = 4);
    01016
    01017
    01023         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    01024
    01029         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    01030
    01035         const GpuNamedConstants& getConstantDefinitions() const;
    01036
    01042         const GpuLogicalBufferStruct* getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    01043
    01049         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01055         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    01056
    01062         const GpuLogicalBufferStruct* getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    01064         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    01066         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    01068         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    01070         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    01072         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    01074         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    01076         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    01077
    01091         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    01092         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    01093
    01097         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    01098             size_t elementSize = 4);
    01102         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01103             size_t elementSize = 4);
    01104
    01105
    01107         void clearAutoConstant(size_t index);
    01108
    01113         void setConstantFromTime(size_t index, Real factor);
    01114
    01116         void clearAutoConstants(void);
    01117         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01119         AutoConstantIterator getAutoConstantIterator(void) const;
    01121         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01126         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01128         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01133         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01138         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01142         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01146         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01150         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01151
    01153         void _updateAutoParamsNoLights(const AutoParamDataSource* source);
    01155         void _updateAutoParamsLightsOnly(const AutoParamDataSource* source);
    01156
    01159         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01160
    01180         void setNamedConstant(const String& name, Real val);
    01200         void setNamedConstant(const String& name, int val);
    01205         void setNamedConstant(const String& name, const Vector4& vec);
    01218         void setNamedConstant(const String& name, const Vector3& vec);
    01223         void setNamedConstant(const String& name, const Matrix4& m);
    01231         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01248         void setNamedConstant(const String& name, const float *val, size_t count,
    01249             size_t multiple = 4);
    01266         void setNamedConstant(const String& name, const double *val, size_t count,
    01267             size_t multiple = 4);
    01272         void setNamedConstant(const String& name, const ColourValue& colour);
    01273
    01290         void setNamedConstant(const String& name, const int *val, size_t count,
    01291             size_t multiple = 4);
    01292
    01307         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01308         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01309
    01317         void setNamedConstantFromTime(const String& name, Real factor);
    01318
    01320         void clearNamedAutoConstant(const String& name);
    01321
    01331         const GpuConstantDefinition* _findNamedConstantDefinition(
    01332             const String& name, bool throwExceptionIfMissing = false) const;
    01339         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01346         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01347
    01348
    01356         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01358         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01359
    01363         void copyConstantsFrom(const GpuProgramParameters& source);
    01364
    01368         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01373         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01376         static size_t getNumAutoConstantDefinitions(void);
    01377
    01378
    01381         void incPassIterationNumber(void);
    01383         bool hasPassIterationNumber() const
    01384         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01386         size_t getPassIterationNumberIndex() const
    01387         { return mActivePassIterationIndex; }
    01388
    01389
    01390     };
    01391
    01393     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01394
    01395     // Forward declaration
    01396     class GpuProgramPtr;
    01397
    01407     class _OgreExport GpuProgram : public Resource
    01408     {
    01409     protected:
    01411         class _OgreExport CmdType : public ParamCommand
    01412         {
    01413         public:
    01414             String doGet(const void* target) const;
    01415             void doSet(void* target, const String& val);
    01416         };
    01417         class _OgreExport CmdSyntax : public ParamCommand
    01418         {
    01419         public:
    01420             String doGet(const void* target) const;
    01421             void doSet(void* target, const String& val);
    01422         };
    01423         class _OgreExport CmdSkeletal : public ParamCommand
    01424         {
    01425         public:
    01426             String doGet(const void* target) const;
    01427             void doSet(void* target, const String& val);
    01428         };
    01429         class _OgreExport CmdMorph : public ParamCommand
    01430         {
    01431         public:
    01432             String doGet(const void* target) const;
    01433             void doSet(void* target, const String& val);
    01434         };
    01435         class _OgreExport CmdPose : public ParamCommand
    01436         {
    01437         public:
    01438             String doGet(const void* target) const;
    01439             void doSet(void* target, const String& val);
    01440         };
    01441         class _OgreExport CmdVTF : public ParamCommand
    01442         {
    01443         public:
    01444             String doGet(const void* target) const;
    01445             void doSet(void* target, const String& val);
    01446         };
    01447         class _OgreExport CmdManualNamedConstsFile : public ParamCommand
    01448         {
    01449         public:
    01450             String doGet(const void* target) const;
    01451             void doSet(void* target, const String& val);
    01452         };
    01453         class _OgreExport CmdAdjacency : public ParamCommand
    01454         {
    01455         public:
    01456             String doGet(const void* target) const;
    01457             void doSet(void* target, const String& val);
    01458         };
    01459         // Command object for setting / getting parameters
    01460         static CmdType msTypeCmd;
    01461         static CmdSyntax msSyntaxCmd;
    01462         static CmdSkeletal msSkeletalCmd;
    01463         static CmdMorph msMorphCmd;
    01464         static CmdPose msPoseCmd;
    01465         static CmdVTF msVTFCmd;
    01466         static CmdManualNamedConstsFile msManNamedConstsFileCmd;
    01467         static CmdAdjacency msAdjacencyCmd;
    01469         GpuProgramType mType;
    01471         String mFilename;
    01473         String mSource;
    01475         bool mLoadFromFile;
    01477         String mSyntaxCode;
    01479         bool mSkeletalAnimation;
    01481         bool mMorphAnimation;
    01483         ushort mPoseAnimation;
    01485         bool mVertexTextureFetch;
    01487         bool mNeedsAdjacencyInfo;
    01489         GpuProgramParametersSharedPtr mDefaultParams;
    01491         bool mPassSurfaceAndLightStates;
    01493         bool mCompileError;
    01496         mutable GpuLogicalBufferStruct mFloatLogicalToPhysical;
    01499         mutable GpuLogicalBufferStruct mIntLogicalToPhysical;
    01501         mutable GpuNamedConstants mConstantDefs;
    01503         String mManualNamedConstantsFile;
    01504         bool mLoadedManualNamedConstants;
    01505
    01506
    01515         void setupBaseParamDictionary(void);
    01516
    01519         bool isRequiredCapabilitiesSupported(void) const;
    01520
    01522         size_t calculateSize(void) const { return 0; } // TODO
    01523
    01525         void loadImpl(void);
    01526     public:
    01527
    01528         GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    01529             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    01530
    01531         virtual ~GpuProgram() {}
    01532
    01537         virtual void setSourceFile(const String& filename);
    01538
    01543         virtual void setSource(const String& source);
    01544
    01546         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
    01547
    01549         virtual void setSyntaxCode(const String& syntax);
    01550
    01552         virtual const String& getSourceFile(void) const { return mFilename; }
    01554         virtual const String& getSource(void) const { return mSource; }
    01556         virtual void setType(GpuProgramType t);
    01558         virtual GpuProgramType getType(void) const { return mType; }
    01559
    01564         virtual GpuProgram* _getBindingDelegate(void) { return this; }
    01565
    01567         virtual bool isSupported(void) const;
    01568
    01576         virtual GpuProgramParametersSharedPtr createParameters(void);
    01577
    01584         virtual void setSkeletalAnimationIncluded(bool included)
    01585         { mSkeletalAnimation = included; }
    01586
    01593         virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
    01594
    01601         virtual void setMorphAnimationIncluded(bool included)
    01602         { mMorphAnimation = included; }
    01603
    01611         virtual void setPoseAnimationIncluded(ushort poseCount)
    01612         { mPoseAnimation = poseCount; }
    01613
    01620         virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
    01621
    01628         virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
    01632         virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
    01636         virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
    01640         virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
    01641
    01645         virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
    01649         virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
    01650
    01661         virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
    01662
    01665         virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
    01666
    01675         virtual void setSurfaceAndPassLightStates(bool state)
    01676             { mPassSurfaceAndLightStates = state; }
    01677
    01681         virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
    01682
    01686         virtual const String& getLanguage(void) const;
    01687
    01690         virtual bool hasCompileError(void) const { return mCompileError; }
    01691
    01694         virtual void resetCompileError(void) { mCompileError = false; }
    01695
    01704         virtual void setManualNamedConstants(const GpuNamedConstants& namedConstants);
    01705
    01707         virtual const GpuNamedConstants& getNamedConstants() const { return mConstantDefs; }
    01708
    01719         virtual void setManualNamedConstantsFile(const String& paramDefFile);
    01720
    01724         virtual const String& getManualNamedConstantsFile() const { return mManualNamedConstantsFile; }
    01731         virtual const GpuNamedConstants& getConstantDefinitions() const { return mConstantDefs; }
    01732
    01733
    01734     protected:
    01736         virtual void loadFromSource(void) = 0;
    01737
    01738     };
    01739
    01740
    01747     class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram>
    01748     {
    01749     public:
    01750         GpuProgramPtr() : SharedPtr<GpuProgram>() {}
    01751         explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
    01752         GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {}
    01753         GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
    01754         {
    01755             // lock & copy other mutex pointer
    01756             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01757             {
    01758                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01759                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01760                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01761                 pUseCount = r.useCountPointer();
    01762                 if (pUseCount)
    01763                 {
    01764                     ++(*pUseCount);
    01765                 }
    01766             }
    01767         }
    01768
    01770         GpuProgramPtr& operator=(const ResourcePtr& r)
    01771         {
    01772             if (pRep == static_cast<GpuProgram*>(r.getPointer()))
    01773                 return *this;
    01774             release();
    01775             // lock & copy other mutex pointer
    01776             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01777             {
    01778                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01779                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01780                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01781                 pUseCount = r.useCountPointer();
    01782                 if (pUseCount)
    01783                 {
    01784                     ++(*pUseCount);
    01785                 }
    01786             }
    01787             else
    01788             {
    01789                 // RHS must be a null pointer
    01790                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    01791                 setNull();
    01792             }
    01793             return *this;
    01794         }
    01796         GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
    01797     };
    01798 }
    01799
    01800 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 14:26:40 2009