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