add framebuffer extension check and fix issues with manual screenshots

pull/3097/head
glassmancody.info 4 years ago
parent 70fac33940
commit d89e37d689

@ -450,6 +450,7 @@ namespace MWGui
osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D);
texture->setImage(result.getImage());
texture->setInternalFormat(GL_RGBA);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);

@ -116,6 +116,8 @@ namespace MWRender
mFbo->setAttachment(osg::Camera::COLOR_BUFFER0, osg::FrameBufferAttachment(mSceneTex));
mFbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(mDepthTex));
mViewer->getCamera()->setUserData(mFbo);
// When MSAA is enabled we must first render to a render buffer, then
// blit the result to the FBO which is either passed to the main frame
// buffer for display or used as the entry point for a post process chain.

@ -462,7 +462,10 @@ namespace MWRender
mRootNode->getOrCreateStateSet()->setAttributeAndModes(clipcontrol, osg::StateAttribute::ON);
}
mPostProcessor.reset(new PostProcessor(viewer, mRootNode));
if (ext && ext->isFrameBufferObjectSupported)
mPostProcessor.reset(new PostProcessor(viewer, mRootNode));
else
Log(Debug::Warning) << "Disabling postprocessing and using default framebuffer for rendering: FrameBufferObjects not supported";
updateProjectionMatrix();
}

@ -12,6 +12,7 @@
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/shader/shadermanager.hpp>
#include <components/sceneutil/util.hpp>
#include <components/settings/settings.hpp>
@ -88,6 +89,19 @@ namespace MWRender
int topPadding = std::max(0, static_cast<int>(screenH - screenW / imageaspect) / 2);
int width = screenW - leftPadding*2;
int height = screenH - topPadding*2;
// Ensure we are reading from the resolved framebuffer and not the multisampled render buffer when in use.
// glReadPixel() cannot read from multisampled targets.
osg::FrameBufferObject* fbo = dynamic_cast<osg::FrameBufferObject*>(renderInfo.getCurrentCamera()->getUserData());
if (fbo)
{
osg::GLExtensions* ext = osg::GLExtensions::Get(renderInfo.getContextID(), false);
if (ext)
ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo->getHandle(renderInfo.getContextID()));
}
mImage->readPixels(leftPadding, topPadding, width, height, GL_RGB, GL_UNSIGNED_BYTE);
mImage->scaleImage(mWidth, mHeight, 1);
}
@ -236,6 +250,7 @@ namespace MWRender
osg::ref_ptr<osg::Camera> screenshotCamera(new osg::Camera);
osg::ref_ptr<osg::ShapeDrawable> quad(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 2.0)));
quad->getOrCreateStateSet()->setRenderBinDetails(100, "RenderBin", osg::StateSet::USE_RENDERBIN_DETAILS);
std::map<std::string, std::string> defineMap;
@ -283,6 +298,9 @@ namespace MWRender
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT,osg::Camera::PIXEL_BUFFER_RTT);
if (MWBase::Environment::get().getResourceSystem()->getSceneManager()->getReverseZ())
camera->setClearDepth(0.0);
camera->setViewport(0, 0, w, h);
osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D);
@ -318,7 +336,10 @@ namespace MWRender
float nearClip = Settings::Manager::getFloat("near clip", "Camera");
float viewDistance = Settings::Manager::getFloat("viewing distance", "Camera");
// each cubemap side sees 90 degrees
rttCamera->setProjectionMatrixAsPerspective(90.0, w/float(h), nearClip, viewDistance);
if (MWBase::Environment::get().getResourceSystem()->getSceneManager()->getReverseZ())
rttCamera->setProjectionMatrix(SceneUtil::getReversedZProjectionMatrixAsPerspectiveInf(90.0, w/float(h), nearClip));
else
rttCamera->setProjectionMatrixAsPerspective(90.0, w/float(h), nearClip, viewDistance);
rttCamera->setViewMatrix(mViewer->getCamera()->getViewMatrix() * cameraTransform);
rttCamera->setUpdateCallback(new NoTraverseCallback);

Loading…
Cancel
Save