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_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,
    00113             ACT_CUSTOM
    00114         };
    00116         class AutoConstantEntry
    00117         {
    00118         public:
    00120             AutoConstantType paramType;
    00122             size_t index;
    00124             size_t data;
    00125
    00126             AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData)
    00127                 : paramType(theType), index(theIndex), data(theData) {}
    00128
    00129         };
    00134         struct RealConstantEntry
    00135         {
    00136             Real val[4];
    00137             bool isSet;
    00138             RealConstantEntry() : isSet(false) {}
    00139         };
    00144         struct IntConstantEntry
    00145         {
    00146             int val[4];
    00147             bool isSet;
    00148             IntConstantEntry() : isSet(false) {}
    00149         };
    00150     protected:
    00151         // Constant lists
    00152         typedef std::vector<RealConstantEntry> RealConstantList;
    00153         typedef std::vector<IntConstantEntry> IntConstantList;
    00154         // Auto parameter storage
    00155         typedef std::vector<AutoConstantEntry> AutoConstantList;
    00157         RealConstantList mRealConstants;
    00159         IntConstantList mIntConstants;
    00161         AutoConstantList mAutoConstants;
    00163         typedef std::map<String, size_t> ParamNameMap;
    00164         ParamNameMap mParamNameMap;
    00166         bool mTransposeMatrices;
    00168         bool mAutoAddParamName;
    00169
    00170     public:
    00171         GpuProgramParameters();
    00172         ~GpuProgramParameters() {}
    00173
    00179         void setConstant(size_t index, const Vector4& vec);
    00187         void setConstant(size_t index, const Vector3& vec);
    00194         void setConstant(size_t index, const Matrix4& m);
    00202         void setConstant(size_t index, const Matrix4* m, size_t numEntries);
    00209         void setConstant(size_t index, const Real *val, size_t count);
    00215         void setConstant(size_t index, const ColourValue& colour);
    00216
    00231         void setConstant(size_t index, const int *val, size_t count);
    00232
    00234         void resetRealConstants(void) { mRealConstants.clear(); }
    00236         void resetIntConstants(void) { mIntConstants.clear(); }
    00237
    00238         typedef ConstVectorIterator<RealConstantList> RealConstantIterator;
    00239         typedef ConstVectorIterator<IntConstantList> IntConstantIterator;
    00241         RealConstantIterator getRealConstantIterator(void) const;
    00243         IntConstantIterator getIntConstantIterator(void) const;
    00244
    00249         RealConstantEntry* getRealConstantEntry(const size_t index);
    00254         IntConstantEntry* getIntConstantEntry(const size_t index);
    00255
    00259         RealConstantEntry* getNamedRealConstantEntry(const String& name);
    00263         IntConstantEntry* getNamedIntConstantEntry(const String& name);
    00265         size_t getRealConstantCount(void) const { return mRealConstants.size(); }
    00267         size_t getIntConstantCount(void) const { return mIntConstants.size(); }
    00269         bool hasRealConstantParams(void) const { return !(mRealConstants.empty()); }
    00271         bool hasIntConstantParams(void) const { return !(mIntConstants.empty()); }
    00272
    00286         void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
    00291         void setConstantFromTime(size_t index, Real factor);
    00292
    00294         void clearAutoConstants(void);
    00295         typedef ConstVectorIterator<AutoConstantList> AutoConstantIterator;
    00297         AutoConstantIterator getAutoConstantIterator(void) const;
    00299         bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
    00301         void _updateAutoParamsNoLights(const AutoParamDataSource& source);
    00303         void _updateAutoParamsLightsOnly(const AutoParamDataSource& source);
    00304
    00316         void setAutoAddParamName(bool state) { mAutoAddParamName = state; }
    00317
    00337         void setNamedConstant(const String& name, Real val);
    00357         void setNamedConstant(const String& name, int val);
    00362         void setNamedConstant(const String& name, const Vector4& vec);
    00375         void setNamedConstant(const String& name, const Vector3& vec);
    00380         void setNamedConstant(const String& name, const Matrix4& m);
    00388         void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
    00409         void setNamedConstant(const String& name, const Real *val, size_t count);
    00414         void setNamedConstant(const String& name, const ColourValue& colour);
    00415
    00436         void setNamedConstant(const String& name, const int *val, size_t count);
    00437
    00452         void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
    00453
    00461         void setNamedConstantFromTime(const String& name, Real factor);
    00463         void _mapParameterNameToIndex(const String& name, size_t index);
    00464
    00466         size_t getParamIndex(const String& name);
    00467
    00468
    00476         void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
    00478         bool getTransposeMatrices(void) const { return mTransposeMatrices; }
    00479
    00483         void copyConstantsFrom(const GpuProgramParameters& source);
    00484
    00485     };
    00486
    00488     typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
    00489
    00499     class _OgreExport GpuProgram : public Resource
    00500     {
    00501     protected:
    00503         GpuProgramType mType;
    00505         String mFilename;
    00507         String mSource;
    00509         bool mLoadFromFile;
    00511         String mSyntaxCode;
    00513         bool mSkeletalAnimation;
    00515         GpuProgramParametersSharedPtr mDefaultParams;
    00517         bool mPassSurfaceAndLightStates;
    00518
    00519     public:
    00520
    00521         GpuProgram(const String& name, GpuProgramType gptype, const String& syntaxCode);
    00522         virtual ~GpuProgram() {}
    00523
    00528         virtual void setSourceFile(const String& filename);
    00529
    00534         virtual void setSource(const String& source);
    00535
    00537         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
    00538
    00540         virtual const String& getSourceFile(void) const { return mFilename; }
    00542         virtual const String& getSource(void) const { return mSource; }
    00544         virtual GpuProgramType getType(void) const { return mType; }
    00545
    00547         void load(void);
    00552         virtual GpuProgram* _getBindingDelegate(void) { return this; }
    00553
    00555         virtual bool isSupported(void) const;
    00556
    00564         virtual GpuProgramParametersSharedPtr createParameters(void);
    00565
    00572         virtual void setSkeletalAnimationIncluded(bool included)
    00573         { mSkeletalAnimation = included; }
    00574
    00581         virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
    00582
    00593         virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
    00594
    00603         virtual void setSurfaceAndPassLightStates(bool state)
    00604             { mPassSurfaceAndLightStates = state; }
    00605
    00609         virtual bool getPassSurfaceAndLightStates(void) const { return mPassSurfaceAndLightStates; }
    00610
    00611     protected:
    00613         virtual void loadFromSource(void) = 0;
    00614
    00615     };
    00616
    00617
    00618 }
    00619
    00620 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:27 2004