Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2003 The OGRE Team
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 */
00025 #ifndef __GpuProgram_H_
00026 #define __GpuProgram_H_
00027 
00028 // Precompiler options
00029 #include "OgrePrerequisites.h"
00030 #include "OgreResource.h"
00031 #include "OgreSharedPtr.h"
00032 #include "OgreIteratorWrappers.h"
00033 
00034 namespace Ogre {
00035 
00037     enum GpuProgramType
00038     {
00039         GPT_VERTEX_PROGRAM,
00040         GPT_FRAGMENT_PROGRAM
00041     };
00042 
00043     
00055     class _OgreExport GpuProgramParameters
00056     {
00057     public:
00061         enum AutoConstantType
00062         {
00064             ACT_WORLD_MATRIX,
00066             ACT_VIEW_MATRIX,
00068             ACT_PROJECTION_MATRIX,
00070             ACT_WORLDVIEW_MATRIX,
00072             ACT_WORLDVIEWPROJ_MATRIX,
00074             ACT_INVERSE_WORLD_MATRIX,
00076             ACT_INVERSE_WORLDVIEW_MATRIX,
00078             ACT_LIGHT_DIFFUSE_COLOUR,
00080             ACT_LIGHT_SPECULAR_COLOUR,
00082             ACT_LIGHT_ATTENUATION,
00084             ACT_LIGHT_POSITION_OBJECT_SPACE,
00086             ACT_LIGHT_DIRECTION_OBJECT_SPACE,
00088             ACT_CAMERA_POSITION_OBJECT_SPACE,
00090             ACT_AMBIENT_LIGHT_COLOUR
00091         };
00093         class AutoConstantEntry
00094         {
00095         public:
00097             AutoConstantType paramType;
00099             size_t index;
00101             size_t data;
00102 
00103             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData)
00104                 : paramType(theType), index(theIndex), data(theData) {}
00105 
00106         };
00111         struct RealConstantEntry
00112         {
00113             Real val[4];
00114             bool isSet;
00115             RealConstantEntry() : isSet(false) {}
00116         };
00121         struct IntConstantEntry
00122         {
00123             int val[4];
00124             bool isSet;
00125             IntConstantEntry() : isSet(false) {}
00126         };
00127     protected:
00128         // Constant lists
00129         typedef std::vector<RealConstantEntry> RealConstantList;
00130         typedef std::vector<IntConstantEntry> IntConstantList;
00131         // Auto parameter storage
00132         typedef std::vector<AutoConstantEntry> AutoConstantList;
00134         RealConstantList mRealConstants;
00136         IntConstantList mIntConstants;
00138         AutoConstantList mAutoConstants;
00140         typedef std::map<String, size_t> ParamNameMap;
00141         ParamNameMap mParamNameMap;
00143         bool mTransposeMatrices;
00144 
00145     public:
00146         GpuProgramParameters();
00147         ~GpuProgramParameters() {}
00148 
00154         void setConstant(size_t index, const Vector4& vec);
00162         void setConstant(size_t index, const Vector3& vec);
00169         void setConstant(size_t index, const Matrix4& m);
00176         void setConstant(size_t index, const Real *val, size_t count);
00182         void setConstant(size_t index, const ColourValue& colour);
00183         
00198         void setConstant(size_t index, const int *val, size_t count);
00199 
00201         void resetRealConstants(void) { mRealConstants.clear(); }
00203         void resetIntConstants(void) { mIntConstants.clear(); }
00204 
00205         typedef VectorIterator<RealConstantList> RealConstantIterator;
00206         typedef VectorIterator<IntConstantList> IntConstantIterator;
00208         RealConstantIterator getRealConstantIterator(void);
00210         IntConstantIterator getIntConstantIterator(void);
00211         
00213         size_t getRealConstantCount(void) const { return mRealConstants.size(); }
00215         size_t getIntConstantCount(void) const { return mIntConstants.size(); }
00217         bool hasRealConstantParams(void) const { return !(mRealConstants.empty()); }
00219         bool hasIntConstantParams(void) const { return !(mIntConstants.empty()); }
00220 
00234         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
00239         void setConstantFromTime(size_t index, Real factor);
00240 
00242         void clearAutoConstants(void);
00243         typedef VectorIterator<AutoConstantList> AutoConstantIterator;
00245         AutoConstantIterator getAutoConstantIterator(void);
00247         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
00249         void _updateAutoParamsNoLights(const AutoParamDataSource& source);
00251         void _updateAutoParamsLightsOnly(const AutoParamDataSource& source);
00252 
00272         void setNamedConstant(const String& name, Real val);
00292         void setNamedConstant(const String& name, int val);
00297         void setNamedConstant(const String& name, const Vector4& vec);
00310         void setNamedConstant(const String& name, const Vector3& vec);
00315         void setNamedConstant(const String& name, const Matrix4& m);
00336         void setNamedConstant(const String& name, const Real *val, size_t count);
00341         void setNamedConstant(const String& name, const ColourValue& colour);
00342         
00363         void setNamedConstant(const String& name, const int *val, size_t count);
00364 
00379         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
00380 
00388         void setNamedConstantFromTime(const String& name, Real factor);
00390         void _mapParameterNameToIndex(const String& name, size_t index);
00391 
00393         size_t getParamIndex(const String& name) const;
00394 
00402         void setTransposeMatrices(bool val) { mTransposeMatrices = val; } 
00404         bool getTransposeMatrices(void) const { return mTransposeMatrices; } 
00405 
00406     };
00407 
00409     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
00410 
00420     class _OgreExport GpuProgram : public Resource
00421     {
00422     protected:
00424         GpuProgramType mType;
00426         String mFilename;
00428         String mSource;
00430         bool mLoadFromFile;
00432         String mSyntaxCode;
00433 
00434     public:
00435 
00436         GpuProgram(const String& name, GpuProgramType gptype, const String& syntaxCode);
00437         virtual ~GpuProgram() {}
00438 
00443         virtual void setSourceFile(const String& filename);
00444 
00449         virtual void setSource(const String& source);
00450 
00452         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
00453 
00455         virtual const String& getSourceFile(void) const { return mFilename; }
00457         virtual const String& getSource(void) const { return mSource; }
00459         virtual GpuProgramType getType(void) const { return mType; }
00460 
00462         void load(void);
00467         virtual GpuProgram* _getBindingDelegate(void) { return this; }
00468 
00470         virtual bool isSupported(void) const;
00471 
00479         virtual GpuProgramParametersSharedPtr createParameters(void);
00480 
00481 
00482     protected:
00484         virtual void loadFromSource(void) = 0;
00485 
00486     };
00487 
00488 
00489 }
00490 
00491 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:12 2004