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-2013 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 | @remarks |
---|
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 incase 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 | protected: |
---|
76 | GpuProgramType mType; |
---|
77 | Pass* mParent; |
---|
78 | /// The program link |
---|
79 | GpuProgramPtr mProgram; |
---|
80 | |
---|
81 | /// Program parameters |
---|
82 | GpuProgramParametersSharedPtr mParameters; |
---|
83 | |
---|
84 | /// Whether to recreate parameters next load |
---|
85 | bool mRecreateParams; |
---|
86 | |
---|
87 | void recreateParameters(); |
---|
88 | |
---|
89 | public: |
---|
90 | /** Default constructor. |
---|
91 | @param gptype The type of program to link to |
---|
92 | */ |
---|
93 | GpuProgramUsage(GpuProgramType gptype, Pass* parent); |
---|
94 | |
---|
95 | /** Copy constructor */ |
---|
96 | GpuProgramUsage(const GpuProgramUsage& rhs, Pass* newparent); |
---|
97 | |
---|
98 | ~GpuProgramUsage(); |
---|
99 | |
---|
100 | /** Gets the type of program we're trying to link to. */ |
---|
101 | GpuProgramType getType(void) const { return mType; } |
---|
102 | |
---|
103 | /** Sets the name of the program to use. |
---|
104 | @param name The name of the program to use |
---|
105 | @param resetParams |
---|
106 | If true, this will create a fresh set of parameters from the |
---|
107 | new program being linked, so if you had previously set parameters |
---|
108 | you will have to set them again. If you set this to false, you must |
---|
109 | be absolutely sure that the parameters match perfectly, and in the |
---|
110 | case of named parameters refers to the indexes underlying them, |
---|
111 | not just the names. |
---|
112 | */ |
---|
113 | void setProgramName(const String& name, bool resetParams = true); |
---|
114 | /** Sets the program to use. |
---|
115 | @remarks |
---|
116 | Note that this will create a fresh set of parameters from the |
---|
117 | new program being linked, so if you had previously set parameters |
---|
118 | you will have to set them again. |
---|
119 | */ |
---|
120 | void setProgram(GpuProgramPtr& prog); |
---|
121 | /** Gets the program being used. */ |
---|
122 | const GpuProgramPtr& getProgram() const { return mProgram; } |
---|
123 | /** Gets the program being used. */ |
---|
124 | const String& getProgramName(void) const { return mProgram->getName(); } |
---|
125 | |
---|
126 | /** Sets the program parameters that should be used; because parameters can be |
---|
127 | shared between multiple usages for efficiency, this method is here for you |
---|
128 | to register externally created parameter objects. Otherwise, the parameters |
---|
129 | will be created for you when a program is linked. |
---|
130 | */ |
---|
131 | void setParameters(GpuProgramParametersSharedPtr params); |
---|
132 | /** Gets the parameters being used here. |
---|
133 | */ |
---|
134 | GpuProgramParametersSharedPtr getParameters(void); |
---|
135 | |
---|
136 | /// Load this usage (and ensure program is loaded) |
---|
137 | void _load(void); |
---|
138 | /// Unload this usage |
---|
139 | void _unload(void); |
---|
140 | |
---|
141 | size_t calculateSize(void) const; |
---|
142 | |
---|
143 | // Resource Listener |
---|
144 | void unloadingComplete(Resource* prog); |
---|
145 | void loadingComplete(Resource* prog); |
---|
146 | |
---|
147 | }; |
---|
148 | /** @} */ |
---|
149 | /** @} */ |
---|
150 | } |
---|
151 | |
---|
152 | #include "OgreHeaderSuffix.h" |
---|
153 | |
---|
154 | #endif |
---|