source: OGRE/trunk/ogrenew/OgreMain/src/OgreHighLevelGpuProgramManager.cpp @ 692

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

adding ogre 1.2 and dependencies

RevLine 
[692]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#include "OgreStableHeaders.h"
26#include "OgreHighLevelGpuProgramManager.h"
27
28namespace Ogre {
29
30        //-----------------------------------------------------------------------
31        template<> HighLevelGpuProgramManager*
32        Singleton<HighLevelGpuProgramManager>::ms_Singleton = 0;
33    HighLevelGpuProgramManager* HighLevelGpuProgramManager::getSingletonPtr(void)
34    {
35        return ms_Singleton;
36    }
37    HighLevelGpuProgramManager& HighLevelGpuProgramManager::getSingleton(void)
38    { 
39        assert( ms_Singleton );  return ( *ms_Singleton ); 
40    }
41        //-----------------------------------------------------------------------
42        HighLevelGpuProgramManager::HighLevelGpuProgramManager()
43        {
44        // Loading order
45        mLoadOrder = 50.0f;
46        // Resource type
47        mResourceType = "HighLevelGpuProgram";
48
49        ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);   
50       
51        }
52        //-----------------------------------------------------------------------
53        HighLevelGpuProgramManager::~HighLevelGpuProgramManager()
54        {
55        ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);   
56        }
57    //---------------------------------------------------------------------------
58        void HighLevelGpuProgramManager::addFactory(HighLevelGpuProgramFactory* factory)
59        {
60                // deliberately allow later plugins to override earlier ones
61                mFactories[factory->getLanguage()] = factory;
62        }
63    //---------------------------------------------------------------------------
64        HighLevelGpuProgramFactory* HighLevelGpuProgramManager::getFactory(const String& language)
65        {
66                FactoryMap::iterator i = mFactories.find(language);
67
68                if (i == mFactories.end())
69                {
70                        OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
71                                "Cannot find factory for language '" + language + "'",
72                                "HighLevelGpuProgramManager::getFactory");
73                }
74                return i->second;
75        }
76    //---------------------------------------------------------------------------
77    Resource* HighLevelGpuProgramManager::createImpl(const String& name, ResourceHandle handle,
78        const String& group, bool isManual, ManualResourceLoader* loader,
79        const NameValuePairList* params)
80    {
81        NameValuePairList::const_iterator paramIt;
82
83        if (!params || (paramIt = params->find("language")) == params->end())
84        {
85            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
86                "You must supply a 'language' parameter",
87                "HighLevelGpuProgramManager::createImpl");
88        }
89
90        return getFactory(paramIt->second)->create(this, name, getNextHandle(),
91            group, isManual, loader);
92    }
93    //---------------------------------------------------------------------------
94    HighLevelGpuProgramPtr HighLevelGpuProgramManager::createProgram(
95                        const String& name, const String& groupName,
96            const String& language, GpuProgramType gptype)
97    {
98        ResourcePtr ret = ResourcePtr(
99            getFactory(language)->create(this, name, getNextHandle(),
100            groupName, false, 0));
101
102        HighLevelGpuProgramPtr prg = ret;
103        prg->setType(gptype);
104        prg->setSyntaxCode(language);
105
106        addImpl(ret);
107        // Tell resource group manager
108        ResourceGroupManager::getSingleton()._notifyResourceCreated(ret);
109        return prg;
110    }
111    //---------------------------------------------------------------------------
112    HighLevelGpuProgramFactory::~HighLevelGpuProgramFactory()
113    {
114    }
115}
Note: See TracBrowser for help on using the repository browser.