OgreShaderProgramManager.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 _ShaderProgramManager_
    00028 #define _ShaderProgramManager_
    00029
    00030 #include "OgreShaderPrerequisites.h"
    00031 #include "OgreShaderProgram.h"
    00032 #include "OgreShaderProgramWriter.h"
    00033
    00034 namespace Ogre {
    00035 namespace RTShader {
    00036
    00046 class _OgreRTSSExport ProgramManager : public Singleton<ProgramManager>, public RTShaderSystemAlloc
    00047 {
    00048 // Interface.
    00049 public:
    00050
    00052     ProgramManager();
    00053
    00055     ~ProgramManager();
    00056
    00057
    00073     static ProgramManager& getSingleton();
    00074
    00090     static ProgramManager* getSingletonPtr();
    00091
    00096     void acquirePrograms(Pass* pass, TargetRenderState* renderState);
    00097
    00102     void releasePrograms(Pass* pass, TargetRenderState* renderState);
    00103
    00106     void flushGpuProgramsCache();
    00107
    00108 protected:
    00109
    00110     //-----------------------------------------------------------------------------
    00111     typedef map<String, GpuProgramPtr>::type            GpuProgramsMap;
    00112     typedef GpuProgramsMap::iterator                    GpuProgramsMapIterator;
    00113     typedef GpuProgramsMap::const_iterator              GpuProgramsMapConstIterator;
    00114
    00115     //-----------------------------------------------------------------------------
    00116     typedef set<Program*>::type                         ProgramList;
    00117     typedef ProgramList::iterator                       ProgramListIterator;
    00118     typedef map<String, ProgramWriter*>::type           ProgramWriterMap;
    00119     typedef ProgramWriterMap::iterator                  ProgramWriterIterator;
    00120     typedef vector<ProgramWriterFactory*>::type         ProgramWriterFactoryList;
    00121
    00122     //-----------------------------------------------------------------------------
    00123     typedef map<String, ProgramProcessor*>::type        ProgramProcessorMap;
    00124     typedef ProgramProcessorMap::iterator               ProgramProcessorIterator;
    00125     typedef ProgramProcessorMap::const_iterator         ProgramProcessorConstIterator;
    00126     typedef vector<ProgramProcessor*>::type             ProgramProcessorList;
    00127
    00128
    00129 protected:
    00131     void createDefaultProgramProcessors();
    00132
    00134     void destroyDefaultProgramProcessors();
    00135
    00137     void createDefaultProgramWriterFactories();
    00138
    00140     void destroyDefaultProgramWriterFactories();
    00141
    00143     void destroyProgramWriters();
    00144
    00148     Program* createCpuProgram(GpuProgramType type);
    00149
    00153     void destroyCpuProgram(Program* shaderProgram);
    00154
    00158     bool createGpuPrograms(ProgramSet* programSet);
    00159
    00168     GpuProgramPtr createGpuProgram(Program* shaderProgram,
    00169         ProgramWriter* programWriter,
    00170         const String& language,
    00171         const String& profiles,
    00172         const StringVector& profilesList,
    00173         const String& cachePath);
    00174
    00179     void addProgramProcessor(ProgramProcessor* processor);
    00180
    00185     void removeProgramProcessor(ProgramProcessor* processor);
    00186
    00191     void destroyGpuProgram(GpuProgramPtr& gpuProgram);
    00192
    00196     void flushGpuProgramsCache(GpuProgramsMap& gpuProgramsMap);
    00197
    00199     size_t getVertexShaderCount() const { return mVertexShaderMap.size(); }
    00200
    00202     size_t getFragmentShaderCount() const { return mFragmentShaderMap.size(); }
    00203
    00205     void synchronizePixelnToBeVertexOut(ProgramSet* programSet);
    00206
    00208     void bindUniformParameters(Program* pCpuProgram, const GpuProgramParametersSharedPtr& passParams);
    00209
    00210
    00211 protected:
    00212
    00213
    00214 protected:
    00215     // CPU programs list.
    00216     ProgramList mCpuProgramsList;
    00217     // Map between target language and shader program writer.
    00218     ProgramWriterMap mProgramWritersMap;
    00219     // Map between target language and shader program processor.
    00220     ProgramProcessorMap mProgramProcessorsMap;
    00221     // Holds standard shader writer factories
    00222     ProgramWriterFactoryList mProgramWriterFactories;
    00223     // The generated vertex shaders.
    00224     GpuProgramsMap mVertexShaderMap;
    00225     // The generated fragment shaders.
    00226     GpuProgramsMap mFragmentShaderMap;
    00227     // The default program processors.
    00228     ProgramProcessorList mDefaultProgramProcessors;
    00229
    00230 private:
    00231     friend class ProgramSet;
    00232     friend class TargetRenderState;
    00233     friend class ShaderGenerator;
    00234 };
    00235
    00239 }
    00240 }
    00241
    00242 #endif
    00243

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