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 __HighLevelGpuProgramManager_H__ |
---|
29 | #define __HighLevelGpuProgramManager_H__ |
---|
30 | |
---|
31 | #include "OgrePrerequisites.h" |
---|
32 | #include "OgreResourceManager.h" |
---|
33 | #include "OgreSingleton.h" |
---|
34 | #include "OgreException.h" |
---|
35 | #include "OgreHighLevelGpuProgram.h" |
---|
36 | #include "OgreHeaderPrefix.h" |
---|
37 | |
---|
38 | namespace Ogre { |
---|
39 | |
---|
40 | /** \addtogroup Core |
---|
41 | * @{ |
---|
42 | */ |
---|
43 | /** \addtogroup Resources |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | /** Interface definition for factories of HighLevelGpuProgram. */ |
---|
47 | class _OgreExport HighLevelGpuProgramFactory : public FactoryAlloc |
---|
48 | { |
---|
49 | public: |
---|
50 | HighLevelGpuProgramFactory() {} |
---|
51 | virtual ~HighLevelGpuProgramFactory(); |
---|
52 | /// Get the name of the language this factory creates programs for |
---|
53 | virtual const String& getLanguage(void) const = 0; |
---|
54 | virtual HighLevelGpuProgram* create(ResourceManager* creator, |
---|
55 | const String& name, ResourceHandle handle, |
---|
56 | const String& group, bool isManual, ManualResourceLoader* loader) = 0; |
---|
57 | virtual void destroy(HighLevelGpuProgram* prog) = 0; |
---|
58 | }; |
---|
59 | /** This ResourceManager manages high-level vertex and fragment programs. |
---|
60 | @remarks |
---|
61 | High-level vertex and fragment programs can be used instead of assembler programs |
---|
62 | as managed by GpuProgramManager; however they typically result in a GpuProgram |
---|
63 | being created as a derivative of the high-level program. High-level programs are |
---|
64 | easier to write, and can often be API-independent, unlike assembler programs. |
---|
65 | @par |
---|
66 | This class not only manages the programs themselves, it also manages the factory |
---|
67 | classes which allow the creation of high-level programs using a variety of high-level |
---|
68 | syntaxes. Plugins can be created which register themselves as high-level program |
---|
69 | factories and as such the engine can be extended to accept virtually any kind of |
---|
70 | program provided a plugin is written. |
---|
71 | */ |
---|
72 | class _OgreExport HighLevelGpuProgramManager |
---|
73 | : public ResourceManager, public Singleton<HighLevelGpuProgramManager> |
---|
74 | { |
---|
75 | public: |
---|
76 | typedef map<String, HighLevelGpuProgramFactory*>::type FactoryMap; |
---|
77 | protected: |
---|
78 | /// Factories capable of creating HighLevelGpuProgram instances |
---|
79 | FactoryMap mFactories; |
---|
80 | |
---|
81 | /// Factory for dealing with programs for languages we can't create |
---|
82 | HighLevelGpuProgramFactory* mNullFactory; |
---|
83 | /// Factory for unified high-level programs |
---|
84 | HighLevelGpuProgramFactory* mUnifiedFactory; |
---|
85 | |
---|
86 | HighLevelGpuProgramFactory* getFactory(const String& language); |
---|
87 | |
---|
88 | /// @copydoc ResourceManager::createImpl |
---|
89 | Resource* createImpl(const String& name, ResourceHandle handle, |
---|
90 | const String& group, bool isManual, ManualResourceLoader* loader, |
---|
91 | const NameValuePairList* createParams); |
---|
92 | public: |
---|
93 | HighLevelGpuProgramManager(); |
---|
94 | ~HighLevelGpuProgramManager(); |
---|
95 | /** Add a new factory object for high-level programs of a given language. */ |
---|
96 | void addFactory(HighLevelGpuProgramFactory* factory); |
---|
97 | /** Remove a factory object for high-level programs of a given language. */ |
---|
98 | void removeFactory(HighLevelGpuProgramFactory* factory); |
---|
99 | |
---|
100 | /** Returns whether a given high-level language is supported. */ |
---|
101 | bool isLanguageSupported(const String& lang); |
---|
102 | |
---|
103 | /// Get a resource by name |
---|
104 | /// @see ResourceManager::getResourceByName |
---|
105 | HighLevelGpuProgramPtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); |
---|
106 | |
---|
107 | /** Create a new, unloaded HighLevelGpuProgram. |
---|
108 | @par |
---|
109 | This method creates a new program of the type specified as the second and third parameters. |
---|
110 | You will have to call further methods on the returned program in order to |
---|
111 | define the program fully before you can load it. |
---|
112 | @param name The identifying name of the program |
---|
113 | @param groupName The name of the resource group which this program is |
---|
114 | to be a member of |
---|
115 | @param language Code of the language to use (e.g. "cg") |
---|
116 | @param gptype The type of program to create |
---|
117 | */ |
---|
118 | HighLevelGpuProgramPtr createProgram( |
---|
119 | const String& name, const String& groupName, |
---|
120 | const String& language, GpuProgramType gptype); |
---|
121 | |
---|
122 | /** Override standard Singleton retrieval. |
---|
123 | @remarks |
---|
124 | Why do we do this? Well, it's because the Singleton |
---|
125 | implementation is in a .h file, which means it gets compiled |
---|
126 | into anybody who includes it. This is needed for the |
---|
127 | Singleton template to work, but we actually only want it |
---|
128 | compiled into the implementation of the class based on the |
---|
129 | Singleton, not all of them. If we don't change this, we get |
---|
130 | link errors when trying to use the Singleton-based class from |
---|
131 | an outside dll. |
---|
132 | @par |
---|
133 | This method just delegates to the template version anyway, |
---|
134 | but the implementation stays in this single compilation unit, |
---|
135 | preventing link errors. |
---|
136 | */ |
---|
137 | static HighLevelGpuProgramManager& getSingleton(void); |
---|
138 | /** Override standard Singleton retrieval. |
---|
139 | @remarks |
---|
140 | Why do we do this? Well, it's because the Singleton |
---|
141 | implementation is in a .h file, which means it gets compiled |
---|
142 | into anybody who includes it. This is needed for the |
---|
143 | Singleton template to work, but we actually only want it |
---|
144 | compiled into the implementation of the class based on the |
---|
145 | Singleton, not all of them. If we don't change this, we get |
---|
146 | link errors when trying to use the Singleton-based class from |
---|
147 | an outside dll. |
---|
148 | @par |
---|
149 | This method just delegates to the template version anyway, |
---|
150 | but the implementation stays in this single compilation unit, |
---|
151 | preventing link errors. |
---|
152 | */ |
---|
153 | static HighLevelGpuProgramManager* getSingletonPtr(void); |
---|
154 | |
---|
155 | |
---|
156 | }; |
---|
157 | /** @} */ |
---|
158 | /** @} */ |
---|
159 | |
---|
160 | } |
---|
161 | |
---|
162 | #include "OgreHeaderSuffix.h" |
---|
163 | |
---|
164 | #endif |
---|