Various work on osgViewer library, including warp point and graphics window resize support
This commit is contained in:
@@ -102,8 +102,8 @@ void AutoTransform::accept(NodeVisitor& nv)
|
||||
if (cs)
|
||||
{
|
||||
|
||||
int width = _previousWidth;
|
||||
int height = _previousHeight;
|
||||
Viewport::value_type width = _previousWidth;
|
||||
Viewport::value_type height = _previousHeight;
|
||||
|
||||
osg::Viewport* viewport = cs->getViewport();
|
||||
if (viewport)
|
||||
|
||||
@@ -50,13 +50,27 @@ Camera::Camera(const Camera& camera,const CopyOp& copyop):
|
||||
_bufferAttachmentMap(camera._bufferAttachmentMap),
|
||||
_postDrawCallback(camera._postDrawCallback)
|
||||
{
|
||||
// need to copy/share graphics context?
|
||||
}
|
||||
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
if (_graphicsContext.valid()) _graphicsContext->removeCamera(this);
|
||||
}
|
||||
|
||||
void Camera::setGraphicsContext(GraphicsContext* context)
|
||||
{
|
||||
if (_graphicsContext == context) return;
|
||||
|
||||
if (_graphicsContext.valid()) _graphicsContext->removeCamera(this);
|
||||
|
||||
_graphicsContext = context;
|
||||
|
||||
if (_graphicsContext.valid()) _graphicsContext->addCamera(this);
|
||||
}
|
||||
|
||||
|
||||
bool Camera::isRenderToTextureCamera() const
|
||||
{
|
||||
return (!_bufferAttachmentMap.empty());
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
|
||||
#include <osg/GraphicsContext>
|
||||
#include <osg/Camera>
|
||||
#include <osg/View>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
@@ -362,3 +366,105 @@ void GraphicsContext::runOperations()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContext::addCamera(osg::Camera* camera)
|
||||
{
|
||||
_cameras.push_back(camera);
|
||||
}
|
||||
|
||||
void GraphicsContext::removeCamera(osg::Camera* camera)
|
||||
{
|
||||
for(Cameras::iterator itr = _cameras.begin();
|
||||
itr != _cameras.end();
|
||||
++itr)
|
||||
{
|
||||
if (*itr == camera)
|
||||
{
|
||||
_cameras.erase(itr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContext::resized(int x, int y, int width, int height)
|
||||
{
|
||||
if (!_traits) return;
|
||||
|
||||
double widthChangeRatio = double(width) / double(_traits->width);
|
||||
double heigtChangeRatio = double(height) / double(_traits->height);
|
||||
double aspectRatioChange = widthChangeRatio / heigtChangeRatio;
|
||||
|
||||
for(Cameras::iterator itr = _cameras.begin();
|
||||
itr != _cameras.end();
|
||||
++itr)
|
||||
{
|
||||
Camera* camera = (*itr);
|
||||
Viewport* viewport = camera->getViewport();
|
||||
if (viewport)
|
||||
{
|
||||
if (viewport->x()==0 && viewport->y()==0 &&
|
||||
viewport->width()>=_traits->width && viewport->height()>=_traits->height)
|
||||
{
|
||||
viewport->setViewport(0,0,width,height);
|
||||
}
|
||||
else
|
||||
{
|
||||
viewport->x() = static_cast<osg::Viewport::value_type>(double(viewport->x())*widthChangeRatio);
|
||||
viewport->y() = static_cast<osg::Viewport::value_type>(double(viewport->y())*heigtChangeRatio);
|
||||
viewport->width() = static_cast<osg::Viewport::value_type>(double(viewport->width())*widthChangeRatio);
|
||||
viewport->height() = static_cast<osg::Viewport::value_type>(double(viewport->height())*heigtChangeRatio);
|
||||
}
|
||||
}
|
||||
|
||||
// if aspect ratio adjusted change the project matrix to suit.
|
||||
if (aspectRatioChange != 1.0)
|
||||
{
|
||||
osg::View* view = camera->getView();
|
||||
osg::View::Slave* slave = view ? view->findSlaveForCamera(camera) : 0;
|
||||
|
||||
if (slave && camera->getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
||||
{
|
||||
slave->_projectionOffset *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
osg::Matrixd& pm = camera->getProjectionMatrix();
|
||||
bool orthographicCamera = (pm(0,3)==0.0) && (pm(1,3)==0.0) && (pm(2,3)==0.0) && (pm(3,3)==1.0);
|
||||
|
||||
if (orthographicCamera)
|
||||
{
|
||||
double left, right, bottom, top, zNear, zFar;
|
||||
camera->getProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);
|
||||
|
||||
double mid = (right+left)*0.5;
|
||||
double halfWidth = (right-left)*0.5;
|
||||
left = mid - halfWidth * aspectRatioChange;
|
||||
right = mid + halfWidth * aspectRatioChange;
|
||||
camera->setProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);
|
||||
}
|
||||
else
|
||||
{
|
||||
double left, right, bottom, top, zNear, zFar;
|
||||
camera->getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar);
|
||||
|
||||
double mid = (right+left)*0.5;
|
||||
double halfWidth = (right-left)*0.5;
|
||||
left = mid - halfWidth * aspectRatioChange;
|
||||
right = mid + halfWidth * aspectRatioChange;
|
||||
camera->setProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar);
|
||||
}
|
||||
#else
|
||||
camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_traits->x = x;
|
||||
_traits->y = y;
|
||||
_traits->width = width;
|
||||
_traits->height = height;
|
||||
}
|
||||
|
||||
@@ -43,20 +43,26 @@ View::~View()
|
||||
|
||||
void View::updateSlaves()
|
||||
{
|
||||
if (!_camera) return;
|
||||
|
||||
for(Slaves::iterator itr = _slaves.begin();
|
||||
itr != _slaves.end();
|
||||
++itr)
|
||||
for(unsigned int i=0; i<_slaves.size(); ++i)
|
||||
{
|
||||
updateSlave(i);
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateSlave(unsigned int i)
|
||||
{
|
||||
if (i >= _slaves.size() || !_camera) return;
|
||||
|
||||
Slave& slave = _slaves[i];
|
||||
|
||||
if (slave._camera->getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
||||
{
|
||||
Slave& slave = *itr;
|
||||
slave._camera->setProjectionMatrix(_camera->getProjectionMatrix() * slave._projectionOffset);
|
||||
slave._camera->setViewMatrix(_camera->getViewMatrix() * slave._viewOffset);
|
||||
slave._camera->inheritCullSettings(*_camera);
|
||||
if (_camera->getInheritanceMask() & osg::CullSettings::CLEAR_COLOR) slave._camera->setClearColor(_camera->getClearColor());
|
||||
}
|
||||
|
||||
|
||||
slave._camera->inheritCullSettings(*_camera);
|
||||
if (_camera->getInheritanceMask() & osg::CullSettings::CLEAR_COLOR) slave._camera->setClearColor(_camera->getClearColor());
|
||||
}
|
||||
|
||||
bool View::addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset)
|
||||
@@ -64,20 +70,12 @@ bool View::addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, co
|
||||
if (!camera) return false;
|
||||
|
||||
camera->setView(this);
|
||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
|
||||
if (_camera.valid())
|
||||
{
|
||||
camera->setProjectionMatrix(projectionOffset * _camera->getProjectionMatrix());
|
||||
camera->setViewMatrix(viewOffset * _camera->getViewMatrix());
|
||||
camera->inheritCullSettings(*_camera);
|
||||
|
||||
if (_camera->getInheritanceMask() & osg::CullSettings::CLEAR_COLOR) camera->setClearColor(_camera->getClearColor());
|
||||
}
|
||||
|
||||
unsigned int i = _slaves.size();
|
||||
|
||||
_slaves.push_back(Slave(camera, projectionOffset, viewOffset));
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Added camera"<<std::endl;
|
||||
updateSlave(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -90,10 +88,19 @@ bool View::removeSlave(unsigned int pos)
|
||||
_slaves[pos]._camera->setCullCallback(0);
|
||||
|
||||
_slaves.erase(_slaves.begin()+pos);
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Removed camera"<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
View::Slave* View::findSlaveForCamera(osg::Camera* camera)
|
||||
{
|
||||
if (_camera == camera) return 0;
|
||||
|
||||
for(unsigned int i=0; i<_slaves.size(); ++i)
|
||||
{
|
||||
if (_slaves[i]._camera == camera) return &(_slaves[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ Viewport::~Viewport()
|
||||
|
||||
void Viewport::apply(State&) const
|
||||
{
|
||||
glViewport(_x,_y,_width,_height);
|
||||
glViewport( static_cast<GLint>(_x),static_cast<GLint>(_y),
|
||||
static_cast<GLsizei>(_width),static_cast<GLsizei>(_height) );
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ bool EventQueue::copyEvents(Events& events) const
|
||||
}
|
||||
|
||||
|
||||
void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height, double time)
|
||||
void EventQueue::windowResize(int x, int y, int width, int height, double time)
|
||||
{
|
||||
_accumulateEventState->setWindowRectangle(x, y, width, height, !_useFixedMouseInputRange);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ GUIEventAdapter::~GUIEventAdapter()
|
||||
{
|
||||
}
|
||||
|
||||
void GUIEventAdapter::setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange)
|
||||
void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
|
||||
{
|
||||
_windowX = x;
|
||||
_windowY = y;
|
||||
|
||||
@@ -232,8 +232,7 @@ bool TrackballManipulator::calcMovement()
|
||||
|
||||
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
|
||||
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
|
||||
|
||||
|
||||
|
||||
// return if there is no movement.
|
||||
if (dx==0.0f && dy==0.0f)
|
||||
{
|
||||
|
||||
@@ -51,10 +51,10 @@ void Viewport::read(DataInputStream* in){
|
||||
throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object.");
|
||||
|
||||
// Read Viewport's properties
|
||||
x() = (GLenum)in->readInt();
|
||||
y() = (GLenum)in->readInt();
|
||||
width() = (GLenum)in->readInt();
|
||||
height() = (GLenum)in->readInt();
|
||||
x() = in->readInt();
|
||||
y() = in->readInt();
|
||||
width() = in->readInt();
|
||||
height() = in->readInt();
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -44,12 +44,10 @@ class Logos: public osg::Drawable
|
||||
osg::Viewport *vp = cv->getViewport();
|
||||
if( vp != NULL )
|
||||
{
|
||||
int x, y, aw, ah, bw, bh;
|
||||
logos->getViewport()->getViewport( x, y, aw, ah );
|
||||
vp->getViewport(x, y, bw, bh );
|
||||
if( aw != bw || ah != bh )
|
||||
if( vp->width() != logos->getViewport()->width() ||
|
||||
vp->height() != logos->getViewport()->height() )
|
||||
{
|
||||
logos->getViewport()->setViewport( x, y, bw, bh );
|
||||
logos->getViewport()->setViewport( vp->x(), vp->y(), vp->width(), vp->height() );
|
||||
logos->dirtyDisplayList();
|
||||
}
|
||||
}
|
||||
@@ -91,13 +89,18 @@ class Logos: public osg::Drawable
|
||||
if( state.getContextID() != _contextID )
|
||||
return;
|
||||
|
||||
int x = 0, y = 0, w = 1, h = 1;
|
||||
if( viewport != NULL )
|
||||
viewport->getViewport( x, y, w, h );
|
||||
float vx = x;
|
||||
float vy = y;
|
||||
float vw = w;
|
||||
float vh = h;
|
||||
|
||||
float vx = 0.0;
|
||||
float vy = 0.0;
|
||||
float vw = 1.0;
|
||||
float vh = 1.0;
|
||||
if (viewport)
|
||||
{
|
||||
vx = viewport->x();
|
||||
vy = viewport->y();
|
||||
vx = viewport->width();
|
||||
vy = viewport->height();
|
||||
}
|
||||
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glPushMatrix();
|
||||
|
||||
@@ -25,28 +25,27 @@ RegisterDotOsgWrapperProxy g_ViewportProxy
|
||||
bool Viewport_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
int x = 0, y = 0, width = 0, height = 0;
|
||||
double x = 0, y = 0, width = 0, height = 0;
|
||||
|
||||
|
||||
if (fr[0].matchWord("x") && fr[1].getInt(x))
|
||||
if (fr[0].matchWord("x") && fr[1].getFloat(x))
|
||||
{
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("y") && fr[1].getInt(y))
|
||||
if (fr[0].matchWord("y") && fr[1].getFloat(y))
|
||||
{
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("width") && fr[1].getInt(width))
|
||||
if (fr[0].matchWord("width") && fr[1].getFloat(width))
|
||||
{
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("height") && fr[1].getInt(height))
|
||||
if (fr[0].matchWord("height") && fr[1].getFloat(height))
|
||||
{
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
|
||||
@@ -24,6 +24,7 @@ CXXFILES = \
|
||||
Simplifier.cpp\
|
||||
SmoothingVisitor.cpp\
|
||||
StateGraph.cpp\
|
||||
Statistics.cpp\
|
||||
TangentSpaceGenerator.cpp\
|
||||
Tesselator.cpp\
|
||||
TransformAttributeFunctor.cpp\
|
||||
|
||||
@@ -104,7 +104,7 @@ SceneView::SceneView(DisplaySettings* ds)
|
||||
_initCalled = false;
|
||||
|
||||
|
||||
_drawBufferValue = GL_BACK;
|
||||
setDrawBufferValue(GL_BACK);
|
||||
|
||||
_requiresFlush = true;
|
||||
|
||||
@@ -134,9 +134,6 @@ SceneView::SceneView(const SceneView& rhs, const osg::CopyOp& copyop):
|
||||
|
||||
_initCalled = rhs._initCalled;
|
||||
|
||||
|
||||
_drawBufferValue = rhs._drawBufferValue;
|
||||
|
||||
_requiresFlush = rhs._requiresFlush;
|
||||
|
||||
_activeUniforms = rhs._activeUniforms;
|
||||
@@ -490,6 +487,8 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi
|
||||
|
||||
void SceneView::cull()
|
||||
{
|
||||
_renderInfo.setView(_camera->getView());
|
||||
|
||||
// update the active uniforms
|
||||
updateUniforms();
|
||||
|
||||
@@ -883,13 +882,13 @@ void SceneView::draw()
|
||||
break;
|
||||
case(osg::DisplaySettings::ANAGLYPHIC):
|
||||
{
|
||||
if( _drawBufferValue != GL_NONE)
|
||||
if( getDrawBufferValue() != GL_NONE)
|
||||
{
|
||||
_renderStageLeft->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setReadBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageLeft->setReadBuffer(getDrawBufferValue());
|
||||
|
||||
_renderStageRight->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageRight->setReadBuffer(_drawBufferValue);
|
||||
_renderStageRight->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageRight->setReadBuffer(getDrawBufferValue());
|
||||
}
|
||||
|
||||
_localStateSet->setAttribute(getViewport());
|
||||
@@ -944,13 +943,13 @@ void SceneView::draw()
|
||||
break;
|
||||
case(osg::DisplaySettings::HORIZONTAL_SPLIT):
|
||||
{
|
||||
if( _drawBufferValue != GL_NONE)
|
||||
if( getDrawBufferValue() != GL_NONE)
|
||||
{
|
||||
_renderStageLeft->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setReadBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageLeft->setReadBuffer(getDrawBufferValue());
|
||||
|
||||
_renderStageRight->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageRight->setReadBuffer(_drawBufferValue);
|
||||
_renderStageRight->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageRight->setReadBuffer(getDrawBufferValue());
|
||||
}
|
||||
|
||||
// ensure that all color planes are active.
|
||||
@@ -1010,13 +1009,13 @@ void SceneView::draw()
|
||||
break;
|
||||
case(osg::DisplaySettings::VERTICAL_SPLIT):
|
||||
{
|
||||
if( _drawBufferValue != GL_NONE)
|
||||
if( getDrawBufferValue() != GL_NONE)
|
||||
{
|
||||
_renderStageLeft->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setReadBuffer(_drawBufferValue);
|
||||
_renderStageLeft->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageLeft->setReadBuffer(getDrawBufferValue());
|
||||
|
||||
_renderStageRight->setDrawBuffer(_drawBufferValue);
|
||||
_renderStageRight->setReadBuffer(_drawBufferValue);
|
||||
_renderStageRight->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStageRight->setReadBuffer(getDrawBufferValue());
|
||||
}
|
||||
|
||||
// ensure that all color planes are active.
|
||||
@@ -1075,10 +1074,10 @@ void SceneView::draw()
|
||||
case(osg::DisplaySettings::RIGHT_EYE):
|
||||
case(osg::DisplaySettings::LEFT_EYE):
|
||||
{
|
||||
if( _drawBufferValue != GL_NONE)
|
||||
if( getDrawBufferValue() != GL_NONE)
|
||||
{
|
||||
_renderStage->setDrawBuffer(_drawBufferValue);
|
||||
_renderStage->setReadBuffer(_drawBufferValue);
|
||||
_renderStage->setDrawBuffer(getDrawBufferValue());
|
||||
_renderStage->setReadBuffer(getDrawBufferValue());
|
||||
}
|
||||
|
||||
// ensure that all color planes are active.
|
||||
@@ -1241,10 +1240,15 @@ void SceneView::draw()
|
||||
{
|
||||
|
||||
// Need to restore draw buffer when toggling Stereo off.
|
||||
if( _drawBufferValue != GL_NONE)
|
||||
if( _camera->getDrawBuffer() != GL_NONE)
|
||||
{
|
||||
_renderStage->setDrawBuffer(_drawBufferValue);
|
||||
_renderStage->setReadBuffer(_drawBufferValue);
|
||||
_renderStage->setDrawBuffer(_camera->getDrawBuffer());
|
||||
_renderStage->setReadBuffer(_camera->getDrawBuffer());
|
||||
}
|
||||
|
||||
if( _camera->getReadBuffer() != GL_NONE)
|
||||
{
|
||||
_renderStage->setReadBuffer(_camera->getReadBuffer());
|
||||
}
|
||||
|
||||
_localStateSet->setAttribute(getViewport());
|
||||
|
||||
320
src/osgUtil/Statistics.cpp
Normal file
320
src/osgUtil/Statistics.cpp
Normal file
@@ -0,0 +1,320 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <osgUtil/Statistics>
|
||||
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Geode>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Transform>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <ostream>
|
||||
|
||||
using namespace osgUtil;
|
||||
|
||||
Statistics::Statistics()
|
||||
{
|
||||
reset();
|
||||
};
|
||||
|
||||
void Statistics::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 Statistics::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);
|
||||
}
|
||||
|
||||
void Statistics::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);
|
||||
}
|
||||
|
||||
void Statistics::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);
|
||||
}
|
||||
|
||||
void Statistics::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);
|
||||
}
|
||||
|
||||
|
||||
void Statistics::begin(GLenum mode)
|
||||
{
|
||||
_currentPrimitiveFunctorMode=mode;
|
||||
PrimitivePair& prim = _primitiveCount[mode];
|
||||
++prim.first;
|
||||
_number_of_vertexes = 0;
|
||||
}
|
||||
|
||||
void Statistics::end()
|
||||
{
|
||||
_primitives_count[_currentPrimitiveFunctorMode] +=
|
||||
_calculate_primitives_number_by_mode(_currentPrimitiveFunctorMode, _number_of_vertexes);
|
||||
|
||||
_vertexCount += _number_of_vertexes;
|
||||
}
|
||||
|
||||
void Statistics::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;
|
||||
}
|
||||
|
||||
StatsVisitor::StatsVisitor():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_numInstancedGroup(0),
|
||||
_numInstancedSwitch(0),
|
||||
_numInstancedLOD(0),
|
||||
_numInstancedTransform(0),
|
||||
_numInstancedGeode(0),
|
||||
_numInstancedDrawable(0),
|
||||
_numInstancedGeometry(0),
|
||||
_numInstancedStateSet(0)
|
||||
{}
|
||||
|
||||
void StatsVisitor::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 StatsVisitor::apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void StatsVisitor::apply(osg::Group& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedGroup;
|
||||
_groupSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void StatsVisitor::apply(osg::Transform& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedTransform;
|
||||
_transformSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void StatsVisitor::apply(osg::LOD& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedLOD;
|
||||
_lodSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void StatsVisitor::apply(osg::Switch& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
++_numInstancedStateSet;
|
||||
_statesetSet.insert(node.getStateSet());
|
||||
}
|
||||
|
||||
++_numInstancedSwitch;
|
||||
_switchSet.insert(&node);
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void StatsVisitor::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 StatsVisitor::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 StatsVisitor::totalUpStats()
|
||||
{
|
||||
_uniqueStats.reset();
|
||||
|
||||
for(DrawableSet::iterator itr = _drawableSet.begin();
|
||||
itr != _drawableSet.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->accept(_uniqueStats);
|
||||
}
|
||||
}
|
||||
|
||||
void StatsVisitor::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;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,141 @@ class GraphicsContextX11 : public osg::GraphicsContext
|
||||
|
||||
}
|
||||
|
||||
class X11KeyboardMap
|
||||
{
|
||||
public:
|
||||
|
||||
X11KeyboardMap()
|
||||
{
|
||||
_keymap[XK_Escape ] = osgGA::GUIEventAdapter::KEY_Escape;
|
||||
_keymap[XK_F1 ] = osgGA::GUIEventAdapter::KEY_F1;
|
||||
_keymap[XK_F2 ] = osgGA::GUIEventAdapter::KEY_F2;
|
||||
_keymap[XK_F3 ] = osgGA::GUIEventAdapter::KEY_F3;
|
||||
_keymap[XK_F4 ] = osgGA::GUIEventAdapter::KEY_F4;
|
||||
_keymap[XK_F5 ] = osgGA::GUIEventAdapter::KEY_F5;
|
||||
_keymap[XK_F6 ] = osgGA::GUIEventAdapter::KEY_F6;
|
||||
_keymap[XK_F7 ] = osgGA::GUIEventAdapter::KEY_F7;
|
||||
_keymap[XK_F8 ] = osgGA::GUIEventAdapter::KEY_F8;
|
||||
_keymap[XK_F9 ] = osgGA::GUIEventAdapter::KEY_F9;
|
||||
_keymap[XK_F10 ] = osgGA::GUIEventAdapter::KEY_F10;
|
||||
_keymap[XK_F11 ] = osgGA::GUIEventAdapter::KEY_F11;
|
||||
_keymap[XK_F12 ] = osgGA::GUIEventAdapter::KEY_F12;
|
||||
_keymap[XK_quoteleft ] = '"';
|
||||
_keymap[XK_1 ] = '1';
|
||||
_keymap[XK_2 ] = '2';
|
||||
_keymap[XK_3 ] = '3';
|
||||
_keymap[XK_4 ] = '4';
|
||||
_keymap[XK_5 ] = '5';
|
||||
_keymap[XK_6 ] = '6';
|
||||
_keymap[XK_7 ] = '7';
|
||||
_keymap[XK_8 ] = '8';
|
||||
_keymap[XK_9 ] = '9';
|
||||
_keymap[XK_0 ] = '0';
|
||||
_keymap[XK_minus ] = '-';
|
||||
_keymap[XK_equal ] = '=';
|
||||
_keymap[XK_BackSpace ] = osgGA::GUIEventAdapter::KEY_BackSpace;
|
||||
_keymap[XK_Tab ] = osgGA::GUIEventAdapter::KEY_Tab;
|
||||
_keymap[XK_a ] = 'A';
|
||||
_keymap[XK_b ] = 'B';
|
||||
_keymap[XK_c ] = 'C';
|
||||
_keymap[XK_d ] = 'D';
|
||||
_keymap[XK_e ] = 'E';
|
||||
_keymap[XK_f ] = 'F';
|
||||
_keymap[XK_g ] = 'G';
|
||||
_keymap[XK_h ] = 'H';
|
||||
_keymap[XK_i ] = 'I';
|
||||
_keymap[XK_j ] = 'J';
|
||||
_keymap[XK_k ] = 'K';
|
||||
_keymap[XK_l ] = 'L';
|
||||
_keymap[XK_m ] = 'M';
|
||||
_keymap[XK_n ] = 'N';
|
||||
_keymap[XK_o ] = 'O';
|
||||
_keymap[XK_p ] = 'P';
|
||||
_keymap[XK_q ] = 'Q';
|
||||
_keymap[XK_r ] = 'R';
|
||||
_keymap[XK_s ] = 'S';
|
||||
_keymap[XK_t ] = 'T';
|
||||
_keymap[XK_u ] = 'U';
|
||||
_keymap[XK_v ] = 'V';
|
||||
_keymap[XK_w ] = 'W';
|
||||
_keymap[XK_x ] = 'X';
|
||||
_keymap[XK_y ] = 'Y';
|
||||
_keymap[XK_z ] = 'Z';
|
||||
_keymap[XK_bracketleft ] = '(';
|
||||
_keymap[XK_bracketright ] = ')';
|
||||
_keymap[XK_backslash ] = '\\';
|
||||
_keymap[XK_Caps_Lock ] = osgGA::GUIEventAdapter::KEY_Caps_Lock;
|
||||
_keymap[XK_semicolon ] = ';';
|
||||
_keymap[XK_apostrophe ] = '\'';
|
||||
_keymap[XK_Return ] = osgGA::GUIEventAdapter::KEY_Return;
|
||||
_keymap[XK_Shift_L ] = osgGA::GUIEventAdapter::KEY_Shift_L;
|
||||
_keymap[XK_comma ] = ',';
|
||||
_keymap[XK_period ] = '.';
|
||||
_keymap[XK_slash ] = '/';
|
||||
_keymap[XK_Shift_R ] = osgGA::GUIEventAdapter::KEY_Shift_R;
|
||||
_keymap[XK_Control_L ] = osgGA::GUIEventAdapter::KEY_Control_L;
|
||||
_keymap[XK_Super_L ] = osgGA::GUIEventAdapter::KEY_Super_L;
|
||||
_keymap[XK_space ] = ' ';
|
||||
_keymap[XK_Alt_L ] = osgGA::GUIEventAdapter::KEY_Alt_L;
|
||||
_keymap[XK_Alt_R ] = osgGA::GUIEventAdapter::KEY_Alt_R;
|
||||
_keymap[XK_Super_R ] = osgGA::GUIEventAdapter::KEY_Super_R;
|
||||
_keymap[XK_Menu ] = osgGA::GUIEventAdapter::KEY_Menu;
|
||||
_keymap[XK_Control_R ] = osgGA::GUIEventAdapter::KEY_Control_R;
|
||||
_keymap[XK_Print ] = osgGA::GUIEventAdapter::KEY_Print;
|
||||
_keymap[XK_Scroll_Lock ] = osgGA::GUIEventAdapter::KEY_Scroll_Lock;
|
||||
_keymap[XK_Pause ] = osgGA::GUIEventAdapter::KEY_Pause;
|
||||
_keymap[XK_Home ] = osgGA::GUIEventAdapter::KEY_Home;
|
||||
_keymap[XK_Page_Up ] = osgGA::GUIEventAdapter::KEY_Page_Up;
|
||||
_keymap[XK_End ] = osgGA::GUIEventAdapter::KEY_End;
|
||||
_keymap[XK_Page_Down ] = osgGA::GUIEventAdapter::KEY_Page_Down;
|
||||
_keymap[XK_Delete ] = osgGA::GUIEventAdapter::KEY_Delete;
|
||||
_keymap[XK_Insert ] = osgGA::GUIEventAdapter::KEY_Insert;
|
||||
_keymap[XK_Left ] = osgGA::GUIEventAdapter::KEY_Left;
|
||||
_keymap[XK_Up ] = osgGA::GUIEventAdapter::KEY_Up;
|
||||
_keymap[XK_Right ] = osgGA::GUIEventAdapter::KEY_Right;
|
||||
_keymap[XK_Down ] = osgGA::GUIEventAdapter::KEY_Down;
|
||||
_keymap[XK_Num_Lock ] = osgGA::GUIEventAdapter::KEY_Num_Lock;
|
||||
_keymap[XK_KP_Divide ] = osgGA::GUIEventAdapter::KEY_KP_Divide;
|
||||
_keymap[XK_KP_Multiply ] = osgGA::GUIEventAdapter::KEY_KP_Multiply;
|
||||
_keymap[XK_KP_Subtract ] = osgGA::GUIEventAdapter::KEY_KP_Subtract;
|
||||
_keymap[XK_KP_Add ] = osgGA::GUIEventAdapter::KEY_KP_Add;
|
||||
_keymap[XK_KP_Home ] = osgGA::GUIEventAdapter::KEY_KP_Home;
|
||||
_keymap[XK_KP_Up ] = osgGA::GUIEventAdapter::KEY_KP_Up;
|
||||
_keymap[XK_KP_Page_Up ] = osgGA::GUIEventAdapter::KEY_KP_Page_Up;
|
||||
_keymap[XK_KP_Left ] = osgGA::GUIEventAdapter::KEY_KP_Left;
|
||||
_keymap[XK_KP_Begin ] = osgGA::GUIEventAdapter::KEY_KP_Begin;
|
||||
_keymap[XK_KP_Right ] = osgGA::GUIEventAdapter::KEY_KP_Right;
|
||||
_keymap[XK_KP_End ] = osgGA::GUIEventAdapter::KEY_KP_End;
|
||||
_keymap[XK_KP_Down ] = osgGA::GUIEventAdapter::KEY_KP_Down;
|
||||
_keymap[XK_KP_Page_Down ] = osgGA::GUIEventAdapter::KEY_KP_Page_Down;
|
||||
_keymap[XK_KP_Insert ] = osgGA::GUIEventAdapter::KEY_KP_Insert;
|
||||
_keymap[XK_KP_Delete ] = osgGA::GUIEventAdapter::KEY_KP_Delete;
|
||||
_keymap[XK_KP_Enter ] = osgGA::GUIEventAdapter::KEY_KP_Enter;
|
||||
|
||||
}
|
||||
|
||||
~X11KeyboardMap() {}
|
||||
|
||||
int remapKey(int key)
|
||||
{
|
||||
KeyMap::iterator itr = _keymap.find(key);
|
||||
if (itr == _keymap.end()) return key;
|
||||
else return itr->second;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
typedef std::map<int, int> KeyMap;
|
||||
KeyMap _keymap;
|
||||
};
|
||||
|
||||
static int remapX11Key(int key)
|
||||
{
|
||||
static X11KeyboardMap s_x11KeyboardMap;
|
||||
return s_x11KeyboardMap.remapKey(key);
|
||||
}
|
||||
|
||||
bool GraphicsWindowX11::createVisualInfo()
|
||||
{
|
||||
typedef std::vector<int> Attributes;
|
||||
@@ -347,9 +482,12 @@ void GraphicsWindowX11::init()
|
||||
|
||||
// now update the window dimensions to account for any size changes made by the window manager,
|
||||
XGetWindowAttributes( _display, _window, &watt );
|
||||
_traits->width = watt.width;
|
||||
_traits->height = watt.height;
|
||||
|
||||
if (_traits->width != watt.width && _traits->height != watt.height)
|
||||
{
|
||||
resized( _traits->x, _traits->y, _traits->width, _traits->height );
|
||||
}
|
||||
|
||||
//osg::notify(osg::NOTICE)<<"After sync apply.x = "<<watt.x<<" watt.y="<<watt.y<<" width="<<watt.width<<" height="<<watt.height<<std::endl;
|
||||
|
||||
_valid = true;
|
||||
@@ -388,7 +526,6 @@ void GraphicsWindowX11::makeCurrentImplementation()
|
||||
// checkEvents();
|
||||
|
||||
glXMakeCurrent( _display, _window, _glxContext );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -422,8 +559,6 @@ void GraphicsWindowX11::swapBuffersImplementation()
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"swapBuffersImplementation "<<this<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
|
||||
|
||||
// makeCurrentImplementation();
|
||||
|
||||
glXSwapBuffers(_display, _window);
|
||||
|
||||
#if 0
|
||||
@@ -437,6 +572,11 @@ void GraphicsWindowX11::checkEvents()
|
||||
{
|
||||
if (!_realized) return;
|
||||
|
||||
int windowX = _traits->x;
|
||||
int windowY = _traits->y;
|
||||
int windowWidth = _traits->width;
|
||||
int windowHeight = _traits->height;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Check events"<<std::endl;
|
||||
while( XPending(_display) )
|
||||
{
|
||||
@@ -462,7 +602,7 @@ void GraphicsWindowX11::checkEvents()
|
||||
break;
|
||||
|
||||
case DestroyNotify :
|
||||
osg::notify(osg::INFO)<<"DestroyNotify"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"DestroyNotify"<<std::endl;
|
||||
_realized = false;
|
||||
break;
|
||||
|
||||
@@ -470,11 +610,17 @@ void GraphicsWindowX11::checkEvents()
|
||||
{
|
||||
osg::notify(osg::INFO)<<"ConfigureNotify x="<<ev.xconfigure.x<<" y="<<ev.xconfigure.y<<" width="<<ev.xconfigure.width<<", height="<<ev.xconfigure.height<<std::endl;
|
||||
|
||||
_traits->x = ev.xconfigure.x;
|
||||
_traits->y = ev.xconfigure.y;
|
||||
_traits->width = ev.xconfigure.width;
|
||||
_traits->height = ev.xconfigure.height;
|
||||
// need to dispatch resize event.
|
||||
if (windowX != ev.xconfigure.x ||
|
||||
windowX != ev.xconfigure.y ||
|
||||
windowWidth != ev.xconfigure.width ||
|
||||
windowHeight != ev.xconfigure.height)
|
||||
{
|
||||
windowX = ev.xconfigure.x;
|
||||
windowY = ev.xconfigure.y;
|
||||
windowWidth = ev.xconfigure.width;
|
||||
windowHeight = ev.xconfigure.height;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -487,8 +633,16 @@ void GraphicsWindowX11::checkEvents()
|
||||
while( watt.map_state != IsViewable );
|
||||
|
||||
osg::notify(osg::INFO)<<"MapNotify x="<<watt.x<<" y="<<watt.y<<" width="<<watt.width<<", height="<<watt.height<<std::endl;
|
||||
|
||||
if (windowWidth != watt.width || windowHeight != watt.height)
|
||||
{
|
||||
windowWidth = watt.width;
|
||||
windowHeight = watt.height;
|
||||
}
|
||||
|
||||
_traits->width = watt.width;
|
||||
_traits->height = watt.height;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -620,6 +774,15 @@ void GraphicsWindowX11::checkEvents()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (windowX != _traits->x ||
|
||||
windowY != _traits->y ||
|
||||
windowWidth != _traits->width ||
|
||||
windowHeight != _traits->height)
|
||||
{
|
||||
resized(windowX, windowY, windowWidth, windowHeight);
|
||||
getEventQueue()->windowResize(windowX, windowY, windowWidth, windowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::grabFocus()
|
||||
@@ -654,8 +817,7 @@ void GraphicsWindowX11::transformMouseXY(float& x, float& y)
|
||||
|
||||
void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask)
|
||||
{
|
||||
// KeySym ks = XKeycodeToKeysym( _display, keyevent.keycode, 0 );
|
||||
|
||||
|
||||
static XComposeStatus state;
|
||||
unsigned char keybuf[32];
|
||||
XLookupString( &keyevent, (char *)keybuf, sizeof(keybuf), NULL, &state );
|
||||
@@ -687,6 +849,33 @@ void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned i
|
||||
}
|
||||
|
||||
keySymbol = keybuf[0];
|
||||
|
||||
KeySym ks = XKeycodeToKeysym( _display, keyevent.keycode, 0 );
|
||||
int remappedKey = remapX11Key(ks);
|
||||
if (remappedKey & 0xff00)
|
||||
{
|
||||
// special keyboard character
|
||||
keySymbol = remappedKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal ascii key
|
||||
keySymbol = keybuf[0];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::requestWarpPointer(float x,float y)
|
||||
{
|
||||
XWarpPointer( _display,
|
||||
None,
|
||||
_window,
|
||||
0, 0, 0, 0,
|
||||
static_cast<int>(x), static_cast<int>(y) );
|
||||
|
||||
XFlush(_display);
|
||||
XSync(_display, 0);
|
||||
}
|
||||
|
||||
struct X11WindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface
|
||||
|
||||
@@ -15,20 +15,10 @@
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osgUtil/SceneView>
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
class ActionAdapter : public osgGA::GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
virtual ~ActionAdapter() {}
|
||||
|
||||
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
|
||||
virtual void requestContinuousUpdate(bool /*needed*/=true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
|
||||
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
|
||||
|
||||
};
|
||||
|
||||
View::View()
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Constructing osgViewer::View"<<std::endl;
|
||||
@@ -57,8 +47,7 @@ void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator)
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
||||
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->home(*dummyEvent, aa);
|
||||
_cameraManipulator->home(*dummyEvent, *this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +82,11 @@ void View::setUpViewAcrossAllScreens()
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
traits->height = height;
|
||||
#if 1
|
||||
traits->windowDecoration = false;
|
||||
#else
|
||||
traits->windowDecoration = true;
|
||||
#endif
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
@@ -112,18 +105,18 @@ void View::setUpViewAcrossAllScreens()
|
||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
_camera->setViewport(new osg::Viewport(0, 0, width, height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
|
||||
_camera->setDrawBuffer(buffer);
|
||||
_camera->setReadBuffer(buffer);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
double rotate_x = - double(numScreens-1) * 0.5 * fovx;
|
||||
|
||||
float inputRangeMinX = 0.0f;
|
||||
float inputRangeMinY = 0.0f;
|
||||
|
||||
float maxHeight = 0.0f;
|
||||
|
||||
|
||||
for(unsigned int i=0; i<numScreens; ++i, rotate_x += fovx)
|
||||
{
|
||||
unsigned int width, height;
|
||||
@@ -150,11 +143,6 @@ void View::setUpViewAcrossAllScreens()
|
||||
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
||||
gw->getEventQueue()->setUseFixedMouseInputRange(true);
|
||||
gw->getEventQueue()->getCurrentEventState()->setInputRange(inputRangeMinX, inputRangeMinY, inputRangeMinX+float(width),inputRangeMinY+float(height) );
|
||||
inputRangeMinX += float(width);
|
||||
|
||||
if (maxHeight < float(height)) maxHeight = float(height);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -163,12 +151,13 @@ void View::setUpViewAcrossAllScreens()
|
||||
|
||||
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate( rotate_x, 0.0, 1.0, 0.0));
|
||||
|
||||
}
|
||||
|
||||
getEventQueue()->setUseFixedMouseInputRange(true);
|
||||
getEventQueue()->getCurrentEventState()->setInputRange(0.0f, 0.0, inputRangeMinX, maxHeight);
|
||||
}
|
||||
|
||||
setUpRenderingSupport();
|
||||
@@ -190,6 +179,9 @@ struct RenderingOperation : public osg::GraphicsOperation
|
||||
{
|
||||
if (!_sceneView) return;
|
||||
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"RenderingOperation"<<std::endl;
|
||||
|
||||
_sceneView->cull();
|
||||
_sceneView->draw();
|
||||
|
||||
@@ -255,8 +247,7 @@ void View::assignSceneDataToCameras()
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
||||
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->home(*dummyEvent, aa);
|
||||
_cameraManipulator->home(*dummyEvent, *this);
|
||||
}
|
||||
|
||||
if (_camera.valid())
|
||||
@@ -275,3 +266,81 @@ void View::assignSceneDataToCameras()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::requestRedraw()
|
||||
{
|
||||
}
|
||||
|
||||
void View::requestContinuousUpdate(bool)
|
||||
{
|
||||
}
|
||||
|
||||
void View::requestWarpPointer(float x,float y)
|
||||
{
|
||||
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
||||
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
|
||||
if (gw)
|
||||
{
|
||||
bool gw_invert_y = gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
||||
|
||||
x = x * float(gw->getTraits()->width) / (eventState->getXmax()-eventState->getXmin());
|
||||
y = y * float(gw->getTraits()->height) / (eventState->getYmax()-eventState->getYmin());
|
||||
|
||||
if (view_invert_y != gw_invert_y) y = gw->getTraits()->height - y;
|
||||
|
||||
gw->requestWarpPointer(x, y);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
|
||||
|
||||
x = (x - eventState->getXmin()) * 2.0 / (eventState->getXmax()-eventState->getXmin()) - 1.0;
|
||||
y = (y - eventState->getYmin())* 2.0 / (eventState->getYmax()-eventState->getYmin()) - 1.0;
|
||||
|
||||
if (view_invert_y) y = - y;
|
||||
|
||||
for(unsigned i=0; i<getNumSlaves(); ++i)
|
||||
{
|
||||
Slave& slave = getSlave(i);
|
||||
if (slave._camera.valid())
|
||||
{
|
||||
osg::Camera* camera = slave._camera.get();
|
||||
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
||||
|
||||
osg::Matrix localCameraVPW = camera->getViewMatrix() * camera->getProjectionMatrix();
|
||||
if (viewport) localCameraVPW *= viewport->computeWindowMatrix();
|
||||
|
||||
osg::Matrix matrix( osg::Matrix::inverse(masterCameraVPW) * localCameraVPW );
|
||||
|
||||
osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix;
|
||||
|
||||
if (viewport &&
|
||||
new_coord.x() >= viewport->x() && new_coord.y() >= viewport->y() &&
|
||||
new_coord.x() <= (viewport->x()+viewport->width()) && new_coord.y() <= (viewport->y()+viewport->height()) )
|
||||
{
|
||||
gw = dynamic_cast<osgViewer::GraphicsWindow*>(camera->getGraphicsContext());
|
||||
if (gw)
|
||||
{
|
||||
x = new_coord.x();
|
||||
y = new_coord.y();
|
||||
|
||||
bool gw_invert_y = gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
||||
|
||||
if (gw_invert_y) y = gw->getTraits()->height - y;
|
||||
|
||||
gw->requestWarpPointer(x, y);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,10 @@
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
#include <osg/GLExtensions>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
class ActionAdapter : public osgGA::GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
virtual ~ActionAdapter() {}
|
||||
|
||||
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
|
||||
virtual void requestContinuousUpdate(bool =true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
|
||||
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
|
||||
|
||||
};
|
||||
|
||||
Viewer::Viewer():
|
||||
_firstFrame(true),
|
||||
_done(false)
|
||||
@@ -69,8 +60,7 @@ void Viewer::init()
|
||||
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->init(*initEvent, aa);
|
||||
_cameraManipulator->init(*initEvent, *this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,12 +147,14 @@ void Viewer::realize()
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Viewer::realize()"<<std::endl;
|
||||
|
||||
setCameraWithFocus(0);
|
||||
|
||||
Contexts::iterator citr;
|
||||
|
||||
Contexts contexts;
|
||||
getContexts(contexts);
|
||||
|
||||
bool multiThreaded = getNumSlaves() > 1;
|
||||
bool multiThreaded = contexts.size() > 1;
|
||||
|
||||
if (multiThreaded)
|
||||
{
|
||||
@@ -223,7 +215,6 @@ void Viewer::realize()
|
||||
// initialize the global timer to be relative to the current time.
|
||||
osg::Timer::instance()->setStartTick();
|
||||
|
||||
|
||||
if (multiThreaded)
|
||||
{
|
||||
for(citr = contexts.begin();
|
||||
@@ -238,7 +229,6 @@ void Viewer::realize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +271,20 @@ void Viewer::frameEventTraversal()
|
||||
Contexts contexts;
|
||||
getContexts(contexts);
|
||||
|
||||
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
||||
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
|
||||
if (getCamera()->getViewport())
|
||||
{
|
||||
osg::Viewport* viewport = getCamera()->getViewport();
|
||||
masterCameraVPW *= viewport->computeWindowMatrix();
|
||||
eventState->setInputRange( viewport->x(), viewport->y(), viewport->x() + viewport->width(), viewport->y() + viewport->height());
|
||||
}
|
||||
else
|
||||
{
|
||||
eventState->setInputRange(-1.0, -1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
for(Contexts::iterator citr = contexts.begin();
|
||||
citr != contexts.end();
|
||||
++citr)
|
||||
@@ -289,11 +293,104 @@ void Viewer::frameEventTraversal()
|
||||
if (gw)
|
||||
{
|
||||
gw->checkEvents();
|
||||
gw->getEventQueue()->takeEvents(events);
|
||||
|
||||
osgGA::EventQueue::Events gw_events;
|
||||
gw->getEventQueue()->takeEvents(gw_events);
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = gw_events.begin();
|
||||
itr != gw_events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
bool pointerEvent = false;
|
||||
|
||||
float x = event->getX();
|
||||
float y = event->getY();
|
||||
|
||||
bool invert_y = event->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
||||
if (invert_y) y = gw->getTraits()->height - y;
|
||||
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
case(osgGA::GUIEventAdapter::RELEASE):
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
case(osgGA::GUIEventAdapter::MOVE):
|
||||
{
|
||||
pointerEvent = true;
|
||||
|
||||
if (event->getEventType()!=osgGA::GUIEventAdapter::DRAG || !getCameraWithFocus())
|
||||
{
|
||||
osg::GraphicsContext::Cameras& cameras = gw->getCameras();
|
||||
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
|
||||
citr != cameras.end();
|
||||
++citr)
|
||||
{
|
||||
osg::Camera* camera = *citr;
|
||||
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
||||
if (viewport &&
|
||||
x >= viewport->x() && y >= viewport->y() &&
|
||||
x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) )
|
||||
{
|
||||
setCameraWithFocus(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pointerEvent)
|
||||
{
|
||||
if (getCameraWithFocus())
|
||||
{
|
||||
osg::Viewport* viewport = getCameraWithFocus()->getViewport();
|
||||
osg::Matrix localCameraVPW = getCameraWithFocus()->getViewMatrix() * getCameraWithFocus()->getProjectionMatrix();
|
||||
if (viewport) localCameraVPW *= viewport->computeWindowMatrix();
|
||||
|
||||
osg::Matrix matrix( osg::Matrix::inverse(localCameraVPW) * masterCameraVPW );
|
||||
|
||||
osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix;
|
||||
|
||||
x = new_coord.x();
|
||||
y = new_coord.y();
|
||||
|
||||
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
||||
event->setX(x);
|
||||
event->setY(y);
|
||||
event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
||||
|
||||
}
|
||||
// pass along the new pointer events details to the eventState of the viewer
|
||||
eventState->setX(x);
|
||||
eventState->setY(y);
|
||||
eventState->setButtonMask(event->getButtonMask());
|
||||
eventState->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
||||
event->setX(eventState->getX());
|
||||
event->setY(eventState->getY());
|
||||
event->setButtonMask(eventState->getButtonMask());
|
||||
event->setMouseYOrientation(eventState->getMouseYOrientation());
|
||||
}
|
||||
//osg::notify(osg::NOTICE)<<" mouse x = "<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<" mouse Xmin = "<<event->getXmin()<<" Ymin="<<event->getYmin()<<" xMax="<<event->getXmax()<<" Ymax="<<event->getYmax()<<std::endl;
|
||||
}
|
||||
|
||||
events.insert(events.end(), gw_events.begin(), gw_events.end());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
||||
#if 0
|
||||
// pointer coordinate transform
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
@@ -321,12 +418,13 @@ void Viewer::frameEventTraversal()
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
|
||||
|
||||
|
||||
_eventQueue->frame( _scene->getFrameStamp()->getReferenceTime() );
|
||||
|
||||
_eventQueue->takeEvents(events);
|
||||
|
||||
|
||||
@@ -360,6 +458,9 @@ void Viewer::frameEventTraversal()
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
osg::notify(osg::NOTICE)<<" KEYUP '"<<(char)event->getKey()<<"'"<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::RESIZE):
|
||||
osg::notify(osg::NOTICE)<<" RESIZE "<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::FRAME):
|
||||
// osg::notify(osg::NOTICE)<<" FRAME "<<std::endl;
|
||||
break;
|
||||
@@ -379,7 +480,7 @@ void Viewer::frameEventTraversal()
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
if (event->getKey()=='q') _done = true;
|
||||
if (event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -388,8 +489,6 @@ void Viewer::frameEventTraversal()
|
||||
|
||||
if (_done) return;
|
||||
|
||||
ActionAdapter aa;
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
@@ -400,16 +499,17 @@ void Viewer::frameEventTraversal()
|
||||
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
_cameraManipulator->handle( *event, aa);
|
||||
_cameraManipulator->handle( *event, *this);
|
||||
}
|
||||
|
||||
for(EventHandlers::iterator hitr = _eventHandlers.begin();
|
||||
hitr != _eventHandlers.end() && !handled;
|
||||
++hitr)
|
||||
{
|
||||
handled = (*hitr)->handle( *event, aa, 0, 0);
|
||||
handled = (*hitr)->handle( *event, *this, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Viewer::frameUpdateTraversal()
|
||||
|
||||
Reference in New Issue
Block a user