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-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __GpuProgram_H_
    00029 #define __GpuProgram_H_
    00030
    00031 // Precompiler options
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreResource.h"
    00034 #include "OgreSharedPtr.h"
    00035 #include "OgreIteratorWrappers.h"
    00036 #include "OgreSerializer.h"
    00037 #include "OgreRenderOperation.h"
    00038 #include "OgreGpuProgramParams.h"
    00039
    00040 namespace Ogre {
    00041
    00049     enum GpuProgramType
    00050     {
    00051         GPT_VERTEX_PROGRAM,
    00052         GPT_FRAGMENT_PROGRAM,
    00053         GPT_GEOMETRY_PROGRAM
    00054     };
    00055
    00056
    00057     // Forward declaration
    00058     class GpuProgramPtr;
    00059
    00069     class _OgreExport GpuProgram : public Resource
    00070     {
    00071     protected:
    00073         class _OgreExport CmdType : public ParamCommand
    00074         {
    00075         public:
    00076             String doGet(const void* target) const;
    00077             void doSet(void* target, const String& val);
    00078         };
    00079         class _OgreExport CmdSyntax : public ParamCommand
    00080         {
    00081         public:
    00082             String doGet(const void* target) const;
    00083             void doSet(void* target, const String& val);
    00084         };
    00085         class _OgreExport CmdSkeletal : public ParamCommand
    00086         {
    00087         public:
    00088             String doGet(const void* target) const;
    00089             void doSet(void* target, const String& val);
    00090         };
    00091         class _OgreExport CmdMorph : public ParamCommand
    00092         {
    00093         public:
    00094             String doGet(const void* target) const;
    00095             void doSet(void* target, const String& val);
    00096         };
    00097         class _OgreExport CmdPose : public ParamCommand
    00098         {
    00099         public:
    00100             String doGet(const void* target) const;
    00101             void doSet(void* target, const String& val);
    00102         };
    00103         class _OgreExport CmdVTF : public ParamCommand
    00104         {
    00105         public:
    00106             String doGet(const void* target) const;
    00107             void doSet(void* target, const String& val);
    00108         };
    00109         class _OgreExport CmdManualNamedConstsFile : public ParamCommand
    00110         {
    00111         public:
    00112             String doGet(const void* target) const;
    00113             void doSet(void* target, const String& val);
    00114         };
    00115         class _OgreExport CmdAdjacency : public ParamCommand
    00116         {
    00117         public:
    00118             String doGet(const void* target) const;
    00119             void doSet(void* target, const String& val);
    00120         };
    00121         // Command object for setting / getting parameters
    00122         static CmdType msTypeCmd;
    00123         static CmdSyntax msSyntaxCmd;
    00124         static CmdSkeletal msSkeletalCmd;
    00125         static CmdMorph msMorphCmd;
    00126         static CmdPose msPoseCmd;
    00127         static CmdVTF msVTFCmd;
    00128         static CmdManualNamedConstsFile msManNamedConstsFileCmd;
    00129         static CmdAdjacency msAdjacencyCmd;
    00131         GpuProgramType mType;
    00133         String mFilename;
    00135         String mSource;
    00137         bool mLoadFromFile;
    00139         String mSyntaxCode;
    00141         bool mSkeletalAnimation;
    00143         bool mMorphAnimation;
    00145         ushort mPoseAnimation;
    00147         bool mVertexTextureFetch;
    00149         bool mNeedsAdjacencyInfo;
    00151         GpuProgramParametersSharedPtr mDefaultParams;
    00153         bool mCompileError;
    00158         mutable GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
    00163         mutable GpuLogicalBufferStructPtr mIntLogicalToPhysical;
    00168         mutable GpuNamedConstantsPtr mConstantDefs;
    00170         String mManualNamedConstantsFile;
    00171         bool mLoadedManualNamedConstants;
    00172
    00173
    00182         void setupBaseParamDictionary(void);
    00183
    00186         bool isRequiredCapabilitiesSupported(void) const;
    00187
    00189         size_t calculateSize(void) const { return 0; } // TODO
    00190
    00192         void loadImpl(void);
    00193
    00195         void createParameterMappingStructures(bool recreateIfExists = true) const;
    00197         void createLogicalParameterMappingStructures(bool recreateIfExists = true) const;
    00199         void createNamedParameterMappingStructures(bool recreateIfExists = true) const;
    00200
    00201     public:
    00202
    00203         GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    00204             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00205
    00206         virtual ~GpuProgram() {}
    00207
    00212         virtual void setSourceFile(const String& filename);
    00213
    00218         virtual void setSource(const String& source);
    00219
    00221         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
    00222
    00224         virtual void setSyntaxCode(const String& syntax);
    00225
    00227         virtual const String& getSourceFile(void) const { return mFilename; }
    00229         virtual const String& getSource(void) const { return mSource; }
    00231         virtual void setType(GpuProgramType t);
    00233         virtual GpuProgramType getType(void) const { return mType; }
    00234
    00239         virtual GpuProgram* _getBindingDelegate(void) { return this; }
    00240
    00242         virtual bool isSupported(void) const;
    00243
    00251         virtual GpuProgramParametersSharedPtr createParameters(void);
    00252
    00259         virtual void setSkeletalAnimationIncluded(bool included)
    00260         { mSkeletalAnimation = included; }
    00261
    00268         virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
    00269
    00276         virtual void setMorphAnimationIncluded(bool included)
    00277         { mMorphAnimation = included; }
    00278
    00286         virtual void setPoseAnimationIncluded(ushort poseCount)
    00287         { mPoseAnimation = poseCount; }
    00288
    00295         virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
    00296
    00303         virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
    00307         virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
    00311         virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
    00315         virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
    00316
    00320         virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
    00324         virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
    00325
    00336         virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
    00337
    00340         virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
    00341
    00348         virtual bool getPassSurfaceAndLightStates(void) const { return false; }
    00349
    00358         virtual bool getPassFogStates(void) const { return true; }
    00359
    00366         virtual bool getPassTransformStates(void) const { return false; }
    00367
    00371         virtual const String& getLanguage(void) const;
    00372
    00375         virtual bool hasCompileError(void) const { return mCompileError; }
    00376
    00379         virtual void resetCompileError(void) { mCompileError = false; }
    00380
    00389         virtual void setManualNamedConstants(const GpuNamedConstants& namedConstants);
    00390
    00392         virtual const GpuNamedConstants& getNamedConstants() const { return *mConstantDefs.get(); }
    00393
    00404         virtual void setManualNamedConstantsFile(const String& paramDefFile);
    00405
    00409         virtual const String& getManualNamedConstantsFile() const { return mManualNamedConstantsFile; }
    00416         virtual const GpuNamedConstants& getConstantDefinitions() const { return *mConstantDefs.get(); }
    00417
    00418
    00419     protected:
    00421         virtual void loadFromSource(void) = 0;
    00422
    00423     };
    00424
    00425
    00432     class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram>
    00433     {
    00434     public:
    00435         GpuProgramPtr() : SharedPtr<GpuProgram>() {}
    00436         explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
    00437         GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {}
    00438         GpuProgramPtr(const ResourcePtr& r) : SharedPtr<GpuProgram>()
    00439         {
    00440             // lock & copy other mutex pointer
    00441             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00442             {
    00443                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00444                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00445                 pRep = static_cast<GpuProgram*>(r.getPointer());
    00446                 pUseCount = r.useCountPointer();
    00447                 if (pUseCount)
    00448                 {
    00449                     ++(*pUseCount);
    00450                 }
    00451             }
    00452         }
    00453
    00455         GpuProgramPtr& operator=(const ResourcePtr& r)
    00456         {
    00457             if (pRep == static_cast<GpuProgram*>(r.getPointer()))
    00458                 return *this;
    00459             release();
    00460             // lock & copy other mutex pointer
    00461             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00462             {
    00463                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00464                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00465                 pRep = static_cast<GpuProgram*>(r.getPointer());
    00466                 pUseCount = r.useCountPointer();
    00467                 if (pUseCount)
    00468                 {
    00469                     ++(*pUseCount);
    00470                 }
    00471             }
    00472             else
    00473             {
    00474                 // RHS must be a null pointer
    00475                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00476                 setNull();
    00477             }
    00478             return *this;
    00479         }
    00481         GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
    00482     };
    00485 }
    00486
    00487 #endif

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