OGRE  2.0
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-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 _ShaderProgramWriterGLSLES_
28 #define _ShaderProgramWriterGLSLES_
29 
32 #include "OgreShaderParameter.h"
33 #include "OgreStringVector.h"
34 
35 namespace Ogre {
36 namespace RTShader {
37 
38  class Function;
39  class FunctionInvocation;
40  class Operand;
41  class Program;
42 
54 {
55  // Interface.
56 public:
57 
61 
63  virtual ~GLSLESProgramWriter ();
64 
65 
69  virtual void writeSourceCode (std::ostream& os, Program* program);
70 
74  virtual const String& getTargetLanguage () const { return TargetLanguage; }
75 
77 
78  protected:
85  typedef FunctionMap::const_iterator FunctionMapIterator;
86  typedef FunctionVector::const_iterator FunctionVectorIterator;
87  typedef GpuConstTypeToStringMap::const_iterator GpuConstTypeToStringMapIterator;
88 
89  // Protected methods.
90 protected:
91 
93  void initializeStringMaps ();
94 
96  virtual void cacheDependencyFunctions(const String & libName);
97 
98 
101 
103  void writeProgramDependencies (std::ostream& os, Program* program);
104 
106  void writeLocalParameter (std::ostream& os, ParameterPtr parameter);
107 
109  void writeInputParameters (std::ostream& os, Function* function, GpuProgramType gpuType);
110 
112  void writeOutParameters (std::ostream& os, Function* function, GpuProgramType gpuType);
113 
115 
117  bool isBasicType(String &type);
118 
120  void discoverFunctionDependencies(const FunctionInvocation &invoc, FunctionVector &depVector);
121 
122  // Attributes.
123 protected:
124  GpuConstTypeToStringMap mGpuConstTypeMap; // Map between GPU constant type to string value.
125  ParamSemanticToStringMap mParamSemanticMap; // Map between parameter semantic to string value.
126 
127  StringMap mInputToGLStatesMap; // Map parameter name to a new parameter name (sometimes renaming is required to match names between vertex and fragment shader)
128  FunctionMap mFunctionCacheMap; // Map function invocation to body. Used as a cache to reduce library file reads and for inlining
129  StringMap mDefinesMap; // Map of #defines and the function library that contains them
130  ParamContentToStringMap mContentToPerVertexAttributes; // Map parameter content to vertex attributes
131  int mGLSLVersion; // Holds the current glsl es version
132  StringVector mFragInputParams; // Holds the fragment input params
133  StringMap mCachedFunctionLibraries; // Holds the cached function libraries
134 };
135 
140 {
141 public:
143  {
144  }
146 
150  virtual const String& getTargetLanguage(void) const
151  {
152  return mLanguage;
153  }
154 
158  virtual ProgramWriter* create(void)
159  {
160  return OGRE_NEW GLSLESProgramWriter();
161  }
162 
163 private:
165 };
166 
170 }
171 }
172 
173 #endif
bool isBasicType(String &type)
Check if a string matches one of the GLSL ES basic types.
std::vector< T, A > type
void writeProgramDependencies(std::ostream &os, Program *program)
Write the program dependencies.
void writeOutParameters(std::ostream &os, Function *function, GpuProgramType gpuType)
Write the output params of the function.
virtual void cacheDependencyFunctions(const String &libName)
Cache functions of a dependency.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
void writeLocalParameter(std::ostream &os, ParameterPtr parameter)
Write a local parameter.
Interface definition for factories of ShaderProgramWriter.
String processOperand(Operand op, GpuProgramType gpuType)
map< GpuConstantType, const char * >::type GpuConstTypeToStringMap
FunctionInvocation * createInvocationFromString(const String &input)
Create a FunctionInvocation object from a string taken out of a shader library.
map< FunctionInvocation, String >::type FunctionMap
GLSL ES target language writer implementation.
void initializeStringMaps()
Initialize string maps.
virtual void writeSourceCode(std::ostream &os, Program *program)
virtual ~GLSLESProgramWriter()
Class destructor.
map< Parameter::Semantic, const char * >::type ParamSemanticToStringMap
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...
vector< FunctionInvocation >::type FunctionVector
GLSLESProgramWriter()
Class constructor.
void writeInputParameters(std::ostream &os, Function *function, GpuProgramType gpuType)
Write the input params of the function.
FunctionVector::const_iterator FunctionVectorIterator
vector< String >::type StringVector
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
Definition: OgreCommon.h:53
A class that represents function invocation code from shader based program function.
map< Parameter::Content, const char * >::type ParamContentToStringMap