# OgreShaderParameter.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-2009 Torus Knot Software Ltd
    00008 Permission is hereby granted, free of charge, to any person obtaining a copy
    00009 of this software and associated documentation files (the "Software"), to deal
    00010 in the Software without restriction, including without limitation the rights
    00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00012 copies of the Software, and to permit persons to whom the Software is
    00013 furnished to do so, subject to the following conditions:
    00014
    00015 The above copyright notice and this permission notice shall be included in
    00016 all copies or substantial portions of the Software.
    00017
    00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00024 THE SOFTWARE.
    00025 -----------------------------------------------------------------------------
    00026 */
    00027 #ifndef _ShaderParameter_
    00028 #define _ShaderParameter_
    00029
    00030 #include "OgreShaderPrerequisites.h"
    00031 #include "OgreGpuProgram.h"
    00032 #include "OgreVector2.h"
    00033 #include "OgreVector3.h"
    00034 #include "OgreVector4.h"
    00035 #include "OgreMatrix4.h"
    00036
    00037 namespace Ogre {
    00038 namespace RTShader {
    00039
    00049 class _OgreRTSSExport Parameter : public RTShaderSystemAlloc
    00050 {
    00051 public:
    00052     // Shader parameter semantic.
    00053     enum Semantic
    00054     {
    00056         SPS_UNKNOWN = 0,
    00058         SPS_POSITION = 1,
    00060         SPS_BLEND_WEIGHTS = 2,
    00062         SPS_BLEND_INDICES = 3,
    00064         SPS_NORMAL = 4,
    00066         SPS_COLOR = 5,
    00068         SPS_TEXTURE_COORDINATES = 7,
    00070         SPS_BINORMAL = 8,
    00072         SPS_TANGENT = 9
    00073     };
    00074
    00075     // Shader parameter content.
    00076     enum Content
    00077     {
    00079         SPC_UNKNOWN,
    00080
    00082         SPC_POSITION_OBJECT_SPACE,
    00083
    00085         SPC_POSITION_WORLD_SPACE,
    00086
    00088         SPC_POSITION_VIEW_SPACE,
    00089
    00091         SPC_POSITION_PROJECTIVE_SPACE,
    00092
    00094         SPC_POSITION_LIGHT_SPACE0,
    00095         SPC_POSITION_LIGHT_SPACE1,
    00096         SPC_POSITION_LIGHT_SPACE2,
    00097         SPC_POSITION_LIGHT_SPACE3,
    00098         SPC_POSITION_LIGHT_SPACE4,
    00099         SPC_POSITION_LIGHT_SPACE5,
    00100         SPC_POSITION_LIGHT_SPACE6,
    00101         SPC_POSITION_LIGHT_SPACE7,
    00102
    00104         SPC_NORMAL_OBJECT_SPACE,
    00105
    00107         SPC_NORMAL_WORLD_SPACE,
    00108
    00110         SPC_NORMAL_VIEW_SPACE,
    00111
    00113         SPC_NORMAL_TANGENT_SPACE,
    00114
    00116         SPC_POSTOCAMERA_OBJECT_SPACE,
    00117
    00119         SPC_POSTOCAMERA_WORLD_SPACE,
    00120
    00122         SPC_POSTOCAMERA_VIEW_SPACE,
    00123
    00125         SPC_POSTOCAMERA_TANGENT_SPACE,
    00126
    00128         SPC_POSTOLIGHT_OBJECT_SPACE0,
    00129         SPC_POSTOLIGHT_OBJECT_SPACE1,
    00130         SPC_POSTOLIGHT_OBJECT_SPACE2,
    00131         SPC_POSTOLIGHT_OBJECT_SPACE3,
    00132         SPC_POSTOLIGHT_OBJECT_SPACE4,
    00133         SPC_POSTOLIGHT_OBJECT_SPACE5,
    00134         SPC_POSTOLIGHT_OBJECT_SPACE6,
    00135         SPC_POSTOLIGHT_OBJECT_SPACE7,
    00136
    00138         SPC_POSTOLIGHT_WORLD_SPACE0,
    00139         SPC_POSTOLIGHT_WORLD_SPACE1,
    00140         SPC_POSTOLIGHT_WORLD_SPACE2,
    00141         SPC_POSTOLIGHT_WORLD_SPACE3,
    00142         SPC_POSTOLIGHT_WORLD_SPACE4,
    00143         SPC_POSTOLIGHT_WORLD_SPACE5,
    00144         SPC_POSTOLIGHT_WORLD_SPACE6,
    00145         SPC_POSTOLIGHT_WORLD_SPACE7,
    00146
    00148         SPC_POSTOLIGHT_VIEW_SPACE0,
    00149         SPC_POSTOLIGHT_VIEW_SPACE1,
    00150         SPC_POSTOLIGHT_VIEW_SPACE2,
    00151         SPC_POSTOLIGHT_VIEW_SPACE3,
    00152         SPC_POSTOLIGHT_VIEW_SPACE4,
    00153         SPC_POSTOLIGHT_VIEW_SPACE5,
    00154         SPC_POSTOLIGHT_VIEW_SPACE6,
    00155         SPC_POSTOLIGHT_VIEW_SPACE7,
    00156
    00158         SPC_POSTOLIGHT_TANGENT_SPACE0,
    00159         SPC_POSTOLIGHT_TANGENT_SPACE1,
    00160         SPC_POSTOLIGHT_TANGENT_SPACE2,
    00161         SPC_POSTOLIGHT_TANGENT_SPACE3,
    00162         SPC_POSTOLIGHT_TANGENT_SPACE4,
    00163         SPC_POSTOLIGHT_TANGENT_SPACE5,
    00164         SPC_POSTOLIGHT_TANGENT_SPACE6,
    00165         SPC_POSTOLIGHT_TANGENT_SPACE7,
    00166
    00167
    00168
    00170         SPC_LIGHTDIRECTION_OBJECT_SPACE0,
    00171         SPC_LIGHTDIRECTION_OBJECT_SPACE1,
    00172         SPC_LIGHTDIRECTION_OBJECT_SPACE2,
    00173         SPC_LIGHTDIRECTION_OBJECT_SPACE3,
    00174         SPC_LIGHTDIRECTION_OBJECT_SPACE4,
    00175         SPC_LIGHTDIRECTION_OBJECT_SPACE5,
    00176         SPC_LIGHTDIRECTION_OBJECT_SPACE6,
    00177         SPC_LIGHTDIRECTION_OBJECT_SPACE7,
    00178
    00180         SPC_LIGHTDIRECTION_WORLD_SPACE0,
    00181         SPC_LIGHTDIRECTION_WORLD_SPACE1,
    00182         SPC_LIGHTDIRECTION_WORLD_SPACE2,
    00183         SPC_LIGHTDIRECTION_WORLD_SPACE3,
    00184         SPC_LIGHTDIRECTION_WORLD_SPACE4,
    00185         SPC_LIGHTDIRECTION_WORLD_SPACE5,
    00186         SPC_LIGHTDIRECTION_WORLD_SPACE6,
    00187         SPC_LIGHTDIRECTION_WORLD_SPACE7,
    00188
    00190         SPC_LIGHTDIRECTION_VIEW_SPACE0,
    00191         SPC_LIGHTDIRECTION_VIEW_SPACE1,
    00192         SPC_LIGHTDIRECTION_VIEW_SPACE2,
    00193         SPC_LIGHTDIRECTION_VIEW_SPACE3,
    00194         SPC_LIGHTDIRECTION_VIEW_SPACE4,
    00195         SPC_LIGHTDIRECTION_VIEW_SPACE5,
    00196         SPC_LIGHTDIRECTION_VIEW_SPACE6,
    00197         SPC_LIGHTDIRECTION_VIEW_SPACE7,
    00198
    00200         SPC_LIGHTDIRECTION_TANGENT_SPACE0,
    00201         SPC_LIGHTDIRECTION_TANGENT_SPACE1,
    00202         SPC_LIGHTDIRECTION_TANGENT_SPACE2,
    00203         SPC_LIGHTDIRECTION_TANGENT_SPACE3,
    00204         SPC_LIGHTDIRECTION_TANGENT_SPACE4,
    00205         SPC_LIGHTDIRECTION_TANGENT_SPACE5,
    00206         SPC_LIGHTDIRECTION_TANGENT_SPACE6,
    00207         SPC_LIGHTDIRECTION_TANGENT_SPACE7,
    00208
    00210         SPC_LIGHTPOSITION_OBJECT_SPACE0,
    00211         SPC_LIGHTPOSITION_OBJECT_SPACE1,
    00212         SPC_LIGHTPOSITION_OBJECT_SPACE2,
    00213         SPC_LIGHTPOSITION_OBJECT_SPACE3,
    00214         SPC_LIGHTPOSITION_OBJECT_SPACE4,
    00215         SPC_LIGHTPOSITION_OBJECT_SPACE5,
    00216         SPC_LIGHTPOSITION_OBJECT_SPACE6,
    00217         SPC_LIGHTPOSITION_OBJECT_SPACE7,
    00218
    00220         SPC_LIGHTPOSITION_WORLD_SPACE0,
    00221         SPC_LIGHTPOSITION_WORLD_SPACE1,
    00222         SPC_LIGHTPOSITION_WORLD_SPACE2,
    00223         SPC_LIGHTPOSITION_WORLD_SPACE3,
    00224         SPC_LIGHTPOSITION_WORLD_SPACE4,
    00225         SPC_LIGHTPOSITION_WORLD_SPACE5,
    00226         SPC_LIGHTPOSITION_WORLD_SPACE6,
    00227         SPC_LIGHTPOSITION_WORLD_SPACE7,
    00228
    00230         SPC_LIGHTPOSITIONVIEW_SPACE0,
    00231         SPC_LIGHTPOSITIONVIEW_SPACE1,
    00232         SPC_LIGHTPOSITIONVIEW_SPACE2,
    00233         SPC_LIGHTPOSITIONVIEW_SPACE3,
    00234         SPC_LIGHTPOSITIONVIEW_SPACE4,
    00235         SPC_LIGHTPOSITIONVIEW_SPACE5,
    00236         SPC_LIGHTPOSITIONVIEW_SPACE6,
    00237         SPC_LIGHTPOSITIONVIEW_SPACE7,
    00238
    00240         SPC_LIGHTPOSITION_TANGENT_SPACE,
    00241
    00243         SPC_TANGENT,
    00244
    00246         SPC_BINORMAL,
    00247
    00249         SPC_COLOR_DIFFUSE,
    00250
    00252         SPC_COLOR_SPECULAR,
    00253
    00255         SPC_DEPTH_OBJECT_SPACE,
    00256
    00258         SPC_DEPTH_WORLD_SPACE,
    00259
    00261         SPC_DEPTH_VIEW_SPACE,
    00262
    00264         SPC_DEPTH_PROJECTIVE_SPACE,
    00265
    00267         SPC_TEXTURE_COORDINATE0,
    00268         SPC_TEXTURE_COORDINATE1,
    00269         SPC_TEXTURE_COORDINATE2,
    00270         SPC_TEXTURE_COORDINATE3,
    00271         SPC_TEXTURE_COORDINATE4,
    00272         SPC_TEXTURE_COORDINATE5,
    00273         SPC_TEXTURE_COORDINATE6,
    00274         SPC_TEXTURE_COORDINATE7,
    00275
    00277         SPC_CUSTOM_CONTENT_BEGIN    = 1000,
    00278         SPC_CUSTOM_CONTENT_END      = 2000
    00279     };
    00280
    00281 // Interface.
    00282 public:
    00284     Parameter() {}
    00285
    00294     Parameter(GpuConstantType type, const String& name,
    00295         const Semantic& semantic, int index,
    00296         const Content& content);
    00297
    00299     virtual ~Parameter() {};
    00300
    00302     const String&           getName                         () const { return mName; }
    00303
    00305     GpuConstantType         getType                         () const { return mType; }
    00306
    00308     const Semantic&         getSemantic                     () const { return mSemantic; }
    00309
    00311     int                     getIndex                        () const { return mIndex; }
    00312
    00314     Content                 getContent                          () const { return mContent; }
    00315
    00317     virtual bool            isConstParameter                    () const { return false; }
    00318
    00320     virtual String          toString                            () const { return mName; }
    00321
    00322 // Attributes.
    00323 protected:
    00324     String                                  mName;                  // Name of this parameter.
    00325     GpuConstantType                         mType;                  // Type of this parameter.
    00326     Semantic                                mSemantic;              // Semantic of this parameter.
    00327     int                                     mIndex;                 // Index of this parameter.
    00328     Content                                 mContent;               // The content of this parameter.
    00329
    00330 };
    00331
    00332 typedef SharedPtr<Parameter>                    ParameterPtr;
    00333 typedef vector<ParameterPtr>::type              ShaderParameterList;
    00334 typedef ShaderParameterList::iterator           ShaderParameterIterator;
    00335 typedef ShaderParameterList::const_iterator     ShaderParameterConstIterator;
    00336
    00339 class UniformParameter : public Parameter
    00340 {
    00341 public:
    00342
    00351     UniformParameter(GpuConstantType type, const String& name,
    00352         const Semantic& semantic, int index,
    00353         const Content& content,
    00354         uint16 variability);
    00355
    00360     UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData);
    00361
    00366     UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData);
    00367
    00368
    00370     size_t                  getAutoConstantIntData          () const { return mAutoConstantIntData; }
    00371
    00373     Real                    getAutoConstantRealData         () const { return mAutoConstantRealData; }
    00374
    00376     bool                    isFloat                         () const;
    00377
    00379     bool                    isSampler                       () const;
    00380
    00382     bool                    isAutoConstantParameter             () const { return mIsAutoConstantReal || mIsAutoConstantInt; }
    00383
    00385     bool                    isAutoConstantIntParameter          () const { return mIsAutoConstantInt; }
    00386
    00388     bool                    isAutoConstantRealParameter         () const { return mIsAutoConstantReal; }
    00389
    00391     GpuProgramParameters::AutoConstantType getAutoConstantType  () const { return mAutoConstantType; }
    00392
    00394     uint16                  getVariability                      () const { return mVariability; }
    00395
    00396
    00398     void                    bind                                (GpuProgramParametersSharedPtr paramsPtr);
    00399
    00400 public:
    00401
    00403     void setGpuParameter(int val)
    00404     {
    00405         if (mParamsPtr != NULL)
    00406         {
    00407             mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
    00408         }
    00409     }
    00410
    00412     void setGpuParameter(Real val)
    00413     {
    00414         if (mParamsPtr != NULL)
    00415         {
    00416             mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
    00417         }
    00418     }
    00419
    00421     void setGpuParameter(const ColourValue& val)
    00422     {
    00423         if (mParamsPtr != NULL)
    00424         {
    00425             mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
    00426         }
    00427     }
    00428
    00430     void setGpuParameter(const Vector2& val)
    00431     {
    00432         if (mParamsPtr != NULL)
    00433         {
    00434             mParamsPtr->_writeRawConstants(mPhysicalIndex, val.ptr(), 2);
    00435         }
    00436     }
    00437
    00439     void setGpuParameter(const Vector3& val)
    00440     {
    00441         if (mParamsPtr != NULL)
    00442         {
    00443             mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
    00444         }
    00445     }
    00446
    00448     void setGpuParameter(const Vector4& val)
    00449     {
    00450         if (mParamsPtr != NULL)
    00451         {
    00452             mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
    00453         }
    00454     }
    00455
    00457     void setGpuParameter(const Matrix4& val)
    00458     {
    00459         if (mParamsPtr != NULL)
    00460         {
    00461             mParamsPtr->_writeRawConstant(mPhysicalIndex, val, 16);
    00462         }
    00463     }
    00464
    00465 protected:
    00466     bool                                    mIsAutoConstantReal;    // Is it auto constant real based parameter.
    00467     bool                                    mIsAutoConstantInt;     // Is it auto constant int based parameter.
    00468     GpuProgramParameters::AutoConstantType  mAutoConstantType;      // The auto constant type of this parameter.
    00469     union
    00470     {
    00471         size_t  mAutoConstantIntData;                               // Auto constant int data.
    00472         Real    mAutoConstantRealData;                              // Auto constant real data.
    00473     };
    00474     uint16                                  mVariability;           // How this parameter varies (bitwise combination of GpuProgramVariability).
    00475     GpuProgramParameters*                   mParamsPtr;             // The actual GPU parameters pointer.
    00476     size_t                                  mPhysicalIndex;         // The physical index of this parameter in the GPU program.
    00477
    00478 };
    00479
    00480 typedef SharedPtr<UniformParameter>             UniformParameterPtr;
    00481 typedef vector<UniformParameterPtr>::type       UniformParameterList;
    00482 typedef UniformParameterList::iterator          UniformParameterIterator;
    00483 typedef UniformParameterList::const_iterator    UniformParameterConstIterator;
    00484
    00487 template <class valueType>
    00488 class ConstParameter : public Parameter
    00489 {
    00490 public:
    00491
    00492     ConstParameter( valueType val,
    00493         GpuConstantType type,
    00494         const Semantic& semantic,
    00495         const Content& content)
    00496         : Parameter(type, "Constant", semantic, 0, content)
    00497     {
    00498         mValue = val;
    00499     }
    00500
    00501     virtual             ~ConstParameter     () {}
    00502
    00504     const valueType&    getValue            () const { return mValue; }
    00505
    00509     virtual bool        isConstParameter    () const { return true; }
    00510
    00514     virtual String      toString            () const = 0;
    00515
    00516 protected:
    00517     valueType mValue;
    00518 };
    00519
    00522 class _OgreRTSSExport ParameterFactory
    00523 {
    00524
    00525     // Interface.
    00526 public:
    00527
    00528     static ParameterPtr createInPosition        (int index);
    00529     static ParameterPtr createOutPosition       (int index);
    00530
    00531     static ParameterPtr createInNormal          (int index);
    00532     static ParameterPtr createOutNormal         (int index);
    00533     static ParameterPtr createInBiNormal        (int index);
    00534     static ParameterPtr createOutBiNormal       (int index);
    00535     static ParameterPtr createInTangent         (int index);
    00536     static ParameterPtr createOutTangent        (int index);
    00537     static ParameterPtr createInColor           (int index);
    00538     static ParameterPtr createOutColor          (int index);
    00539
    00540     static ParameterPtr createInTexcoord        (GpuConstantType type, int index, Parameter::Content content);
    00541     static ParameterPtr createOutTexcoord       (GpuConstantType type, int index, Parameter::Content content);
    00542     static ParameterPtr createInTexcoord1       (int index, Parameter::Content content);
    00543     static ParameterPtr createOutTexcoord1      (int index, Parameter::Content content);
    00544     static ParameterPtr createInTexcoord2       (int index, Parameter::Content content);
    00545     static ParameterPtr createOutTexcoord2      (int index, Parameter::Content content);
    00546     static ParameterPtr createInTexcoord3       (int index, Parameter::Content content);
    00547     static ParameterPtr createOutTexcoord3      (int index, Parameter::Content content);
    00548     static ParameterPtr createInTexcoord4       (int index, Parameter::Content content);
    00549     static ParameterPtr createOutTexcoord4      (int index, Parameter::Content content);
    00550
    00551     static ParameterPtr createConstParamVector2 (Vector2 val);
    00552     static ParameterPtr createConstParamVector3 (Vector3 val);
    00553     static ParameterPtr createConstParamVector4 (Vector4 val);
    00554     static ParameterPtr createConstParamFloat   (float val);
    00555
    00556     static UniformParameterPtr  createSampler           (GpuConstantType type, int index);
    00557     static UniformParameterPtr  createSampler1D         (int index);
    00558     static UniformParameterPtr  createSampler2D         (int index);
    00559     static UniformParameterPtr  createSampler3D         (int index);
    00560     static UniformParameterPtr  createSamplerCUBE       (int index);
    00561
    00562     static UniformParameterPtr  createUniform           (GpuConstantType type,  int index, uint16 variability, const String& suggestedName);
    00563 };
    00564
    00565
    00566
    00570 }
    00571 }
    00572
    00573 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:09