Jetson Inference
DNN Vision Library
glTexture Class Reference

OpenGL texture with CUDA interoperability. More...

#include <glTexture.h>

Public Member Functions

 ~glTexture ()
 Free the texture. More...
 
bool Bind ()
 Activate using the texture. More...
 
void Unbind ()
 Deactivate using the texture. More...
 
void Render (float x, float y)
 Render the texture at the specified window coordinates. More...
 
void Render (float x, float y, float width, float height)
 Render the texture with the specified position and size. More...
 
void Render (const float4 &rect)
 Render the texture to the specific screen rectangle. More...
 
uint32_t GetID () const
 Retrieve the OpenGL resource handle of the texture. More...
 
uint32_t GetWidth () const
 Retrieve the width in pixels of the texture. More...
 
uint32_t GetHeight () const
 Retrieve the height in pixels of the texture. More...
 
uint32_t GetFormat () const
 Retrieve the texture's format (e.g. More...
 
uint32_t GetSize () const
 Retrieve the size in bytes of the texture. More...
 
void * Map (uint32_t device, uint32_t flags)
 Map the texture for accessing from the CPU or CUDA. More...
 
void Unmap ()
 Unmap the texture from CPU/CUDA access. More...
 
bool Copy (void *ptr, uint32_t flags)
 Copy entire contents of the texture to/from CPU or CUDA memory. More...
 
bool Copy (void *ptr, uint32_t size, uint32_t flags)
 Copy contents of the texture to/from CPU or CUDA memory. More...
 
bool Copy (void *ptr, uint32_t offset, uint32_t size, uint32_t flags)
 Copy contents of the texture to/from CPU or CUDA memory. More...
 

Static Public Member Functions

static glTextureCreate (uint32_t width, uint32_t height, uint32_t format, void *data=NULL)
 Allocate an OpenGL texture. More...
 

Detailed Description

OpenGL texture with CUDA interoperability.

Constructor & Destructor Documentation

◆ ~glTexture()

glTexture::~glTexture ( )

Free the texture.

Member Function Documentation

◆ Bind()

bool glTexture::Bind ( )

Activate using the texture.

◆ Copy() [1/3]

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

Copy entire contents of the texture 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 glTexture::Copy ( void *  ptr,
uint32_t  size,
uint32_t  flags 
)

Copy contents of the texture 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

◆ Copy() [3/3]

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

Copy contents of the texture 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

◆ Create()

static glTexture* glTexture::Create ( uint32_t  width,
uint32_t  height,
uint32_t  format,
void *  data = NULL 
)
static

Allocate an OpenGL texture.

Parameters
widththe width of the texture in pixels
heightthe height of the texture in pixels
formatGL_RGBA8, GL_RGBA32F, ect.
datainitialize the texture's memory with this CPU pointer, size is width*height*bpp

◆ GetFormat()

uint32_t glTexture::GetFormat ( ) const
inline

Retrieve the texture's format (e.g.

GL_RGBA8, GL_RGBA32F, ect.)

◆ GetHeight()

uint32_t glTexture::GetHeight ( ) const
inline

Retrieve the height in pixels of the texture.

◆ GetID()

uint32_t glTexture::GetID ( ) const
inline

Retrieve the OpenGL resource handle of the texture.

◆ GetSize()

uint32_t glTexture::GetSize ( ) const
inline

Retrieve the size in bytes of the texture.

◆ GetWidth()

uint32_t glTexture::GetWidth ( ) const
inline

Retrieve the width in pixels of the texture.

◆ Map()

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

Map the texture 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.

◆ Render() [1/3]

void glTexture::Render ( float  x,
float  y 
)

Render the texture at the specified window coordinates.

◆ Render() [2/3]

void glTexture::Render ( float  x,
float  y,
float  width,
float  height 
)

Render the texture with the specified position and size.

◆ Render() [3/3]

void glTexture::Render ( const float4 &  rect)

Render the texture to the specific screen rectangle.

◆ Unbind()

void glTexture::Unbind ( )

Deactivate using the texture.

◆ Unmap()

void glTexture::Unmap ( )

Unmap the texture from CPU/CUDA access.

Note
the texture will be unbound after calling Unmap()

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