Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreGpuProgramUsage.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 3.9 KB
Line 
1
2/*
3-----------------------------------------------------------------------------
4This source file is part of OGRE
5    (Object-oriented Graphics Rendering Engine)
6For the latest info, see http://www.ogre3d.org/
7
8Copyright (c) 2000-2006 Torus Knot Software Ltd
9Also see acknowledgements in Readme.html
10
11This program is free software you can redistribute it and/or modify it under
12the terms of the GNU Lesser General Public License as published by the Free Software
13Foundation either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public License along with
21this program if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/copyleft/lesser.txt.
24
25You may alternatively use this source under the terms of a specific version of
26the OGRE Unrestricted License provided you have obtained such a license from
27Torus Knot Software Ltd.
28-----------------------------------------------------------------------------
29*/
30#include "OgreStableHeaders.h"
31#include "OgreGpuProgramUsage.h"
32#include "OgreGpuProgramManager.h"
33#include "OgreException.h"
34
35namespace Ogre
36{
37    //-----------------------------------------------------------------------------
38    GpuProgramUsage::GpuProgramUsage(GpuProgramType gptype) :
39        mType(gptype), mProgram()
40    {
41    }
42        //-----------------------------------------------------------------------------
43        GpuProgramUsage::GpuProgramUsage(const GpuProgramUsage& oth)
44        : mType(oth.mType)
45        , mProgram(oth.mProgram)
46        // nfz: parameters should be copied not just use a shared ptr to the original
47                , mParameters(new GpuProgramParameters(*oth.mParameters))
48        {
49        }
50        //-----------------------------------------------------------------------------
51        void GpuProgramUsage::setProgramName(const String& name, bool resetParams)
52        {
53                mProgram = GpuProgramManager::getSingleton().getByName(name);
54
55        if (mProgram.isNull())
56        {
57            String progType = (mType == GPT_VERTEX_PROGRAM ? "vertex" : "fragment");
58            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
59                "Unable to locate " + progType + " program called " + name + ".",
60                "GpuProgramUsage::setProgramName");
61        }
62        // Reset parameters
63        if (resetParams || mParameters.isNull())
64            mParameters = mProgram->createParameters();
65
66        }
67    //-----------------------------------------------------------------------------
68    void GpuProgramUsage::setParameters(GpuProgramParametersSharedPtr params)
69    {
70        mParameters = params;
71    }
72    //-----------------------------------------------------------------------------
73    GpuProgramParametersSharedPtr GpuProgramUsage::getParameters(void)
74    {
75        if (mParameters.isNull())
76        {
77            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "You must specify a program before "
78                "you can retrieve parameters.", "GpuProgramUsage::getParameters");
79        }
80
81        return mParameters;
82    }
83    //-----------------------------------------------------------------------------
84        void GpuProgramUsage::setProgram(GpuProgramPtr& prog) 
85        {
86        mProgram = prog;
87        // Reset parameters
88        mParameters = mProgram->createParameters();
89    }
90    //-----------------------------------------------------------------------------
91    void GpuProgramUsage::_load(void)
92    {
93        if (!mProgram->isLoaded())
94            mProgram->load();
95    }
96    //-----------------------------------------------------------------------------
97    void GpuProgramUsage::_unload(void)
98    {
99        // TODO?
100    }
101
102}
Note: See TracBrowser for help on using the repository browser.