OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreRenderQueueSortingGrouping.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 __RenderQueueSortingGrouping_H__
29 #define __RenderQueueSortingGrouping_H__
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 #include "OgrePass.h"
34 #include "OgreRadixSort.h"
35 
36 namespace Ogre {
37 
49  {
54 
55  RenderablePass(Renderable* rend, Pass* p) :renderable(rend), pass(p) {}
56  };
57 
58 
67  {
68  public:
71 
78  virtual void visit(RenderablePass* rp) = 0;
79 
80  /* When visiting a collection grouped by pass, this is
81  called when the grouping pass changes.
82  @remarks
83  If this method is called, the RenderablePass visit
84  method will not be called for this collection. The
85  Renderable visit method will be called for each item
86  underneath the pass grouping level.
87  @return True to continue, false to skip the Renderables underneath
88  */
89  virtual bool visit(const Pass* p) = 0;
96  virtual void visit(Renderable* r) = 0;
97 
98 
99  };
100 
111  {
112  public:
122  {
124  OM_PASS_GROUP = 1,
126  OM_SORT_DESCENDING = 2,
130  OM_SORT_ASCENDING = 6
131  };
132 
133  protected:
136  {
137  bool _OgreExport operator()(const Pass* a, const Pass* b) const
138  {
139  // Sort by passHash, which is pass, then texture unit changes
140  uint32 hasha = a->getHash();
141  uint32 hashb = b->getHash();
142  if (hasha == hashb)
143  {
144  // Must differentTransparentQueueItemLessiate by pointer incase 2 passes end up with the same hash
145  return a < b;
146  }
147  else
148  {
149  return hasha < hashb;
150  }
151  }
152  };
155  {
156  const Camera* camera;
157 
159  : camera(cam)
160  {
161  }
162 
163  bool _OgreExport operator()(const RenderablePass& a, const RenderablePass& b) const
164  {
165  if (a.renderable == b.renderable)
166  {
167  // Same renderable, sort by pass hash
168  return a.pass->getHash() < b.pass->getHash();
169  }
170  else
171  {
172  // Different renderables, sort by depth
173  Real adepth = a.renderable->getSquaredViewDepth(camera);
174  Real bdepth = b.renderable->getSquaredViewDepth(camera);
175  if (Math::RealEqual(adepth, bdepth))
176  {
177  // Must return deterministic result, doesn't matter what
178  return a.pass < b.pass;
179  }
180  else
181  {
182  // Sort DESCENDING by depth (i.e. far objects first)
183  return (adepth > bdepth);
184  }
185  }
186 
187  }
188  };
189 
197 
200  {
202  {
203  return p.pass->getHash();
204  }
205  };
206 
209 
212  {
213  const Camera* camera;
214 
216  : camera(cam)
217  {
218  }
219 
220  float operator()(const RenderablePass& p) const
221  {
222  // Sort DESCENDING by depth (ie far objects first), use negative distance
223  // here because radix sorter always dealing with accessing sort
224  return static_cast<float>(- p.renderable->getSquaredViewDepth(camera));
225  }
226  };
227 
230 
233 
238 
240  void acceptVisitorGrouped(QueuedRenderableVisitor* visitor) const;
242  void acceptVisitorDescending(QueuedRenderableVisitor* visitor) const;
244  void acceptVisitorAscending(QueuedRenderableVisitor* visitor) const;
245 
246  public:
249 
251  void clear(void);
252 
258  void removePassGroup(Pass* p);
259 
266  {
267  mOrganisationMode = 0;
268  }
269 
276  {
277  mOrganisationMode |= om;
278  }
279 
281  void addRenderable(Pass* pass, Renderable* rend);
282 
286  void sort(const Camera* cam);
287 
294  void acceptVisitor(QueuedRenderableVisitor* visitor, OrganisationMode om) const;
295 
298  void merge( const QueuedRenderableCollection& rhs );
299  };
300 
321  {
322  protected:
323 
332 
334  void removePassEntry(Pass* p);
335 
337  void addSolidRenderable(Technique* pTech, Renderable* rend);
339  void addUnsortedTransparentRenderable(Technique* pTech, Renderable* rend);
341  void addTransparentRenderable(Technique* pTech, Renderable* rend);
342 
343  public:
345 
347 
353  { return mSolidsBasic; }
356  { return mTransparentsUnsorted; }
359  { return mTransparents; }
360 
361 
368  void resetOrganisationModes(void);
369 
376  void addOrganisationMode(QueuedRenderableCollection::OrganisationMode om);
377 
384  void defaultOrganisationMode(void);
385 
387  void addRenderable(Renderable* pRend, Technique* pTech);
388 
391  void sort(const Camera* cam);
392 
395  void clear(void);
396 
399  void merge( const RenderPriorityGroup* rhs );
400 
401 
402  };
403 
404 
413  {
414  public:
418  protected:
424 
425 
426  public:
428  : mParent(parent)
429  , mOrganisationMode(0)
430  {
431  }
432 
434  // destroy contents now
435  PriorityMap::iterator i;
436  for (i = mPriorityGroups.begin(); i != mPriorityGroups.end(); ++i)
437  {
438  OGRE_DELETE i->second;
439  }
440  }
441 
444  {
445  return PriorityMapIterator(mPriorityGroups.begin(), mPriorityGroups.end());
446  }
447 
450  {
451  return ConstPriorityMapIterator(mPriorityGroups.begin(), mPriorityGroups.end());
452  }
453 
455  void addRenderable(Renderable* pRend, Technique* pTech, ushort priority)
456  {
457  // Check if priority group is there
458  PriorityMap::iterator i = mPriorityGroups.find(priority);
459  RenderPriorityGroup* pPriorityGrp;
460  if (i == mPriorityGroups.end())
461  {
462  // Missing, create
463  pPriorityGrp = OGRE_NEW RenderPriorityGroup(this);
464  if (mOrganisationMode)
465  {
466  pPriorityGrp->resetOrganisationModes();
467  pPriorityGrp->addOrganisationMode((QueuedRenderableCollection::OrganisationMode)mOrganisationMode);
468  }
469 
470  mPriorityGroups.insert(PriorityMap::value_type(priority, pPriorityGrp));
471  }
472  else
473  {
474  pPriorityGrp = i->second;
475  }
476 
477  // Add
478  pPriorityGrp->addRenderable(pRend, pTech);
479 
480  }
481 
489  void clear(bool destroy = false)
490  {
491  PriorityMap::iterator i, iend;
492  iend = mPriorityGroups.end();
493  for (i = mPriorityGroups.begin(); i != iend; ++i)
494  {
495  if (destroy)
496  OGRE_DELETE i->second;
497  else
498  i->second->clear();
499  }
500 
501  if (destroy)
502  mPriorityGroups.clear();
503 
504  }
505 
513  {
514  mOrganisationMode = 0;
515 
516  PriorityMap::iterator i, iend;
517  iend = mPriorityGroups.end();
518  for (i = mPriorityGroups.begin(); i != iend; ++i)
519  {
520  i->second->resetOrganisationModes();
521  }
522  }
523 
531  {
532  mOrganisationMode |= om;
533 
534  PriorityMap::iterator i, iend;
535  iend = mPriorityGroups.end();
536  for (i = mPriorityGroups.begin(); i != iend; ++i)
537  {
538  i->second->addOrganisationMode(om);
539  }
540  }
541 
549  {
550  mOrganisationMode = 0;
551 
552  PriorityMap::iterator i, iend;
553  iend = mPriorityGroups.end();
554  for (i = mPriorityGroups.begin(); i != iend; ++i)
555  {
556  i->second->defaultOrganisationMode();
557  }
558  }
559 
562  void merge( const RenderQueueGroup* rhs )
563  {
565 
566  while( it.hasMoreElements() )
567  {
568  ushort priority = it.peekNextKey();
569  RenderPriorityGroup* pSrcPriorityGrp = it.getNext();
570  RenderPriorityGroup* pDstPriorityGrp;
571 
572  // Check if priority group is there
573  PriorityMap::iterator i = mPriorityGroups.find(priority);
574  if (i == mPriorityGroups.end())
575  {
576  // Missing, create
577  pDstPriorityGrp = OGRE_NEW RenderPriorityGroup( this );
578  if (mOrganisationMode)
579  {
580  pDstPriorityGrp->resetOrganisationModes();
581  pDstPriorityGrp->addOrganisationMode((QueuedRenderableCollection::OrganisationMode)mOrganisationMode);
582  }
583 
584  mPriorityGroups.insert(PriorityMap::value_type(priority, pDstPriorityGrp));
585  }
586  else
587  {
588  pDstPriorityGrp = i->second;
589  }
590 
591  // merge
592  pDstPriorityGrp->merge( pSrcPriorityGrp );
593  }
594  }
595  };
596 
601 }
602 
603 #endif
604 
605 
Functor for accessing sort value 1 for radix sort (Pass)
unsigned char uint8
Definition: OgrePlatform.h:422
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
void merge(const RenderQueueGroup *rhs)
Merge group of renderables.
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
RenderablePassList mSortedDescending
Sorted descending (can iterate backwards to get ascending)
#define _OgreExport
Definition: OgrePlatform.h:255
Struct associating a single Pass with a single Renderable.
std::vector< T, A > type
Class for performing a radix sort (fast comparison-less sort based on byte value) on various standard...
Definition: OgreRadixSort.h:88
Comparator to order objects by descending camera distance.
A grouping level underneath RenderQueue which groups renderables to be issued at coarsely the same ti...
void resetOrganisationModes(void)
Reset the organisation modes required for the solids in this group.
void addOrganisationMode(OrganisationMode om)
Add a required sorting / grouping mode to this collection when next used.
Collection of renderables by priority.
static RadixSort< RenderablePassList, RenderablePass, uint32 > msRadixSorter1
Radix sorter for accessing sort value 1 (Pass)
map< Pass *, RenderableList *, PassGroupLess >::type PassGroupRenderableMap
Map of pass to renderable lists, this is a grouping by pass.
ConstMapIterator< PriorityMap > ConstPriorityMapIterator
const QueuedRenderableCollection & getTransparentsUnsorted(void) const
Get the collection of transparent objects currently queued.
void addOrganisationMode(QueuedRenderableCollection::OrganisationMode om)
Add a required sorting / grouping mode for the solids in this group.
OrganisationMode
Organisation modes required for this collection.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:50
QueuedRenderableCollection mTransparents
Transparent list.
void resetOrganisationModes(void)
Reset the organisation modes required for the solids in this group.
RenderQueueGroup * mParent
Parent queue group.
void resetOrganisationModes(void)
Reset the organisation modes required for this collection.
Class defining a single pass of a Technique (of a Material), i.e.
Definition: OgrePass.h:78
static bool RealEqual(Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
Compare 2 reals, using tolerance for inaccuracies.
Abstract class defining the interface all renderable objects must implement.
void addOrganisationMode(QueuedRenderableCollection::OrganisationMode om)
Add a required sorting / grouping mode for the solids in this group.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
bool hasMoreElements() const
Returns true if there are more items in the collection.
Lowest level collection of renderables.
void defaultOrganisationMode(void)
Setthe sorting / grouping mode for the solids in this group to the default.
const QueuedRenderableCollection & getSolidsBasic(void) const
Get the collection of basic solids currently queued, this includes all solids when there are no shado...
Functor for descending sort value 2 for radix sort (distance)
uint8 mOrganisationMode
Bitmask of the organisation modes requested (for new priority groups)
vector< RenderablePass >::type RenderablePassList
Vector of RenderablePass objects, this is built on the assumption that vectors only ever increase in ...
RenderablePass(Renderable *rend, Pass *p)
void addRenderable(Renderable *pRend, Technique *pTech, ushort priority)
Add a renderable to this group, with the given priority.
KeyType peekNextKey(void) const
Returns the next(=current) key element in the collection, without advancing to the next...
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
uint8 mOrganisationMode
Bitmask of the organisation modes requested.
QueuedRenderableCollection mSolidsBasic
Solid pass list, used when no shadows, modulative shadows, or ambient passes for additive.
PassGroupRenderableMap mGrouped
Grouped.
#define OGRE_DELETE
Visitor interface for items in a QueuedRenderableCollection.
ConstPriorityMapIterator getIterator(void) const
Get a const iterator for browsing through child contents.
uint32 getHash(void) const
Gets the 'hash' of this pass, ie a precomputed number to use for sorting.
Definition: OgrePass.h:1425
unsigned short ushort
void clear(bool destroy=false)
Clears this group of renderables.
static RadixSort< RenderablePassList, RenderablePass, float > msRadixSorter2
Radix sorter for sort value 2 (distance)
QueuedRenderableCollection mTransparentsUnsorted
Unsorted transparent list.
void addRenderable(Renderable *pRend, Technique *pTech)
Add a renderable to this group.
PriorityMap mPriorityGroups
Map of RenderPriorityGroup objects.
#define OGRE_NEW
void merge(const RenderPriorityGroup *rhs)
Merge group of renderables.
Class to manage the scene object rendering queue.
Concrete IteratorWrapper for const access to the underlying key-value container.
const QueuedRenderableCollection & getTransparents(void) const
Get the collection of transparent objects currently queued.
MapIterator< PriorityMap > PriorityMapIterator
ValueType getNext()
Returns the next(=current) value element in the collection, and advances to the next.
Pass * pass
Pointer to the Pass.
virtual Real getSquaredViewDepth(const Camera *cam) const =0
Returns the camera-relative squared depth of this renderable.
bool _OgreExport operator()(const Pass *a, const Pass *b) const
bool _OgreExport operator()(const RenderablePass &a, const RenderablePass &b) const
map< ushort, RenderPriorityGroup *, std::less< ushort > >::type PriorityMap
PriorityMapIterator getIterator(void)
Get an iterator for browsing through child contents.
Renderable * renderable
Pointer to the Renderable details.