OgreShaderFunctionAtom.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-2013 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 _ShaderFunctionAtom_
00028 #define _ShaderFunctionAtom_
00029 
00030 #include "OgreShaderPrerequisites.h"
00031 #include "OgreGpuProgram.h"
00032 #include "OgreSingleton.h"
00033 #include "OgreShaderParameter.h"
00034 #include "OgreStringVector.h"
00035 
00036 namespace Ogre {
00037 namespace RTShader {
00038 
00048 class _OgreRTSSExport FunctionAtom : public RTShaderSystemAlloc
00049 {
00050 // Interface.
00051 public:
00053     FunctionAtom();
00054 
00056     virtual ~FunctionAtom() {}
00057 
00059     int getGroupExecutionOrder() const;
00060     
00062     int getInternalExecutionOrder() const;
00063     
00065     virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const = 0;
00066     
00068     virtual const String& getFunctionAtomType() = 0;
00069 
00070 // Attributes.
00071 protected:
00072     // The owner group execution order. 
00073     int mGroupExecutionOrder;
00074     // The execution order within the group.        
00075     int mInternalExecutionOrder;
00076 };
00077 
00080 class _OgreRTSSExport Operand : public RTShaderSystemAlloc
00081 {
00082 public:
00083 
00084     // InOut semantic
00085     enum OpSemantic
00086     {
00088         OPS_IN, 
00090         OPS_OUT,
00092         OPS_INOUT
00093     };
00094 
00095     // Used field mask
00096     enum OpMask
00097     {
00098         OPM_ALL     = 0x0001,
00099         OPM_X       = 0x0002,
00100         OPM_Y       = 0x0004,
00101         OPM_Z       = 0x0008,
00102         OPM_W       = 0x0010,
00103         OPM_XY      = OPM_X | OPM_Y,
00104         OPM_XZ      = OPM_X | OPM_Z,
00105         OPM_XW      = OPM_X | OPM_W,
00106         OPM_YZ      = OPM_Y | OPM_Z,
00107         OPM_YW      = OPM_Y | OPM_W,
00108         OPM_ZW      = OPM_Z | OPM_W,
00109         OPM_XYZ     = OPM_X | OPM_Y | OPM_Z,
00110         OPM_XYW     = OPM_X | OPM_Y | OPM_W,
00111         OPM_XZW     = OPM_X | OPM_Z | OPM_W,
00112         OPM_YZW     = OPM_Y | OPM_Z | OPM_W,
00113         OPM_XYZW    = OPM_X | OPM_Y | OPM_Z | OPM_W
00114     };
00115 
00121     Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, ushort indirectionLevel = 0);
00122 
00124     Operand(const Operand& rhs);
00125 
00129     Operand& operator= (const Operand & rhs);
00130 
00132     ~Operand();
00133 
00135     const ParameterPtr& getParameter()  const { return mParameter; }
00136 
00138     bool hasFreeFields()    const { return ((mMask & ~OPM_ALL) && ((mMask & ~OPM_X) || (mMask & ~OPM_Y) || (mMask & ~OPM_Z) || (mMask & ~OPM_W))); }
00139     
00141     int getMask()   const { return mMask; }
00142 
00144     OpSemantic getSemantic()    const { return mSemantic; }
00145 
00151     ushort getIndirectionLevel()    const { return mIndirectionLevel; }
00152 
00154     String toString()   const;
00155 
00157     static String getMaskAsString(int mask);
00158 
00160     static int getFloatCount(int mask);
00161 
00163     static GpuConstantType getGpuConstantType(int mask);
00164 
00165 protected:
00167     ParameterPtr mParameter;
00169     OpSemantic mSemantic;
00171     int mMask;
00173     ushort mIndirectionLevel;
00174 };
00175 
00178 class _OgreRTSSExport FunctionInvocation : public FunctionAtom
00179 {
00180     // Interface.
00181 public: 
00182     typedef vector<Operand>::type OperandVector;
00183 
00190     FunctionInvocation(const String& functionName, int groupOrder, int internalOrder, String returnType = "void");
00191 
00193     FunctionInvocation(const FunctionInvocation& rhs);
00194 
00198     virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const;
00199 
00203     virtual const String& getFunctionAtomType() { return Type; }
00204 
00206     OperandVector& getOperandList() { return mOperands; }
00207     
00214     void pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, int indirectionLevel = 0);
00215 
00217     const String& getFunctionName() const { return mFunctionName; }
00218 
00220     const String& getReturnType() const { return mReturnType; }
00221 
00223     bool operator == ( const FunctionInvocation& rhs ) const;
00224 
00226     bool operator != ( const FunctionInvocation& rhs ) const;
00227 
00229     bool operator <  ( const FunctionInvocation& rhs ) const;
00230 
00234     struct FunctionInvocationLessThan
00235     {
00236         bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
00237     };
00238 
00242     struct FunctionInvocationCompare
00243     {
00244         bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
00245     };
00246 
00248     static String Type;
00249 
00250     // Attributes.
00251 protected:  
00252     String mFunctionName;
00253     String mReturnType;
00254     OperandVector mOperands;    
00255 };
00256 
00257 typedef vector<FunctionAtom*>::type                 FunctionAtomInstanceList;
00258 typedef FunctionAtomInstanceList::iterator          FunctionAtomInstanceIterator;
00259 typedef FunctionAtomInstanceList::const_iterator    FunctionAtomInstanceConstIterator;
00260 
00264 }
00265 }
00266 
00267 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:46