Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgreGpuProgramManager.cpp @ 45

Last change on this file since 45 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 5.9 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30#include "OgreGpuProgramManager.h"
31#include "OgreHighLevelGpuProgramManager.h"
32
33namespace Ogre {
34    //-----------------------------------------------------------------------
35    template<> GpuProgramManager* Singleton<GpuProgramManager>::ms_Singleton = 0;
36    GpuProgramManager* GpuProgramManager::getSingletonPtr(void)
37    {
38        return ms_Singleton;
39    }
40    GpuProgramManager& GpuProgramManager::getSingleton(void)
41    { 
42        assert( ms_Singleton );  return ( *ms_Singleton ); 
43    }
44        //---------------------------------------------------------------------------
45        GpuProgramManager::GpuProgramManager()
46        {
47                // Loading order
48                mLoadOrder = 50.0f;
49                // Resource type
50                mResourceType = "GpuProgram";
51
52                // subclasses should register with resource group manager
53        }
54        //---------------------------------------------------------------------------
55        GpuProgramManager::~GpuProgramManager()
56        {
57                // subclasses should unregister with resource group manager
58        }
59        //---------------------------------------------------------------------------
60    GpuProgramPtr GpuProgramManager::load(const String& name,
61                const String& groupName, const String& filename, 
62                GpuProgramType gptype, const String& syntaxCode)
63    {
64                GpuProgramPtr prg;
65                {
66                        OGRE_LOCK_AUTO_MUTEX
67                        prg = getByName(name);
68                        if (prg.isNull())
69                        {
70                                prg = createProgram(name, groupName, filename, gptype, syntaxCode);
71                        }
72
73                }
74        prg->load();
75        return prg;
76    }
77    //---------------------------------------------------------------------------
78        GpuProgramPtr GpuProgramManager::loadFromString(const String& name, 
79                const String& groupName, const String& code, 
80        GpuProgramType gptype, const String& syntaxCode)
81    {
82                GpuProgramPtr prg;
83                {
84                        OGRE_LOCK_AUTO_MUTEX
85                        prg = getByName(name);
86                        if (prg.isNull())
87                        {
88                                prg = createProgramFromString(name, groupName, code, gptype, syntaxCode);
89                        }
90
91                }
92        prg->load();
93        return prg;
94    }
95    //---------------------------------------------------------------------------
96    ResourcePtr GpuProgramManager::create(const String& name, const String& group, 
97        GpuProgramType gptype, const String& syntaxCode, bool isManual, 
98        ManualResourceLoader* loader)
99    {
100        // Call creation implementation
101        ResourcePtr ret = ResourcePtr(
102            createImpl(name, getNextHandle(), group, isManual, loader, gptype, syntaxCode));
103
104        addImpl(ret);
105        // Tell resource group manager
106        ResourceGroupManager::getSingleton()._notifyResourceCreated(ret);
107        return ret;
108    }
109    //---------------------------------------------------------------------------
110        GpuProgramPtr GpuProgramManager::createProgram(const String& name, 
111                const String& groupName, const String& filename, 
112                GpuProgramType gptype, const String& syntaxCode)
113    {
114                GpuProgramPtr prg = create(name, groupName, gptype, syntaxCode);
115        // Set all prarmeters (create does not set, just determines factory)
116                prg->setType(gptype);
117                prg->setSyntaxCode(syntaxCode);
118                prg->setSourceFile(filename);
119        return prg;
120    }
121    //---------------------------------------------------------------------------
122        GpuProgramPtr GpuProgramManager::createProgramFromString(const String& name, 
123                const String& groupName, const String& code, GpuProgramType gptype, 
124                const String& syntaxCode)
125    {
126                GpuProgramPtr prg = create(name, groupName, gptype, syntaxCode);
127        // Set all prarmeters (create does not set, just determines factory)
128                prg->setType(gptype);
129                prg->setSyntaxCode(syntaxCode);
130                prg->setSource(code);
131        return prg;
132    }
133    //---------------------------------------------------------------------------
134    bool GpuProgramManager::isSyntaxSupported(const String& syntaxCode) const
135    {
136        if (std::find(mSyntaxCodes.begin(), mSyntaxCodes.end(), syntaxCode) != mSyntaxCodes.end())
137        {
138            return true;
139        }
140        else
141        {
142            return false;
143        }
144    }
145    //---------------------------------------------------------------------------
146    ResourcePtr GpuProgramManager::getByName(const String& name, bool preferHighLevelPrograms)
147    {
148        ResourcePtr ret;
149        if (preferHighLevelPrograms)
150        {
151            ret = HighLevelGpuProgramManager::getSingleton().getByName(name);
152            if (!ret.isNull())
153                return ret;
154        }
155        return ResourceManager::getByName(name);
156    }
157        //-----------------------------------------------------------------------------
158        GpuProgramParametersSharedPtr GpuProgramManager::createParameters(void)
159        {
160                return GpuProgramParametersSharedPtr(new GpuProgramParameters());
161        }
162
163}
Note: See TracBrowser for help on using the repository browser.