Jetson Inference
DNN Vision Library
glBuffer Class Reference

OpenGL buffer with CUDA interoperability. More...

#include <glBuffer.h>

Public Member Functions

 ~glBuffer ()
 Free the buffer. More...
 
bool Bind ()
 Activate using the buffer. More...
 
void Unbind ()
 Deactivate using the buffer. More...
 
uint32_t GetID () const
 Retrieve the OpenGL resource handle of the buffer. More...
 
uint32_t GetType () const
 Retrieve the buffer type (GL_VERTEX_BUFFER or GL_INDEX_BUFFER) More...
 
uint32_t GetSize () const
 Retrieve the total size in bytes of the buffer. More...
 
uint32_t GetNumElements () const
 Retrieve the number of elements (i.e. More...
 
uint32_t GetElementSize () const
 Retrieve the size in bytes of each element. More...
 
void * Map (uint32_t device, uint32_t flags)
 Map the buffer for accessing from the CPU or CUDA. More...
 
void Unmap ()
 Unmap the buffer from CPU/CUDA access. More...
 
bool Copy (void *ptr, uint32_t flags)
 Copy entire contents of the buffer to/from CPU or CUDA memory. More...
 
bool Copy (void *ptr, uint32_t size, uint32_t flags)
 Copy contents of the buffer to/from CPU or CUDA memory. More...
 
bool Copy (void *ptr, uint32_t offset, uint32_t size, uint32_t flags)
 Copy contents of the buffer to/from CPU or CUDA memory. More...
 

Static Public Member Functions

static glBufferCreate (uint32_t type, uint32_t size, void *data=NULL, uint32_t usage=GL_STATIC_DRAW)
 Allocate an OpenGL buffer. More...
 
static glBufferCreate (uint32_t type, uint32_t numElements, uint32_t elementSize, void *data=NULL, uint32_t usage=GL_STATIC_DRAW)
 Allocate an OpenGL buffer. More...
 

Detailed Description

OpenGL buffer with CUDA interoperability.

Constructor & Destructor Documentation

◆ ~glBuffer()

glBuffer::~glBuffer ( )

Free the buffer.

Member Function Documentation

◆ Bind()

bool glBuffer::Bind ( )

Activate using the buffer.

◆ Copy() [1/3]

bool glBuffer::Copy ( void *  ptr,
uint32_t  flags 
)

Copy entire contents of the buffer to/from CPU or CUDA memory.

Parameters
ptrthe memory pointer to copy to/from, either in CPU or CUDA address space depending on flags. It's assumed that the size of the memory from this pointer is equal to GetSize(), and the entire contents of the buffer will be copied.
flagsshould be one of the following:
  • GL_FROM_CPU (copy from CPU->OpenGL)
  • GL_FROM_CUDA (copy from CUDA->OpenGL)
  • GL_TO_CPU (copy from OpenGL->CPU)
  • GL_TO_CUDA (copy from OpenGL->CUDA)
Returns
true on success, false on failure

◆ Copy() [2/3]

bool glBuffer::Copy ( void *  ptr,
uint32_t  offset,
uint32_t  size,
uint32_t  flags 
)

Copy contents of the buffer to/from CPU or CUDA memory.

Parameters
ptrthe memory buffer to copy to/from, either in CPU or CUDA address space depending on flags
offsetthe offset into the OpenGL buffer to copy. It is assumed any offset to the CPU/CUDA pointer argument has already been applied.
sizethe number of bytes to copy
flagsshould be one of the following:
  • GL_FROM_CPU (copy from CPU->OpenGL)
  • GL_FROM_CUDA (copy from CUDA->OpenGL)
  • GL_TO_CPU (copy from OpenGL->CPU)
  • GL_TO_CUDA (copy from OpenGL->CUDA)
Returns
true on success, false on failure

◆ Copy() [3/3]

bool glBuffer::Copy ( void *  ptr,
uint32_t  size,
uint32_t  flags 
)

Copy contents of the buffer to/from CPU or CUDA memory.

Parameters
ptrthe memory pointer to copy to/from, either in CPU or CUDA address space depending on flags.
sizethe number of bytes to copy
flagsshould be one of the following:
  • GL_FROM_CPU (copy from CPU->OpenGL)
  • GL_FROM_CUDA (copy from CUDA->OpenGL)
  • GL_TO_CPU (copy from OpenGL->CPU)
  • GL_TO_CUDA (copy from OpenGL->CUDA)
Returns
true on success, false on failure

◆ Create() [1/2]

static glBuffer* glBuffer::Create ( uint32_t  type,
uint32_t  numElements,
uint32_t  elementSize,
void *  data = NULL,
uint32_t  usage = GL_STATIC_DRAW 
)
static

Allocate an OpenGL buffer.

Parameters
typeeither GL_VERTEX_BUFFER for a vertex buffer, or GL_INDEX_BUFFER for an index buffer
numElementsthe number of elements (i.e. vertices or indices) in the buffer
elementSizethe size in bytes of each element
datapointer to the initial memory of this buffer
usageGL_STATIC_DRAW (never updated), GL_STREAM_DRAW (occasional updates), or GL_DYNAMIC_DRAW (per-frame updates)

◆ Create() [2/2]

static glBuffer* glBuffer::Create ( uint32_t  type,
uint32_t  size,
void *  data = NULL,
uint32_t  usage = GL_STATIC_DRAW 
)
static

Allocate an OpenGL buffer.

Parameters
typeeither GL_VERTEX_BUFFER for a vertex buffer, or GL_INDEX_BUFFER for an index buffer
sizethe size in bytes to allocated for the buffer
datapointer to the initial memory of this buffer
usageGL_STATIC_DRAW (never updated), GL_STREAM_DRAW (occasional updates), or GL_DYNAMIC_DRAW (per-frame updates)

◆ GetElementSize()

uint32_t glBuffer::GetElementSize ( ) const
inline

Retrieve the size in bytes of each element.

Note
if the element size wasn't specified while creating the buffer, GetElementSize() will be equal to 1

◆ GetID()

uint32_t glBuffer::GetID ( ) const
inline

Retrieve the OpenGL resource handle of the buffer.

◆ GetNumElements()

uint32_t glBuffer::GetNumElements ( ) const
inline

Retrieve the number of elements (i.e.

vertices or indices)

Note
if the number of elements weren't specified while creating the buffer, GetNumElements() will be equal to GetSize()

◆ GetSize()

uint32_t glBuffer::GetSize ( ) const
inline

Retrieve the total size in bytes of the buffer.

◆ GetType()

uint32_t glBuffer::GetType ( ) const
inline

Retrieve the buffer type (GL_VERTEX_BUFFER or GL_INDEX_BUFFER)

◆ Map()

void* glBuffer::Map ( uint32_t  device,
uint32_t  flags 
)

Map the buffer for accessing from the CPU or CUDA.

Parameters
deviceeither GL_MAP_CPU or GL_MAP_CUDA
flagsshould be one of the following:
  • GL_READ_WRITE
  • GL_READ_ONLY
  • GL_WRITE_ONLY
  • GL_WRITE_DISCARD
Returns
CPU pointer to buffer if GL_MAP_CPU was specified, CUDA device pointer to buffer if GL_MAP_CUDA was specified, or NULL if an error occurred mapping the buffer.

◆ Unbind()

void glBuffer::Unbind ( )

Deactivate using the buffer.

◆ Unmap()

void glBuffer::Unmap ( )

Unmap the buffer from CPU/CUDA access.

Note
the buffer will be unbound after calling Unmap()

The documentation for this class was generated from the following file: