From df66decddab00a497eca7dcef27fb720ca0a5e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Thu, 29 Jul 2021 08:38:18 +0200 Subject: [PATCH] Compositor: Replace OSG camera resize function by own implementation --- simgear/scene/viewer/Compositor.cxx | 86 ++++++++++++++++++++++--- simgear/scene/viewer/CompositorPass.cxx | 8 +-- 2 files changed, 79 insertions(+), 15 deletions(-) diff --git a/simgear/scene/viewer/Compositor.cxx b/simgear/scene/viewer/Compositor.cxx index f474d793..8c591e9c 100644 --- a/simgear/scene/viewer/Compositor.cxx +++ b/simgear/scene/viewer/Compositor.cxx @@ -18,8 +18,14 @@ #include +#include +#include +#include +#include +#include +#include +#include #include - #include #include @@ -251,14 +257,78 @@ Compositor::resized() // viewport size. for (const auto &pass : _passes) { osg::Camera *camera = pass->camera; - if (!camera->isRenderToTextureCamera() || - pass->viewport_width_scale == 0.0f || - pass->viewport_height_scale == 0.0f) - continue; + if (camera && camera->isRenderToTextureCamera() + && pass->viewport_width_scale != 0.0f + && pass->viewport_height_scale != 0.0f) { - // Resize both the viewport and its texture attachments - camera->resize(pass->viewport_width_scale * _viewport->width(), - pass->viewport_height_scale * _viewport->height()); + // Resize the viewport + camera->setViewport(0, 0, + pass->viewport_width_scale * _viewport->width(), + pass->viewport_height_scale * _viewport->height()); + // Force the OSG rendering backend to handle the new sizes + camera->dirtyAttachmentMap(); + } + } + + // Resize buffers that must be a multiple of the screen size + for (const auto &buffer : _buffers) { + osg::Texture *texture = buffer.second->texture; + if (texture + && buffer.second->width_scale != 0.0f + && buffer.second->height_scale != 0.0f) { + + int width = buffer.second->width_scale * _viewport->width(); + int height = buffer.second->height_scale * _viewport->height(); + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureWidth(width); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height, tex->getTextureDepth()); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height, tex->getTextureDepth()); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height); + tex->dirtyTextureObject(); + } + } + { + auto tex = dynamic_cast(texture); + if (tex) { + tex->setTextureSize(width, height); + tex->dirtyTextureObject(); + } + } + } } } diff --git a/simgear/scene/viewer/CompositorPass.cxx b/simgear/scene/viewer/CompositorPass.cxx index ed174306..7c91f507 100644 --- a/simgear/scene/viewer/CompositorPass.cxx +++ b/simgear/scene/viewer/CompositorPass.cxx @@ -395,9 +395,7 @@ public: camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1)); // Do not automatically add a depth renderbuffer - camera->setImplicitBufferAttachmentMask( - osg::DisplaySettings::IMPLICIT_COLOR_BUFFER_ATTACHMENT, - osg::DisplaySettings::IMPLICIT_COLOR_BUFFER_ATTACHMENT); + camera->setImplicitBufferAttachmentMask(0, 0); float left = 0.0f, bottom = 0.0f, width = 1.0f, height = 1.0f, scale = 1.0f; const SGPropertyNode *p_geometry = root->getNode("geometry"); @@ -432,10 +430,6 @@ public: for (const auto &uniform : compositor->getUniforms()) ss->addUniform(uniform); - int cubemap_face = root->getIntValue("cubemap-face", -1); - if (cubemap_face >= 0) - ss->addUniform(new osg::Uniform("fg_CubemapFace", cubemap_face)); - return pass.release(); } protected: