source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreGpuProgramManager.h @ 1812

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