Skip to content

Commit

Permalink
rt_optix: fix graphics intereoperability cuda not found
Browse files Browse the repository at this point in the history
  • Loading branch information
larc committed Oct 11, 2022
1 parent 17671b2 commit e1ef647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions include/gproshan/viewer/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include <gproshan/viewer/shader.h>
#include <gproshan/viewer/include_opengl.h>

#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#ifdef GPROSHAN_CUDA
#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#endif // GPROSHAN_CUDA


// geometry processing and shape analysis framework
namespace gproshan {
Expand All @@ -26,7 +29,9 @@ class frame

shader program;

cudaGraphicsResource * pbo_cuda;
#ifdef GPROSHAN_CUDA
cudaGraphicsResource_t pbo_cuda;
#endif // GPROSHAN_CUDA

public:
frame();
Expand Down
14 changes: 10 additions & 4 deletions src/gproshan/viewer/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ frame::frame()
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);


glGenBuffers(1, &pbo);


glGenTextures(1, &render_tex);
glBindTexture(GL_TEXTURE_2D, render_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand All @@ -50,8 +48,10 @@ frame::frame()

frame::~frame()
{
#ifdef GPROSHAN_CUDA
if(width && height)
cudaGraphicsUnregisterResource(pbo_cuda);
#endif // GPROSHAN_CUDA

glDeleteBuffers(1, &vbo);
glDeleteVertexArrays(1, &vao);
Expand All @@ -66,6 +66,7 @@ frame::operator const GLuint & () const

vec4 * frame::map_pbo(bool cuda)
{
#ifdef GPROSHAN_CUDA
if(cuda)
{
vec4 * img = nullptr;
Expand All @@ -74,18 +75,21 @@ vec4 * frame::map_pbo(bool cuda)
cudaGraphicsResourceGetMappedPointer((void **) &img, &num_bytes, pbo_cuda);
return img;
}
#endif // GPROSHAN_CUDA

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
return (vec4 *) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
}

void frame::unmap_pbo(bool cuda)
{
#ifdef GPROSHAN_CUDA
if(cuda)
{
cudaGraphicsUnmapResources(1, &pbo_cuda, 0);
return;
}
#endif // GPROSHAN_CUDA

glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
Expand All @@ -98,12 +102,14 @@ bool frame::resize(const size_t & w, const size_t & h)

if(w * h > width * height)
{
if(width && height)
cudaGraphicsUnregisterResource(pbo_cuda);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 4 * sizeof(float) * w * h, 0, GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
#ifdef GPROSHAN_CUDA
if(width && height)
cudaGraphicsUnregisterResource(pbo_cuda);
cudaGraphicsGLRegisterBuffer(&pbo_cuda, pbo, cudaGraphicsMapFlagsNone);
#endif // GPROSHAN_CUDA
}

width = w;
Expand Down

0 comments on commit e1ef647

Please sign in to comment.