1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __Renderable_H__
|
---|
26 | #define __Renderable_H__
|
---|
27 |
|
---|
28 | #include "OgrePrerequisites.h"
|
---|
29 | #include "OgreCommon.h"
|
---|
30 |
|
---|
31 | #include "OgreRenderOperation.h"
|
---|
32 | #include "OgreMatrix4.h"
|
---|
33 | #include "OgreMaterial.h"
|
---|
34 | #include "OgrePlane.h"
|
---|
35 | #include "OgreGpuProgram.h"
|
---|
36 | #include "OgreVector4.h"
|
---|
37 | #include "OgreException.h"
|
---|
38 |
|
---|
39 | namespace Ogre {
|
---|
40 |
|
---|
41 | /** Abstract class defining the interface all renderable objects must implement.
|
---|
42 | @remarks
|
---|
43 | This interface abstracts renderable discrete objects which will be queued in the render pipeline,
|
---|
44 | grouped by material. Classes implementing this interface must be based on a single material, a single
|
---|
45 | world matrix (or a collection of world matrices which are blended by weights), and must be
|
---|
46 | renderable via a single render operation.
|
---|
47 | @par
|
---|
48 | Note that deciding whether to put these objects in the rendering pipeline is done from the more specific
|
---|
49 | classes e.g. entities. Only once it is decided that the specific class is to be rendered is the abstract version
|
---|
50 | created (could be more than one per visible object) and pushed onto the rendering queue.
|
---|
51 | */
|
---|
52 | class _OgreExport Renderable
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | Renderable() : mPolygonModeOverrideable(true)
|
---|
56 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
57 | , mId(-1)
|
---|
58 | #endif // GTP_VISIBILITY_MODIFIED_OGRE
|
---|
59 |
|
---|
60 |
|
---|
61 | {
|
---|
62 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
63 | this->mRenderTechniqueGroup = 0;
|
---|
64 | #endif
|
---|
65 | }
|
---|
66 |
|
---|
67 | /** Virtual destructor needed as class has virtual methods. */
|
---|
68 | virtual ~Renderable() { }
|
---|
69 | /** Retrieves a weak reference to the material this renderable object uses.
|
---|
70 | @remarks
|
---|
71 | Note that the Renderable also has the option to override the getTechnique method
|
---|
72 | to specify a particular Technique to use instead of the best one available.
|
---|
73 | */
|
---|
74 | virtual const MaterialPtr& getMaterial(void) const = 0;
|
---|
75 | /** Retrieves a pointer to the Material Technique this renderable object uses.
|
---|
76 | @remarks
|
---|
77 | This is to allow Renderables to use a chosen Technique if they wish, otherwise
|
---|
78 | they will use the best Technique available for the Material they are using.
|
---|
79 | */
|
---|
80 | virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(); }
|
---|
81 | /** Gets the render operation required to send this object to the frame buffer.
|
---|
82 | */
|
---|
83 | virtual void getRenderOperation(RenderOperation& op) = 0;
|
---|
84 | /** Gets the world transform matrix / matrices for this renderable object.
|
---|
85 | @remarks
|
---|
86 | If the object has any derived transforms, these are expected to be up to date as long as
|
---|
87 | all the SceneNode structures have been updated before this is called.
|
---|
88 | @par
|
---|
89 | This method will populate xform with 1 matrix if it does not use vertex blending. If it
|
---|
90 | does use vertex blending it will fill the passed in pointer with an array of matrices,
|
---|
91 | the length being the value returned from getNumWorldTransforms.
|
---|
92 | */
|
---|
93 | virtual void getWorldTransforms(Matrix4* xform) const = 0;
|
---|
94 | /** Gets the worldspace orientation of this renderable; this is used in order to
|
---|
95 | more efficiently update parameters to vertex & fragment programs, since inverting Quaterion
|
---|
96 | and Vector in order to derive object-space positions / directions for cameras and
|
---|
97 | lights is much more efficient than inverting a complete 4x4 matrix, and also
|
---|
98 | eliminates problems introduced by scaling. */
|
---|
99 | virtual const Quaternion& getWorldOrientation(void) const = 0;
|
---|
100 | /** Gets the worldspace orientation of this renderable; this is used in order to
|
---|
101 | more efficiently update parameters to vertex & fragment programs, since inverting Quaterion
|
---|
102 | and Vector in order to derive object-space positions / directions for cameras and
|
---|
103 | lights is much more efficient than inverting a complete 4x4 matrix, and also
|
---|
104 | eliminates problems introduced by scaling. */
|
---|
105 | virtual const Vector3& getWorldPosition(void) const = 0;
|
---|
106 |
|
---|
107 | /** Returns the number of world transform matrices this renderable requires.
|
---|
108 | @remarks
|
---|
109 | When a renderable uses vertex blending, it uses multiple world matrices instead of a single
|
---|
110 | one. Each vertex sent to the pipeline can reference one or more matrices in this list
|
---|
111 | with given weights.
|
---|
112 | If a renderable does not use vertex blending this method returns 1, which is the default for
|
---|
113 | simplicity.
|
---|
114 | */
|
---|
115 | virtual unsigned short getNumWorldTransforms(void) const { return 1; }
|
---|
116 |
|
---|
117 | /** Returns whether or not to use an 'identity' projection.
|
---|
118 | @remarks
|
---|
119 | Usually Renderable objects will use a projection matrix as determined
|
---|
120 | by the active camera. However, if they want they can cancel this out
|
---|
121 | and use an identity projection, which effectively projects in 2D using
|
---|
122 | a {-1, 1} view space. Useful for overlay rendering. Normal renderables need
|
---|
123 | not override this.
|
---|
124 | */
|
---|
125 | virtual bool useIdentityProjection(void) const { return false; }
|
---|
126 |
|
---|
127 | /** Returns whether or not to use an 'identity' projection.
|
---|
128 | @remarks
|
---|
129 | Usually Renderable objects will use a view matrix as determined
|
---|
130 | by the active camera. However, if they want they can cancel this out
|
---|
131 | and use an identity matrix, which means all geometry is assumed
|
---|
132 | to be relative to camera space already. Useful for overlay rendering.
|
---|
133 | Normal renderables need not override this.
|
---|
134 | */
|
---|
135 | virtual bool useIdentityView(void) const { return false; }
|
---|
136 |
|
---|
137 | /** Returns the camera-relative squared depth of this renderable.
|
---|
138 | @remarks
|
---|
139 | Used to sort transparent objects. Squared depth is used rather than
|
---|
140 | actual depth to avoid having to perform a square root on the result.
|
---|
141 | */
|
---|
142 | virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
|
---|
143 |
|
---|
144 | /** Returns whether or not this Renderable wishes the hardware to normalise normals. */
|
---|
145 | virtual bool getNormaliseNormals(void) const { return false; }
|
---|
146 |
|
---|
147 | /** Gets a list of lights, ordered relative to how close they are to this renderable.
|
---|
148 | @remarks
|
---|
149 | Directional lights, which have no position, will always be first on this list.
|
---|
150 | */
|
---|
151 | virtual const LightList& getLights(void) const = 0;
|
---|
152 |
|
---|
153 | virtual const PlaneList& getClipPlanes() const { return msDummyPlaneList; };
|
---|
154 |
|
---|
155 | /** Method which reports whether this renderable would normally cast a
|
---|
156 | shadow.
|
---|
157 | @remarks
|
---|
158 | Subclasses should override this if they could have been used to
|
---|
159 | generate a shadow.
|
---|
160 | */
|
---|
161 | virtual bool getCastsShadows(void) const { return false; }
|
---|
162 |
|
---|
163 | /** Sets a custom parameter for this Renderable, which may be used to
|
---|
164 | drive calculations for this specific Renderable, like GPU program parameters.
|
---|
165 | @remarks
|
---|
166 | Calling this method simply associates a numeric index with a 4-dimensional
|
---|
167 | value for this specific Renderable. This is most useful if the material
|
---|
168 | which this Renderable uses a vertex or fragment program, and has an
|
---|
169 | ACT_CUSTOM parameter entry. This parameter entry can refer to the
|
---|
170 | index you specify as part of this call, thereby mapping a custom
|
---|
171 | parameter for this renderable to a program parameter.
|
---|
172 | @param index The index with which to associate the value. Note that this
|
---|
173 | does not have to start at 0, and can include gaps. It also has no direct
|
---|
174 | correlation with a GPU program parameter index - the mapping between the
|
---|
175 | two is performed by the ACT_CUSTOM entry, if that is used.
|
---|
176 | @param value The value to associate.
|
---|
177 | */
|
---|
178 | void setCustomParameter(size_t index, const Vector4& value)
|
---|
179 | {
|
---|
180 | mCustomParameters[index] = value;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /** Gets the custom value associated with this Renderable at the given index.
|
---|
184 | @param
|
---|
185 | @see setCustomParaemter for full details.
|
---|
186 | */
|
---|
187 | const Vector4& getCustomParameter(size_t index) const
|
---|
188 | {
|
---|
189 | CustomParameterMap::const_iterator i = mCustomParameters.find(index);
|
---|
190 | if (i != mCustomParameters.end())
|
---|
191 | {
|
---|
192 | return i->second;
|
---|
193 | }
|
---|
194 | else
|
---|
195 | {
|
---|
196 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
197 | "Parameter at the given index was not found.",
|
---|
198 | "Renderable::getCustomParameter");
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | /** Update a custom GpuProgramParameters constant which is derived from
|
---|
203 | information only this Renderable knows.
|
---|
204 | @remarks
|
---|
205 | This method allows a Renderable to map in a custom GPU program parameter
|
---|
206 | based on it's own data. This is represented by a GPU auto parameter
|
---|
207 | of ACT_CUSTOM, and to allow there to be more than one of these per
|
---|
208 | Renderable, the 'data' field on the auto parameter will identify
|
---|
209 | which parameter is being updated. The implementation of this method
|
---|
210 | must identify the parameter being updated, and call a 'setConstant'
|
---|
211 | method on the passed in GpuProgramParameters object, using the details
|
---|
212 | provided in the incoming auto constant setting to identify the index
|
---|
213 | at which to set the parameter.
|
---|
214 | @par
|
---|
215 | You do not need to override this method if you're using the standard
|
---|
216 | sets of data associated with the Renderable as provided by setCustomParameter
|
---|
217 | and getCustomParameter. By default, the implementation will map from the
|
---|
218 | value indexed by the 'constantEntry.data' parameter to a value previously
|
---|
219 | set by setCustomParameter. But custom Renderables are free to override
|
---|
220 | this if they want, in any case.
|
---|
221 | @param constantEntry The auto constant entry referring to the parameter
|
---|
222 | being updated
|
---|
223 | @param params The parameters object which this method should call to
|
---|
224 | set the updated parameters.
|
---|
225 | */
|
---|
226 | virtual void _updateCustomGpuParameter(
|
---|
227 | const GpuProgramParameters::AutoConstantEntry& constantEntry,
|
---|
228 | GpuProgramParameters* params) const
|
---|
229 | {
|
---|
230 | CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
|
---|
231 | if (i != mCustomParameters.end())
|
---|
232 | {
|
---|
233 | params->setConstant(constantEntry.index, i->second);
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | /** Sets whether this renderable's chosen detail level can be
|
---|
238 | overridden (downgraded) by the camera setting.
|
---|
239 | @param override true means that a lower camera detail will override this
|
---|
240 | renderables detail level, false means it won't.
|
---|
241 | */
|
---|
242 | virtual void setPolygonModeOverrideable(bool override)
|
---|
243 | {
|
---|
244 | mPolygonModeOverrideable = override;
|
---|
245 | }
|
---|
246 |
|
---|
247 | /** Gets whether this renderable's chosen detail level can be
|
---|
248 | overridden (downgraded) by the camera setting.
|
---|
249 | */
|
---|
250 | virtual bool getPolygonModeOverrideable(void) const
|
---|
251 | {
|
---|
252 | return mPolygonModeOverrideable;
|
---|
253 | }
|
---|
254 |
|
---|
255 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
256 | /** Sets an id for this renderable.
|
---|
257 | */
|
---|
258 | void setId(int id) {mId = id;}
|
---|
259 | /** see set
|
---|
260 | */
|
---|
261 | int getId() {return mId;}
|
---|
262 | #endif // GTP_VISIBILITY_MODIFIED_OGRE
|
---|
263 | protected:
|
---|
264 | static const PlaneList msDummyPlaneList;
|
---|
265 | typedef std::map<size_t, Vector4> CustomParameterMap;
|
---|
266 | CustomParameterMap mCustomParameters;
|
---|
267 | bool mPolygonModeOverrideable;
|
---|
268 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
269 | int mId;
|
---|
270 | #endif // GTP_VISIBILITY_MODIFIED_OGRE
|
---|
271 |
|
---|
272 |
|
---|
273 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
274 | public:
|
---|
275 |
|
---|
276 | virtual void setRenderTechniqueGroup(UserDefinedObject* renderTechniqueGroup)
|
---|
277 | {
|
---|
278 | this->mRenderTechniqueGroup = renderTechniqueGroup;
|
---|
279 | }
|
---|
280 |
|
---|
281 | virtual UserDefinedObject* getRenderTechniqueGroup(void) const
|
---|
282 | {
|
---|
283 | return this->mRenderTechniqueGroup;
|
---|
284 | }
|
---|
285 |
|
---|
286 | virtual void setMaterialName(const String &name){}
|
---|
287 |
|
---|
288 | protected:
|
---|
289 |
|
---|
290 | UserDefinedObject* mRenderTechniqueGroup;
|
---|
291 | #endif
|
---|
292 |
|
---|
293 | };
|
---|
294 |
|
---|
295 |
|
---|
296 |
|
---|
297 | }
|
---|
298 |
|
---|
299 | #endif //__Renderable_H__
|
---|