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

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