|
|
|
@ -831,7 +831,7 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
cubeTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::NEAREST);
|
|
|
|
|
cubeTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::NEAREST);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cubeTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
cubeTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
|
@ -856,19 +856,14 @@ namespace MWRender
|
|
|
|
|
stateset->addUniform(new osg::Uniform("cubeMap",0));
|
|
|
|
|
stateset->addUniform(new osg::Uniform("mapping",screenshotMapping));
|
|
|
|
|
stateset->setTextureAttributeAndModes(0,cubeTexture,osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quad->setStateSet(stateset);
|
|
|
|
|
quad->setUpdateCallback(nullptr);
|
|
|
|
|
|
|
|
|
|
screenshotCamera->addChild(quad);
|
|
|
|
|
|
|
|
|
|
mRootNode->addChild(screenshotCamera);
|
|
|
|
|
|
|
|
|
|
renderCameraToImage(screenshotCamera,image,screenshotW,screenshotH);
|
|
|
|
|
|
|
|
|
|
screenshotCamera->removeChildren(0,screenshotCamera->getNumChildren());
|
|
|
|
|
mRootNode->removeChild(screenshotCamera);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -893,6 +888,8 @@ namespace MWRender
|
|
|
|
|
image->setDataType(GL_UNSIGNED_BYTE);
|
|
|
|
|
image->setPixelFormat(texture->getInternalFormat());
|
|
|
|
|
|
|
|
|
|
mRootNode->addChild(camera);
|
|
|
|
|
|
|
|
|
|
// The draw needs to complete before we can copy back our image.
|
|
|
|
|
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback);
|
|
|
|
|
camera->setFinalDrawCallback(callback);
|
|
|
|
@ -908,32 +905,17 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
// now that we've "used up" the current frame, get a fresh framenumber for the next frame() following after the screenshot is completed
|
|
|
|
|
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
|
|
|
|
|
|
|
|
|
|
camera->removeChildren(0, camera->getNumChildren());
|
|
|
|
|
mRootNode->removeChild(camera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderingManager::screenshot(osg::Image *image, int w, int h, osg::Matrixd cameraTransform)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Camera> rttCamera (new osg::Camera);
|
|
|
|
|
rttCamera->setNodeMask(Mask_RenderToTexture);
|
|
|
|
|
rttCamera->attach(osg::Camera::COLOR_BUFFER, image);
|
|
|
|
|
rttCamera->setRenderOrder(osg::Camera::PRE_RENDER);
|
|
|
|
|
rttCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
|
rttCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::PIXEL_BUFFER_RTT);
|
|
|
|
|
rttCamera->setProjectionMatrixAsPerspective(mFieldOfView, w/float(h), mNearClip, mViewDistance);
|
|
|
|
|
rttCamera->setViewMatrix(mViewer->getCamera()->getViewMatrix() * cameraTransform);
|
|
|
|
|
|
|
|
|
|
rttCamera->setViewport(0, 0, w, h);
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D);
|
|
|
|
|
texture->setInternalFormat(GL_RGB);
|
|
|
|
|
texture->setTextureSize(w, h);
|
|
|
|
|
texture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
rttCamera->attach(osg::Camera::COLOR_BUFFER, texture);
|
|
|
|
|
|
|
|
|
|
image->setDataType(GL_UNSIGNED_BYTE);
|
|
|
|
|
image->setPixelFormat(texture->getInternalFormat());
|
|
|
|
|
|
|
|
|
|
rttCamera->setUpdateCallback(new NoTraverseCallback);
|
|
|
|
|
rttCamera->addChild(mSceneRoot);
|
|
|
|
|
|
|
|
|
@ -942,14 +924,9 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
rttCamera->setCullMask(mViewer->getCamera()->getCullMask() & (~Mask_GUI));
|
|
|
|
|
|
|
|
|
|
mRootNode->addChild(rttCamera);
|
|
|
|
|
|
|
|
|
|
rttCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
renderCameraToImage(rttCamera.get(),image,w,h);
|
|
|
|
|
|
|
|
|
|
rttCamera->removeChildren(0, rttCamera->getNumChildren());
|
|
|
|
|
mRootNode->removeChild(rttCamera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::Vec4f RenderingManager::getScreenBounds(const MWWorld::Ptr& ptr)
|
|
|
|
|