OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreRenderable.h
Go to the documentation of this file.
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-2011 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 __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"
41 #include "OgreUserObjectBindings.h"
42 
43 namespace Ogre {
44 
63  {
64  public:
70  class RenderSystemData {};
71  public:
72  Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL) {}
74  virtual ~Renderable()
75  {
76  if (mRenderSystemData)
77  {
78  delete mRenderSystemData;
79  mRenderSystemData = NULL;
80  }
81  }
87  virtual const MaterialPtr& getMaterial(void) const = 0;
93  virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); }
96  virtual void getRenderOperation(RenderOperation& op) = 0;
97 
122  virtual bool preRender(SceneManager* sm, RenderSystem* rsys)
123  { (void)sm; (void)rsys; return true; }
124 
127  virtual void postRender(SceneManager* sm, RenderSystem* rsys)
128  { (void)sm; (void)rsys; }
129 
142  virtual void getWorldTransforms(Matrix4* xform) const = 0;
143 
152  virtual unsigned short getNumWorldTransforms(void) const { return 1; }
153 
163  void setUseIdentityProjection(bool useIdentityProjection)
164  {
165  mUseIdentityProjection = useIdentityProjection;
166  }
167 
177  bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
178 
188  void setUseIdentityView(bool useIdentityView)
189  {
190  mUseIdentityView = useIdentityView;
191  }
192 
202  bool getUseIdentityView(void) const { return mUseIdentityView; }
203 
209  virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
210 
215  virtual const LightList& getLights(void) const = 0;
216 
223  virtual bool getCastsShadows(void) const { return false; }
224 
240  void setCustomParameter(size_t index, const Vector4& value)
241  {
242  mCustomParameters[index] = value;
243  }
244 
249  const Vector4& getCustomParameter(size_t index) const
250  {
251  CustomParameterMap::const_iterator i = mCustomParameters.find(index);
252  if (i != mCustomParameters.end())
253  {
254  return i->second;
255  }
256  else
257  {
259  "Parameter at the given index was not found.",
260  "Renderable::getCustomParameter");
261  }
262  }
263 
289  const GpuProgramParameters::AutoConstantEntry& constantEntry,
290  GpuProgramParameters* params) const
291  {
292  CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
293  if (i != mCustomParameters.end())
294  {
295  params->_writeRawConstant(constantEntry.physicalIndex, i->second,
296  constantEntry.elementCount);
297  }
298  }
299 
305  virtual void setPolygonModeOverrideable(bool override)
306  {
307  mPolygonModeOverrideable = override;
308  }
309 
313  virtual bool getPolygonModeOverrideable(void) const
314  {
315  return mPolygonModeOverrideable;
316  }
317 
325  virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
326 
330  virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
331 
336  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
337 
342  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
343 
344 
358  class Visitor
359  {
360  public:
362  virtual ~Visitor() { }
372  virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug,
373  Any* pAny = 0) = 0;
374  };
375 
381  {
382  return mRenderSystemData;
383  }
388  virtual void setRenderSystemData(RenderSystemData * val) const
389  {
390  mRenderSystemData = val;
391  }
392 
393 
394  protected:
400  UserObjectBindings mUserObjectBindings; // User objects binding.
401  mutable RenderSystemData * mRenderSystemData;// this should be used only by a render system for internal use
402  };
403 
408 }
409 
410 #endif //__Renderable_H__
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
bool getUseIdentityProjection(void) const
Returns whether or not to use an 'identity' projection.
float Real
Software floating point type.
virtual ~Visitor()
Virtual destructor needed as class has virtual methods.
#define _OgreExport
Definition: OgrePlatform.h:203
void setUseIdentityView(bool useIdentityView)
Sets whether or not to use an 'identity' view.
size_t elementCount
The number of elements per individual entry in this constant Used in case people used packed elements...
virtual bool getPolygonModeOverrideable(void) const
Gets whether this renderable's chosen detail level can be overridden (downgraded) by the camera setti...
Variant type that can hold Any other type.
Definition: OgreAny.h:56
CustomParameterMap mCustomParameters
virtual void _updateCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry &constantEntry, GpuProgramParameters *params) const
Update a custom GpuProgramParameters constant which is derived from information only this Renderable ...
Manages the organisation and rendering of a 'scene' i.e.
const Vector4 & getCustomParameter(size_t index) const
Gets the custom value associated with this Renderable at the given index.
virtual bool getCastsShadows(void) const
Method which reports whether this renderable would normally cast a shadow.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
void setUseIdentityProjection(bool useIdentityProjection)
Sets whether or not to use an 'identity' projection.
RenderSystemData * mRenderSystemData
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...
Abstract class defining the interface all renderable objects must implement.
virtual bool preRender(SceneManager *sm, RenderSystem *rsys)
Called just prior to the Renderable being rendered.
Structure recording the use of an automatic parameter.
virtual void setPolygonModeOverrideable(bool override)
Sets whether this renderable's chosen detail level can be overridden (downgraded) by the camera setti...
virtual unsigned short getNumWorldTransforms(void) const
Returns the number of world transform matrices this renderable requires.
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
#define OGRE_EXCEPT(num, desc, src)
Collects together the program parameters used for a GpuProgram.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
virtual Technique * getTechnique(void) const
Retrieves a pointer to the Material Technique this renderable object uses.
virtual RenderSystemData * getRenderSystemData() const
Sets render system private data.
virtual const Any & getUserAny(void) const
bool getUseIdentityView(void) const
Returns whether or not to use an 'identity' view.
UserObjectBindings mUserObjectBindings
unsigned short ushort
'New' rendering operation using vertex buffers.
size_t data
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...
virtual ~Renderable()
Virtual destructor needed as class has virtual methods.
virtual void setRenderSystemData(RenderSystemData *val) const
gets render system private data
virtual void setUserAny(const Any &anything)
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
Defines the functionality of a 3D API.
size_t physicalIndex
The target (physical) constant index.
map< size_t, Vector4 >::type CustomParameterMap
An internal class that should be used only by a render system for internal use.
Class that provide convenient interface to establish a linkage between custom user application object...
virtual void postRender(SceneManager *sm, RenderSystem *rsys)
Called immediately after the Renderable has been rendered.