OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-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 __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 #include "OgreHeaderPrefix.h"
43 
44 namespace Ogre {
45 
64  {
65  public:
71  class RenderSystemData {};
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  {
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 
377  class Visitor
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__
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
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:260
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
User objects binding.
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.
void removeCustomParameter(size_t index)
Removes a custom value which is associated with this Renderable at the given index.
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
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
Gets RenderSystem private data.
bool getUseIdentityView(void) const
Returns whether or not to use an 'identity' view.
#define OGRE_EXCEPT(code, desc, src)
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...
bool hasCustomParameter(size_t index) const
Checks whether a custom value is associated with this Renderable at the given index.
virtual ~Renderable()
Virtual destructor needed as class has virtual methods.
virtual void setRenderSystemData(RenderSystemData *val) const
Sets RenderSystem private data.
#define OGRE_DEPRECATED
Definition: OgrePlatform.h:192
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
Defines the functionality of a 3D API.
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
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 provides convenient interface to establish a linkage between custom user application objec...
virtual void postRender(SceneManager *sm, RenderSystem *rsys)
Called immediately after the Renderable has been rendered.