1
0
Fork 0

Merge branch 'tbm/graphics-bug' into next

This commit is contained in:
Tim Moore 2009-01-04 00:03:26 +01:00
commit 0603aba9ae
5 changed files with 45 additions and 20 deletions

View file

@ -37,6 +37,7 @@
#include <osg/StateSet>
#include <osgDB/FileNameUtils>
#include <simgear/scene/util/RenderConstants.hxx>
#include <simgear/screen/extensions.hxx>
#include <simgear/debug/logstream.hxx>
@ -53,6 +54,8 @@ FGODGauge::FGODGauge() :
void FGODGauge::allocRT () {
camera = new osg::Camera;
// Only the far camera should trigger this texture to be rendered.
camera->setNodeMask(simgear::BACKGROUND_BIT);
camera->setProjectionMatrix(osg::Matrix::ortho2D(-256.0, 256.0, -256.0,
256.0));
camera->setViewport(0, 0, textureWH, textureWH);

View file

@ -134,8 +134,12 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
Camera* farCamera = 0;
if ((flags & (GUI | ORTHO)) == 0) {
farCamera = simgear::clone(camera);
farCamera = new Camera;
farCamera->setAllowEventFocus(camera->getAllowEventFocus());
farCamera->setGraphicsContext(camera->getGraphicsContext());
farCamera->setCullingMode(camera->getCullingMode());
farCamera->setInheritanceMask(camera->getInheritanceMask());
farCamera->setReferenceFrame(Transform::ABSOLUTE_RF);
// Each camera's viewport is written when the window is
// resized; if the the viewport isn't copied here, it gets updated
// twice and ends up with the wrong value.
@ -144,15 +148,15 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
installCullVisitor(farCamera);
info->farCamera = farCamera;
info->farSlaveIndex = _viewer->getNumSlaves() - 1;
farCamera->setRenderOrder(Camera::NESTED_RENDER, info->farSlaveIndex);
farCamera->setRenderOrder(Camera::POST_RENDER, info->farSlaveIndex);
camera->setCullMask(camera->getCullMask() & ~simgear::BACKGROUND_BIT);
}
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
}
_viewer->addSlave(camera, view, projection, useMasterSceneData);
installCullVisitor(camera);
info->camera = camera;
info->slaveIndex = _viewer->getNumSlaves() - 1;
camera->setRenderOrder(Camera::NESTED_RENDER, info->slaveIndex);
camera->setRenderOrder(Camera::POST_RENDER, info->slaveIndex);
_cameras.push_back(info);
return info;
}
@ -190,18 +194,22 @@ void CameraGroup::update(const osg::Vec3d& position,
double left, right, bottom, top, parentNear, parentFar;
projectionMatrix.getFrustum(left, right, bottom, top,
parentNear, parentFar);
if (parentFar < 100.0) {
if (parentFar < _nearField || _nearField == 0.0f) {
camera->setProjectionMatrix(projectionMatrix);
camera->setCullMask(camera->getCullMask()
| simgear::BACKGROUND_BIT);
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
farCamera->setNodeMask(0);
} else {
Matrix nearProj, farProj;
makeNewProjMat(projectionMatrix, parentNear, 100.0, nearProj);
makeNewProjMat(projectionMatrix, 100.0, parentFar, farProj);
makeNewProjMat(projectionMatrix, parentNear, _nearField,
nearProj);
makeNewProjMat(projectionMatrix, _nearField, parentFar,
farProj);
camera->setProjectionMatrix(nearProj);
camera->setCullMask(camera->getCullMask()
& ~simgear::BACKGROUND_BIT);
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
farCamera->setProjectionMatrix(farProj);
farCamera->setNodeMask(camera->getNodeMask());
}
@ -211,11 +219,9 @@ void CameraGroup::update(const osg::Vec3d& position,
void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
{
const float zNear = .1f;
const float zFar = 120000.0f;
_viewer->getCamera()->setProjectionMatrixAsPerspective(vfov,
1.0f / aspectRatio,
zNear, zFar);
_zNear, _zFar);
}
}
@ -444,16 +450,25 @@ CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer,
cgroup->buildGUICamera(pNode);
}
}
bindMemberToNode(gnode, "znear", cgroup, &CameraGroup::_zNear, .4f);
bindMemberToNode(gnode, "zfar", cgroup, &CameraGroup::_zFar, 120000.0f);
bindMemberToNode(gnode, "near-field", cgroup, &CameraGroup::_nearField,
100.0f);
return cgroup;
}
void CameraGroup::setCameraCullMasks(Node::NodeMask nm)
{
for (CameraIterator i = camerasBegin(), e = camerasEnd(); i != e; ++i) {
if ((*i)->flags & GUI)
CameraInfo* info = i->get();
if (info->flags & GUI)
continue;
(*i)->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
(*i)->farCamera->setCullMask(nm);
if (info->farCamera.valid() && info->farCamera->getNodeMask() != 0) {
info->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
info->farCamera->setCullMask(nm);
} else {
info->camera->setCullMask(nm);
}
}
}
@ -512,8 +527,11 @@ bool computeIntersections(const CameraGroup* cgroup,
Matrix windowMat = viewport->computeWindowMatrix();
Matrix startPtMat = Matrix::inverse(camera->getProjectionMatrix()
* windowMat);
Matrix endPtMat
= Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
Matrix endPtMat;
if (!cinfo->farCamera.valid() || cinfo->farCamera->getNodeMask() == 0)
endPtMat = startPtMat;
else
endPtMat = Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
* windowMat);
start = start * startPtMat;
start /= start.w();

View file

@ -182,6 +182,10 @@ protected:
CameraList _cameras;
osg::ref_ptr<osgViewer::Viewer> _viewer;
static osg::ref_ptr<CameraGroup> _defaultGroup;
// Near, far for the master camera if used.
float _zNear;
float _zFar;
float _nearField;
};
}

View file

@ -103,9 +103,9 @@ void fgOSOpenWindow(bool stencil)
// Look for windows, camera groups, and the old syntax of
// top-level cameras
SGPropertyNode* renderingNode = fgGetNode("/sim/rendering");
SGPropertyNode* cgroupNode = renderingNode->getChild("camera-group");
if (!cgroupNode) {
cgroupNode = renderingNode->getNode("camera-group", true);
SGPropertyNode* cgroupNode = renderingNode->getNode("camera-group", true);
bool oldSyntax = !cgroupNode->hasChild("camera");
if (oldSyntax) {
for (int i = 0; i < renderingNode->nChildren(); ++i) {
SGPropertyNode* propNode = renderingNode->getChild(i);
const char* propName = propNode->getName();

View file

@ -101,7 +101,7 @@ osg::Node* FGCreateRedoutNode()
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
camera->setViewMatrix(osg::Matrix::identity());
camera->setRenderOrder(osg::Camera::POST_RENDER, 10);
camera->setRenderOrder(osg::Camera::POST_RENDER, 99);
camera->setClearMask(0);
camera->setAllowEventFocus(false);
camera->setCullingActive(false);