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 // 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 = 1 << 0, 00099 OPM_X = 1 << 1, 00100 OPM_Y = 1 << 2, 00101 OPM_Z = 1 << 3, 00102 OPM_W = 1 << 4 00103 }; 00104 00110 Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, ushort indirectionLevel = 0); 00111 00113 Operand(const Operand& rhs); 00114 00118 Operand& operator= (const Operand & rhs); 00119 00121 ~Operand(); 00122 00124 const ParameterPtr& getParameter() const { return mParameter; } 00125 00127 bool hasFreeFields() const { return ((mMask & ~OPM_ALL) && ((mMask & ~OPM_X) || (mMask & ~OPM_Y) || (mMask & ~OPM_Z) || (mMask & ~OPM_W))); } 00128 00130 int getMask() const { return mMask; } 00131 00133 OpSemantic getSemantic() const { return mSemantic; } 00134 00140 ushort getIndirectionLevel() const { return mIndirectionLevel; } 00141 00143 String toString() const; 00144 00146 static String getMaskAsString(int mask); 00147 00149 static int getFloatCount(int mask); 00150 00152 static GpuConstantType getGpuConstantType(int mask); 00153 00154 protected: 00156 ParameterPtr mParameter; 00158 OpSemantic mSemantic; 00160 int mMask; 00162 ushort mIndirectionLevel; 00163 }; 00164 00167 class _OgreRTSSExport FunctionInvocation : public FunctionAtom 00168 { 00169 // Interface. 00170 public: 00171 typedef vector<Operand>::type OperandVector; 00172 00179 FunctionInvocation(const String& functionName, int groupOrder, int internalOrder, String returnType = "void"); 00180 00182 FunctionInvocation(const FunctionInvocation& rhs); 00183 00187 virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const; 00188 00192 virtual const String& getFunctionAtomType() { return Type; } 00193 00195 OperandVector& getOperandList() { return mOperands; } 00196 00203 void pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, int indirectionLevel = 0); 00204 00206 const String& getFunctionName() const { return mFunctionName; } 00207 00209 const String& getReturnType() const { return mReturnType; } 00210 00212 bool operator == ( const FunctionInvocation& rhs ) const; 00213 00215 bool operator != ( const FunctionInvocation& rhs ) const; 00216 00218 bool operator < ( const FunctionInvocation& rhs ) const; 00219 00223 struct FunctionInvocationLessThan 00224 { 00225 bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const; 00226 }; 00227 00231 struct FunctionInvocationCompare 00232 { 00233 bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const; 00234 }; 00235 00237 static String Type; 00238 00239 // Attributes. 00240 protected: 00241 String mFunctionName; 00242 String mReturnType; 00243 OperandVector mOperands; 00244 }; 00245 00246 typedef vector<FunctionAtom*>::type FunctionAtomInstanceList; 00247 typedef FunctionAtomInstanceList::iterator FunctionAtomInstanceIterator; 00248 typedef FunctionAtomInstanceList::const_iterator FunctionAtomInstanceConstIterator; 00249 00253 } 00254 } 00255 00256 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23