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 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | #ifndef __GpuProgramManager_H_ |
---|
29 | #define __GpuProgramManager_H_ |
---|
30 | |
---|
31 | // Precompiler options |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | #include "OgreResourceManager.h" |
---|
34 | #include "OgreException.h" |
---|
35 | #include "OgreGpuProgram.h" |
---|
36 | #include "OgreSingleton.h" |
---|
37 | #include "OgreHeaderPrefix.h" |
---|
38 | |
---|
39 | namespace Ogre { |
---|
40 | |
---|
41 | /** \addtogroup Core |
---|
42 | * @{ |
---|
43 | */ |
---|
44 | /** \addtogroup Resources |
---|
45 | * @{ |
---|
46 | */ |
---|
47 | class _OgreExport GpuProgramManager : public ResourceManager, public Singleton<GpuProgramManager> |
---|
48 | { |
---|
49 | public: |
---|
50 | |
---|
51 | typedef set<String>::type SyntaxCodes; |
---|
52 | typedef map<String, GpuSharedParametersPtr>::type SharedParametersMap; |
---|
53 | |
---|
54 | typedef MemoryDataStreamPtr Microcode; |
---|
55 | typedef map<String, Microcode>::type MicrocodeMap; |
---|
56 | |
---|
57 | protected: |
---|
58 | |
---|
59 | SharedParametersMap mSharedParametersMap; |
---|
60 | MicrocodeMap mMicrocodeCache; |
---|
61 | bool mSaveMicrocodesToCache; |
---|
62 | bool mCacheDirty; // When this is true the cache is 'dirty' and should be resaved to disk. |
---|
63 | |
---|
64 | static String addRenderSystemToName( const String & name ); |
---|
65 | |
---|
66 | /// Specialised create method with specific parameters |
---|
67 | virtual Resource* createImpl(const String& name, ResourceHandle handle, |
---|
68 | const String& group, bool isManual, ManualResourceLoader* loader, |
---|
69 | GpuProgramType gptype, const String& syntaxCode) = 0; |
---|
70 | public: |
---|
71 | GpuProgramManager(); |
---|
72 | virtual ~GpuProgramManager(); |
---|
73 | |
---|
74 | /// Get a resource by name |
---|
75 | /// @see GpuProgramManager::getResourceByName |
---|
76 | GpuProgramPtr getByName(const String& name, bool preferHighLevelPrograms = true); |
---|
77 | |
---|
78 | /** Loads a GPU program from a file of assembly. |
---|
79 | @remarks |
---|
80 | This method creates a new program of the type specified as the second parameter. |
---|
81 | As with all types of ResourceManager, this class will search for the file in |
---|
82 | all resource locations it has been configured to look in. |
---|
83 | @param name The name of the GpuProgram |
---|
84 | @param groupName The name of the resource group |
---|
85 | @param filename The file to load |
---|
86 | @param gptype The type of program to create |
---|
87 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
---|
88 | */ |
---|
89 | virtual GpuProgramPtr load(const String& name, const String& groupName, |
---|
90 | const String& filename, GpuProgramType gptype, |
---|
91 | const String& syntaxCode); |
---|
92 | |
---|
93 | /** Loads a GPU program from a string of assembly code. |
---|
94 | @remarks |
---|
95 | The assembly code must be compatible with this manager - call the |
---|
96 | getSupportedSyntax method for details of the supported syntaxes |
---|
97 | @param name The identifying name to give this program, which can be used to |
---|
98 | retrieve this program later with getByName. |
---|
99 | @param groupName The name of the resource group |
---|
100 | @param code A string of assembly code which will form the program to run |
---|
101 | @param gptype The type of program to create. |
---|
102 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
---|
103 | */ |
---|
104 | virtual GpuProgramPtr loadFromString(const String& name, const String& groupName, |
---|
105 | const String& code, GpuProgramType gptype, |
---|
106 | const String& syntaxCode); |
---|
107 | |
---|
108 | /** Returns the syntaxes that this manager supports. */ |
---|
109 | virtual const SyntaxCodes& getSupportedSyntax(void) const; |
---|
110 | |
---|
111 | |
---|
112 | /** Returns whether a given syntax code (e.g. "ps_1_3", "fp20", "arbvp1") is supported. */ |
---|
113 | virtual bool isSyntaxSupported(const String& syntaxCode) const; |
---|
114 | |
---|
115 | /** Creates a new GpuProgramParameters instance which can be used to bind |
---|
116 | parameters to your programs. |
---|
117 | @remarks |
---|
118 | Program parameters can be shared between multiple programs if you wish. |
---|
119 | */ |
---|
120 | virtual GpuProgramParametersSharedPtr createParameters(void); |
---|
121 | |
---|
122 | /** Create a new, unloaded GpuProgram from a file of assembly. |
---|
123 | @remarks |
---|
124 | Use this method in preference to the 'load' methods if you wish to define |
---|
125 | a GpuProgram, but not load it yet; useful for saving memory. |
---|
126 | @par |
---|
127 | This method creates a new program of the type specified as the second parameter. |
---|
128 | As with all types of ResourceManager, this class will search for the file in |
---|
129 | all resource locations it has been configured to look in. |
---|
130 | @param name The name of the program |
---|
131 | @param groupName The name of the resource group |
---|
132 | @param filename The file to load |
---|
133 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
---|
134 | @param gptype The type of program to create |
---|
135 | */ |
---|
136 | virtual GpuProgramPtr createProgram(const String& name, |
---|
137 | const String& groupName, const String& filename, |
---|
138 | GpuProgramType gptype, const String& syntaxCode); |
---|
139 | |
---|
140 | /** Create a GPU program from a string of assembly code. |
---|
141 | @remarks |
---|
142 | Use this method in preference to the 'load' methods if you wish to define |
---|
143 | a GpuProgram, but not load it yet; useful for saving memory. |
---|
144 | @par |
---|
145 | The assembly code must be compatible with this manager - call the |
---|
146 | getSupportedSyntax method for details of the supported syntaxes |
---|
147 | @param name The identifying name to give this program, which can be used to |
---|
148 | retrieve this program later with getByName. |
---|
149 | @param groupName The name of the resource group |
---|
150 | @param code A string of assembly code which will form the program to run |
---|
151 | @param gptype The type of program to create. |
---|
152 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
---|
153 | */ |
---|
154 | virtual GpuProgramPtr createProgramFromString(const String& name, |
---|
155 | const String& groupName, const String& code, |
---|
156 | GpuProgramType gptype, const String& syntaxCode); |
---|
157 | |
---|
158 | /** General create method, using specific create parameters |
---|
159 | instead of name / value pairs. |
---|
160 | */ |
---|
161 | virtual ResourcePtr create(const String& name, const String& group, |
---|
162 | GpuProgramType gptype, const String& syntaxCode, bool isManual = false, |
---|
163 | ManualResourceLoader* loader = 0); |
---|
164 | |
---|
165 | /** Overrides the standard ResourceManager getResourceByName method. |
---|
166 | @param name The name of the program to retrieve |
---|
167 | @param preferHighLevelPrograms If set to true (the default), high level programs will be |
---|
168 | returned in preference to low-level programs. |
---|
169 | */ |
---|
170 | ResourcePtr getResourceByName(const String& name, bool preferHighLevelPrograms = true); |
---|
171 | |
---|
172 | |
---|
173 | /** Create a new set of shared parameters, which can be used across many |
---|
174 | GpuProgramParameters objects of different structures. |
---|
175 | @param name The name to give the shared parameters so you can refer to them |
---|
176 | later. |
---|
177 | */ |
---|
178 | virtual GpuSharedParametersPtr createSharedParameters(const String& name); |
---|
179 | |
---|
180 | /** Retrieve a set of shared parameters, which can be used across many |
---|
181 | GpuProgramParameters objects of different structures. |
---|
182 | */ |
---|
183 | virtual GpuSharedParametersPtr getSharedParameters(const String& name) const; |
---|
184 | |
---|
185 | /** Get (const) access to the available shared parameter sets. |
---|
186 | */ |
---|
187 | virtual const SharedParametersMap& getAvailableSharedParameters() const; |
---|
188 | |
---|
189 | /** Get if the microcode of a shader should be saved to a cache |
---|
190 | */ |
---|
191 | bool getSaveMicrocodesToCache(); |
---|
192 | /** Set if the microcode of a shader should be saved to a cache |
---|
193 | */ |
---|
194 | void setSaveMicrocodesToCache( const bool val ); |
---|
195 | |
---|
196 | /** Returns true if the microcodecache changed during the run. |
---|
197 | */ |
---|
198 | bool isCacheDirty(void) const; |
---|
199 | |
---|
200 | bool canGetCompiledShaderBuffer(); |
---|
201 | /** Check if a microcode is available for a program in the microcode cache. |
---|
202 | @param name The name of the program. |
---|
203 | */ |
---|
204 | virtual bool isMicrocodeAvailableInCache( const String & name ) const; |
---|
205 | /** Returns a microcode for a program from the microcode cache. |
---|
206 | @param name The name of the program. |
---|
207 | */ |
---|
208 | virtual const Microcode & getMicrocodeFromCache( const String & name ) const; |
---|
209 | |
---|
210 | /** Creates a microcode to be later added to the cache. |
---|
211 | @param size The size of the microcode in bytes |
---|
212 | */ |
---|
213 | virtual Microcode createMicrocode( const uint32 size ) const; |
---|
214 | |
---|
215 | /** Adds a microcode for a program to the microcode cache. |
---|
216 | @param name The name of the program. |
---|
217 | */ |
---|
218 | virtual void addMicrocodeToCache( const String & name, const Microcode & microcode ); |
---|
219 | |
---|
220 | /** Removes a microcode for a program from the microcode cache. |
---|
221 | @param name The name of the program. |
---|
222 | */ |
---|
223 | virtual void removeMicrocodeFromCache( const String & name ); |
---|
224 | |
---|
225 | /** Saves the microcode cache to disk. |
---|
226 | @param stream The destination stream |
---|
227 | */ |
---|
228 | virtual void saveMicrocodeCache( DataStreamPtr stream ) const; |
---|
229 | /** Loads the microcode cache from disk. |
---|
230 | @param stream The source stream |
---|
231 | */ |
---|
232 | virtual void loadMicrocodeCache( DataStreamPtr stream ); |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | /** Override standard Singleton retrieval. |
---|
237 | @remarks |
---|
238 | Why do we do this? Well, it's because the Singleton |
---|
239 | implementation is in a .h file, which means it gets compiled |
---|
240 | into anybody who includes it. This is needed for the |
---|
241 | Singleton template to work, but we actually only want it |
---|
242 | compiled into the implementation of the class based on the |
---|
243 | Singleton, not all of them. If we don't change this, we get |
---|
244 | link errors when trying to use the Singleton-based class from |
---|
245 | an outside dll. |
---|
246 | @par |
---|
247 | This method just delegates to the template version anyway, |
---|
248 | but the implementation stays in this single compilation unit, |
---|
249 | preventing link errors. |
---|
250 | */ |
---|
251 | static GpuProgramManager& getSingleton(void); |
---|
252 | /** Override standard Singleton retrieval. |
---|
253 | @remarks |
---|
254 | Why do we do this? Well, it's because the Singleton |
---|
255 | implementation is in a .h file, which means it gets compiled |
---|
256 | into anybody who includes it. This is needed for the |
---|
257 | Singleton template to work, but we actually only want it |
---|
258 | compiled into the implementation of the class based on the |
---|
259 | Singleton, not all of them. If we don't change this, we get |
---|
260 | link errors when trying to use the Singleton-based class from |
---|
261 | an outside dll. |
---|
262 | @par |
---|
263 | This method just delegates to the template version anyway, |
---|
264 | but the implementation stays in this single compilation unit, |
---|
265 | preventing link errors. |
---|
266 | */ |
---|
267 | static GpuProgramManager* getSingletonPtr(void); |
---|
268 | |
---|
269 | |
---|
270 | |
---|
271 | }; |
---|
272 | |
---|
273 | /** @} */ |
---|
274 | /** @} */ |
---|
275 | } |
---|
276 | |
---|
277 | #include "OgreHeaderSuffix.h" |
---|
278 | |
---|
279 | #endif |
---|