source: OGRE/trunk/ogrenew/OgreMain/src/OgreHighLevelGpuProgram.cpp @ 657

Revision 657, 4.9 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

RevLine 
[657]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 "OgreHighLevelGpuProgram.h"
27#include "OgreException.h"
28#include "OgreGpuProgramManager.h"
29
30namespace Ogre
31{
32    //---------------------------------------------------------------------------
33    HighLevelGpuProgram::HighLevelGpuProgram(ResourceManager* creator,
34        const String& name, ResourceHandle handle, const String& group,
35        bool isManual, ManualResourceLoader* loader)
36        : GpuProgram(creator, name, handle, group, isManual, loader),
37        mHighLevelLoaded(false), mAssemblerProgram(0)
38    {
39    }
40    //---------------------------------------------------------------------------
41    void HighLevelGpuProgram::loadImpl()
42    {
43        // load self
44        loadHighLevel();
45
46        // create low-level implementation
47        createLowLevelImpl();
48        // load constructed assembler program (if it exists)
49                if (!mAssemblerProgram.isNull())
50                {
51                        mAssemblerProgram->load();
52                        mIsLoaded = true;
53                }
54    }
55    //---------------------------------------------------------------------------
56    void HighLevelGpuProgram::unloadImpl()
57    {   
58        if (!mAssemblerProgram.isNull())
59        {
60            mAssemblerProgram->getCreator()->remove(mAssemblerProgram->getHandle());
61            mAssemblerProgram.setNull();
62        }
63
64        unloadHighLevel();
65    }
66    //---------------------------------------------------------------------------
67    HighLevelGpuProgram::~HighLevelGpuProgram()
68    {
69        // superclasses will trigger unload
70    }
71    //---------------------------------------------------------------------------
72    GpuProgramParametersSharedPtr HighLevelGpuProgram::createParameters(void)
73    {
74        // Make sure param defs are loaded
75        GpuProgramParametersSharedPtr params = GpuProgramManager::getSingleton().createParameters();
76                // Only populate named parameters if we can support this program
77                if (this->isSupported())
78                {
79                        loadHighLevel();
80                        populateParameterNames(params);
81                }
82                // Copy in default parameters if present
83                if (!mDefaultParams.isNull())
84                        params->copyConstantsFrom(*(mDefaultParams.get()));
85        return params;
86    }
87    //---------------------------------------------------------------------------
88    void HighLevelGpuProgram::loadHighLevel(void)
89    {
90        if (!mHighLevelLoaded)
91        {
92            loadHighLevelImpl();
93            mHighLevelLoaded = true;
94        }
95    }
96    //---------------------------------------------------------------------------
97    void HighLevelGpuProgram::unloadHighLevel(void)
98    {
99        if (mHighLevelLoaded)
100        {
101            unloadHighLevelImpl();
102            mHighLevelLoaded = false;
103        }
104    }
105    //---------------------------------------------------------------------------
106    void HighLevelGpuProgram::loadHighLevelImpl(void)
107    {
108        if (mLoadFromFile)
109        {
110            // find & load source code
111            DataStreamPtr stream =
112                ResourceGroupManager::getSingleton().openResource(
113                    mFilename, mGroup);
114
115            mSource = stream->getAsString();
116        }
117
118        loadFromSource();
119    }
120        //-----------------------------------------------------------------------
121        //-----------------------------------------------------------------------
122        HighLevelGpuProgramPtr& HighLevelGpuProgramPtr::operator=(const GpuProgramPtr& r)
123        {
124                // Can assign direct
125                if (pRep == static_cast<HighLevelGpuProgram*>(r.getPointer()))
126                        return *this;
127                release();
128                // lock & copy other mutex pointer
129                OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
130                OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
131                pRep = static_cast<HighLevelGpuProgram*>(r.getPointer());
132                pUseCount = r.useCountPointer();
133                if (pUseCount)
134                {
135                        ++(*pUseCount);
136                }
137                return *this;
138        }
139
140
141}
Note: See TracBrowser for help on using the repository browser.