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_WORLD_MATRIX_ARRAY_3x4, 00068 ACT_WORLD_MATRIX_ARRAY, 00070 ACT_VIEW_MATRIX, 00072 ACT_PROJECTION_MATRIX, 00074 ACT_VIEWPROJ_MATRIX, 00076 ACT_WORLDVIEW_MATRIX, 00078 ACT_WORLDVIEWPROJ_MATRIX, 00080 ACT_INVERSE_WORLD_MATRIX, 00082 ACT_INVERSE_WORLDVIEW_MATRIX, 00084 ACT_LIGHT_DIFFUSE_COLOUR, 00086 ACT_LIGHT_SPECULAR_COLOUR, 00088 ACT_LIGHT_ATTENUATION, 00090 ACT_LIGHT_POSITION, 00092 ACT_LIGHT_DIRECTION, 00094 ACT_LIGHT_POSITION_OBJECT_SPACE, 00096 ACT_LIGHT_DIRECTION_OBJECT_SPACE, 00101 ACT_LIGHT_DISTANCE_OBJECT_SPACE, 00105 ACT_SHADOW_EXTRUSION_DISTANCE, 00107 ACT_CAMERA_POSITION_OBJECT_SPACE, 00109 ACT_AMBIENT_LIGHT_COLOUR, 00111 ACT_TEXTURE_VIEWPROJ_MATRIX 00112 }; 00114 class AutoConstantEntry 00115 { 00116 public: 00118 AutoConstantType paramType; 00120 size_t index; 00122 size_t data; 00123 00124 AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData) 00125 : paramType(theType), index(theIndex), data(theData) {} 00126 00127 }; 00132 struct RealConstantEntry 00133 { 00134 Real val[4]; 00135 bool isSet; 00136 RealConstantEntry() : isSet(false) {} 00137 }; 00142 struct IntConstantEntry 00143 { 00144 int val[4]; 00145 bool isSet; 00146 IntConstantEntry() : isSet(false) {} 00147 }; 00148 protected: 00149 // Constant lists 00150 typedef std::vector<RealConstantEntry> RealConstantList; 00151 typedef std::vector<IntConstantEntry> IntConstantList; 00152 // Auto parameter storage 00153 typedef std::vector<AutoConstantEntry> AutoConstantList; 00155 RealConstantList mRealConstants; 00157 IntConstantList mIntConstants; 00159 AutoConstantList mAutoConstants; 00161 typedef std::map<String, size_t> ParamNameMap; 00162 ParamNameMap mParamNameMap; 00164 bool mTransposeMatrices; 00165 00166 public: 00167 GpuProgramParameters(); 00168 ~GpuProgramParameters() {} 00169 00175 void setConstant(size_t index, const Vector4& vec); 00183 void setConstant(size_t index, const Vector3& vec); 00190 void setConstant(size_t index, const Matrix4& m); 00198 void setConstant(size_t index, const Matrix4* m, size_t numEntries); 00205 void setConstant(size_t index, const Real *val, size_t count); 00211 void setConstant(size_t index, const ColourValue& colour); 00212 00227 void setConstant(size_t index, const int *val, size_t count); 00228 00230 void resetRealConstants(void) { mRealConstants.clear(); } 00232 void resetIntConstants(void) { mIntConstants.clear(); } 00233 00234 typedef VectorIterator<RealConstantList> RealConstantIterator; 00235 typedef VectorIterator<IntConstantList> IntConstantIterator; 00237 RealConstantIterator getRealConstantIterator(void); 00239 IntConstantIterator getIntConstantIterator(void); 00240 00242 size_t getRealConstantCount(void) const { return mRealConstants.size(); } 00244 size_t getIntConstantCount(void) const { return mIntConstants.size(); } 00246 bool hasRealConstantParams(void) const { return !(mRealConstants.empty()); } 00248 bool hasIntConstantParams(void) const { return !(mIntConstants.empty()); } 00249 00263 void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0); 00268 void setConstantFromTime(size_t index, Real factor); 00269 00271 void clearAutoConstants(void); 00272 typedef VectorIterator<AutoConstantList> AutoConstantIterator; 00274 AutoConstantIterator getAutoConstantIterator(void); 00276 bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); } 00278 void _updateAutoParamsNoLights(const AutoParamDataSource& source); 00280 void _updateAutoParamsLightsOnly(const AutoParamDataSource& source); 00281 00301 void setNamedConstant(const String& name, Real val); 00321 void setNamedConstant(const String& name, int val); 00326 void setNamedConstant(const String& name, const Vector4& vec); 00339 void setNamedConstant(const String& name, const Vector3& vec); 00344 void setNamedConstant(const String& name, const Matrix4& m); 00352 void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries); 00373 void setNamedConstant(const String& name, const Real *val, size_t count); 00378 void setNamedConstant(const String& name, const ColourValue& colour); 00379 00400 void setNamedConstant(const String& name, const int *val, size_t count); 00401 00416 void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0); 00417 00425 void setNamedConstantFromTime(const String& name, Real factor); 00427 void _mapParameterNameToIndex(const String& name, size_t index); 00428 00430 size_t getParamIndex(const String& name) const; 00431 00439 void setTransposeMatrices(bool val) { mTransposeMatrices = val; } 00441 bool getTransposeMatrices(void) const { return mTransposeMatrices; } 00442 00443 }; 00444 00446 typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr; 00447 00457 class _OgreExport GpuProgram : public Resource 00458 { 00459 protected: 00461 GpuProgramType mType; 00463 String mFilename; 00465 String mSource; 00467 bool mLoadFromFile; 00469 String mSyntaxCode; 00471 bool mSkeletalAnimation; 00472 00473 public: 00474 00475 GpuProgram(const String& name, GpuProgramType gptype, const String& syntaxCode); 00476 virtual ~GpuProgram() {} 00477 00482 virtual void setSourceFile(const String& filename); 00483 00488 virtual void setSource(const String& source); 00489 00491 virtual const String& getSyntaxCode(void) const { return mSyntaxCode; } 00492 00494 virtual const String& getSourceFile(void) const { return mFilename; } 00496 virtual const String& getSource(void) const { return mSource; } 00498 virtual GpuProgramType getType(void) const { return mType; } 00499 00501 void load(void); 00506 virtual GpuProgram* _getBindingDelegate(void) { return this; } 00507 00509 virtual bool isSupported(void) const; 00510 00518 virtual GpuProgramParametersSharedPtr createParameters(void); 00519 00526 virtual void setSkeletalAnimationIncluded(bool included) 00527 { mSkeletalAnimation = included; } 00528 00535 virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; } 00536 00537 00538 protected: 00540 virtual void loadFromSource(void) = 0; 00541 00542 }; 00543 00544 00545 } 00546 00547 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:14 2004