Merge branch 'tbm/graphics-bug' into next
This commit is contained in:
commit
0603aba9ae
5 changed files with 45 additions and 20 deletions
|
@ -37,6 +37,7 @@
|
||||||
#include <osg/StateSet>
|
#include <osg/StateSet>
|
||||||
#include <osgDB/FileNameUtils>
|
#include <osgDB/FileNameUtils>
|
||||||
|
|
||||||
|
#include <simgear/scene/util/RenderConstants.hxx>
|
||||||
#include <simgear/screen/extensions.hxx>
|
#include <simgear/screen/extensions.hxx>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
|
||||||
|
@ -53,6 +54,8 @@ FGODGauge::FGODGauge() :
|
||||||
|
|
||||||
void FGODGauge::allocRT () {
|
void FGODGauge::allocRT () {
|
||||||
camera = new osg::Camera;
|
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,
|
camera->setProjectionMatrix(osg::Matrix::ortho2D(-256.0, 256.0, -256.0,
|
||||||
256.0));
|
256.0));
|
||||||
camera->setViewport(0, 0, textureWH, textureWH);
|
camera->setViewport(0, 0, textureWH, textureWH);
|
||||||
|
|
|
@ -134,8 +134,12 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
|
||||||
|
|
||||||
Camera* farCamera = 0;
|
Camera* farCamera = 0;
|
||||||
if ((flags & (GUI | ORTHO)) == 0) {
|
if ((flags & (GUI | ORTHO)) == 0) {
|
||||||
farCamera = simgear::clone(camera);
|
farCamera = new Camera;
|
||||||
|
farCamera->setAllowEventFocus(camera->getAllowEventFocus());
|
||||||
farCamera->setGraphicsContext(camera->getGraphicsContext());
|
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
|
// Each camera's viewport is written when the window is
|
||||||
// resized; if the the viewport isn't copied here, it gets updated
|
// resized; if the the viewport isn't copied here, it gets updated
|
||||||
// twice and ends up with the wrong value.
|
// twice and ends up with the wrong value.
|
||||||
|
@ -144,15 +148,15 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
|
||||||
installCullVisitor(farCamera);
|
installCullVisitor(farCamera);
|
||||||
info->farCamera = farCamera;
|
info->farCamera = farCamera;
|
||||||
info->farSlaveIndex = _viewer->getNumSlaves() - 1;
|
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->setCullMask(camera->getCullMask() & ~simgear::BACKGROUND_BIT);
|
||||||
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
|
||||||
_viewer->addSlave(camera, view, projection, useMasterSceneData);
|
_viewer->addSlave(camera, view, projection, useMasterSceneData);
|
||||||
installCullVisitor(camera);
|
installCullVisitor(camera);
|
||||||
info->camera = camera;
|
info->camera = camera;
|
||||||
info->slaveIndex = _viewer->getNumSlaves() - 1;
|
info->slaveIndex = _viewer->getNumSlaves() - 1;
|
||||||
camera->setRenderOrder(Camera::NESTED_RENDER, info->slaveIndex);
|
camera->setRenderOrder(Camera::POST_RENDER, info->slaveIndex);
|
||||||
_cameras.push_back(info);
|
_cameras.push_back(info);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -190,18 +194,22 @@ void CameraGroup::update(const osg::Vec3d& position,
|
||||||
double left, right, bottom, top, parentNear, parentFar;
|
double left, right, bottom, top, parentNear, parentFar;
|
||||||
projectionMatrix.getFrustum(left, right, bottom, top,
|
projectionMatrix.getFrustum(left, right, bottom, top,
|
||||||
parentNear, parentFar);
|
parentNear, parentFar);
|
||||||
if (parentFar < 100.0) {
|
if (parentFar < _nearField || _nearField == 0.0f) {
|
||||||
camera->setProjectionMatrix(projectionMatrix);
|
camera->setProjectionMatrix(projectionMatrix);
|
||||||
camera->setCullMask(camera->getCullMask()
|
camera->setCullMask(camera->getCullMask()
|
||||||
| simgear::BACKGROUND_BIT);
|
| simgear::BACKGROUND_BIT);
|
||||||
|
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
farCamera->setNodeMask(0);
|
farCamera->setNodeMask(0);
|
||||||
} else {
|
} else {
|
||||||
Matrix nearProj, farProj;
|
Matrix nearProj, farProj;
|
||||||
makeNewProjMat(projectionMatrix, parentNear, 100.0, nearProj);
|
makeNewProjMat(projectionMatrix, parentNear, _nearField,
|
||||||
makeNewProjMat(projectionMatrix, 100.0, parentFar, farProj);
|
nearProj);
|
||||||
|
makeNewProjMat(projectionMatrix, _nearField, parentFar,
|
||||||
|
farProj);
|
||||||
camera->setProjectionMatrix(nearProj);
|
camera->setProjectionMatrix(nearProj);
|
||||||
camera->setCullMask(camera->getCullMask()
|
camera->setCullMask(camera->getCullMask()
|
||||||
& ~simgear::BACKGROUND_BIT);
|
& ~simgear::BACKGROUND_BIT);
|
||||||
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
||||||
farCamera->setProjectionMatrix(farProj);
|
farCamera->setProjectionMatrix(farProj);
|
||||||
farCamera->setNodeMask(camera->getNodeMask());
|
farCamera->setNodeMask(camera->getNodeMask());
|
||||||
}
|
}
|
||||||
|
@ -211,11 +219,9 @@ void CameraGroup::update(const osg::Vec3d& position,
|
||||||
|
|
||||||
void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
|
void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
|
||||||
{
|
{
|
||||||
const float zNear = .1f;
|
|
||||||
const float zFar = 120000.0f;
|
|
||||||
_viewer->getCamera()->setProjectionMatrixAsPerspective(vfov,
|
_viewer->getCamera()->setProjectionMatrixAsPerspective(vfov,
|
||||||
1.0f / aspectRatio,
|
1.0f / aspectRatio,
|
||||||
zNear, zFar);
|
_zNear, _zFar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,16 +450,25 @@ CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer,
|
||||||
cgroup->buildGUICamera(pNode);
|
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;
|
return cgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraGroup::setCameraCullMasks(Node::NodeMask nm)
|
void CameraGroup::setCameraCullMasks(Node::NodeMask nm)
|
||||||
{
|
{
|
||||||
for (CameraIterator i = camerasBegin(), e = camerasEnd(); i != e; ++i) {
|
for (CameraIterator i = camerasBegin(), e = camerasEnd(); i != e; ++i) {
|
||||||
if ((*i)->flags & GUI)
|
CameraInfo* info = i->get();
|
||||||
|
if (info->flags & GUI)
|
||||||
continue;
|
continue;
|
||||||
(*i)->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
|
if (info->farCamera.valid() && info->farCamera->getNodeMask() != 0) {
|
||||||
(*i)->farCamera->setCullMask(nm);
|
info->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
|
||||||
|
info->farCamera->setCullMask(nm);
|
||||||
|
} else {
|
||||||
|
info->camera->setCullMask(nm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,9 +527,12 @@ bool computeIntersections(const CameraGroup* cgroup,
|
||||||
Matrix windowMat = viewport->computeWindowMatrix();
|
Matrix windowMat = viewport->computeWindowMatrix();
|
||||||
Matrix startPtMat = Matrix::inverse(camera->getProjectionMatrix()
|
Matrix startPtMat = Matrix::inverse(camera->getProjectionMatrix()
|
||||||
* windowMat);
|
* windowMat);
|
||||||
Matrix endPtMat
|
Matrix endPtMat;
|
||||||
= Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
|
if (!cinfo->farCamera.valid() || cinfo->farCamera->getNodeMask() == 0)
|
||||||
* windowMat);
|
endPtMat = startPtMat;
|
||||||
|
else
|
||||||
|
endPtMat = Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
|
||||||
|
* windowMat);
|
||||||
start = start * startPtMat;
|
start = start * startPtMat;
|
||||||
start /= start.w();
|
start /= start.w();
|
||||||
end = end * endPtMat;
|
end = end * endPtMat;
|
||||||
|
|
|
@ -182,6 +182,10 @@ protected:
|
||||||
CameraList _cameras;
|
CameraList _cameras;
|
||||||
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
||||||
static osg::ref_ptr<CameraGroup> _defaultGroup;
|
static osg::ref_ptr<CameraGroup> _defaultGroup;
|
||||||
|
// Near, far for the master camera if used.
|
||||||
|
float _zNear;
|
||||||
|
float _zFar;
|
||||||
|
float _nearField;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,9 +103,9 @@ void fgOSOpenWindow(bool stencil)
|
||||||
// Look for windows, camera groups, and the old syntax of
|
// Look for windows, camera groups, and the old syntax of
|
||||||
// top-level cameras
|
// top-level cameras
|
||||||
SGPropertyNode* renderingNode = fgGetNode("/sim/rendering");
|
SGPropertyNode* renderingNode = fgGetNode("/sim/rendering");
|
||||||
SGPropertyNode* cgroupNode = renderingNode->getChild("camera-group");
|
SGPropertyNode* cgroupNode = renderingNode->getNode("camera-group", true);
|
||||||
if (!cgroupNode) {
|
bool oldSyntax = !cgroupNode->hasChild("camera");
|
||||||
cgroupNode = renderingNode->getNode("camera-group", true);
|
if (oldSyntax) {
|
||||||
for (int i = 0; i < renderingNode->nChildren(); ++i) {
|
for (int i = 0; i < renderingNode->nChildren(); ++i) {
|
||||||
SGPropertyNode* propNode = renderingNode->getChild(i);
|
SGPropertyNode* propNode = renderingNode->getChild(i);
|
||||||
const char* propName = propNode->getName();
|
const char* propName = propNode->getName();
|
||||||
|
|
|
@ -101,7 +101,7 @@ osg::Node* FGCreateRedoutNode()
|
||||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||||
camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
|
camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
|
||||||
camera->setViewMatrix(osg::Matrix::identity());
|
camera->setViewMatrix(osg::Matrix::identity());
|
||||||
camera->setRenderOrder(osg::Camera::POST_RENDER, 10);
|
camera->setRenderOrder(osg::Camera::POST_RENDER, 99);
|
||||||
camera->setClearMask(0);
|
camera->setClearMask(0);
|
||||||
camera->setAllowEventFocus(false);
|
camera->setAllowEventFocus(false);
|
||||||
camera->setCullingActive(false);
|
camera->setCullingActive(false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue