2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSGUTIL_RENDERBIN
|
|
|
|
#define OSGUTIL_RENDERBIN 1
|
|
|
|
|
2005-10-13 20:51:00 +08:00
|
|
|
#include <osgUtil/StateGraph>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
class RenderStage;
|
2003-07-15 21:46:19 +08:00
|
|
|
class Statistics;
|
2001-09-20 05:19:47 +08:00
|
|
|
/**
|
2004-09-27 02:39:34 +08:00
|
|
|
* RenderBin base class. Renderbin contains geometries to be rendered as a group,
|
|
|
|
* renderbins are rendered once each. They can improve efficiency or
|
|
|
|
* use different rendering algorithms.
|
|
|
|
* A renderBin can contain further renderBins producing a tree hierarchy of renderBins.
|
2001-09-20 05:19:47 +08:00
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT RenderBin : public osg::Object
|
|
|
|
{
|
|
|
|
public:
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
typedef std::vector<RenderLeaf*> RenderLeafList;
|
2005-10-13 20:51:00 +08:00
|
|
|
typedef std::vector<StateGraph*> StateGraphList;
|
2001-09-20 05:19:47 +08:00
|
|
|
typedef std::map< int, osg::ref_ptr<RenderBin> > RenderBinList;
|
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
enum SortMode
|
|
|
|
{
|
|
|
|
SORT_BY_STATE,
|
2005-05-19 23:17:53 +08:00
|
|
|
SORT_BY_STATE_THEN_FRONT_TO_BACK,
|
2002-09-17 23:47:23 +08:00
|
|
|
SORT_FRONT_TO_BACK,
|
2009-05-27 17:54:17 +08:00
|
|
|
SORT_BACK_TO_FRONT,
|
|
|
|
TRAVERSAL_ORDER
|
2002-09-17 23:47:23 +08:00
|
|
|
};
|
|
|
|
|
2005-05-19 23:17:53 +08:00
|
|
|
// static methods.
|
|
|
|
static RenderBin* createRenderBin(const std::string& binName);
|
|
|
|
static RenderBin* getRenderBinPrototype(const std::string& binName);
|
|
|
|
static void addRenderBinPrototype(const std::string& binName,RenderBin* proto);
|
|
|
|
static void removeRenderBinPrototype(RenderBin* proto);
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2005-05-19 23:17:53 +08:00
|
|
|
static void setDefaultRenderBinSortMode(SortMode mode);
|
|
|
|
static SortMode getDefaultRenderBinSortMode();
|
|
|
|
|
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
|
2005-05-24 23:34:23 +08:00
|
|
|
RenderBin();
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2005-05-24 23:34:23 +08:00
|
|
|
RenderBin(SortMode mode);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
RenderBin(const RenderBin& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new RenderBin(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new RenderBin(*this,copyop); } // note only implements a clone of type.
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RenderBin*>(obj)!=0L; }
|
2002-06-06 21:25:36 +08:00
|
|
|
virtual const char* libraryName() const { return "osgUtil"; }
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const char* className() const { return "RenderBin"; }
|
|
|
|
|
|
|
|
virtual void reset();
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2006-06-29 23:57:24 +08:00
|
|
|
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
|
|
|
osg::StateSet* getStateSet() { return _stateset.get(); }
|
|
|
|
const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
2009-05-27 17:54:17 +08:00
|
|
|
|
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
RenderBin* getParent() { return _parent; }
|
|
|
|
const RenderBin* getParent() const { return _parent; }
|
|
|
|
|
|
|
|
RenderStage* getStage() { return _stage; }
|
|
|
|
const RenderStage* getStage() const { return _stage; }
|
|
|
|
|
2004-09-27 02:39:34 +08:00
|
|
|
int getBinNum() const { return _binNum; }
|
2004-08-18 02:57:02 +08:00
|
|
|
|
2005-10-13 20:51:00 +08:00
|
|
|
StateGraphList& getStateGraphList() { return _stateGraphList; }
|
|
|
|
const StateGraphList& getStateGraphList() const { return _stateGraphList; }
|
2004-08-02 20:19:50 +08:00
|
|
|
|
|
|
|
RenderBinList& getRenderBinList() { return _bins; }
|
|
|
|
const RenderBinList& getRenderBinList() const { return _bins; }
|
|
|
|
|
|
|
|
RenderLeafList& getRenderLeafList() { return _renderLeafList; }
|
|
|
|
const RenderLeafList& getRenderLeafList() const { return _renderLeafList; }
|
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
RenderBin* find_or_insert(int binNum,const std::string& binName);
|
|
|
|
|
2005-10-13 20:51:00 +08:00
|
|
|
void addStateGraph(StateGraph* rg)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2005-10-13 20:51:00 +08:00
|
|
|
_stateGraphList.push_back(rg);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2005-11-08 19:46:52 +08:00
|
|
|
virtual void sort();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void sortImplementation();
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
void setSortMode(SortMode mode);
|
2002-08-04 00:49:42 +08:00
|
|
|
SortMode getSortMode() const { return _sortMode; }
|
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void sortByState();
|
2005-05-19 23:17:53 +08:00
|
|
|
virtual void sortByStateThenFrontToBack();
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void sortFrontToBack();
|
|
|
|
virtual void sortBackToFront();
|
2009-05-27 17:54:17 +08:00
|
|
|
virtual void sortTraversalOrder();
|
|
|
|
|
2002-08-04 00:49:42 +08:00
|
|
|
struct SortCallback : public osg::Referenced
|
|
|
|
{
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void sortImplementation(RenderBin*) = 0;
|
2002-08-04 00:49:42 +08:00
|
|
|
};
|
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
void setSortCallback(SortCallback* sortCallback) { _sortCallback = sortCallback; }
|
|
|
|
SortCallback* getSortCallback() { return _sortCallback.get(); }
|
|
|
|
const SortCallback* getSortCallback() const { return _sortCallback.get(); }
|
|
|
|
|
2002-08-04 00:49:42 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2006-09-19 04:54:48 +08:00
|
|
|
virtual void draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2006-09-19 04:54:48 +08:00
|
|
|
virtual void drawImplementation(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
|
2002-10-17 21:48:46 +08:00
|
|
|
|
|
|
|
struct DrawCallback : public osg::Referenced
|
|
|
|
{
|
2006-09-19 04:54:48 +08:00
|
|
|
virtual void drawImplementation(RenderBin* bin,osg::RenderInfo& renderInfo,RenderLeaf*& previous) = 0;
|
2002-10-17 21:48:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void setDrawCallback(DrawCallback* drawCallback) { _drawCallback = drawCallback; }
|
|
|
|
DrawCallback* getDrawCallback() { return _drawCallback.get(); }
|
|
|
|
const DrawCallback* getDrawCallback() const { return _drawCallback.get(); }
|
|
|
|
|
2004-09-27 02:39:34 +08:00
|
|
|
/** Extract stats for current draw list. */
|
2005-12-16 01:14:40 +08:00
|
|
|
bool getStats(Statistics& primStats) const;
|
2009-05-27 17:54:17 +08:00
|
|
|
|
2007-01-30 06:44:29 +08:00
|
|
|
/** Compute the number of dynamic RenderLeaves.*/
|
|
|
|
virtual unsigned int computeNumberOfDynamicRenderLeaves() const;
|
2001-11-05 03:29:20 +08:00
|
|
|
|
2005-10-13 20:51:00 +08:00
|
|
|
void copyLeavesFromStateGraphListToRenderLeafList();
|
2005-09-15 17:03:14 +08:00
|
|
|
|
2011-04-20 19:45:01 +08:00
|
|
|
/** If State is non-zero, this function releases any associated OpenGL objects for
|
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objexts
|
|
|
|
* for all graphics contexts. */
|
|
|
|
virtual void releaseGLObjects(osg::State* state= 0) const;
|
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
protected:
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
virtual ~RenderBin();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-08-04 00:49:42 +08:00
|
|
|
int _binNum;
|
|
|
|
RenderBin* _parent;
|
|
|
|
RenderStage* _stage;
|
|
|
|
RenderBinList _bins;
|
2005-10-13 20:51:00 +08:00
|
|
|
StateGraphList _stateGraphList;
|
2002-08-04 00:49:42 +08:00
|
|
|
RenderLeafList _renderLeafList;
|
2007-01-27 20:54:33 +08:00
|
|
|
|
|
|
|
bool _sorted;
|
2002-08-04 00:49:42 +08:00
|
|
|
SortMode _sortMode;
|
2002-10-17 21:48:46 +08:00
|
|
|
osg::ref_ptr<SortCallback> _sortCallback;
|
2002-08-04 00:49:42 +08:00
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
osg::ref_ptr<DrawCallback> _drawCallback;
|
2002-08-04 00:49:42 +08:00
|
|
|
|
2006-06-29 23:57:24 +08:00
|
|
|
osg::ref_ptr<osg::StateSet> _stateset;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
|