Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# 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
    00038 namespace Ogre {
    00039
    00041     enum GpuProgramType
    00042     {
    00043         GPT_VERTEX_PROGRAM,
    00044         GPT_FRAGMENT_PROGRAM
    00045     };
    00046
    00052     enum GpuConstantType
    00053     {
    00054         GCT_FLOAT1,
    00055         GCT_FLOAT2,
    00056         GCT_FLOAT3,
    00057         GCT_FLOAT4,
    00058         GCT_SAMPLER1D,
    00059         GCT_SAMPLER2D,
    00060         GCT_SAMPLER3D,
    00061         GCT_SAMPLERCUBE,
    00062         GCT_SAMPLER1DSHADOW,
    00063         GCT_SAMPLER2DSHADOW,
    00064         GCT_MATRIX_2X2,
    00065         GCT_MATRIX_2X3,
    00066         GCT_MATRIX_2X4,
    00067         GCT_MATRIX_3X2,
    00068         GCT_MATRIX_3X3,
    00069         GCT_MATRIX_3X4,
    00070         GCT_MATRIX_4X2,
    00071         GCT_MATRIX_4X3,
    00072         GCT_MATRIX_4X4,
    00073         GCT_INT1,
    00074         GCT_INT2,
    00075         GCT_INT3,
    00076         GCT_INT4,
    00077         GCT_UNKNOWN
    00078     };
    00079
    00084     struct _OgreExport GpuConstantDefinition
    00085     {
    00087         GpuConstantType constType;
    00089         size_t physicalIndex;
    00092         size_t elementSize;
    00094         size_t arraySize;
    00095
    00096         bool isFloat() const
    00097         {
    00098             switch(constType)
    00099             {
    00100             case GCT_INT1:
    00101             case GCT_INT2:
    00102             case GCT_INT3:
    00103             case GCT_INT4:
    00104             case GCT_SAMPLER1D:
    00105             case GCT_SAMPLER2D:
    00106             case GCT_SAMPLER3D:
    00107             case GCT_SAMPLERCUBE:
    00108             case GCT_SAMPLER1DSHADOW:
    00109             case GCT_SAMPLER2DSHADOW:
    00110                 return false;
    00111             default:
    00112                 return true;
    00113             };
    00114
    00115         }
    00116
    00117         bool isSampler() const
    00118         {
    00119             switch(constType)
    00120             {
    00121             case GCT_SAMPLER1D:
    00122             case GCT_SAMPLER2D:
    00123             case GCT_SAMPLER3D:
    00124             case GCT_SAMPLERCUBE:
    00125             case GCT_SAMPLER1DSHADOW:
    00126             case GCT_SAMPLER2DSHADOW:
    00127                 return true;
    00128             default:
    00129                 return false;
    00130             };
    00131
    00132         }
    00133
    00134         GpuConstantDefinition()
    00135             : constType(GCT_UNKNOWN)
    00136             , physicalIndex((std::numeric_limits<size_t>::max)())
    00137             , elementSize(0)
    00138             , arraySize(1) {}
    00139     };
    00140     typedef std::map<String, GpuConstantDefinition> GpuConstantDefinitionMap;
    00141     typedef ConstMapIterator<GpuConstantDefinitionMap> GpuConstantDefinitionIterator;
    00142
    00144     struct _OgreExport GpuNamedConstants
    00145     {
    00147         size_t floatBufferSize;
    00149         size_t intBufferSize;
    00151         GpuConstantDefinitionMap map;
    00152
    00164         void generateConstantDefinitionArrayEntries(const String& paramName,
    00165             const GpuConstantDefinition& baseDef);
    00166
    00167     };
    00168
    00172     struct _OgreExport GpuLogicalIndexUse
    00173     {
    00175         size_t physicalIndex;
    00177         size_t currentSize;
    00178
    00179         GpuLogicalIndexUse(size_t bufIdx, size_t curSz)
    00180             : physicalIndex(bufIdx), currentSize(curSz) {}
    00181     };
    00182     typedef std::map<size_t, GpuLogicalIndexUse> GpuLogicalIndexUseMap;
    00184     struct _OgreExport GpuLogicalBufferStruct
    00185     {
    00186         OGRE_MUTEX(mutex)
    00188         GpuLogicalIndexUseMap map;
    00190         size_t bufferSize;
    00191         GpuLogicalBufferStruct() : bufferSize(0) {}
    00192     };
    00193
    00224     class _OgreExport GpuProgramParameters
    00225     {
    00226     public:
    00230         enum AutoConstantType
    00231         {
    00233             ACT_WORLD_MATRIX,
    00235             ACT_INVERSE_WORLD_MATRIX,
    00239             ACT_TRANSPOSE_WORLD_MATRIX,
    00241             ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
    00242
    00243
    00245             ACT_WORLD_MATRIX_ARRAY_3x4,
    00247             ACT_WORLD_MATRIX_ARRAY,
    00248
    00250             ACT_VIEW_MATRIX,
    00252             ACT_INVERSE_VIEW_MATRIX,
    00256             ACT_TRANSPOSE_VIEW_MATRIX,
    00260             ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
    00261
    00262
    00264             ACT_PROJECTION_MATRIX,
    00268             ACT_INVERSE_PROJECTION_MATRIX,
    00272             ACT_TRANSPOSE_PROJECTION_MATRIX,
    00276             ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
    00277
    00278
    00280             ACT_VIEWPROJ_MATRIX,
    00284             ACT_INVERSE_VIEWPROJ_MATRIX,
    00288             ACT_TRANSPOSE_VIEWPROJ_MATRIX,
    00292             ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
    00293
    00294
    00296             ACT_WORLDVIEW_MATRIX,
    00298             ACT_INVERSE_WORLDVIEW_MATRIX,
    00302             ACT_TRANSPOSE_WORLDVIEW_MATRIX,
    00304             ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
    00306
    00307
    00309             ACT_WORLDVIEWPROJ_MATRIX,
    00313             ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
    00317             ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00321             ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
    00322
    00323
    00325
    00328             ACT_RENDER_TARGET_FLIPPING,
    00329
    00330
    00332             ACT_FOG_COLOUR,
    00334             ACT_FOG_PARAMS,
    00335
    00336
    00338             ACT_SURFACE_AMBIENT_COLOUR,
    00340             ACT_SURFACE_DIFFUSE_COLOUR,
    00342             ACT_SURFACE_SPECULAR_COLOUR,
    00344             ACT_SURFACE_EMISSIVE_COLOUR,
    00346             ACT_SURFACE_SHININESS,
    00347
    00348
    00350             ACT_AMBIENT_LIGHT_COLOUR,
    00351
    00353             ACT_LIGHT_DIFFUSE_COLOUR,
    00355             ACT_LIGHT_SPECULAR_COLOUR,
    00357             ACT_LIGHT_ATTENUATION,
    00363             ACT_SPOTLIGHT_PARAMS,
    00365             ACT_LIGHT_POSITION,
    00367             ACT_LIGHT_POSITION_OBJECT_SPACE,
    00369             ACT_LIGHT_POSITION_VIEW_SPACE,
    00371             ACT_LIGHT_DIRECTION,
    00373             ACT_LIGHT_DIRECTION_OBJECT_SPACE,
    00375             ACT_LIGHT_DIRECTION_VIEW_SPACE,
    00380             ACT_LIGHT_DISTANCE_OBJECT_SPACE,
    00382             ACT_LIGHT_POWER_SCALE,
    00384             ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00386             ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
    00388             ACT_LIGHT_ATTENUATION_ARRAY,
    00390             ACT_LIGHT_POSITION_ARRAY,
    00392             ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
    00394             ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
    00396             ACT_LIGHT_DIRECTION_ARRAY,
    00398             ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
    00400             ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
    00405             ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
    00409             ACT_LIGHT_POWER_SCALE_ARRAY,
    00416             ACT_SPOTLIGHT_PARAMS_ARRAY,
    00417
    00422             ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
    00427             ACT_DERIVED_SCENE_COLOUR,
    00428
    00434             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
    00440             ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
    00441
    00443             ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
    00445             ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
    00446
    00447
    00451             ACT_SHADOW_EXTRUSION_DISTANCE,
    00453             ACT_CAMERA_POSITION,
    00455             ACT_CAMERA_POSITION_OBJECT_SPACE,
    00457             ACT_TEXTURE_VIEWPROJ_MATRIX,
    00459             ACT_CUSTOM,
    00462             ACT_TIME,
    00466             ACT_TIME_0_X,
    00468             ACT_COSTIME_0_X,
    00470             ACT_SINTIME_0_X,
    00472             ACT_TANTIME_0_X,
    00476             ACT_TIME_0_X_PACKED,
    00481             ACT_TIME_0_1,
    00483             ACT_COSTIME_0_1,
    00485             ACT_SINTIME_0_1,
    00487             ACT_TANTIME_0_1,
    00491             ACT_TIME_0_1_PACKED,
    00496             ACT_TIME_0_2PI,
    00498             ACT_COSTIME_0_2PI,
    00500             ACT_SINTIME_0_2PI,
    00502             ACT_TANTIME_0_2PI,
    00506             ACT_TIME_0_2PI_PACKED,
    00508             ACT_FRAME_TIME,
    00510             ACT_FPS,
    00512
    00515             ACT_VIEWPORT_WIDTH,
    00519             ACT_VIEWPORT_HEIGHT,
    00523             ACT_INVERSE_VIEWPORT_WIDTH,
    00527             ACT_INVERSE_VIEWPORT_HEIGHT,
    00531             ACT_VIEWPORT_SIZE,
    00532
    00534
    00537             ACT_VIEW_DIRECTION,
    00541             ACT_VIEW_SIDE_VECTOR,
    00545             ACT_VIEW_UP_VECTOR,
    00549             ACT_FOV,
    00553             ACT_NEAR_CLIP_DISTANCE,
    00557             ACT_FAR_CLIP_DISTANCE,
    00558
    00562             ACT_PASS_NUMBER,
    00563
    00568             ACT_PASS_ITERATION_NUMBER,
    00569
    00570
    00574             ACT_ANIMATION_PARAMETRIC,
    00575
    00581             ACT_TEXEL_OFFSETS,
    00582
    00587             ACT_SCENE_DEPTH_RANGE,
    00588
    00594             ACT_SHADOW_SCENE_DEPTH_RANGE,
    00595
    00599             ACT_TEXTURE_SIZE,
    00603             ACT_INVERSE_TEXTURE_SIZE,
    00607             ACT_PACKED_TEXTURE_SIZE,
    00608
    00609
    00610         };
    00611
    00615         enum ACDataType {
    00617             ACDT_NONE,
    00619             ACDT_INT,
    00621             ACDT_REAL
    00622         };
    00623
    00626         enum ElementType {
    00627             ET_INT,
    00628             ET_REAL
    00629         };
    00630
    00634         struct AutoConstantDefinition
    00635         {
    00636             AutoConstantType acType;
    00637             String name;
    00638             size_t elementCount;
    00640             ElementType elementType;
    00642             ACDataType dataType;
    00643
    00644             AutoConstantDefinition(AutoConstantType _acType, const String& _name,
    00645                 size_t _elementCount, ElementType _elementType,
    00646                 ACDataType _dataType)
    00647                 :acType(_acType), name(_name), elementCount(_elementCount),
    00648                 elementType(_elementType), dataType(_dataType)
    00649             {
    00650
    00651             }
    00652         };
    00653
    00655         class AutoConstantEntry
    00656         {
    00657         public:
    00659             AutoConstantType paramType;
    00661             size_t physicalIndex;
    00665             size_t elementCount;
    00667             union{
    00668                 size_t data;
    00669                 Real fData;
    00670             };
    00671
    00672             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
    00673                 size_t theElemCount = 4)
    00674                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), data(theData) {}
    00675
    00676             AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
    00677                 size_t theElemCount = 4)
    00678                 : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), fData(theData) {}
    00679
    00680         };
    00681         // Auto parameter storage
    00682         typedef std::vector<AutoConstantEntry> AutoConstantList;
    00683
    00688         typedef std::vector<float> FloatConstantList;
    00693         typedef std::vector<int> IntConstantList;
    00694
    00695     protected:
    00696         static AutoConstantDefinition AutoConstantDictionary[];
    00698         FloatConstantList mFloatConstants;
    00700         IntConstantList mIntConstants;
    00703         GpuLogicalBufferStruct* mFloatLogicalToPhysical;
    00706         GpuLogicalBufferStruct* mIntLogicalToPhysical;
    00708         const GpuNamedConstants* mNamedConstants;
    00710         AutoConstantList mAutoConstants;
    00712         bool mTransposeMatrices;
    00714         bool mIgnoreMissingParams;
    00716         size_t mActivePassIterationIndex;
    00717
    00718     public:
    00719         GpuProgramParameters();
    00720         ~GpuProgramParameters() {}
    00721
    00723         GpuProgramParameters(const GpuProgramParameters& oth);
    00725         GpuProgramParameters& operator=(const GpuProgramParameters& oth);
    00726
    00728         void _setNamedConstants(const GpuNamedConstants* constantmap);
    00729
    00731         void _setLogicalIndexes(GpuLogicalBufferStruct* floatIndexMap,
    00732             GpuLogicalBufferStruct* intIndexMap);
    00733
    00734
    00736         bool hasNamedParameters() const { return mNamedConstants != 0;}
    00742         bool hasLogicalIndexedParameters() const { return mFloatLogicalToPhysical != 0;}
    00743
    00749         void setConstant(size_t index, const Vector4& vec);
    00757         void setConstant(size_t index, Real val);
    00765         void setConstant(size_t index, const Vector3& vec);
    00772         void setConstant(size_t index, const Matrix4& m);
    00780         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    00787         void setConstant(size_t index, const float *val, size_t count);
    00794         void setConstant(size_t index, const double *val, size_t count);
    00800         void setConstant(size_t index, const ColourValue& colour);
    00801
    00816         void setConstant(size_t index, const int *val, size_t count);
    00817
    00824         void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
    00831         void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
    00838         void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
    00845         void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
    00852         void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
    00853
    00864         void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
    00865             size_t count = 4);
    00873         void _writeRawConstant(size_t physicalIndex, Real val);
    00881         void _writeRawConstant(size_t physicalIndex, int val);
    00889         void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
    00897         void _writeRawConstant(size_t physicalIndex, const Matrix4& m);
    00905         void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
    00915         void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
    00916             size_t count = 4);
    00917
    00918
    00924         GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
    00925
    00930         const GpuConstantDefinition& getConstantDefinition(const String& name) const;
    00931
    00936         const GpuNamedConstants& getConstantDefinitions() const;
    00937
    00943         const GpuLogicalBufferStruct* getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
    00944
    00950         size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
    00956         size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
    00957
    00963         const GpuLogicalBufferStruct* getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
    00965         const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
    00967         float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
    00969         const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
    00971         const IntConstantList& getIntConstantList() const { return mIntConstants; }
    00973         int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
    00975         const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
    00977         const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
    00978
    00992         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    00993         void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
    00994
    00998         void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
    00999             size_t elementSize = 4);
    01003         void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
    01004             size_t elementSize = 4);
    01005
    01006
    01008         void clearAutoConstant(size_t index);
    01009
    01014         void setConstantFromTime(size_t index, Real factor);
    01015
    01017         void clearAutoConstants(void);
    01018         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    01020         AutoConstantIterator getAutoConstantIterator(void) const;
    01022         size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
    01027         AutoConstantEntry* getAutoConstantEntry(const size_t index);
    01029         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    01034         const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
    01039         const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
    01043         const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
    01047         const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
    01051         const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
    01052
    01054         void _updateAutoParamsNoLights(const AutoParamDataSource& source);
    01056         void _updateAutoParamsLightsOnly(const AutoParamDataSource& source);
    01057
    01060         void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
    01061
    01081         void setNamedConstant(const String& name, Real val);
    01101         void setNamedConstant(const String& name, int val);
    01106         void setNamedConstant(const String& name, const Vector4& vec);
    01119         void setNamedConstant(const String& name, const Vector3& vec);
    01124         void setNamedConstant(const String& name, const Matrix4& m);
    01132         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    01149         void setNamedConstant(const String& name, const float *val, size_t count,
    01150             size_t multiple = 4);
    01167         void setNamedConstant(const String& name, const double *val, size_t count,
    01168             size_t multiple = 4);
    01173         void setNamedConstant(const String& name, const ColourValue& colour);
    01174
    01191         void setNamedConstant(const String& name, const int *val, size_t count,
    01192             size_t multiple = 4);
    01193
    01208         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    01209         void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
    01210
    01218         void setNamedConstantFromTime(const String& name, Real factor);
    01219
    01221         void clearNamedAutoConstant(const String& name);
    01222
    01232         const GpuConstantDefinition* _findNamedConstantDefinition(
    01233             const String& name, bool throwExceptionIfMissing = false) const;
    01240         size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01247         size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize);
    01248
    01249
    01257         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    01259         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    01260
    01264         void copyConstantsFrom(const GpuProgramParameters& source);
    01265
    01269         static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
    01274         static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
    01277         static size_t getNumAutoConstantDefinitions(void);
    01278
    01279
    01282         void incPassIterationNumber(void);
    01284         bool hasPassIterationNumber() const
    01285         { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
    01287         size_t getPassIterationNumberIndex() const
    01288         { return mActivePassIterationIndex; }
    01289
    01290
    01291     };
    01292
    01294     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    01295
    01296     // Forward declaration
    01297     class GpuProgramPtr;
    01298
    01308     class _OgreExport GpuProgram : public Resource
    01309     {
    01310     protected:
    01312         class _OgreExport CmdType : public ParamCommand
    01313         {
    01314         public:
    01315             String doGet(const void* target) const;
    01316             void doSet(void* target, const String& val);
    01317         };
    01318         class _OgreExport CmdSyntax : public ParamCommand
    01319         {
    01320         public:
    01321             String doGet(const void* target) const;
    01322             void doSet(void* target, const String& val);
    01323         };
    01324         class _OgreExport CmdSkeletal : public ParamCommand
    01325         {
    01326         public:
    01327             String doGet(const void* target) const;
    01328             void doSet(void* target, const String& val);
    01329         };
    01330         class _OgreExport CmdMorph : public ParamCommand
    01331         {
    01332         public:
    01333             String doGet(const void* target) const;
    01334             void doSet(void* target, const String& val);
    01335         };
    01336         class _OgreExport CmdPose : public ParamCommand
    01337         {
    01338         public:
    01339             String doGet(const void* target) const;
    01340             void doSet(void* target, const String& val);
    01341         };
    01342         class _OgreExport CmdVTF : public ParamCommand
    01343         {
    01344         public:
    01345             String doGet(const void* target) const;
    01346             void doSet(void* target, const String& val);
    01347         };
    01348         // Command object for setting / getting parameters
    01349         static CmdType msTypeCmd;
    01350         static CmdSyntax msSyntaxCmd;
    01351         static CmdSkeletal msSkeletalCmd;
    01352         static CmdMorph msMorphCmd;
    01353         static CmdPose msPoseCmd;
    01354         static CmdVTF msVTFCmd;
    01355
    01357         GpuProgramType mType;
    01359         String mFilename;
    01361         String mSource;
    01363         bool mLoadFromFile;
    01365         String mSyntaxCode;
    01367         bool mSkeletalAnimation;
    01369         bool mMorphAnimation;
    01371         ushort mPoseAnimation;
    01373         bool mVertexTextureFetch;
    01375         GpuProgramParametersSharedPtr mDefaultParams;
    01377         bool mPassSurfaceAndLightStates;
    01379         bool mCompileError;
    01382         mutable GpuLogicalBufferStruct mFloatLogicalToPhysical;
    01385         mutable GpuLogicalBufferStruct mIntLogicalToPhysical;
    01386
    01395         void setupBaseParamDictionary(void);
    01396
    01399         bool isRequiredCapabilitiesSupported(void) const;
    01400
    01402         size_t calculateSize(void) const { return 0; } // TODO
    01403
    01405         void loadImpl(void);
    01406     public:
    01407
    01408         GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    01409             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    01410
    01411         virtual ~GpuProgram() {}
    01412
    01417         virtual void setSourceFile(const String& filename);
    01418
    01423         virtual void setSource(const String& source);
    01424
    01426         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
    01427
    01429         virtual void setSyntaxCode(const String& syntax);
    01430
    01432         virtual const String& getSourceFile(void) const { return mFilename; }
    01434         virtual const String& getSource(void) const { return mSource; }
    01436         virtual void setType(GpuProgramType t);
    01438         virtual GpuProgramType getType(void) const { return mType; }
    01439
    01444         virtual GpuProgram* _getBindingDelegate(void) { return this; }
    01445
    01447         virtual bool isSupported(void) const;
    01448
    01456         virtual GpuProgramParametersSharedPtr createParameters(void);
    01457
    01464         virtual void setSkeletalAnimationIncluded(bool included)
    01465         { mSkeletalAnimation = included; }
    01466
    01473         virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
    01474
    01481         virtual void setMorphAnimationIncluded(bool included)
    01482         { mMorphAnimation = included; }
    01483
    01491         virtual void setPoseAnimationIncluded(ushort poseCount)
    01492         { mPoseAnimation = poseCount; }
    01493
    01500         virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
    01501
    01508         virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
    01512         virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
    01516         virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
    01520         virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
    01521
    01532         virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
    01533
    01536         virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
    01537
    01546         virtual void setSurfaceAndPassLightStates(bool state)
    01547             { mPassSurfaceAndLightStates = state; }
    01548
    01552         virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
    01553
    01557         virtual const String& getLanguage(void) const;
    01558
    01561         virtual bool hasCompileError(void) const { return mCompileError; }
    01562
    01565         virtual void resetCompileError(void) { mCompileError = false; }
    01566     protected:
    01568         virtual void loadFromSource(void) = 0;
    01569
    01570     };
    01571
    01572
    01579     class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram>
    01580     {
    01581     public:
    01582         GpuProgramPtr() : SharedPtr<GpuProgram>() {}
    01583         explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
    01584         GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {}
    01585         GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
    01586         {
    01587             // lock & copy other mutex pointer
    01588             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01589             {
    01590                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01591                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01592                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01593                 pUseCount = r.useCountPointer();
    01594                 if (pUseCount)
    01595                 {
    01596                     ++(*pUseCount);
    01597                 }
    01598             }
    01599         }
    01600
    01602         GpuProgramPtr& operator=(const ResourcePtr& r)
    01603         {
    01604             if (pRep == static_cast<GpuProgram*>(r.getPointer()))
    01605                 return *this;
    01606             release();
    01607             // lock & copy other mutex pointer
    01608             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    01609             {
    01610                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    01611                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    01612                 pRep = static_cast<GpuProgram*>(r.getPointer());
    01613                 pUseCount = r.useCountPointer();
    01614                 if (pUseCount)
    01615                 {
    01616                     ++(*pUseCount);
    01617                 }
    01618             }
    01619             else
    01620             {
    01621                 // RHS must be a null pointer
    01622                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    01623                 setNull();
    01624             }
    01625             return *this;
    01626         }
    01628         GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
    01629     };
    01630 }
    01631
    01632 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:56 2007