OGRE  1.9.0
OgreRenderable.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __Renderable_H__
29#define __Renderable_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreCommon.h"
33
34#include "OgreRenderOperation.h"
35#include "OgreMatrix4.h"
36#include "OgreMaterial.h"
37#include "OgrePlane.h"
38#include "OgreGpuProgram.h"
39#include "OgreVector4.h"
40#include "OgreException.h"
42#include "OgreHeaderPrefix.h"
43
44namespace Ogre {
45
64 {
65 public:
72 public:
73 Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL) {}
75 virtual ~Renderable()
76 {
77 if (mRenderSystemData)
78 {
79 delete mRenderSystemData;
80 mRenderSystemData = NULL;
81 }
82 }
88 virtual const MaterialPtr& getMaterial(void) const = 0;
94 virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); }
97 virtual void getRenderOperation(RenderOperation& op) = 0;
98
123 virtual bool preRender(SceneManager* sm, RenderSystem* rsys)
124 { (void)sm; (void)rsys; return true; }
125
128 virtual void postRender(SceneManager* sm, RenderSystem* rsys)
129 { (void)sm; (void)rsys; }
130
143 virtual void getWorldTransforms(Matrix4* xform) const = 0;
144
153 virtual unsigned short getNumWorldTransforms(void) const { return 1; }
154
164 void setUseIdentityProjection(bool useIdentityProjection)
165 {
166 mUseIdentityProjection = useIdentityProjection;
167 }
168
178 bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
179
189 void setUseIdentityView(bool useIdentityView)
190 {
191 mUseIdentityView = useIdentityView;
192 }
193
203 bool getUseIdentityView(void) const { return mUseIdentityView; }
204
210 virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
211
216 virtual const LightList& getLights(void) const = 0;
217
224 virtual bool getCastsShadows(void) const { return false; }
225
241 void setCustomParameter(size_t index, const Vector4& value)
242 {
243 mCustomParameters[index] = value;
244 }
245
250 void removeCustomParameter(size_t index)
251 {
252 mCustomParameters.erase(index);
253 }
254
259 bool hasCustomParameter(size_t index) const
260 {
261 return mCustomParameters.find(index) != mCustomParameters.end();
262 }
263
268 const Vector4& getCustomParameter(size_t index) const
269 {
270 CustomParameterMap::const_iterator i = mCustomParameters.find(index);
271 if (i != mCustomParameters.end())
272 {
273 return i->second;
274 }
275 else
276 {
277 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
278 "Parameter at the given index was not found.",
279 "Renderable::getCustomParameter");
280 }
281 }
282
308 const GpuProgramParameters::AutoConstantEntry& constantEntry,
309 GpuProgramParameters* params) const
310 {
311 CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
312 if (i != mCustomParameters.end())
313 {
314 params->_writeRawConstant(constantEntry.physicalIndex, i->second,
315 constantEntry.elementCount);
316 }
317 }
318
324 virtual void setPolygonModeOverrideable(bool override)
325 {
326 mPolygonModeOverrideable = override;
327 }
328
332 virtual bool getPolygonModeOverrideable(void) const
333 {
334 return mPolygonModeOverrideable;
335 }
336
344 OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
345
349 OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
350
355 UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
356
361 const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
362
363
378 {
379 public:
381 virtual ~Visitor() { }
391 virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug,
392 Any* pAny = 0) = 0;
393 };
394
400 {
401 return mRenderSystemData;
402 }
407 virtual void setRenderSystemData(RenderSystemData * val) const
408 {
409 mRenderSystemData = val;
410 }
411
412
413 protected:
421 };
422
426} // namespace Ogre
427
428#include "OgreHeaderSuffix.h"
429
430#endif //__Renderable_H__
#define _OgreExport
#define OGRE_DEPRECATED
Variant type that can hold Any other type.
Definition OgreAny.h:57
A viewpoint from which the scene will be rendered.
Definition OgreCamera.h:87
Structure recording the use of an automatic parameter.
size_t elementCount
The number of elements per individual entry in this constant Used in case people used packed elements...
size_t physicalIndex
The target (physical) constant index.
Collects together the program parameters used for a GpuProgram.
void _writeRawConstant(size_t physicalIndex, const Vector4 &vec, size_t count=4)
Write a 4-element floating-point parameter to the program directly to the underlying constants buffer...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition OgreMatrix4.h:79
'New' rendering operation using vertex buffers.
Defines the functionality of a 3D API.
An internal class that should be used only by a render system for internal use.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
virtual ~Visitor()
Virtual destructor needed as class has virtual methods.
virtual void visit(Renderable *rend, ushort lodIndex, bool isDebug, Any *pAny=0)=0
Generic visitor method.
Abstract class defining the interface all renderable objects must implement.
RenderSystemData * mRenderSystemData
User objects binding.
virtual const LightList & getLights(void) const =0
Gets a list of lights, ordered relative to how close they are to this renderable.
void removeCustomParameter(size_t index)
Removes a custom value which is associated with this Renderable at the given index.
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
map< size_t, Vector4 >::type CustomParameterMap
virtual void setPolygonModeOverrideable(bool override)
Sets whether this renderable's chosen detail level can be overridden (downgraded) by the camera setti...
virtual Real getSquaredViewDepth(const Camera *cam) const =0
Returns the camera-relative squared depth of this renderable.
virtual void getRenderOperation(RenderOperation &op)=0
Gets the render operation required to send this object to the frame buffer.
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
virtual bool getCastsShadows(void) const
Method which reports whether this renderable would normally cast a shadow.
void setUseIdentityProjection(bool useIdentityProjection)
Sets whether or not to use an 'identity' projection.
virtual unsigned short getNumWorldTransforms(void) const
Returns the number of world transform matrices this renderable requires.
void setCustomParameter(size_t index, const Vector4 &value)
Sets a custom parameter for this Renderable, which may be used to drive calculations for this specifi...
virtual bool getPolygonModeOverrideable(void) const
Gets whether this renderable's chosen detail level can be overridden (downgraded) by the camera setti...
virtual void _updateCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry &constantEntry, GpuProgramParameters *params) const
Update a custom GpuProgramParameters constant which is derived from information only this Renderable ...
virtual void setRenderSystemData(RenderSystemData *val) const
Sets RenderSystem private data.
virtual void postRender(SceneManager *sm, RenderSystem *rsys)
Called immediately after the Renderable has been rendered.
CustomParameterMap mCustomParameters
bool hasCustomParameter(size_t index) const
Checks whether a custom value is associated with this Renderable at the given index.
bool getUseIdentityView(void) const
Returns whether or not to use an 'identity' view.
virtual void getWorldTransforms(Matrix4 *xform) const =0
Gets the world transform matrix / matrices for this renderable object.
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
UserObjectBindings mUserObjectBindings
virtual Technique * getTechnique(void) const
Retrieves a pointer to the Material Technique this renderable object uses.
virtual RenderSystemData * getRenderSystemData() const
Gets RenderSystem private data.
const Vector4 & getCustomParameter(size_t index) const
Gets the custom value associated with this Renderable at the given index.
void setUseIdentityView(bool useIdentityView)
Sets whether or not to use an 'identity' view.
virtual ~Renderable()
Virtual destructor needed as class has virtual methods.
virtual const MaterialPtr & getMaterial(void) const =0
Retrieves a weak reference to the material this renderable object uses.
bool getUseIdentityProjection(void) const
Returns whether or not to use an 'identity' projection.
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
virtual bool preRender(SceneManager *sm, RenderSystem *rsys)
Called just prior to the Renderable being rendered.
Manages the organisation and rendering of a 'scene' i.e.
Class representing an approach to rendering this particular Material.
Class that provides convenient interface to establish a linkage between custom user application objec...
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
#define OGRE_EXCEPT(code, desc, src)
float Real
Software floating point type.
unsigned short ushort
std::map< K, V, P, A > type