OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderFunctionAtom.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderFunctionAtom_
28 #define _ShaderFunctionAtom_
29 
31 #include "OgreStringVector.h"
32 #include "OgreGpuProgramParams.h"
33 
34 namespace Ogre {
35 namespace RTShader {
36 
47 {
48 // Interface.
49 public:
51  FunctionAtom();
52 
54  virtual ~FunctionAtom() {}
55 
57  int getGroupExecutionOrder() const;
58 
60  int getInternalExecutionOrder() const;
61 
63  virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const = 0;
64 
66  virtual const String& getFunctionAtomType() = 0;
67 
68 // Attributes.
69 protected:
70  // The owner group execution order.
72  // The execution order within the group.
74 };
75 
79 {
80 public:
81 
82  // InOut semantic
84  {
90  OPS_INOUT
91  };
92 
93  // Used field mask
94  enum OpMask
95  {
96  OPM_ALL = 0x0001,
97  OPM_X = 0x0002,
98  OPM_Y = 0x0004,
99  OPM_Z = 0x0008,
100  OPM_W = 0x0010,
101  OPM_XY = OPM_X | OPM_Y,
102  OPM_XZ = OPM_X | OPM_Z,
103  OPM_XW = OPM_X | OPM_W,
104  OPM_YZ = OPM_Y | OPM_Z,
105  OPM_YW = OPM_Y | OPM_W,
106  OPM_ZW = OPM_Z | OPM_W,
107  OPM_XYZ = OPM_X | OPM_Y | OPM_Z,
108  OPM_XYW = OPM_X | OPM_Y | OPM_W,
109  OPM_XZW = OPM_X | OPM_Z | OPM_W,
110  OPM_YZW = OPM_Y | OPM_Z | OPM_W,
111  OPM_XYZW = OPM_X | OPM_Y | OPM_Z | OPM_W
112  };
113 
119  Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, ushort indirectionLevel = 0);
120 
122  Operand(const Operand& rhs);
123 
127  Operand& operator= (const Operand & rhs);
128 
130  ~Operand();
131 
133  const ParameterPtr& getParameter() const { return mParameter; }
134 
136  bool hasFreeFields() const { return ((mMask & ~OPM_ALL) && ((mMask & ~OPM_X) || (mMask & ~OPM_Y) || (mMask & ~OPM_Z) || (mMask & ~OPM_W))); }
137 
139  int getMask() const { return mMask; }
140 
142  OpSemantic getSemantic() const { return mSemantic; }
143 
149  ushort getIndirectionLevel() const { return mIndirectionLevel; }
150 
152  String toString() const;
153 
155  static String getMaskAsString(int mask);
156 
158  static int getFloatCount(int mask);
159 
161  static GpuConstantType getGpuConstantType(int mask);
162 
163 protected:
169  int mMask;
172 };
173 
177 {
178  // Interface.
179 public:
181 
188  FunctionInvocation(const String& functionName, int groupOrder, int internalOrder, String returnType = "void");
189 
192 
196  virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const;
197 
201  virtual const String& getFunctionAtomType() { return Type; }
202 
204  OperandVector& getOperandList() { return mOperands; }
205 
212  void pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, int indirectionLevel = 0);
213 
215  const String& getFunctionName() const { return mFunctionName; }
216 
218  const String& getReturnType() const { return mReturnType; }
219 
221  bool operator == ( const FunctionInvocation& rhs ) const;
222 
224  bool operator != ( const FunctionInvocation& rhs ) const;
225 
227  bool operator < ( const FunctionInvocation& rhs ) const;
228 
233  {
234  bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
235  };
236 
241  {
242  bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
243  };
244 
246  static String Type;
247 
248  // Attributes.
249 protected:
253 };
254 
256 typedef FunctionAtomInstanceList::iterator FunctionAtomInstanceIterator;
257 typedef FunctionAtomInstanceList::const_iterator FunctionAtomInstanceConstIterator;
258 
262 }
263 }
264 
265 #endif
static String Type
The type of this class.
The parameter is a output parameter.
FunctionAtomInstanceList::iterator FunctionAtomInstanceIterator
ushort mIndirectionLevel
The level of indirection.
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
const String & getReturnType() const
Return the return type.
FunctionAtomInstanceList::const_iterator FunctionAtomInstanceConstIterator
int getMask() const
Returns the mask bitfield.
bool hasFreeFields() const
Returns true if not all fields used.
The parameter is a input parameter.
ushort getIndirectionLevel() const
Returns the level of indirection.
#define _OgreRTSSExport
const ParameterPtr & getParameter() const
Returns the parameter object as weak reference.
virtual ~FunctionAtom()
Class default destructor.
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
OpSemantic mSemantic
Tells if the parameter is of type input,output or both.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Comparator function to be used for comparisons.
OperandVector & getOperandList()
Get a list of parameters this function invocation will use in the function call as arguments...
unsigned short ushort
vector< FunctionAtom * >::type FunctionAtomInstanceList
A class that represents an atomic code section of shader based program function.
const String & getFunctionName() const
Return the function name.
A class that represents a function operand (its the combination of a parameter the in/out semantic an...
ParameterPtr mParameter
The parameter being carried by the operand.
OpSemantic getSemantic() const
Returns the operand semantic (do we read/write or both with the parameter).
_StringBase String
Definition: OgreCommon.h:53
A class that represents function invocation code from shader based program function.
int mMask
Which part of the parameter should be passed (x,y,z,w)
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
virtual const String & getFunctionAtomType()
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)