OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-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 _ShaderProgramManager_
28 #define _ShaderProgramManager_
29 
31 #include "OgreSingleton.h"
32 #include "OgreGpuProgram.h"
33 #include "OgreStringVector.h"
34 
35 namespace Ogre {
36 namespace RTShader {
37 
38  class ProgramWriter;
39 
49 class _OgreRTSSExport ProgramManager : public Singleton<ProgramManager>, public RTShaderSystemAlloc
50 {
51 // Interface.
52 public:
53 
56 
58  ~ProgramManager();
59 
60 
76  static ProgramManager& getSingleton();
77 
93  static ProgramManager* getSingletonPtr();
94 
99  void acquirePrograms(Pass* pass, TargetRenderState* renderState);
100 
105  void releasePrograms(Pass* pass, TargetRenderState* renderState);
106 
109  void flushGpuProgramsCache();
110 
111 protected:
112 
113  //-----------------------------------------------------------------------------
116  typedef GpuProgramsMap::iterator GpuProgramsMapIterator;
117  typedef GpuProgramsMap::const_iterator GpuProgramsMapConstIterator;
118 
119  //-----------------------------------------------------------------------------
121  typedef ProgramList::iterator ProgramListIterator;
123  typedef ProgramWriterMap::iterator ProgramWriterIterator;
125 
126  //-----------------------------------------------------------------------------
128  typedef ProgramProcessorMap::iterator ProgramProcessorIterator;
129  typedef ProgramProcessorMap::const_iterator ProgramProcessorConstIterator;
131 
132 
133 protected:
135  void createDefaultProgramProcessors();
136 
138  void destroyDefaultProgramProcessors();
139 
141  void createDefaultProgramWriterFactories();
142 
144  void destroyDefaultProgramWriterFactories();
145 
147  void destroyProgramWriters();
148 
152  Program* createCpuProgram(GpuProgramType type);
153 
157  void destroyCpuProgram(Program* shaderProgram);
158 
162  bool createGpuPrograms(ProgramSet* programSet);
163 
169  String generateGUID(const String& programString);
170 
179  GpuProgramPtr createGpuProgram(Program* shaderProgram,
180  ProgramWriter* programWriter,
181  const String& language,
182  const String& profiles,
183  const StringVector& profilesList,
184  const String& cachePath);
185 
190  void addProgramProcessor(ProgramProcessor* processor);
191 
196  void removeProgramProcessor(ProgramProcessor* processor);
197 
201  void destroyGpuProgram(GpuProgramPtr& gpuProgram);
202 
206  void flushGpuProgramsCache(GpuProgramsMap& gpuProgramsMap);
207 
209  size_t getVertexShaderCount() const { return mVertexShaderMap.size(); }
210 
212  size_t getFragmentShaderCount() const { return mFragmentShaderMap.size(); }
213 
215  void synchronizePixelnToBeVertexOut(ProgramSet* programSet);
216 
218  void bindUniformParameters(Program* pCpuProgram, const GpuProgramParametersSharedPtr& passParams);
219 
220 
221 protected:
222 
223 
224 protected:
225  // CPU programs list.
227  // Map between target language and shader program writer.
229  // Map between target language and shader program processor.
231  // Holds standard shader writer factories
233  // The generated vertex shaders.
235  // The generated fragment shaders.
237  // The default program processors.
239  // map the source code of the shaders to a name for them
241 
242 private:
243  friend class ProgramSet;
244  friend class TargetRenderState;
245  friend class ShaderGenerator;
246 };
247 
251 }
252 }
253 
254 #endif
255 
GpuProgramsMap::const_iterator GpuProgramsMapConstIterator
ProgramWriterMap::iterator ProgramWriterIterator
map< String, ProgramProcessor * >::type ProgramProcessorMap
vector< ProgramWriterFactory * >::type ProgramWriterFactoryList
map< String, ProgramWriter * >::type ProgramWriterMap
GpuProgramsMap::iterator GpuProgramsMapIterator
ProgramProcessorMap::iterator ProgramProcessorIterator
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
GpuProgramType
Enumerates the types of programs which can run on the GPU.
A class that provides extra processing services on CPU based programs.
#define _OgreRTSSExport
ProgramProcessorList mDefaultProgramProcessors
vector< ProgramProcessor * >::type ProgramProcessorList
Class defining a single pass of a Technique (of a Material), i.e.
Definition: OgrePass.h:78
This is the target render state.
Shader generator system main interface.
Base class interface for shader program writers.
map< String, GpuProgramPtr >::type GpuProgramsMap
ProgramProcessorMap::const_iterator ProgramProcessorConstIterator
map< String, String >::type ProgramSourceToNameMap
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
vector< String >::type StringVector
size_t getVertexShaderCount() const
Return the number of created vertex shaders.
A class that represents a shader based program.
ProgramWriterFactoryList mProgramWriterFactories
_StringBase String
Definition: OgreCommon.h:53
Container class for shader based programs.
size_t getFragmentShaderCount() const
Return the number of created fragment shaders.
ProgramSourceToNameMap mProgramSourceToNameMap
A singleton manager class that manages shader based programs.