Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::CPUPixelTransferBuffer Class Reference

A PixelTransferBuffer in main memory. More...

Inherits G3D::PixelTransferBuffer.

Public Member Functions

virtual ~CPUPixelTransferBuffer ()
 
void * buffer ()
 Returns pointer to raw pixel data. More...
 
const void * buffer () const
 Returns pointer to raw pixel data. More...
 
int depth () const
 
const ImageFormatformat () const
 
virtual void getData (void *data) const override
 Read back the current contents to data. More...
 
int height () const
 
virtual const void * mapRead () const override
 Obtain a pointer for read-only access. More...
 
virtual void * mapReadWrite () override
 Obtain a pointer for general access. More...
 
virtual void * mapWrite () override
 Obtain a pointer for write-only access. More...
 
virtual bool ownsMemory () const override
 If true, the data lifetime is independent of the PixelTransferBuffer lifetime. More...
 
int pixelCount () const
 
virtual bool readyToMap () const override
 If true, mapReadWrite, mapRead, and mapWrite will return immediately. More...
 
virtual bool requiresGPUContext () const override
 If true, then readyToMap(), mapRead(), mapWrite(), mapReadWrite(), and unmap() can only be invoked on a thread that currently has an active OpenGL context. More...
 
void * row (int y, int d=0)
 Return row to raw pixel data at start of row y of depth d. More...
 
const void * row (int y, int d=0) const
 Return row to raw pixel data at start of row y of depth d. More...
 
size_t rowAlignment () const
 Returns alignment of each row of pixel data in bytes. More...
 
size_t rowOffset (int y, int d=0) const
 Return the byte offset from the mapped pointer for the row to raw pixel data at start of row y of depth d. More...
 
virtual void setData (const void *data) override
 Overwrite the current contents with data. More...
 
size_t size () const
 Returns entire size of pixel data in bytes. More...
 
size_t stride () const
 Returns size of each row of pixel data in bytes. More...
 
virtual void unmap () const override
 
template<class T >
void unmap (const T *&setToNull) const
 
int width () const
 

Static Public Member Functions

static shared_ptr< CPUPixelTransferBuffercreate (int width, int height, const ImageFormat *format, const shared_ptr< MemoryManager > &memoryManager=MemoryManager::create(), int depth=1, int rowAlignment=1)
 Creates a buffer backed by a CPU array of uninitialized contents. More...
 
static shared_ptr< CPUPixelTransferBufferfromData (int width, int height, const ImageFormat *format, void *data, int depth=1, int rowAlignment=1)
 Creates a buffer backed by a CPU array of existing data that will be managed by the caller. More...
 

Protected Member Functions

 CPUPixelTransferBuffer (const ImageFormat *format, int width, int height, int depth, int rowAlignment)
 
void allocateBuffer (const shared_ptr< MemoryManager > &memoryManager)
 
void freeBuffer ()
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

void * m_buffer
 
int m_depth
 
const ImageFormatm_format
 
int m_height
 
void * m_mappedPointer
 nullptr if not currently mapped. More...
 
shared_ptr< MemoryManagerm_memoryManager
 
size_t m_rowAlignment
 
size_t m_rowStride
 
int m_width
 

Detailed Description

A PixelTransferBuffer in main memory.

See also
GLPixelTransferBuffer, Image

Constructor & Destructor Documentation

◆ CPUPixelTransferBuffer()

G3D::CPUPixelTransferBuffer::CPUPixelTransferBuffer ( const ImageFormat format,
int  width,
int  height,
int  depth,
int  rowAlignment 
)
protected

◆ ~CPUPixelTransferBuffer()

virtual G3D::CPUPixelTransferBuffer::~CPUPixelTransferBuffer ( )
virtual

Member Function Documentation

◆ allocateBuffer()

void G3D::CPUPixelTransferBuffer::allocateBuffer ( const shared_ptr< MemoryManager > &  memoryManager)
protected

◆ buffer() [1/2]

void* G3D::CPUPixelTransferBuffer::buffer ( )
inline

Returns pointer to raw pixel data.

◆ buffer() [2/2]

const void* G3D::CPUPixelTransferBuffer::buffer ( ) const
inline

Returns pointer to raw pixel data.

◆ create()

static shared_ptr<CPUPixelTransferBuffer> G3D::CPUPixelTransferBuffer::create ( int  width,
int  height,
const ImageFormat format,
const shared_ptr< MemoryManager > &  memoryManager = MemoryManager::create(),
int  depth = 1,
int  rowAlignment = 1 
)
static

Creates a buffer backed by a CPU array of uninitialized contents.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ depth()

int G3D::PixelTransferBuffer::depth ( ) const
inlineinherited

◆ format()

const ImageFormat* G3D::PixelTransferBuffer::format ( ) const
inlineinherited

◆ freeBuffer()

void G3D::CPUPixelTransferBuffer::freeBuffer ( )
protected

◆ fromData()

static shared_ptr<CPUPixelTransferBuffer> G3D::CPUPixelTransferBuffer::fromData ( int  width,
int  height,
const ImageFormat format,
void *  data,
int  depth = 1,
int  rowAlignment = 1 
)
static

Creates a buffer backed by a CPU array of existing data that will be managed by the caller.

It is the caller's responsibility to ensure that data remains allocated while the buffer is in use.

