Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering issues with Panda3D #1559

Merged
merged 12 commits into from
Jan 31, 2025
46 changes: 12 additions & 34 deletions modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@
#include <visp3/core/vpCameraParameters.h>
#include <visp3/ar/vpPanda3DRenderParameters.h>

#include <pandaFramework.h>
#include <pandaSystem.h>
#include <windowFramework.h>
#include <graphicsOutput.h>

#include <nodePath.h>
#include <pointerTo.h>
#include <camera.h>


BEGIN_VISP_NAMESPACE
/**
Expand All @@ -63,19 +68,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer
setVerticalSyncEnabled(false);
}

virtual ~vpPanda3DBaseRenderer()
{
if (m_window != nullptr) {
for (GraphicsOutput *buffer: m_buffers) {
buffer->get_engine()->remove_window(buffer);
}
}
if (m_isWindowOwner) {
framework.close_window(m_window);
}

m_window = nullptr;
}
virtual ~vpPanda3DBaseRenderer();

/**
* @brief Initialize the whole Panda3D framework. Create a new PandaFramework object and a new window.
Expand All @@ -88,13 +81,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer

virtual void beforeFrameRendered() { }
virtual void renderFrame();
virtual void afterFrameRendered()
{
GraphicsOutput *mainBuffer = getMainOutputBuffer();
if (mainBuffer != nullptr) {
m_window->get_graphics_output()->get_engine()->extract_texture_data(mainBuffer->get_texture(), mainBuffer->get_gsg());
}
}
virtual void afterFrameRendered();

/**
* @brief Get the name of the renderer
Expand Down Expand Up @@ -134,14 +121,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer
*/
int getRenderOrder() const { return m_renderOrder; }

void setRenderOrder(int order)
{
int previousOrder = m_renderOrder;
m_renderOrder = order;
for (GraphicsOutput *buffer: m_buffers) {
buffer->set_sort(buffer->get_sort() + (order - previousOrder));
}
}
void setRenderOrder(int order);

/**
* @brief Set the camera's pose.
Expand Down Expand Up @@ -250,7 +230,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer

void printStructure();

virtual GraphicsOutput *getMainOutputBuffer() { return nullptr; }
virtual PointerTo<GraphicsOutput> getMainOutputBuffer() { return nullptr; }

virtual void enableSharedDepthBuffer(vpPanda3DBaseRenderer &sourceBuffer);

Expand Down Expand Up @@ -278,8 +258,6 @@ class VISP_EXPORT vpPanda3DBaseRenderer

const static vpHomogeneousMatrix VISP_T_PANDA; //! Homogeneous transformation matrix to convert from the Panda coordinate system (right-handed Z-up) to the ViSP coordinate system (right-handed Y-Down)
const static vpHomogeneousMatrix PANDA_T_VISP; //! Inverse of VISP_T_PANDA
static PandaFramework framework; //! Panda Rendering framework
static bool frameworkIsOpen;

protected:
std::string m_name; //! name of the renderer
Expand All @@ -289,7 +267,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer
NodePath m_renderRoot; //! Node containing all the objects and the camera for this renderer
PointerTo<Camera> m_camera;
NodePath m_cameraPath; //! NodePath of the camera
std::vector<GraphicsOutput *> m_buffers; //! Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should not deallocate them.
std::vector<PointerTo<GraphicsOutput>> m_buffers; //! Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should not deallocate them.
bool m_isWindowOwner; // Whether this panda subrenderer is the "owner" of the window framework and should close all associated windows when getting destroyed
};

Expand Down
1 change: 1 addition & 0 deletions modules/ar/include/visp3/ar/vpPanda3DCommonFilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <visp3/ar/vpPanda3DPostProcessFilter.h>


BEGIN_VISP_NAMESPACE
class vpPanda3DRGBRenderer;

Expand Down
96 changes: 96 additions & 0 deletions modules/ar/include/visp3/ar/vpPanda3DFrameworkManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at [email protected]
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef VP_PANDA3D_FRAMEWORK_MANAGER_H
#define VP_PANDA3D_FRAMEWORK_MANAGER_H

#include <visp3/core/vpConfig.h>

#if defined(VISP_HAVE_PANDA3D)

#include <pandaFramework.h>
#include <pandaSystem.h>


BEGIN_VISP_NAMESPACE
/**
* \ingroup group_ar_renderer_panda3d
*
* \brief Base class for a panda3D renderer. This class handles basic functionalities,
* such as loading object, changing camera parameters.
*
* For a subclass to have a novel behaviour (e.g, display something else) These methods should be overriden:
*
* - setupScene: This is where you should apply your shaders.
* - setupCamera: This is where cameras are created and intrinsics parameters are applied
* - setupRenderTarget: This is where you should create the texture buffers, where the render results should be stored.
*/
class VISP_EXPORT vpPanda3DFrameworkManager
{
private:

vpPanda3DFrameworkManager() : m_frameworkIsOpen(false)
{ }

virtual ~vpPanda3DFrameworkManager()
{ }


public:

void initFramework();

void exit();

PandaFramework &getFramework() { return m_framework; }

void registerDisabledWindow(PointerTo<WindowFramework> wf);

void disableAllOtherRenderers(PointerTo<WindowFramework> &active);

void enableAllRenderers();

static vpPanda3DFrameworkManager &getInstance()
{
static vpPanda3DFrameworkManager instance;
return instance;
}

protected:

PandaFramework m_framework; //! Panda Rendering framework
bool m_frameworkIsOpen;
std::vector<PointerTo<WindowFramework>> m_disabledWindows;

};

