OgreShaderProgramManager.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 _ShaderProgramManager_
28 #define _ShaderProgramManager_
29 
31 #include "OgreShaderProgram.h"
33 
34 namespace Ogre {
35 namespace RTShader {
36 
46 class _OgreRTSSExport ProgramManager : public Singleton<ProgramManager>, public RTShaderSystemAlloc
47 {
48 // Interface.
49 public:
50 
53 
56 
57 
74 
91 
96  void acquirePrograms(Pass* pass, TargetRenderState* renderState);
97 
102  void releasePrograms(Pass* pass, TargetRenderState* renderState);
103 
107 
108 protected:
109 
110  //-----------------------------------------------------------------------------
112  typedef GpuProgramsMap::iterator GpuProgramsMapIterator;
113  typedef GpuProgramsMap::const_iterator GpuProgramsMapConstIterator;
114 
115  //-----------------------------------------------------------------------------
117  typedef ProgramList::iterator ProgramListIterator;
119  typedef ProgramWriterMap::iterator ProgramWriterIterator;
121 
122  //-----------------------------------------------------------------------------
124  typedef ProgramProcessorMap::iterator ProgramProcessorIterator;
125  typedef ProgramProcessorMap::const_iterator ProgramProcessorConstIterator;
127 
128 
129 protected:
132 
135 
138 
141 
144 
149 
153  void destroyCpuProgram(Program* shaderProgram);
154 
158  bool createGpuPrograms(ProgramSet* programSet);
159 
165  String generateGUID(const String& programString);
166 
176  ProgramWriter* programWriter,
177  const String& language,
178  const String& profiles,
179  const StringVector& profilesList,
180  const String& cachePath);
181 
187 
193 
197  void destroyGpuProgram(GpuProgramPtr& gpuProgram);
198 
202  void flushGpuProgramsCache(GpuProgramsMap& gpuProgramsMap);
203 
205  size_t getVertexShaderCount() const { return mVertexShaderMap.size(); }
206 
208  size_t getFragmentShaderCount() const { return mFragmentShaderMap.size(); }
209 
212 
214  void bindUniformParameters(Program* pCpuProgram, const GpuProgramParametersSharedPtr& passParams);
215 
216 
217 protected:
218 
219 
220 protected:
221  // CPU programs list.
223  // Map between target language and shader program writer.
225  // Map between target language and shader program processor.
227  // Holds standard shader writer factories
229  // The generated vertex shaders.
231  // The generated fragment shaders.
233  // The default program processors.
235 
236 private:
237  friend class ProgramSet;
238  friend class TargetRenderState;
239  friend class ShaderGenerator;
240 };
241 
245 }
246 }
247 
248 #endif
249 
#define _OgreRTSSExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class defining a single pass of a Technique (of a Material), i.e.
Definition: OgrePass.h:81
A singleton manager class that manages shader based programs.
void acquirePrograms(Pass *pass, TargetRenderState *renderState)
Acquire CPU/GPU programs set associated with the given render state and bind them to the pass.
ProgramProcessorMap::iterator ProgramProcessorIterator
void addProgramProcessor(ProgramProcessor *processor)
Add program processor instance to this manager.
String generateGUID(const String &programString)
Generates a unique guid value from a string.
void removeProgramProcessor(ProgramProcessor *processor)
Remove program processor instance from this manager.
ProgramWriterFactoryList mProgramWriterFactories
void bindUniformParameters(Program *pCpuProgram, const GpuProgramParametersSharedPtr &passParams)
Bind the uniform parameters of a given CPU and GPU program set.
GpuProgramsMap::const_iterator GpuProgramsMapConstIterator
~ProgramManager()
Class destructor.
ProgramWriterMap::iterator ProgramWriterIterator
void synchronizePixelnToBeVertexOut(ProgramSet *programSet)
Fix the input of the pixel shader to be the same as the output of the vertex shader.
map< String, ProgramProcessor * >::type ProgramProcessorMap
GpuProgramsMap::iterator GpuProgramsMapIterator
void flushGpuProgramsCache()
Flush the local GPU programs cache.
void destroyDefaultProgramWriterFactories()
Destroy default program processors.
void destroyDefaultProgramProcessors()
Destroy default program processors.
map< String, GpuProgramPtr >::type GpuProgramsMap
void createDefaultProgramProcessors()
Create default program processors.
static ProgramManager * getSingletonPtr()
Override standard Singleton retrieval.
ProgramManager()
Class default constructor.
ProgramProcessorMap::const_iterator ProgramProcessorConstIterator
size_t getFragmentShaderCount() const
Return the number of created fragment shaders.
GpuProgramPtr createGpuProgram(Program *shaderProgram, ProgramWriter *programWriter, const String &language, const String &profiles, const StringVector &profilesList, const String &cachePath)
Create GPU program based on the give CPU program.
void releasePrograms(Pass *pass, TargetRenderState *renderState)
Release CPU/GPU programs set associated with the given render state and pass.
void createDefaultProgramWriterFactories()
Create default program processors.
static ProgramManager & getSingleton()
Override standard Singleton retrieval.
void destroyProgramWriters()
Destroy all program writers.
bool createGpuPrograms(ProgramSet *programSet)
Create GPU programs for the given program set based on the CPU programs it contains.
Program * createCpuProgram(GpuProgramType type)
Create CPU program .
size_t getVertexShaderCount() const
Return the number of created vertex shaders.
void flushGpuProgramsCache(GpuProgramsMap &gpuProgramsMap)
Flush the local GPU programs cache.
void destroyGpuProgram(GpuProgramPtr &gpuProgram)
Destroy a GPU program by name.
map< String, ProgramWriter * >::type ProgramWriterMap
void destroyCpuProgram(Program *shaderProgram)
Destroy a CPU program by name.
vector< ProgramProcessor * >::type ProgramProcessorList
vector< ProgramWriterFactory * >::type ProgramWriterFactoryList
ProgramProcessorList mDefaultProgramProcessors
A class that provides extra processing services on CPU based programs.
Container class for shader based programs.
Base class interface for shader program writers.
A class that represents a shader based program.
Shader generator system main interface.
This is the target render state.
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:65
vector< String >::type StringVector
GpuProgramType
Enumerates the types of programs which can run on the GPU.
_StringBase String

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.