◆ getData()

virtual void G3D::CPUPixelTransferBuffer::getData ( void *  data) const
overridevirtual

Read back the current contents to data.

Cannot call while mapped.

Implements G3D::PixelTransferBuffer.

◆ height()

int G3D::PixelTransferBuffer::height ( ) const
inlineinherited

◆ mapRead()

virtual const void* G3D::CPUPixelTransferBuffer::mapRead ( ) const
overridevirtual

Obtain a pointer for read-only access.

See also
mapReadWrite, mapWrite, unmap

Implements G3D::PixelTransferBuffer.

◆ mapReadWrite()

virtual void* G3D::CPUPixelTransferBuffer::mapReadWrite ( )
overridevirtual

Obtain a pointer for general access.

See also
mapRead, mapWrite, unmap

Implements G3D::PixelTransferBuffer.

◆ mapWrite()

virtual void* G3D::CPUPixelTransferBuffer::mapWrite ( )
overridevirtual

Obtain a pointer for write-only access.

See also
mapRead, mapReadWrite, unmap

Implements G3D::PixelTransferBuffer.

◆ ownsMemory()

virtual bool G3D::CPUPixelTransferBuffer::ownsMemory ( ) const
inlineoverridevirtual

If true, the data lifetime is independent of the PixelTransferBuffer lifetime.

For example, holding the PixelTransferBuffer may not keep the data valid if ownsMemory() = false.

Reimplemented from G3D::PixelTransferBuffer.

◆ pixelCount()

int G3D::PixelTransferBuffer::pixelCount ( ) const
inlineinherited

◆ readyToMap()

virtual bool G3D::CPUPixelTransferBuffer::readyToMap ( ) const
inlineoverridevirtual

If true, mapReadWrite, mapRead, and mapWrite will return immediately.

This is always true for the base class but subclasses that map Pixel Buffer Objects and files may have a delay between when they are constructed and when they are available for mapping. The standard usage in those cases is to have the GL thread check if data is ready to map, and if not, then wait until the next frame to perform the mapping.

Implements G3D::PixelTransferBuffer.

◆ requiresGPUContext()

virtual bool G3D::CPUPixelTransferBuffer::requiresGPUContext ( ) const
inlineoverridevirtual

If true, then readyToMap(), mapRead(), mapWrite(), mapReadWrite(), and unmap() can only be invoked on a thread that currently has an active OpenGL context.

Always returns false for the base class.

Implements G3D::PixelTransferBuffer.

◆ row() [1/2]

void* G3D::CPUPixelTransferBuffer::row ( int  y,
int  d = 0 
)
inline

Return row to raw pixel data at start of row y of depth d.

Referenced by row().

◆ row() [2/2]

const void* G3D::CPUPixelTransferBuffer::row ( int  y,
int  d = 0 
) const
inline

Return row to raw pixel data at start of row y of depth d.

◆ rowAlignment()

size_t G3D::PixelTransferBuffer::rowAlignment ( ) const
inlineinherited

Returns alignment of each row of pixel data in bytes.

◆ rowOffset()

size_t G3D::PixelTransferBuffer::rowOffset ( int  y,
int  d = 0 
) const
inlineinherited

Return the byte offset from the mapped pointer for the row to raw pixel data at start of row y of depth d.

Referenced by row().

◆ setData()

virtual void G3D::CPUPixelTransferBuffer::setData ( const void *  data)
overridevirtual

Overwrite the current contents with data.

Cannot call while mapped.

Implements G3D::PixelTransferBuffer.

◆ size()

size_t G3D::PixelTransferBuffer::size ( ) const
inlineinherited

Returns entire size of pixel data in bytes.

◆ stride()

size_t G3D::PixelTransferBuffer::stride ( ) const
inlineinherited

Returns size of each row of pixel data in bytes.

◆ unmap() [1/2]

virtual void G3D::CPUPixelTransferBuffer::unmap ( ) const
overridevirtual

◆ unmap() [2/2]

template<class T >
void G3D::PixelTransferBuffer::unmap ( const T *&  setToNull) const
inlineinherited

◆ width()

int G3D::PixelTransferBuffer::width ( ) const
inlineinherited

Member Data Documentation

◆ m_buffer

void* G3D::CPUPixelTransferBuffer::m_buffer
protected

Referenced by buffer(), and row().

◆ m_depth

int G3D::PixelTransferBuffer::m_depth
protectedinherited

◆ m_format

const ImageFormat* G3D::PixelTransferBuffer::m_format
protectedinherited

◆ m_height

int G3D::PixelTransferBuffer::m_height
protectedinherited

◆ m_mappedPointer

void* G3D::PixelTransferBuffer::m_mappedPointer
mutableprotectedinherited

nullptr if not currently mapped.

◆ m_memoryManager

shared_ptr<MemoryManager> G3D::CPUPixelTransferBuffer::m_memoryManager
protected

Referenced by ownsMemory().

◆ m_rowAlignment

size_t G3D::PixelTransferBuffer::m_rowAlignment
protectedinherited

◆ m_rowStride

size_t G3D::PixelTransferBuffer::m_rowStride
protectedinherited

◆ m_width

int G3D::PixelTransferBuffer::m_width
protectedinherited

documentation generated on Wed Nov 24 2021 08:01:54 using doxygen 1.8.15