1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.stevestreeting.com/ogre/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
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 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 General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU 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/gpl.html.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include "OgreGLGpuProgramManager.h"
|
---|
27 | #include "OgreGLGpuProgram.h"
|
---|
28 | #include "OgreLogManager.h"
|
---|
29 |
|
---|
30 | using namespace Ogre;
|
---|
31 |
|
---|
32 | GLGpuProgramManager::GLGpuProgramManager()
|
---|
33 | {
|
---|
34 | // Superclass sets up members
|
---|
35 |
|
---|
36 | // Register with resource group manager
|
---|
37 | ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | GLGpuProgramManager::~GLGpuProgramManager()
|
---|
42 | {
|
---|
43 | // Unregister with resource group manager
|
---|
44 | ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
|
---|
45 | }
|
---|
46 |
|
---|
47 | bool GLGpuProgramManager::registerProgramFactory(const String& syntaxCode, CreateGpuProgramCallback createFn)
|
---|
48 | {
|
---|
49 | return mProgramMap.insert(ProgramMap::value_type(syntaxCode, createFn)).second;
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool GLGpuProgramManager::unregisterProgramFactory(const String& syntaxCode)
|
---|
53 | {
|
---|
54 | return mProgramMap.erase(syntaxCode) != 0;
|
---|
55 | }
|
---|
56 |
|
---|
57 | GpuProgramParametersSharedPtr GLGpuProgramManager::createParameters(void)
|
---|
58 | {
|
---|
59 | return GpuProgramParametersSharedPtr(new GpuProgramParameters());
|
---|
60 | }
|
---|
61 |
|
---|
62 | /// @copydoc ResourceManager::createImpl
|
---|
63 | Resource* GLGpuProgramManager::createImpl(const String& name, ResourceHandle handle,
|
---|
64 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
65 | const NameValuePairList* params)
|
---|
66 | {
|
---|
67 | NameValuePairList::const_iterator paramSyntax, paramType;
|
---|
68 |
|
---|
69 | if (!params || (paramSyntax = params->find("syntax")) == params->end() ||
|
---|
70 | (paramType = params->find("type")) == params->end())
|
---|
71 | {
|
---|
72 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
|
---|
73 | "You must supply 'syntax' and 'type' parameters",
|
---|
74 | "GLGpuProgramManager::createImpl");
|
---|
75 | }
|
---|
76 |
|
---|
77 | ProgramMap::const_iterator iter = mProgramMap.find(paramSyntax->second);
|
---|
78 | if(iter == mProgramMap.end())
|
---|
79 | {
|
---|
80 | // No factory, this is an unsupported syntax code, probably for another rendersystem
|
---|
81 | // Create a basic one, it doesn't matter what it is since it won't be used
|
---|
82 | return new GLGpuProgram(this, name, handle, group, isManual, loader);
|
---|
83 | }
|
---|
84 |
|
---|
85 | GpuProgramType gpt;
|
---|
86 | if (paramType->second == "vertex_program")
|
---|
87 | {
|
---|
88 | gpt = GPT_VERTEX_PROGRAM;
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | gpt = GPT_FRAGMENT_PROGRAM;
|
---|
93 | }
|
---|
94 |
|
---|
95 | return (iter->second)(this, name, handle, group, isManual, loader, gpt, paramSyntax->second);
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | Resource* GLGpuProgramManager::createImpl(const String& name, ResourceHandle handle,
|
---|
100 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
101 | GpuProgramType gptype, const String& syntaxCode)
|
---|
102 | {
|
---|
103 | ProgramMap::const_iterator iter = mProgramMap.find(syntaxCode);
|
---|
104 | if(iter == mProgramMap.end())
|
---|
105 | {
|
---|
106 | // No factory, this is an unsupported syntax code, probably for another rendersystem
|
---|
107 | // Create a basic one, it doesn't matter what it is since it won't be used
|
---|
108 | return new GLGpuProgram(this, name, handle, group, isManual, loader);
|
---|
109 | }
|
---|
110 |
|
---|
111 | return (iter->second)(this, name, handle, group, isManual, loader, gptype, syntaxCode);
|
---|
112 | }
|
---|
113 |
|
---|