/src/ogre/OgreMain/include/OgreGpuProgramUsage.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __GpuProgramUsage_H__ |
29 | | #define __GpuProgramUsage_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | #include "OgreGpuProgram.h" |
33 | | #include "OgreHeaderPrefix.h" |
34 | | |
35 | | namespace Ogre |
36 | | { |
37 | | class Pass; |
38 | | |
39 | | /** \addtogroup Core |
40 | | * @{ |
41 | | */ |
42 | | /** \addtogroup Materials |
43 | | * @{ |
44 | | */ |
45 | | /** This class makes the usage of a vertex and fragment programs (low-level or high-level), |
46 | | with a given set of parameters, explicit. |
47 | | |
48 | | Using a vertex or fragment program can get fairly complex; besides the fairly rudimentary |
49 | | process of binding a program to the GPU for rendering, managing usage has few |
50 | | complications, such as: |
51 | | <ul> |
52 | | <li>Programs can be high level (e.g. Cg, RenderMonkey) or low level (assembler). Using |
53 | | either should be relatively seamless, although high-level programs give you the advantage |
54 | | of being able to use named parameters, instead of just indexed registers</li> |
55 | | <li>Programs and parameters can be shared between multiple usages, in order to save |
56 | | memory</li> |
57 | | <li>When you define a user of a program, such as a material, you often want to be able to |
58 | | set up the definition but not load / compile / assemble the program at that stage, because |
59 | | it is not needed just yet. The program should be loaded when it is first needed, or |
60 | | earlier if specifically requested. The program may not be defined at this time, you |
61 | | may want to have scripts that can set up the definitions independent of the order in which |
62 | | those scripts are loaded.</li> |
63 | | </ul> |
64 | | This class packages up those details so you don't have to worry about them. For example, |
65 | | this class lets you define a high-level program and set up the parameters for it, without |
66 | | having loaded the program (which you normally could not do). When the program is loaded and |
67 | | compiled, this class will then validate the parameters you supplied earlier and turn them |
68 | | into runtime parameters. |
69 | | @par |
70 | | Just in case it wasn't clear from the above, this class provides linkage to both |
71 | | GpuProgram and HighLevelGpuProgram, despite its name. |
72 | | */ |
73 | | class _OgreExport GpuProgramUsage : public Resource::Listener, public PassAlloc |
74 | | { |
75 | | private: |
76 | | Pass* mParent; |
77 | | /// The program link |
78 | | GpuProgramPtr mProgram; |
79 | | |
80 | | /// Program parameters |
81 | | GpuProgramParametersSharedPtr mParameters; |
82 | | |
83 | | /// Whether to recreate parameters next load |
84 | | bool mRecreateParams; |
85 | | GpuProgramType mType; |
86 | | |
87 | | void recreateParameters(); |
88 | | |
89 | | public: |
90 | | /** Default constructor. |
91 | | @param gptype The type of program to link to |
92 | | @param parent |
93 | | */ |
94 | | GpuProgramUsage(GpuProgramType gptype, Pass* parent); |
95 | | |
96 | | /** Copy constructor */ |
97 | | GpuProgramUsage(const GpuProgramUsage& rhs, Pass* newparent); |
98 | | |
99 | | ~GpuProgramUsage(); |
100 | | |
101 | | /** Gets the type of program we're trying to link to. */ |
102 | 0 | GpuProgramType getType(void) const { return mType; } |
103 | | |
104 | | /** Sets the name of the program to use. |
105 | | @param name The name of the program to use |
106 | | @param resetParams |
107 | | If true, this will create a fresh set of parameters from the |
108 | | new program being linked, so if you had previously set parameters |
109 | | you will have to set them again. If you set this to false, you must |
110 | | be absolutely sure that the parameters match perfectly, and in the |
111 | | case of named parameters refers to the indexes underlying them, |
112 | | not just the names. |
113 | | */ |
114 | | void setProgramName(const String& name, bool resetParams = true); |
115 | | /** Sets the program to use. |
116 | | |
117 | | Note that this will create a fresh set of parameters from the |
118 | | new program being linked, so if you had previously set parameters |
119 | | you will have to set them again. |
120 | | */ |
121 | | void setProgram(const GpuProgramPtr& prog, bool resetParams = true); |
122 | | /** Gets the program being used. */ |
123 | 0 | const GpuProgramPtr& getProgram() const { return mProgram; } |
124 | | /** Gets the program being used. */ |
125 | 0 | const String& getProgramName(void) const { return mProgram->getName(); } |
126 | | |
127 | | /** Sets the program parameters that should be used; because parameters can be |
128 | | shared between multiple usages for efficiency, this method is here for you |
129 | | to register externally created parameter objects. Otherwise, the parameters |
130 | | will be created for you when a program is linked. |
131 | | */ |
132 | | void setParameters(const GpuProgramParametersSharedPtr& params); |
133 | | /** Gets the parameters being used here. |
134 | | */ |
135 | | const GpuProgramParametersSharedPtr& getParameters(void) const; |
136 | | |
137 | | /// Load this usage (and ensure program is loaded) |
138 | | void _load(void); |
139 | | /// Unload this usage |
140 | | void _unload(void); |
141 | | |
142 | | size_t calculateSize(void) const; |
143 | | |
144 | | // Resource Listener |
145 | | void unloadingComplete(Resource* prog) override; |
146 | | void loadingComplete(Resource* prog) override; |
147 | | |
148 | | static GpuProgramPtr _getProgramByName(const String& name, const String& group, |
149 | | GpuProgramType type); |
150 | | }; |
151 | | /** @} */ |
152 | | /** @} */ |
153 | | } |
154 | | |
155 | | #include "OgreHeaderSuffix.h" |
156 | | |
157 | | #endif |