END_VISP_NAMESPACE
#endif //VISP_HAVE_PANDA3D
#endif
4 changes: 2 additions & 2 deletions modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer
};

vpPanda3DGeometryRenderer(vpRenderType renderType);
~vpPanda3DGeometryRenderer() = default;


/**
* @brief Get render results into ViSP readable structures
Expand All @@ -85,7 +85,7 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer
*/
void getRender(vpImage<float> &depth) const;

GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_normalDepthBuffer; }
PointerTo<GraphicsOutput> getMainOutputBuffer() VP_OVERRIDE { return m_normalDepthBuffer; }


protected:
Expand Down
3 changes: 2 additions & 1 deletion modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <visp3/ar/vpPanda3DBaseRenderer.h>
#include "cardMaker.h"
#include "orthographicLens.h"
#include "frameBufferProperties.h"

BEGIN_VISP_NAMESPACE
/**
Expand Down Expand Up @@ -69,7 +70,7 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer
return false;
}

GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_buffer; }
PointerTo<GraphicsOutput> getMainOutputBuffer() VP_OVERRIDE { return m_buffer; }

void afterFrameRendered() VP_OVERRIDE
{
Expand Down
3 changes: 1 addition & 2 deletions modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp
*/
vpPanda3DRGBRenderer(bool showSpeculars) : vpPanda3DBaseRenderer(showSpeculars ? "RGB" : "RGB-diffuse"), m_showSpeculars(showSpeculars) { }

virtual ~vpPanda3DRGBRenderer() = default;

/**
* @brief Store the render resulting from calling renderFrame() into a vpImage.
Expand All @@ -95,7 +94,7 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp

void setBackgroundImage(const vpImage<vpRGBa> &background);

GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_colorBuffer; }
PointerTo<GraphicsOutput> getMainOutputBuffer() VP_OVERRIDE { return m_colorBuffer; }

bool isShowingSpeculars() const { return m_showSpeculars; }

Expand Down
4 changes: 2 additions & 2 deletions modules/ar/include/visp3/ar/vpPanda3DRendererSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp
return nullptr;
}

void beforeFrameRendered() VP_OVERRIDE
virtual void beforeFrameRendered() VP_OVERRIDE
{
for (std::shared_ptr<vpPanda3DBaseRenderer> &renderer: m_subRenderers) {
renderer->beforeFrameRendered();
}
}

void afterFrameRendered() VP_OVERRIDE
virtual void afterFrameRendered() VP_OVERRIDE
{
for (std::shared_ptr<vpPanda3DBaseRenderer> &renderer: m_subRenderers) {
renderer->afterFrameRendered();
Expand Down
Loading
Loading