| 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-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #ifndef __GpuProgramManager_H_ |
|---|
| 30 | #define __GpuProgramManager_H_ |
|---|
| 31 | |
|---|
| 32 | // Precompiler options |
|---|
| 33 | #include "OgrePrerequisites.h" |
|---|
| 34 | #include "OgreResourceManager.h" |
|---|
| 35 | #include "OgreException.h" |
|---|
| 36 | #include "OgreGpuProgram.h" |
|---|
| 37 | #include "OgreSingleton.h" |
|---|
| 38 | |
|---|
| 39 | namespace Ogre { |
|---|
| 40 | |
|---|
| 41 | class _OgreExport GpuProgramManager : public ResourceManager, public Singleton<GpuProgramManager> |
|---|
| 42 | { |
|---|
| 43 | public: |
|---|
| 44 | typedef std::set<String> SyntaxCodes; |
|---|
| 45 | |
|---|
| 46 | protected: |
|---|
| 47 | /// Supported program syntax codes |
|---|
| 48 | SyntaxCodes mSyntaxCodes; |
|---|
| 49 | /// Specialised create method with specific parameters |
|---|
| 50 | virtual Resource* createImpl(const String& name, ResourceHandle handle, |
|---|
| 51 | const String& group, bool isManual, ManualResourceLoader* loader, |
|---|
| 52 | GpuProgramType gptype, const String& syntaxCode) = 0; |
|---|
| 53 | public: |
|---|
| 54 | GpuProgramManager(); |
|---|
| 55 | virtual ~GpuProgramManager(); |
|---|
| 56 | |
|---|
| 57 | /** Loads a GPU program from a file of assembly. |
|---|
| 58 | @remarks |
|---|
| 59 | This method creates a new program of the type specified as the second parameter. |
|---|
| 60 | As with all types of ResourceManager, this class will search for the file in |
|---|
| 61 | all resource locations it has been configured to look in. |
|---|
| 62 | @param name The name of the GpuProgram |
|---|
| 63 | @param groupName The name of the resource group |
|---|
| 64 | @param filename The file to load |
|---|
| 65 | @param gptype The type of program to create |
|---|
| 66 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
|---|
| 67 | */ |
|---|
| 68 | virtual GpuProgramPtr load(const String& name, const String& groupName, |
|---|
| 69 | const String& filename, GpuProgramType gptype, |
|---|
| 70 | const String& syntaxCode); |
|---|
| 71 | |
|---|
| 72 | /** Loads a GPU program from a string of assembly code. |
|---|
| 73 | @remarks |
|---|
| 74 | The assembly code must be compatible with this manager - call the |
|---|
| 75 | getSupportedSyntax method for details of the supported syntaxes |
|---|
| 76 | @param name The identifying name to give this program, which can be used to |
|---|
| 77 | retrieve this program later with getByName. |
|---|
| 78 | @param groupName The name of the resource group |
|---|
| 79 | @param code A string of assembly code which will form the program to run |
|---|
| 80 | @param gptype The type of prgram to create. |
|---|
| 81 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
|---|
| 82 | */ |
|---|
| 83 | virtual GpuProgramPtr loadFromString(const String& name, const String& groupName, |
|---|
| 84 | const String& code, GpuProgramType gptype, |
|---|
| 85 | const String& syntaxCode); |
|---|
| 86 | |
|---|
| 87 | /** Returns the syntaxes that this manager supports. */ |
|---|
| 88 | virtual const SyntaxCodes& getSupportedSyntax(void) const { return mSyntaxCodes; }; |
|---|
| 89 | |
|---|
| 90 | /** Returns whether a given syntax code (e.g. "ps_1_3", "fp20", "arbvp1") is supported. */ |
|---|
| 91 | virtual bool isSyntaxSupported(const String& syntaxCode) const; |
|---|
| 92 | |
|---|
| 93 | /** Creates a new GpuProgramParameters instance which can be used to bind |
|---|
| 94 | parameters to your programs. |
|---|
| 95 | @remarks |
|---|
| 96 | Program parameters can be shared between multiple programs if you wish. |
|---|
| 97 | */ |
|---|
| 98 | virtual GpuProgramParametersSharedPtr createParameters(void); |
|---|
| 99 | |
|---|
| 100 | /** Create a new, unloaded GpuProgram from a file of assembly. |
|---|
| 101 | @remarks |
|---|
| 102 | Use this method in preference to the 'load' methods if you wish to define |
|---|
| 103 | a GpuProgram, but not load it yet; useful for saving memory. |
|---|
| 104 | @par |
|---|
| 105 | This method creates a new program of the type specified as the second parameter. |
|---|
| 106 | As with all types of ResourceManager, this class will search for the file in |
|---|
| 107 | all resource locations it has been configured to look in. |
|---|
| 108 | @param name The name of the program |
|---|
| 109 | @param groupName The name of the resource group |
|---|
| 110 | @param filename The file to load |
|---|
| 111 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
|---|
| 112 | @param gptype The type of program to create |
|---|
| 113 | */ |
|---|
| 114 | virtual GpuProgramPtr createProgram(const String& name, |
|---|
| 115 | const String& groupName, const String& filename, |
|---|
| 116 | GpuProgramType gptype, const String& syntaxCode); |
|---|
| 117 | |
|---|
| 118 | /** Create a GPU program from a string of assembly code. |
|---|
| 119 | @remarks |
|---|
| 120 | Use this method in preference to the 'load' methods if you wish to define |
|---|
| 121 | a GpuProgram, but not load it yet; useful for saving memory. |
|---|
| 122 | @par |
|---|
| 123 | The assembly code must be compatible with this manager - call the |
|---|
| 124 | getSupportedSyntax method for details of the supported syntaxes |
|---|
| 125 | @param name The identifying name to give this program, which can be used to |
|---|
| 126 | retrieve this program later with getByName. |
|---|
| 127 | @param groupName The name of the resource group |
|---|
| 128 | @param code A string of assembly code which will form the program to run |
|---|
| 129 | @param gptype The type of prgram to create. |
|---|
| 130 | @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1 |
|---|
| 131 | */ |
|---|
| 132 | virtual GpuProgramPtr createProgramFromString(const String& name, |
|---|
| 133 | const String& groupName, const String& code, |
|---|
| 134 | GpuProgramType gptype, const String& syntaxCode); |
|---|
| 135 | |
|---|
| 136 | /** General create method, using specific create parameters |
|---|
| 137 | instead of name / value pairs. |
|---|
| 138 | */ |
|---|
| 139 | virtual ResourcePtr create(const String& name, const String& group, |
|---|
| 140 | GpuProgramType gptype, const String& syntaxCode, bool isManual = false, |
|---|
| 141 | ManualResourceLoader* loader = 0); |
|---|
| 142 | |
|---|
| 143 | /** Internal method for populating the supported syntax codes, called by RenderSystem. */ |
|---|
| 144 | virtual void _pushSyntaxCode(const String& syntaxCode) { mSyntaxCodes.insert(syntaxCode); } |
|---|
| 145 | /** Overrides the standard ResourceManager getByName method. |
|---|
| 146 | @param name The name of the program to retrieve |
|---|
| 147 | @param preferHighLevelPrograms If set to true (the default), high level programs will be |
|---|
| 148 | returned in preference to low-level programs. |
|---|
| 149 | */ |
|---|
| 150 | ResourcePtr getByName(const String& name, bool preferHighLevelPrograms = true); |
|---|
| 151 | /** Override standard Singleton retrieval. |
|---|
| 152 | @remarks |
|---|
| 153 | Why do we do this? Well, it's because the Singleton |
|---|
| 154 | implementation is in a .h file, which means it gets compiled |
|---|
| 155 | into anybody who includes it. This is needed for the |
|---|
| 156 | Singleton template to work, but we actually only want it |
|---|
| 157 | compiled into the implementation of the class based on the |
|---|
| 158 | Singleton, not all of them. If we don't change this, we get |
|---|
| 159 | link errors when trying to use the Singleton-based class from |
|---|
| 160 | an outside dll. |
|---|
| 161 | @par |
|---|
| 162 | This method just delegates to the template version anyway, |
|---|
| 163 | but the implementation stays in this single compilation unit, |
|---|
| 164 | preventing link errors. |
|---|
| 165 | */ |
|---|
| 166 | static GpuProgramManager& getSingleton(void); |
|---|
| 167 | /** Override standard Singleton retrieval. |
|---|
| 168 | @remarks |
|---|
| 169 | Why do we do this? Well, it's because the Singleton |
|---|
| 170 | implementation is in a .h file, which means it gets compiled |
|---|
| 171 | into anybody who includes it. This is needed for the |
|---|
| 172 | Singleton template to work, but we actually only want it |
|---|
| 173 | compiled into the implementation of the class based on the |
|---|
| 174 | Singleton, not all of them. If we don't change this, we get |
|---|
| 175 | link errors when trying to use the Singleton-based class from |
|---|
| 176 | an outside dll. |
|---|
| 177 | @par |
|---|
| 178 | This method just delegates to the template version anyway, |
|---|
| 179 | but the implementation stays in this single compilation unit, |
|---|
| 180 | preventing link errors. |
|---|
| 181 | */ |
|---|
| 182 | static GpuProgramManager* getSingletonPtr(void); |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | }; |
|---|
| 187 | |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | #endif |
|---|