OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderGLSLESProgramWriter.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-2013 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 _ShaderProgramWriterGLSLES_
28 #define _ShaderProgramWriterGLSLES_
29 
31 
32 namespace Ogre {
33 namespace RTShader {
34 
46 {
47  // Interface.
48 public:
49 
54 
56  virtual ~GLSLESProgramWriter();
57 
58 
62 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
63  virtual void writeSourceCode(StringSerialiser& os, Program* program);
64 #else
65  virtual void writeSourceCode(std::ostream& os, Program* program);
66 #endif
67 
71  virtual const String& getTargetLanguage() const { return TargetLanguage; }
72 
74 
75  protected:
76  typedef std::map<GpuConstantType, const char*> GpuConstTypeToStringMap;
77  typedef std::map<Parameter::Semantic, const char*> ParamSemanticToStringMap;
78  typedef std::map<Parameter::Content, const char*> ParamContentToStringMap;
79  typedef std::map<String, String> StringMap;
80  typedef std::map<FunctionInvocation, String> FunctionMap;
81  typedef std::vector<FunctionInvocation> FunctionVector;
82  typedef FunctionMap::const_iterator FunctionMapIterator;
83  typedef FunctionVector::const_iterator FunctionVectorIterator;
84  typedef GpuConstTypeToStringMap::const_iterator GpuConstTypeToStringMapIterator;
85 
86  // Protected methods.
87 protected:
88 
90  void initializeStringMaps();
91 
93  virtual void cacheDependencyFunctions(const String & libName);
94 
95 
98 
100 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
102 #else
103  void writeProgramDependencies(std::ostream& os, Program* program);
104 #endif
105 
107 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
109 #else
110  void writeLocalParameter(std::ostream& os, ParameterPtr parameter);
111 #endif
112 
114 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
115  void writeInputParameters(StringSerialiser& os, Function* function, GpuProgramType gpuType);
116 #else
117  void writeInputParameters(std::ostream& os, Function* function, GpuProgramType gpuType);
118 #endif
119 
121 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
122  void writeOutParameters(StringSerialiser& os, Function* function, GpuProgramType gpuType);
123 #else
124  void writeOutParameters(std::ostream& os, Function* function, GpuProgramType gpuType);
125 #endif
126 
127 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
128  void writeAssignFunction(StringSerialiser& os, FunctionInvocation::OperandVector::iterator itOperand, FunctionInvocation::OperandVector::iterator itOperandEnd, GpuProgramType gpuType);
129 #else
130  void writeAssignFunction(std::stringstream& os, FunctionInvocation::OperandVector::iterator itOperand, FunctionInvocation::OperandVector::iterator itOperandEnd, GpuProgramType gpuType);
131 #endif
132 
134 
136  bool isBasicType(String &type);
137 
139  void discoverFunctionDependencies(const FunctionInvocation &invoc, FunctionVector &depVector);
140 
141  // Attributes.
142 protected:
143  // Map between GPU constant type to string value.
145  // Map between parameter semantic to string value.
147 
148  // Map parameter name to a new parameter name (sometimes renaming is required to match names between vertex and fragment shader)
150  // Map function invocation to body. Used as a cache to reduce library file reads and for inlining
152  // Map of #defines and the function library that contains them
154  // Map parameter content to vertex attributes
156  // Holds the current glsl es version
158  // Holds the fragment input params
160  // Holds the cached function libraries
162 };
163 
168 {
169 public:
171  {
172  mLanguage = "glsles";
173  }
175 
179  virtual const String& getTargetLanguage(void) const
180  {
181  return mLanguage;
182  }
183 
187  virtual ProgramWriter* create(void)
188  {
189  return OGRE_NEW GLSLESProgramWriter();
190  }
191 
192 private:
194 };
195 
199 }
200 }
201 
202 #endif
void writeProgramDependencies(StringSerialiser &os, Program *program)
Write the program dependencies.
void writeLocalParameter(StringSerialiser &os, ParameterPtr parameter)
Write a local parameter.
bool isBasicType(String &type)
Check if a string matches one of the GLSL ES basic types.
std::map< Parameter::Semantic, const char * > ParamSemanticToStringMap
void writeAssignFunction(StringSerialiser &os, FunctionInvocation::OperandVector::iterator itOperand, FunctionInvocation::OperandVector::iterator itOperandEnd, GpuProgramType gpuType)
virtual void cacheDependencyFunctions(const String &libName)
Cache functions of a dependency.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
Interface definition for factories of ShaderProgramWriter.
String processOperand(Operand op, GpuProgramType gpuType)
void writeOutParameters(StringSerialiser &os, Function *function, GpuProgramType gpuType)
Write the output params of the function.
FunctionInvocation * createInvocationFromString(const String &input)
Create a FunctionInvocation object from a string taken out of a shader library.
GLSL ES target language writer implementation.
void initializeStringMaps()
Initialize string maps.
virtual ~GLSLESProgramWriter()
Class destructor.
Serializes data values into a string using sprintf functions.
std::map< GpuConstantType, const char * > GpuConstTypeToStringMap
virtual void writeSourceCode(StringSerialiser &os, Program *program)
void writeInputParameters(StringSerialiser &os, Function *function, GpuProgramType gpuType)
Write the input params of the function.
A class that represents a shader based program function.
Base class interface for shader program writers.
virtual const String & getTargetLanguage() const
void discoverFunctionDependencies(const FunctionInvocation &invoc, FunctionVector &depVector)
Search within a function body for non-builtin functions that a given function invocation depends on...
std::vector< FunctionInvocation > FunctionVector
std::map< Parameter::Content, const char * > ParamContentToStringMap
GLSLESProgramWriter()
Class constructor.
FunctionVector::const_iterator FunctionVectorIterator
vector< String >::type StringVector
StringStream stringstream
GpuConstTypeToStringMap::const_iterator GpuConstTypeToStringMapIterator
GLSL ES program writer factory implementation.
A class that represents a shader based program.
#define OGRE_NEW
A class that represents a function operand (its the combination of a parameter the in/out semantic an...
_StringBase String
A class that represents function invocation code from shader based program function.
std::map< FunctionInvocation, String > FunctionMap