OgreShaderGLSLESProgramWriter.h
Go to the documentation of this file.

    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 _ShaderProgramWriterGLSLES_
    00028 #define _ShaderProgramWriterGLSLES_
    00029
    00030 #include "OgreShaderProgramWriterManager.h"
    00031
    00032 namespace Ogre {
    00033 namespace RTShader {
    00034
    00045 class GLSLESProgramWriter : public ProgramWriter
    00046 {
    00047     // Interface.
    00048 public:
    00049
    00053     GLSLESProgramWriter();
    00054
    00056     virtual ~GLSLESProgramWriter();
    00057
    00058
    00062 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00063     virtual void writeSourceCode(StringSerialiser& os, Program* program);
    00064 #else
    00065     virtual void writeSourceCode(std::ostream& os, Program* program);
    00066 #endif
    00067
    00071     virtual const String& getTargetLanguage() const { return TargetLanguage; }
    00072
    00073     static String TargetLanguage;
    00074
    00075     protected:
    00076     typedef std::map<GpuConstantType, const char*>      GpuConstTypeToStringMap;
    00077     typedef std::map<Parameter::Semantic, const char*>  ParamSemanticToStringMap;
    00078     typedef std::map<Parameter::Content, const char*>   ParamContentToStringMap;
    00079     typedef std::map<String, String>                    StringMap;
    00080     typedef std::map<FunctionInvocation, String>        FunctionMap;
    00081     typedef std::vector<FunctionInvocation>             FunctionVector;
    00082     typedef FunctionMap::const_iterator                 FunctionMapIterator;
    00083     typedef FunctionVector::const_iterator              FunctionVectorIterator;
    00084     typedef GpuConstTypeToStringMap::const_iterator     GpuConstTypeToStringMapIterator;
    00085
    00086     // Protected methods.
    00087 protected:
    00088
    00090     void initializeStringMaps();
    00091
    00093     virtual void cacheDependencyFunctions(const String & libName);
    00094
    00095
    00097     FunctionInvocation  *createInvocationFromString (const String & input);
    00098
    00100 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00101     void writeProgramDependencies(StringSerialiser& os, Program* program);
    00102 #else
    00103     void writeProgramDependencies(std::ostream& os, Program* program);
    00104 #endif
    00105
    00107 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00108     void writeLocalParameter(StringSerialiser& os, ParameterPtr parameter);
    00109 #else
    00110     void writeLocalParameter(std::ostream& os, ParameterPtr parameter);
    00111 #endif
    00112
    00114 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00115     void writeInputParameters(StringSerialiser& os, Function* function, GpuProgramType gpuType);
    00116 #else
    00117     void writeInputParameters(std::ostream& os, Function* function, GpuProgramType gpuType);
    00118 #endif
    00119
    00121 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00122     void writeOutParameters(StringSerialiser& os, Function* function, GpuProgramType gpuType);
    00123 #else
    00124     void writeOutParameters(std::ostream& os, Function* function, GpuProgramType gpuType);
    00125 #endif
    00126
    00127 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    00128     void writeAssignFunction(StringSerialiser& os, FunctionInvocation::OperandVector::iterator itOperand, FunctionInvocation::OperandVector::iterator itOperandEnd, GpuProgramType gpuType);
    00129 #else
    00130     void writeAssignFunction(std::stringstream& os, FunctionInvocation::OperandVector::iterator itOperand, FunctionInvocation::OperandVector::iterator itOperandEnd, GpuProgramType gpuType);
    00131 #endif
    00132
    00133     String processOperand(Operand op, GpuProgramType gpuType);
    00134
    00136     bool isBasicType(String &type);
    00137
    00139     void discoverFunctionDependencies(const FunctionInvocation &invoc, FunctionVector &depVector);
    00140
    00141     // Attributes.
    00142 protected:
    00143     // Map between GPU constant type to string value.
    00144     GpuConstTypeToStringMap mGpuConstTypeMap;
    00145     // Map between parameter semantic to string value.
    00146     ParamSemanticToStringMap mParamSemanticMap;
    00147
    00148     // Map parameter name to a new parameter name (sometimes renaming is required to match names between vertex and fragment shader)
    00149     StringMap mInputToGLStatesMap;
    00150     // Map function invocation to body.  Used as a cache to reduce library file reads and for inlining
    00151     FunctionMap mFunctionCacheMap;
    00152     // Map of #defines and the function library that contains them
    00153     StringMap mDefinesMap;
    00154     // Map parameter content to vertex attributes
    00155     ParamContentToStringMap mContentToPerVertexAttributes;
    00156     // Holds the current glsl es version
    00157     int mGLSLVersion;
    00158     // Holds the fragment input params
    00159     StringVector mFragInputParams;
    00160     // Holds the cached function libraries
    00161     StringMap mCachedFunctionLibraries;
    00162 };
    00163
    00167 class ShaderProgramWriterGLSLESFactory : public ProgramWriterFactory
    00168 {
    00169 public:
    00170     ShaderProgramWriterGLSLESFactory()
    00171     {
    00172         mLanguage = "glsles";
    00173     }
    00174     virtual ~ShaderProgramWriterGLSLESFactory() {}
    00175
    00179     virtual const String& getTargetLanguage(void) const
    00180     {
    00181         return mLanguage;
    00182     }
    00183
    00187     virtual ProgramWriter* create(void)
    00188     {
    00189         return OGRE_NEW GLSLESProgramWriter();
    00190     }
    00191
    00192 private:
    00193     String mLanguage;
    00194 };
    00195
    00199 }
    00200 }
    00201
    00202 #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