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

Revision 692, 5.5 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 "OgreGpuProgramManager.h"
27#include "OgreHighLevelGpuProgramManager.h"
28
29namespace Ogre {
30    //-----------------------------------------------------------------------
31    template<> GpuProgramManager* Singleton<GpuProgramManager>::ms_Singleton = 0;
32    GpuProgramManager* GpuProgramManager::getSingletonPtr(void)
33    {
34        return ms_Singleton;
35    }
36    GpuProgramManager& GpuProgramManager::getSingleton(void)
37    { 
38        assert( ms_Singleton );  return ( *ms_Singleton ); 
39    }
40        //---------------------------------------------------------------------------
41        GpuProgramManager::GpuProgramManager()
42        {
43                // Loading order
44                mLoadOrder = 50.0f;
45                // Resource type
46                mResourceType = "GpuProgram";
47
48                // subclasses should register with resource group manager
49        }
50        //---------------------------------------------------------------------------
51        GpuProgramManager::~GpuProgramManager()
52        {
53                // subclasses should unregister with resource group manager
54        }
55        //---------------------------------------------------------------------------
56    GpuProgramPtr GpuProgramManager::load(const String& name,
57                const String& groupName, const String& filename,
58                GpuProgramType gptype, const String& syntaxCode)
59    {
60        GpuProgramPtr prg = getByName(name);
61        if (prg.isNull())
62        {
63                prg = createProgram(name, groupName, filename, gptype, syntaxCode);
64                }
65        prg->load();
66        return prg;
67    }
68    //---------------------------------------------------------------------------
69        GpuProgramPtr GpuProgramManager::loadFromString(const String& name,
70                const String& groupName, const String& code,
71        GpuProgramType gptype, const String& syntaxCode)
72    {
73        GpuProgramPtr prg = getByName(name);
74        if (prg.isNull())
75                {
76                        prg = createProgramFromString(name, groupName, code, gptype, syntaxCode);
77                }
78        prg->load();
79        return prg;
80    }
81    //---------------------------------------------------------------------------
82    ResourcePtr GpuProgramManager::create(const String& name, const String& group,
83        GpuProgramType gptype, const String& syntaxCode, bool isManual,
84        ManualResourceLoader* loader)
85    {
86        // Call creation implementation
87        ResourcePtr ret = ResourcePtr(
88            createImpl(name, getNextHandle(), group, isManual, loader, gptype, syntaxCode));
89
90        addImpl(ret);
91        // Tell resource group manager
92        ResourceGroupManager::getSingleton()._notifyResourceCreated(ret);
93        return ret;
94    }
95    //---------------------------------------------------------------------------
96        GpuProgramPtr GpuProgramManager::createProgram(const String& name,
97                const String& groupName, const String& filename,
98                GpuProgramType gptype, const String& syntaxCode)
99    {
100                GpuProgramPtr prg = create(name, groupName, gptype, syntaxCode);
101        // Set all prarmeters (create does not set, just determines factory)
102                prg->setType(gptype);
103                prg->setSyntaxCode(syntaxCode);
104                prg->setSourceFile(filename);
105        return prg;
106    }
107    //---------------------------------------------------------------------------
108        GpuProgramPtr GpuProgramManager::createProgramFromString(const String& name,
109                const String& groupName, const String& code, GpuProgramType gptype,
110                const String& syntaxCode)
111    {
112                GpuProgramPtr prg = create(name, groupName, gptype, syntaxCode);
113        // Set all prarmeters (create does not set, just determines factory)
114                prg->setType(gptype);
115                prg->setSyntaxCode(syntaxCode);
116                prg->setSource(code);
117        return prg;
118    }
119    //---------------------------------------------------------------------------
120    bool GpuProgramManager::isSyntaxSupported(const String& syntaxCode) const
121    {
122        if (std::find(mSyntaxCodes.begin(), mSyntaxCodes.end(), syntaxCode) != mSyntaxCodes.end())
123        {
124            return true;
125        }
126        else
127        {
128            return false;
129        }
130    }
131    //---------------------------------------------------------------------------
132    ResourcePtr GpuProgramManager::getByName(const String& name, bool preferHighLevelPrograms)
133    {
134        ResourcePtr ret;
135        if (preferHighLevelPrograms)
136        {
137            ret = HighLevelGpuProgramManager::getSingleton().getByName(name);
138            if (!ret.isNull())
139                return ret;
140        }
141        return ResourceManager::getByName(name);
142    }
143
144}
Note: See TracBrowser for help on using the repository browser.