OGRE  2.0
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 "OgreGpuProgram.h"
35 #include "OgreGpuProgramParams.h"
36 #include "OgreMatrix4.h"
37 #include "OgreMaterial.h"
38 #include "OgrePlane.h"
39 #include "OgreVector4.h"
40 #include "OgreException.h"
41 #include "OgreUserObjectBindings.h"
42 #include "OgreHlms.h"
43 #include "OgreHeaderPrefix.h"
44 
45 namespace Ogre {
46 
65  {
66  public:
72  class RenderSystemData {};
73  public:
74  Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL) {}
76  virtual ~Renderable()
77  {
78  if (mRenderSystemData)
79  {
80  delete mRenderSystemData;
81  mRenderSystemData = NULL;
82  }
83  }
89  virtual const MaterialPtr& getMaterial(void) const = 0;
95  virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); }
98  virtual void getRenderOperation(RenderOperation& op) = 0;
99 
124  virtual bool preRender(SceneManager* sm, RenderSystem* rsys)
125  { (void)sm; (void)rsys; return true; }
126 
129  virtual void postRender(SceneManager* sm, RenderSystem* rsys)
130  { (void)sm; (void)rsys; }
131 
144  virtual void getWorldTransforms(Matrix4* xform) const = 0;
145 
154  virtual unsigned short getNumWorldTransforms(void) const { return 1; }
155 
165  void setUseIdentityProjection(bool useIdentityProjection)
166  {
167  mUseIdentityProjection = useIdentityProjection;
168  }
169 
179  bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
180 
190  void setUseIdentityView(bool useIdentityView)
191  {
192  mUseIdentityView = useIdentityView;
193  }
194 
204  bool getUseIdentityView(void) const { return mUseIdentityView; }
205 
211  virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
212 
217  virtual const LightList& getLights(void) const = 0;
218 
225  virtual bool getCastsShadows(void) const { return false; }
226 
242  void setCustomParameter(size_t index, const Vector4& value)
243  {
244  mCustomParameters[index] = value;
245  }
246 
251  void removeCustomParameter(size_t index)
252  {
253  mCustomParameters.erase(index);
254  }
255 
260  bool hasCustomParameter(size_t index) const
261  {
262  return mCustomParameters.find(index) != mCustomParameters.end();
263  }
264 
269  const Vector4& getCustomParameter(size_t index) const
270  {
271  CustomParameterMap::const_iterator i = mCustomParameters.find(index);
272  if (i != mCustomParameters.end())
273  {
274  return i->second;
275  }
276  else
277  {
279  "Parameter at the given index was not found.",
280  "Renderable::getCustomParameter");
281  }
282  }
283 
309  const GpuProgramParameters::AutoConstantEntry& constantEntry,
310  GpuProgramParameters* params) const
311  {
312  CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
313  if (i != mCustomParameters.end())
314  {
315  params->_writeRawConstant(constantEntry.physicalIndex, i->second,
316  constantEntry.elementCount);
317  }
318  }
319 
325  virtual void setPolygonModeOverrideable(bool override)
326  {
327  mPolygonModeOverrideable = override;
328  }
329 
333  virtual bool getPolygonModeOverrideable(void) const
334  {
335  return mPolygonModeOverrideable;
336  }
337 
345  OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
346 
350  OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
351 
356  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
357 
362  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
363 
364 
378  class Visitor
379  {
380  public:
382  virtual ~Visitor() { }
392  virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug,
393  Any* pAny = 0) = 0;
394  };
395 
401  {
402  return mRenderSystemData;
403  }
408  virtual void setRenderSystemData(RenderSystemData * val) const
409  {
410  mRenderSystemData = val;
411  }
412 
413  uint32 getHlmsHash(void) const { return mHlmsHash; }
414  uint32 getHlmsCasterHash(void) const { return mHlmsCasterHash; }
415 
416  void setHlms( Hlms *hlms, const HlmsParamVec &params )
417  {
418  hlms->calculateHashFor( this, params, mHlmsHash, mHlmsCasterHash );
419  }
420 
421  protected:
431  };
432 
436 } // namespace Ogre
437 
438 #include "OgreHeaderSuffix.h"
439 #endif //__Renderable_H__
uint32 getHlmsHash(void) const
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
bool getUseIdentityProjection(void) const
Returns whether or not to use an 'identity' projection.
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
virtual ~Visitor()
Virtual destructor needed as class has virtual methods.
#define _OgreExport
Definition: OgrePlatform.h:255
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:54
CustomParameterMap mCustomParameters
vector< std::pair< IdString, String > >::type HlmsParamVec
virtual void _updateCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry &constantEntry, GpuProgramParameters *params) const
Update a custom GpuProgramParameters constant which is derived from information only this Renderable ...
void setHlms(Hlms *hlms, const HlmsParamVec &params)
Manages the organisation and rendering of a 'scene' i.e.
HLMS stands for "High Level Material System".
Definition: OgreHlms.h:46
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:50
uint32 getHlmsCasterHash(void) const
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.
#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
Gets RenderSystem private data.
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...
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:185
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
virtual void calculateHashFor(Renderable *renderable, const HlmsParamVec &params, uint32 &outHash, uint32 &outCasterHash)
Called by the renderable when either it changes the material, or its properties change (e...
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.