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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
26 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
27 | Torus Knot Software Ltd. |
---|
28 | ----------------------------------------------------------------------------- |
---|
29 | */ |
---|
30 | #include "OgreStableHeaders.h" |
---|
31 | #include "OgreGpuProgramUsage.h" |
---|
32 | #include "OgreGpuProgramManager.h" |
---|
33 | #include "OgreException.h" |
---|
34 | |
---|
35 | namespace 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 | } |
---|