OGRE  1.9.0
OgreShaderFunctionAtom.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25-----------------------------------------------------------------------------
26*/
27#ifndef _ShaderFunctionAtom_
28#define _ShaderFunctionAtom_
29
31#include "OgreGpuProgram.h"
32#include "OgreSingleton.h"
33#include "OgreShaderParameter.h"
34#include "OgreStringVector.h"
35
36namespace Ogre {
37namespace RTShader {
38
45
49{
50// Interface.
51public:
54
56 virtual ~FunctionAtom() {}
57
60
63
65 virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const = 0;
66
68 virtual const String& getFunctionAtomType() = 0;
69
70// Attributes.
71protected:
72 // The owner group execution order.
74 // The execution order within the group.
76};
77
81{
82public:
83
84 // InOut semantic
94
95 // Used field mask
115
121 Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, ushort indirectionLevel = 0);
122
124 Operand(const Operand& rhs);
125
129 Operand& operator= (const Operand & rhs);
130
133
135 const ParameterPtr& getParameter() const { return mParameter; }
136
138 bool hasFreeFields() const { return ((mMask & ~OPM_ALL) && ((mMask & ~OPM_X) || (mMask & ~OPM_Y) || (mMask & ~OPM_Z) || (mMask & ~OPM_W))); }
139
141 int getMask() const { return mMask; }
142
144 OpSemantic getSemantic() const { return mSemantic; }
145
152
155
157 static String getMaskAsString(int mask);
158
160 static int getFloatCount(int mask);
161
164
165protected:
171 int mMask;
174};
175
179{
180 // Interface.
181public:
183
190 FunctionInvocation(const String& functionName, int groupOrder, int internalOrder, String returnType = "void");
191
194
198 virtual void writeSourceCode(std::ostream& os, const String& targetLanguage) const;
199
203 virtual const String& getFunctionAtomType() { return Type; }
204
207
214 void pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask = Operand::OPM_ALL, int indirectionLevel = 0);
215
217 const String& getFunctionName() const { return mFunctionName; }
218
220 const String& getReturnType() const { return mReturnType; }
221
223 bool operator == ( const FunctionInvocation& rhs ) const;
224
226 bool operator != ( const FunctionInvocation& rhs ) const;
227
229 bool operator < ( const FunctionInvocation& rhs ) const;
230
235 {
236 bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
237 };
238
243 {
244 bool operator()(FunctionInvocation const& lhs, FunctionInvocation const& rhs) const;
245 };
246
248 static String Type;
249
250 // Attributes.
251protected:
255};
256
258typedef FunctionAtomInstanceList::iterator FunctionAtomInstanceIterator;
259typedef FunctionAtomInstanceList::const_iterator FunctionAtomInstanceConstIterator;
260
263
264}
265}
266
267#endif
#define _OgreRTSSExport
virtual void writeSourceCode(std::ostream &os, const String &targetLanguage) const =0
Abstract method that writes a source code to the given output stream in the target shader language.
FunctionAtom()
Class default constructor.
int getInternalExecutionOrder() const
Get an internal execution order within a group of this function atom.
virtual const String & getFunctionAtomType()=0
Return the type of this atom instance implementation.
int getGroupExecutionOrder() const
Get the group execution order of this function atom.
virtual ~FunctionAtom()
Class default destructor.
OperandVector & getOperandList()
Get a list of parameters this function invocation will use in the function call as arguments.
virtual void writeSourceCode(std::ostream &os, const String &targetLanguage) const
FunctionInvocation(const String &functionName, int groupOrder, int internalOrder, String returnType="void")
Class constructor.
const String & getReturnType() const
Return the return type.
static String Type
The type of this class.
FunctionInvocation(const FunctionInvocation &rhs)
Copy constructor.
const String & getFunctionName() const
Return the function name.
void pushOperand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask=Operand::OPM_ALL, int indirectionLevel=0)
Push a new operand (on the end) to the function.
~Operand()
Class destructor.
static GpuConstantType getGpuConstantType(int mask)
Return the gpu constant type of the given mask.
static int getFloatCount(int mask)
Return the float count of the given mask.
ushort mIndirectionLevel
The level of indirection.
OpSemantic mSemantic
Tells if the parameter is of type input,output or both.
int getMask() const
Returns the mask bitfield.
@ OPS_IN
The parameter is a input parameter.
@ OPS_OUT
The parameter is a output parameter.
@ OPS_INOUT
The parameter is a input/output parameter.
OpSemantic getSemantic() const
Returns the operand semantic (do we read/write or both with the parameter).
ushort getIndirectionLevel() const
Returns the level of indirection.
Operand(const Operand &rhs)
Copy constructor.
const ParameterPtr & getParameter() const
Returns the parameter object as weak reference.
bool hasFreeFields() const
Returns true if not all fields used.
String toString() const
Returns the parameter name and the usage mask like this 'color.xyz'.
Operand(ParameterPtr parameter, Operand::OpSemantic opSemantic, int opMask=Operand::OPM_ALL, ushort indirectionLevel=0)
Class constructor.
int mMask
Which part of the parameter should be passed (x,y,z,w)
ParameterPtr mParameter
The parameter being carried by the operand.
static String getMaskAsString(int mask)
Returns the given mask as string representation.
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
vector< FunctionAtom * >::type FunctionAtomInstanceList
FunctionAtomInstanceList::iterator FunctionAtomInstanceIterator
SharedPtr< Parameter > ParameterPtr
FunctionAtomInstanceList::const_iterator FunctionAtomInstanceConstIterator
GeneralAllocatedObject RTShaderSystemAlloc
_StringBase String
unsigned short ushort
bool operator()(FunctionInvocation const &lhs, FunctionInvocation const &rhs) const
bool operator()(FunctionInvocation const &lhs, FunctionInvocation const &rhs) const
std::vector< T, A > type