From 984c775c0bd8116b463e4b0db0746ad2e8d8e8f4 Mon Sep 17 00:00:00 2001 From: Samuel Felton Date: Mon, 22 Apr 2024 18:35:10 +0200 Subject: [PATCH] Working on adding resizable buffers --- .../include/visp3/ar/vpPanda3DBaseRenderer.h | 18 ++++++++++++++++++ .../vpPanda3DGeometryRenderer.cpp | 7 ++++++- .../panda3d-simulator/vpPanda3DRGBRenderer.cpp | 13 +++++-------- tutorial/ar/tutorial-panda3d-renderer.cpp | 1 - 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h index 8fc61bc633..01674660c5 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h @@ -102,7 +102,24 @@ class VISP_EXPORT vpPanda3DBaseRenderer */ virtual void setRenderParameters(const vpPanda3DRenderParameters ¶ms) { + unsigned int previousH = m_renderParameters.getImageHeight(), previousW = m_renderParameters.getImageWidth(); + bool resize = previousH != params.getImageHeight() || previousW != params.getImageWidth(); + m_renderParameters = params; + + if (resize) { + for (GraphicsOutput *buffer: m_buffers) { + GraphicsBuffer *buf = dynamic_cast(buffer); + if (buf == nullptr) { + throw vpException(vpException::fatalError, "Panda3D: could not cast to GraphicsBuffer when rendering."); + } + else { + buf->set_size(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()); + } + } + } + + // If renderer is already initialize, modify camera properties if (m_camera != nullptr) { m_renderParameters.setupPandaCamera(m_camera); } @@ -243,6 +260,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer NodePath m_renderRoot; //! Node containing all the objects and the camera for this renderer PT(Camera) m_camera; NodePath m_cameraPath; //! NodePath of the camera + std::vector m_buffers; //! Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should not deallocate them. }; #endif //VISP_HAVE_PANDA3D diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp index f6698e83d3..254adece07 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp @@ -141,13 +141,18 @@ void vpPanda3DGeometryRenderer::setupRenderTarget() win_prop.set_size(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()); // Don't open a window - force it to be an offscreen buffer. - int flags = GraphicsPipe::BF_refuse_window; + int flags = GraphicsPipe::BF_refuse_window | GraphicsPipe::BF_resizeable; GraphicsOutput *windowOutput = m_window->get_graphics_output(); GraphicsEngine *engine = windowOutput->get_engine(); GraphicsPipe *pipe = windowOutput->get_pipe(); m_normalDepthBuffer = engine->make_output(pipe, "My Buffer", -100, fbp, win_prop, flags, windowOutput->get_gsg(), windowOutput); + + if (m_normalDepthBuffer == nullptr) { + throw vpException(vpException::fatalError, "Could not create geometry info buffer"); + } + m_buffers.push_back(m_normalDepthBuffer); m_normalDepthTexture = new Texture(); m_normalDepthBuffer->set_inverted(windowOutput->get_gsg()->get_copy_texture_inverted()); fbp.setup_color_texture(m_normalDepthTexture); diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp index cfa4fb692d..d26cb5754a 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp @@ -36,12 +36,7 @@ void vpPanda3DRGBRenderer::getRender(vpImage &I) const { I.resize(m_colorTexture->get_y_size(), m_colorTexture->get_x_size()); - std::cout << "Before request" << std::endl; unsigned char *data = (unsigned char *)(&(m_colorTexture->get_ram_image().front())); - std::cout << m_colorTexture->get_format() << std::endl; - // CPTA_uchar p((const unsigned char *)I.bitmap, ((const unsigned char *)I.bitmap) + I.getSize() * 4); - // m_colorTexture->set_ram_image_as(p, "rgba"); - std::cout << "After request" << std::endl; // BGRA order in panda3d for (unsigned int i = 0; i < I.getSize(); ++i) { I.bitmap[i].B = data[i * 4]; @@ -65,7 +60,7 @@ void vpPanda3DRGBRenderer::setupRenderTarget() win_prop.set_size(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()); // Don't open a window - force it to be an offscreen buffer. - int flags = GraphicsPipe::BF_refuse_window; + int flags = GraphicsPipe::BF_refuse_window | GraphicsPipe::BF_resizeable; GraphicsOutput *windowOutput = m_window->get_graphics_output(); GraphicsEngine *engine = windowOutput->get_engine(); GraphicsStateGuardian *gsg = windowOutput->get_gsg(); @@ -73,9 +68,11 @@ void vpPanda3DRGBRenderer::setupRenderTarget() m_colorBuffer = engine->make_output(pipe, "Color Buffer", -100, fbp, win_prop, flags, gsg, windowOutput); - std::cout << "GSG inverted = " << gsg->get_copy_texture_inverted() << std::endl; + if (m_colorBuffer == nullptr) { + throw vpException(vpException::fatalError, "Could not create color buffer"); + } + m_buffers.push_back(m_colorBuffer); m_colorBuffer->set_inverted(gsg->get_copy_texture_inverted()); - std::cout << "BUFFER inverted = " << m_colorBuffer->get_inverted() << std::endl; m_colorTexture = new Texture(); fbp.setup_color_texture(m_colorTexture); m_colorBuffer->add_render_texture(m_colorTexture, GraphicsOutput::RenderTextureMode::RTM_copy_ram); diff --git a/tutorial/ar/tutorial-panda3d-renderer.cpp b/tutorial/ar/tutorial-panda3d-renderer.cpp index fb789e4ec0..d688d976d0 100644 --- a/tutorial/ar/tutorial-panda3d-renderer.cpp +++ b/tutorial/ar/tutorial-panda3d-renderer.cpp @@ -174,7 +174,6 @@ int main(int argc, const char **argv) const double afterAll = vpTime::measureTimeMs(); const double delta = (afterAll - beforeRender) / 1000.0; vpHomogeneousMatrix wTo = renderer.getNodePose(objectName); - std::cout << wTo << std::endl; vpHomogeneousMatrix oToo = vpExponentialMap::direct(vpColVector({ 0.0, 0.0, 0.0, 0.0, vpMath::rad(20.0), 0.0 }), delta); renderer.setNodePose(objectName, wTo * oToo);