Skip to content

Commit

Permalink
Working on adding resizable buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Apr 22, 2024
1 parent 858afb6 commit 984c775
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
18 changes: 18 additions & 0 deletions modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,24 @@ class VISP_EXPORT vpPanda3DBaseRenderer
*/
virtual void setRenderParameters(const vpPanda3DRenderParameters &params)
{
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<GraphicsBuffer *>(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);
}
Expand Down Expand Up @@ -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<GraphicsOutput *> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@
void vpPanda3DRGBRenderer::getRender(vpImage<vpRGBa> &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];
Expand All @@ -65,17 +60,19 @@ 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();
GraphicsPipe *pipe = windowOutput->get_pipe();
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);
Expand Down
1 change: 0 additions & 1 deletion tutorial/ar/tutorial-panda3d-renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 984c775

Please sign in to comment.