source: OGRE/trunk/ogrenew/RenderSystems/GL/src/OgreGLGpuProgramManager.cpp @ 692

Revision 692, 4.1 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.stevestreeting.com/ogre/
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 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 General Public License for more details.
18
19You should have received a copy of the GNU 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/gpl.html.
23-----------------------------------------------------------------------------
24*/
25
26#include "OgreGLGpuProgramManager.h"
27#include "OgreGLGpuProgram.h"
28#include "OgreLogManager.h"
29
30using namespace Ogre;
31
32GLGpuProgramManager::GLGpuProgramManager()
33{
34    // Superclass sets up members
35
36    // Register with resource group manager
37    ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
38}
39
40
41GLGpuProgramManager::~GLGpuProgramManager()
42{
43    // Unregister with resource group manager
44    ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
45}
46
47bool GLGpuProgramManager::registerProgramFactory(const String& syntaxCode, CreateGpuProgramCallback createFn)
48{
49    return mProgramMap.insert(ProgramMap::value_type(syntaxCode, createFn)).second;
50}
51
52bool GLGpuProgramManager::unregisterProgramFactory(const String& syntaxCode)
53{
54    return mProgramMap.erase(syntaxCode) != 0;
55}
56
57GpuProgramParametersSharedPtr GLGpuProgramManager::createParameters(void)
58{
59    return GpuProgramParametersSharedPtr(new GpuProgramParameters());
60}
61
62/// @copydoc ResourceManager::createImpl
63Resource* 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
99Resource* 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
Note: See TracBrowser for help on using the repository browser.