Various work on osgViewer library, including warp point and graphics window resize support
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <osg/Group>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Quat>
|
||||
#include <osg/Viewport>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -60,8 +61,6 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
|
||||
|
||||
|
||||
|
||||
|
||||
enum AutoRotateMode
|
||||
{
|
||||
NO_ROTATION,
|
||||
@@ -88,25 +87,24 @@ class OSG_EXPORT AutoTransform : public Transform
|
||||
protected :
|
||||
|
||||
virtual ~AutoTransform() {}
|
||||
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
|
||||
AutoRotateMode _autoRotateMode;
|
||||
|
||||
bool _autoScaleToScreen;
|
||||
|
||||
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
|
||||
AutoRotateMode _autoRotateMode;
|
||||
|
||||
bool _autoScaleToScreen;
|
||||
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable osg::Vec3 _previousLocalUp;
|
||||
mutable int _previousWidth;
|
||||
mutable int _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable osg::Vec3 _previousLocalUp;
|
||||
mutable Viewport::value_type _previousWidth;
|
||||
mutable Viewport::value_type _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
|
||||
|
||||
void computeMatrix() const;
|
||||
|
||||
@@ -310,7 +310,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
|
||||
|
||||
|
||||
/** Set the GraphicsContext that provides the mechansim for managing the OpenGL graphics context associated with this camera.*/
|
||||
void setGraphicsContext(GraphicsContext* context) { _graphicsContext = context; }
|
||||
void setGraphicsContext(GraphicsContext* context);
|
||||
|
||||
/** Get the GraphicsContext.*/
|
||||
GraphicsContext* getGraphicsContext() { return _graphicsContext.get(); }
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare osg::Camera
|
||||
class Camera;
|
||||
|
||||
/** Base class for providing Windowing API agnostic access to creating and managing graphics context.*/
|
||||
class OSG_EXPORT GraphicsContext : public Referenced
|
||||
{
|
||||
@@ -74,10 +77,10 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
||||
sharedContext(0) {}
|
||||
|
||||
// graphics context orginal and size
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
// window decoration and baviour
|
||||
std::string windowName;
|
||||
@@ -258,12 +261,30 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
||||
virtual void swapBuffersImplementation() = 0;
|
||||
|
||||
|
||||
/** resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must
|
||||
be updated to keep in sync with the new size. */
|
||||
void resized(int x, int y, int width, int height);
|
||||
|
||||
typedef std::list< osg::Camera* > Cameras;
|
||||
|
||||
/** Get the the list of cameras associated with this graphics context.*/
|
||||
Cameras& getCameras() { return _cameras; }
|
||||
|
||||
/** Get the the const list of cameras associated with this graphics context.*/
|
||||
const Cameras& getCameras() const { return _cameras; }
|
||||
|
||||
protected:
|
||||
|
||||
GraphicsContext();
|
||||
|
||||
virtual ~GraphicsContext();
|
||||
|
||||
void addCamera(osg::Camera* camera);
|
||||
void removeCamera(osg::Camera* camera);
|
||||
|
||||
Cameras _cameras;
|
||||
|
||||
friend class osg::Camera;
|
||||
|
||||
ref_ptr<Traits> _traits;
|
||||
ref_ptr<State> _state;
|
||||
|
||||
@@ -200,13 +200,15 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0):
|
||||
_primitiveType(primType),
|
||||
_mode(mode),
|
||||
_modifiedCount(0) {}
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(prim,copyop),
|
||||
_primitiveType(prim._primitiveType),
|
||||
_mode(prim._mode),
|
||||
_modifiedCount(0) {}
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
@@ -245,6 +247,8 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* /*state*/=0) const {}
|
||||
|
||||
virtual void computeRange() const {}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~PrimitiveSet() {}
|
||||
@@ -252,7 +256,7 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
Type _primitiveType;
|
||||
GLenum _mode;
|
||||
unsigned int _modifiedCount;
|
||||
|
||||
mutable unsigned int _rangeModifiedCount;
|
||||
|
||||
struct ObjectIDModifiedCountPair
|
||||
{
|
||||
@@ -435,10 +439,34 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUByte();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
|
||||
};
|
||||
@@ -491,10 +519,34 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUShort();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
};
|
||||
|
||||
@@ -545,10 +597,34 @@ class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorGLuint
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
virtual void computeRange() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
_minIndex = 0;
|
||||
_maxIndex = 0;
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
return;
|
||||
}
|
||||
|
||||
_minIndex = front();
|
||||
_maxIndex = _minIndex;
|
||||
|
||||
for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr)
|
||||
{
|
||||
if (*itr<_minIndex) _minIndex = *itr;
|
||||
if (*itr>_maxIndex) _maxIndex = *itr;
|
||||
}
|
||||
_rangeModifiedCount = _modifiedCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElementsUInt();
|
||||
|
||||
mutable unsigned int _minIndex;
|
||||
mutable unsigned int _maxIndex;
|
||||
|
||||
mutable GLObjectList _vboList;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ class OSG_EXPORT View : public virtual osg::Referenced
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
osg::Matrixd _projectionOffset;
|
||||
osg::Matrixd _viewOffset;
|
||||
};
|
||||
|
||||
bool addSlave(osg::Camera* camera) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity()); }
|
||||
@@ -73,8 +73,12 @@ class OSG_EXPORT View : public virtual osg::Referenced
|
||||
|
||||
Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
|
||||
const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
|
||||
|
||||
Slave* findSlaveForCamera(osg::Camera* camera);
|
||||
|
||||
void updateSlaves();
|
||||
|
||||
void updateSlave(unsigned int i);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -23,9 +23,15 @@ namespace osg {
|
||||
class OSG_EXPORT Viewport : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
#if 0
|
||||
typedef int value_type;
|
||||
#else
|
||||
typedef double value_type;
|
||||
#endif
|
||||
Viewport();
|
||||
|
||||
Viewport(int x,int y,int width,int height):
|
||||
Viewport(value_type x,value_type y,value_type width,value_type height):
|
||||
_x(x),
|
||||
_y(y),
|
||||
_width(width),
|
||||
@@ -58,14 +64,15 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
inline void setViewport(int x,int y,int width,int height)
|
||||
inline void setViewport(value_type x,value_type y,value_type width,value_type height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void getViewport(int& x,int& y,int& width,int& height) const
|
||||
{
|
||||
x = _x;
|
||||
@@ -74,24 +81,32 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
height = _height;
|
||||
}
|
||||
|
||||
inline int& x() { return _x; }
|
||||
inline int x() const { return _x; }
|
||||
void getViewport(double& x,double& y,double& width,double& height) const
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
width = _width;
|
||||
height = _height;
|
||||
}
|
||||
#endif
|
||||
inline value_type& x() { return _x; }
|
||||
inline value_type x() const { return _x; }
|
||||
|
||||
inline int& y() { return _y; }
|
||||
inline int y() const { return _y; }
|
||||
inline value_type& y() { return _y; }
|
||||
inline value_type y() const { return _y; }
|
||||
|
||||
inline int& width() { return _width; }
|
||||
inline int width() const { return _width; }
|
||||
inline value_type& width() { return _width; }
|
||||
inline value_type width() const { return _width; }
|
||||
|
||||
inline int& height() { return _height; }
|
||||
inline int height() const { return _height; }
|
||||
inline value_type& height() { return _height; }
|
||||
inline value_type height() const { return _height; }
|
||||
|
||||
inline bool valid() const { return _width!=0 && _height!=0; }
|
||||
inline bool valid() const { return _width>0 && _height>0; }
|
||||
|
||||
/** Return the aspectRatio of the viewport, which is equal to width/height.
|
||||
* If height is zero, the potental division by zero is avoided by simply returning 1.0f.
|
||||
*/
|
||||
inline float aspectRatio() const { if (_height!=0) return (float)_width/(float)_height; else return 1.0f; }
|
||||
inline double aspectRatio() const { if (_height!=0) return (double)_width/(double)_height; else return 1.0; }
|
||||
|
||||
/** Compute the Window Matrix which takes projected coords into Window coordinates.
|
||||
* To convert local coordinates into window coordinates use v_window = v_local * MVPW matrix,
|
||||
@@ -101,7 +116,7 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
*/
|
||||
inline const osg::Matrix computeWindowMatrix() const
|
||||
{
|
||||
return osg::Matrix::translate(1.0f,1.0f,1.0f)*osg::Matrix::scale(0.5f*width(),0.5f*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f);
|
||||
return osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*width(),0.5*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
@@ -110,10 +125,10 @@ class OSG_EXPORT Viewport : public StateAttribute
|
||||
|
||||
virtual ~Viewport();
|
||||
|
||||
int _x;
|
||||
int _y;
|
||||
int _width;
|
||||
int _height;
|
||||
value_type _x;
|
||||
value_type _y;
|
||||
value_type _width;
|
||||
value_type _height;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
||||
|
||||
|
||||
/** Method for adapting window resize event, placing this event on the back of the event queue. */
|
||||
void windowResize(int x, int y, unsigned int width, unsigned int height) { windowResize(x,y,width,height,getTime()); }
|
||||
void windowResize(int x, int y, int width, int height) { windowResize(x,y,width,height,getTime()); }
|
||||
|
||||
/** Method for adapting window resize event, placing this event on the back of the event queue, with specified time. */
|
||||
void windowResize(int x, int y, unsigned int width, unsigned int height, double time);
|
||||
void windowResize(int x, int y, int width, int height, double time);
|
||||
|
||||
|
||||
/** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
|
||||
|
||||
@@ -274,7 +274,7 @@ public:
|
||||
|
||||
|
||||
/** set window rectangle. */
|
||||
void setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange = true);
|
||||
void setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange = true);
|
||||
|
||||
/** get window x origin.*/
|
||||
int getWindowX() const { return _windowX; }
|
||||
@@ -283,10 +283,10 @@ public:
|
||||
int getWindowY() const { return _windowY; }
|
||||
|
||||
/** get window width.*/
|
||||
unsigned int getWindowWidth() const { return _windowWidth; }
|
||||
int getWindowWidth() const { return _windowWidth; }
|
||||
|
||||
/** get window height.*/
|
||||
unsigned int getWindowHeight() const { return _windowHeight; }
|
||||
int getWindowHeight() const { return _windowHeight; }
|
||||
|
||||
|
||||
/** set key pressed. */
|
||||
|
||||
@@ -99,16 +99,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
|
||||
/** Get the const viewport. */
|
||||
const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
|
||||
|
||||
/** Get the viewport of the scene view. */
|
||||
void getViewport(int& x,int& y,int& width,int& height) const
|
||||
{
|
||||
if (_camera->getViewport()!=0)
|
||||
_camera->getViewport()->getViewport(x,y,width,height);
|
||||
else
|
||||
x = y = width = height = 0;
|
||||
|
||||
}
|
||||
|
||||
/** Set the DisplaySettings. */
|
||||
inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; }
|
||||
|
||||
@@ -178,9 +168,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
|
||||
osg::State* getState() { return _renderInfo.getState(); }
|
||||
const osg::State* getState() const { return _renderInfo.getState(); }
|
||||
|
||||
void setView(osg::View* view) { _renderInfo.setView(view); }
|
||||
osg::View* getView() { return _renderInfo.getView(); }
|
||||
const osg::View* getView() const { return _renderInfo.getView(); }
|
||||
void setView(osg::View* view) { _camera->setView(view); }
|
||||
osg::View* getView() { return _camera->getView(); }
|
||||
const osg::View* getView() const { return _camera->getView(); }
|
||||
|
||||
void setRenderInfo(osg::RenderInfo& renderInfo) { _renderInfo = renderInfo; }
|
||||
osg::RenderInfo& getRenderInfo() { return _renderInfo; }
|
||||
@@ -315,16 +305,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
|
||||
|
||||
|
||||
/** Set the draw buffer value used at the start of each frame draw. Note, overridden in quad buffer stereo mode */
|
||||
void setDrawBufferValue( GLenum drawBufferValue )
|
||||
{
|
||||
_drawBufferValue = drawBufferValue;
|
||||
}
|
||||
void setDrawBufferValue( GLenum drawBufferValue ) { _camera->setDrawBuffer(drawBufferValue); }
|
||||
|
||||
/** Get the draw buffer value used at the start of each frame draw. */
|
||||
GLenum getDrawBufferValue() const
|
||||
{
|
||||
return _drawBufferValue;
|
||||
}
|
||||
GLenum getDrawBufferValue() const { return _camera->getDrawBuffer(); }
|
||||
|
||||
|
||||
/** FusionDistanceMode is used only when working in stereo.*/
|
||||
@@ -504,7 +488,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
|
||||
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
osg::ref_ptr<osg::StateSet> _globalStateSet;
|
||||
osg::ref_ptr<osg::Light> _light;
|
||||
@@ -517,8 +501,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
|
||||
|
||||
bool _prioritizeTextures;
|
||||
|
||||
GLenum _drawBufferValue;
|
||||
|
||||
bool _requiresFlush;
|
||||
|
||||
int _activeUniforms;
|
||||
|
||||
@@ -51,10 +51,7 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
typedef std::map<GLenum, unsigned int> PrimitiveCountMap;
|
||||
|
||||
|
||||
Statistics()
|
||||
{
|
||||
reset();
|
||||
};
|
||||
Statistics();
|
||||
|
||||
enum StatsType
|
||||
{
|
||||
@@ -68,25 +65,7 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
STAT_RESTART // hint to restart the stats
|
||||
};
|
||||
|
||||
void reset()
|
||||
{
|
||||
numDrawables=0;
|
||||
nummat=0;
|
||||
depth=0;
|
||||
stattype=STAT_NONE;
|
||||
nlights=0;
|
||||
nbins=0;
|
||||
nimpostor=0;
|
||||
|
||||
_vertexCount=0;
|
||||
_primitiveCount.clear();
|
||||
|
||||
_currentPrimitiveFunctorMode=0;
|
||||
|
||||
_primitives_count.clear();
|
||||
_total_primitives_count=0;
|
||||
_number_of_vertexes=0;
|
||||
}
|
||||
void reset();
|
||||
|
||||
void setType(StatsType t) {stattype=t;}
|
||||
|
||||
@@ -94,42 +73,12 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
virtual void setVertexArray(unsigned int count,const osg::Vec2*) { _vertexCount += count; }
|
||||
virtual void setVertexArray(unsigned int count,const osg::Vec4*) { _vertexCount += count; }
|
||||
|
||||
virtual void drawArrays(GLenum mode,GLint,GLsizei count)
|
||||
{
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
prim.second+=count;
|
||||
_primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count);
|
||||
}
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*)
|
||||
{
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
prim.second+=count;
|
||||
_primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count);
|
||||
}
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLushort*)
|
||||
{
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
prim.second+=count;
|
||||
_primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count);
|
||||
}
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLuint*)
|
||||
{
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
prim.second+=count;
|
||||
_primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count);
|
||||
}
|
||||
virtual void drawArrays(GLenum mode,GLint,GLsizei count);
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*);
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLushort*);
|
||||
virtual void drawElements(GLenum mode,GLsizei count,const GLuint*);
|
||||
|
||||
virtual void begin(GLenum mode)
|
||||
{
|
||||
_currentPrimitiveFunctorMode=mode;
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
_number_of_vertexes = 0;
|
||||
}
|
||||
virtual void begin(GLenum mode);
|
||||
|
||||
inline void vertex()
|
||||
{
|
||||
@@ -137,6 +86,7 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
++prim.second;
|
||||
_number_of_vertexes++;
|
||||
}
|
||||
|
||||
virtual void vertex(float,float,float) { vertex(); }
|
||||
virtual void vertex(const osg::Vec3&) { vertex(); }
|
||||
virtual void vertex(const osg::Vec2&) { vertex(); }
|
||||
@@ -144,13 +94,7 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
virtual void vertex(float,float) { vertex(); }
|
||||
virtual void vertex(float,float,float,float) { vertex(); }
|
||||
|
||||
virtual void end()
|
||||
{
|
||||
_primitives_count[_currentPrimitiveFunctorMode] +=
|
||||
_calculate_primitives_number_by_mode(_currentPrimitiveFunctorMode, _number_of_vertexes);
|
||||
|
||||
_vertexCount += _number_of_vertexes;
|
||||
}
|
||||
virtual void end();
|
||||
|
||||
void addDrawable() { numDrawables++;}
|
||||
void addMatrix() { nummat++;}
|
||||
@@ -162,37 +106,7 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
|
||||
void setBinNo(int n) { _binNo=n;}
|
||||
|
||||
void add(const Statistics& stats)
|
||||
{
|
||||
numDrawables += stats.numDrawables;
|
||||
nummat += stats.nummat;
|
||||
depth += stats.depth;
|
||||
nlights += stats.nlights;
|
||||
nbins += stats.nbins;
|
||||
nimpostor += stats.nimpostor;
|
||||
|
||||
_vertexCount += stats._vertexCount;
|
||||
// _primitiveCount += stats._primitiveCount;
|
||||
for(PrimitiveValueMap::const_iterator pitr = stats._primitiveCount.begin();
|
||||
pitr != stats._primitiveCount.end();
|
||||
++pitr)
|
||||
{
|
||||
_primitiveCount[pitr->first].first += pitr->second.first;
|
||||
_primitiveCount[pitr->first].second += pitr->second.second;
|
||||
}
|
||||
|
||||
_currentPrimitiveFunctorMode += stats._currentPrimitiveFunctorMode;
|
||||
|
||||
for(PrimitiveCountMap::const_iterator citr = stats._primitives_count.begin();
|
||||
citr != stats._primitives_count.end();
|
||||
++citr)
|
||||
{
|
||||
_primitives_count[citr->first] += citr->second;
|
||||
}
|
||||
|
||||
_total_primitives_count += stats._total_primitives_count;
|
||||
_number_of_vertexes += stats._number_of_vertexes;
|
||||
}
|
||||
void add(const Statistics& stats);
|
||||
|
||||
public:
|
||||
|
||||
@@ -221,19 +135,19 @@ class Statistics : public osg::PrimitiveFunctor
|
||||
|
||||
inline unsigned int Statistics::_calculate_primitives_number_by_mode(GLenum mode, GLsizei count)
|
||||
{
|
||||
switch (mode)
|
||||
switch (mode)
|
||||
{
|
||||
case GL_POINTS:
|
||||
case GL_LINE_LOOP:
|
||||
case GL_POLYGON: return count;
|
||||
case GL_LINES: return count / 2;
|
||||
case GL_LINE_STRIP: return count - 1;
|
||||
case GL_TRIANGLES: return count / 3;
|
||||
case GL_TRIANGLE_STRIP:
|
||||
case GL_TRIANGLE_FAN: return count - 2;
|
||||
case GL_QUADS: return count / 4;
|
||||
case GL_QUAD_STRIP: return count / 2 - 1;
|
||||
default: return 0;
|
||||
case GL_POINTS:
|
||||
case GL_LINE_LOOP:
|
||||
case GL_POLYGON: return count;
|
||||
case GL_LINES: return count / 2;
|
||||
case GL_LINE_STRIP: return count - 1;
|
||||
case GL_TRIANGLES: return count / 3;
|
||||
case GL_TRIANGLE_STRIP:
|
||||
case GL_TRIANGLE_FAN: return count - 2;
|
||||
case GL_QUADS: return count / 4;
|
||||
case GL_QUAD_STRIP: return count / 2 - 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,188 +160,27 @@ public:
|
||||
typedef std::set<osg::Drawable*> DrawableSet;
|
||||
typedef std::set<osg::StateSet*> StateSetSet;
|
||||
|
||||
StatsVisitor():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_numInstancedGroup(0),
|
||||
_numInstancedSwitch(0),
|
||||
_numInstancedLOD(0),
|
||||
_numInstancedTransform(0),
|
||||
_numInstancedGeode(0),
|
||||
_numInstancedDrawable(0),
|
||||
_numInstancedGeometry(0),
|
||||
_numInstancedStateSet(0) {}
|
||||
StatsVisitor();
|
||||
|
||||
void reset()
|
||||
{
|
||||
_numInstancedGroup = 0;
|
||||
_numInstancedSwitch = 0;
|
||||
_numInstancedLOD = 0;
|
||||
_numInstancedTransform = 0;
|
||||
_numInstancedGeode = 0;
|
||||
_numInstancedDrawable = 0;
|
||||
_numInstancedGeometry = 0;
|
||||
_numInstancedStateSet = 0;
|
||||
|
||||
_groupSet.clear();
|
||||
_transformSet.clear();
|
||||
_lodSet.clear();
|
||||
_switchSet.clear();
|
||||
_geodeSet.clear();
|
||||
_drawableSet.clear();
|
||||
_geometrySet.clear();
|
||||
_statesetSet.clear();
|
||||
|
||||
_uniqueStats.reset();
|
||||
_instancedStats.reset();
|
||||
}
|
||||
void reset();
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
void apply(osg::Node& node);
|
||||
|
||||
void apply(osg::Group& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
void apply(osg::Group& node);
|
||||
|
||||
void apply(osg::Transform& node);
|
||||
|
||||
void apply(osg::LOD& node);
|
||||
|
||||
void apply(osg::Switch& node);
|
||||
|
||||
void apply(osg::Geode& node);
|
||||
|
||||
void apply(osg::Drawable& drawable);
|
||||
|
||||
void totalUpStats();
|
||||
|
||||
++_numInstancedGroup;
|
||||
_groupSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::Transform& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedTransform;
|
||||
_transformSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::LOD& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedLOD;
|
||||
_lodSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::Switch& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedSwitch;
|
||||
_switchSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::Geode& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedGeode;
|
||||
_geodeSet.insert(&node);
|
||||
|
||||
for(unsigned int i=0; i<node.getNumDrawables();++i)
|
||||
{
|
||||
apply(*node.getDrawable(i));
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::Drawable& drawable)
|
||||
{
|
||||
if (drawable.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(drawable.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedDrawable;
|
||||
|
||||
drawable.accept(_instancedStats);
|
||||
|
||||
_drawableSet.insert(&drawable);
|
||||
|
||||
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(&drawable);
|
||||
if (geometry)
|
||||
{
|
||||
++_numInstancedGeometry;
|
||||
_geometrySet.insert(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
void totalUpStats()
|
||||
{
|
||||
_uniqueStats.reset();
|
||||
|
||||
for(DrawableSet::iterator itr = _drawableSet.begin();
|
||||
itr != _drawableSet.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->accept(_uniqueStats);
|
||||
}
|
||||
}
|
||||
|
||||
void print(std::ostream& out)
|
||||
{
|
||||
|
||||
unsigned int unique_primitives = 0;
|
||||
osgUtil::Statistics::PrimitiveCountMap::iterator pcmitr;
|
||||
for(pcmitr = _uniqueStats.GetPrimitivesBegin();
|
||||
pcmitr != _uniqueStats.GetPrimitivesEnd();
|
||||
++pcmitr)
|
||||
{
|
||||
unique_primitives += pcmitr->second;
|
||||
}
|
||||
|
||||
unsigned int instanced_primitives = 0;
|
||||
for(pcmitr = _instancedStats.GetPrimitivesBegin();
|
||||
pcmitr != _instancedStats.GetPrimitivesEnd();
|
||||
++pcmitr)
|
||||
{
|
||||
instanced_primitives += pcmitr->second;
|
||||
}
|
||||
|
||||
out<<"Object Type\t#Unique\t#Instanced"<<std::endl;
|
||||
out<<"StateSet \t"<<_statesetSet.size()<<"\t"<<_numInstancedStateSet<<std::endl;
|
||||
out<<"Group \t"<<_groupSet.size()<<"\t"<<_numInstancedGroup<<std::endl;
|
||||
out<<"Transform \t"<<_transformSet.size()<<"\t"<<_numInstancedTransform<<std::endl;
|
||||
out<<"LOD \t"<<_lodSet.size()<<"\t"<<_numInstancedLOD<<std::endl;
|
||||
out<<"Switch \t"<<_switchSet.size()<<"\t"<<_numInstancedSwitch<<std::endl;
|
||||
out<<"Geode \t"<<_geodeSet.size()<<"\t"<<_numInstancedGeode<<std::endl;
|
||||
out<<"Drawable \t"<<_drawableSet.size()<<"\t"<<_numInstancedDrawable<<std::endl;
|
||||
out<<"Geometry \t"<<_geometrySet.size()<<"\t"<<_numInstancedGeometry<<std::endl;
|
||||
out<<"Vertices \t"<<_uniqueStats._vertexCount<<"\t"<<_instancedStats._vertexCount<<std::endl;
|
||||
out<<"Primitives \t"<<unique_primitives<<"\t"<<instanced_primitives<<std::endl;
|
||||
}
|
||||
void print(std::ostream& out);
|
||||
|
||||
unsigned int _numInstancedGroup;
|
||||
unsigned int _numInstancedSwitch;
|
||||
|
||||
@@ -86,6 +86,9 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
||||
/** Get focus on if the pointer is in this window.*/
|
||||
virtual void grabFocusIfPointerInWindow();
|
||||
|
||||
// Override from GUIActionAdapter
|
||||
virtual void requestWarpPointer(float x,float y);
|
||||
|
||||
protected:
|
||||
|
||||
bool createVisualInfo();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace osgViewer {
|
||||
|
||||
/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
|
||||
class OSGVIEWER_EXPORT View : public osg::View
|
||||
class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -50,6 +50,9 @@ class OSGVIEWER_EXPORT View : public osg::View
|
||||
/** Convinience method for creating slave Cameras and associated GraphicsWindows across all screens.*/
|
||||
void setUpViewAcrossAllScreens();
|
||||
|
||||
virtual void requestRedraw();
|
||||
virtual void requestContinuousUpdate(bool needed=true);
|
||||
virtual void requestWarpPointer(float x,float y);
|
||||
|
||||
public:
|
||||
|
||||
@@ -57,6 +60,7 @@ class OSGVIEWER_EXPORT View : public osg::View
|
||||
|
||||
void assignSceneDataToCameras();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~View();
|
||||
|
||||
@@ -54,6 +54,10 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
||||
/** Clean up all OpenGL objects associated with this viewer's scenegraph.*/
|
||||
virtual void cleanup();
|
||||
|
||||
void setCameraWithFocus(osg::Camera* camera) { _cameraWithFocus = camera; }
|
||||
osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
|
||||
const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }
|
||||
|
||||
public:
|
||||
|
||||
void init();
|
||||
@@ -66,6 +70,8 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
||||
|
||||
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
|
||||
osg::ref_ptr<osg::BarrierOperation> _endRenderingDispatchBarrier;
|
||||
|
||||
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user