2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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
|
|
|
|
|
|
|
|
#include <osgUtil/RenderGraph>
|
|
|
|
|
|
|
|
#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:
|
|
|
|
|
|
|
|
typedef std::vector<RenderLeaf*> RenderLeafList;
|
|
|
|
typedef std::vector<RenderGraph*> RenderGraphList;
|
|
|
|
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,
|
|
|
|
SORT_BACK_TO_FRONT
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
RenderGraphList& getRenderGraphList() { return _renderGraphList; }
|
|
|
|
const RenderGraphList& getRenderGraphList() const { return _renderGraphList; }
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void addRenderGraph(RenderGraph* rg)
|
|
|
|
{
|
|
|
|
_renderGraphList.push_back(rg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sort();
|
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void sortImplementation();
|
2004-09-27 02:39:34 +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();
|
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
|
|
|
|
|
|
|
virtual void draw(osg::State& state,RenderLeaf*& previous);
|
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void drawImplementation(osg::State& state,RenderLeaf*& previous);
|
|
|
|
|
|
|
|
struct DrawCallback : public osg::Referenced
|
|
|
|
{
|
|
|
|
virtual void drawImplementation(RenderBin* bin,osg::State& state,RenderLeaf*& previous) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
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. */
|
2003-07-15 21:46:19 +08:00
|
|
|
bool getStats(Statistics* primStats);
|
|
|
|
void getPrims(Statistics* primStats);
|
|
|
|
bool getPrims(Statistics* primStats, int nbin);
|
2001-11-05 03:29:20 +08:00
|
|
|
|
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();
|
2002-08-04 00:49:42 +08:00
|
|
|
|
|
|
|
void copyLeavesFromRenderGraphListToRenderLeafList();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-08-04 00:49:42 +08:00
|
|
|
int _binNum;
|
|
|
|
RenderBin* _parent;
|
|
|
|
RenderStage* _stage;
|
|
|
|
RenderBinList _bins;
|
|
|
|
RenderGraphList _renderGraphList;
|
|
|
|
RenderLeafList _renderLeafList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
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
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Proxy class for automatic registration of renderbins with the RenderBin prototypelist.*/
|
|
|
|
class RegisterRenderBinProxy
|
|
|
|
{
|
|
|
|
public:
|
2002-09-17 23:47:23 +08:00
|
|
|
RegisterRenderBinProxy(const std::string& binName,RenderBin* proto)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-09-17 23:47:23 +08:00
|
|
|
_rb = proto;
|
|
|
|
RenderBin::addRenderBinPrototype(binName,_rb.get());
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~RegisterRenderBinProxy()
|
|
|
|
{
|
|
|
|
RenderBin::removeRenderBinPrototype(_rb.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2002-09-17 23:47:23 +08:00
|
|
|
osg::ref_ptr<RenderBin> _rb;
|
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
|
|
|
|