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-2012 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     int         mGroupExecutionOrder;       // The owner group execution order. 
00073     int         mInternalExecutionOrder;        // The execution order within the group.        
00074 };
00075 
00078 class _OgreRTSSExport Operand : public RTShaderSystemAlloc
00079 {
00080 public:
00081 
00082     // InOut semantic
00083     enum OpSemantic
00084     {
00086         OPS_IN, 
00088         OPS_OUT,
00090         OPS_INOUT
00091     };
00092 
00093     // Used field mask
00094     enum OpMask
00095     {
00096         OPM_ALL = 1 << 0,
00097         OPM_X   = 1 << 1,
00098         OPM_Y   = 1 << 2,
00099         OPM_Z   = 1 << 3,
00100         OPM_W   = 1 << 4
00101     };
00102 
00108     Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, ushort indirectionLevel = 0);
00109 
00111     Operand(const Operand& rhs);
00112 
00116     Operand& operator= (const Operand & rhs);
00117 
00119     ~Operand();
00120 
00122     const ParameterPtr& getParameter    ()  const { return mParameter; }
00123 
00125     bool                hasFreeFields   ()  const { return ((mMask & ~OPM_ALL) && ((mMask & ~OPM_X) || (mMask & ~OPM_Y) || (mMask & ~OPM_Z) || (mMask & ~OPM_W))); }
00126     
00128     int                 getMask         ()  const { return mMask; }
00129 
00131     OpSemantic          getSemantic     ()  const { return mSemantic; }
00132 
00138     ushort              getIndirectionLevel()   const { return mIndirectionLevel; }
00139 
00141     String              toString        ()  const;
00142 
00144     static String               getMaskAsString     (int mask);
00145 
00147     static int                  getFloatCount       (int mask);
00148 
00150     static GpuConstantType      getGpuConstantType  (int mask);
00151 
00152 protected:
00153     ParameterPtr    mParameter;         
00154     OpSemantic      mSemantic;          
00155     int             mMask;              
00156     ushort          mIndirectionLevel;  
00157 };
00158 
00161 class _OgreRTSSExport FunctionInvocation : public FunctionAtom
00162 {
00163     // Interface.
00164 public: 
00165     typedef vector<Operand>::type OperandVector;
00166 
00173     FunctionInvocation(const String& functionName, int groupOrder, int internalOrder, String returnType = "void");
00174 
00176     FunctionInvocation(const FunctionInvocation& rhs);
00177 
00181     virtual void            writeSourceCode (std::ostream& os, const String& targetLanguage) const;
00182 
00186     virtual const String&   getFunctionAtomType () { return Type; }
00187 
00189     OperandVector&          getOperandList  () { return mOperands; }
00190     
00197     void                    pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, int indirectionLevel = 0);
00198 
00200     const String&           getFunctionName () const { return mFunctionName; }
00201 
00203     const String&           getReturnType   () const { return mReturnType; }
00204 
00206     bool operator == ( const FunctionInvocation& rhs ) const;
00207 
00209     bool operator != ( const FunctionInvocation& rhs ) const;
00210 
00212     bool operator <  ( const FunctionInvocation& rhs ) const;
00213 
00217     struct FunctionInvocationLessThan
00218     {
00219         bool operator ()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
00220     };
00221 
00225     struct FunctionInvocationCompare
00226     {
00227         bool operator ()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
00228     };
00229 
00231     static String Type;
00232 
00233     // Attributes.
00234 protected:  
00235     String              mFunctionName;
00236     String              mReturnType;
00237     OperandVector       mOperands;  
00238 };
00239 
00240 typedef vector<FunctionAtom*>::type                 FunctionAtomInstanceList;
00241 typedef FunctionAtomInstanceList::iterator          FunctionAtomInstanceIterator;
00242 typedef FunctionAtomInstanceList::const_iterator    FunctionAtomInstanceConstIterator;
00243 
00247 }
00248 }
00249 
00250 #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 Fri May 25 23:36:26 2012