|
std::atomic< bool > | stale { true } |
|
Definition at line 27 of file PixelBuffer.hpp.
◆ PixelBuffer()
ASGE::PixelBuffer::PixelBuffer |
( |
unsigned int |
width, |
|
|
unsigned int |
height |
|
) |
| |
|
inline |
A pixel buffer is a handle to a texture's pixel data.
This abstract class can be used to directly download pixel data from the GPU or to modify the pixels on the CPU before then updating the GPU data using the pixel buffer. Modifying the contents of the CPU-side of the buffer will result in the PixelBuffer being out of sync with the GPU. In order to synchronise the CPU and GPU, an upload function is also provided. To synchronise the GPU and the CPU, a download can be scheduled.
- Parameters
-
[in] | width | The width of the buffer. |
[in] | height | The height of the buffer. |
auto* sprite = renderer->createRawSprite();
sprite->width(200);
sprite->height(200);
auto* blank_texture = renderer->createNonCachedTexture(200, 200, ASGE::Texture2D::Format::RGBA, nullptr);
auto *pixel_buffer = blank_texture->getPixelBuffer();
pixel_buffer->download(0);
for (int i = 0; i < pixel_buffer->getWidth() * pixel_buffer->getHeight() * 4; ++i)
{
static_cast<std::byte*>(pixel_buffer->getPixelData())[i] =
static_cast<std::byte>((unsigned int)(std::rand() % 256));
}
pixel_buffer->upload(0);
sprite->attach(blank_texture);
Resultant random noise generation
Definition at line 69 of file PixelBuffer.hpp.
◆ download()
virtual void ASGE::PixelBuffer::download |
( |
unsigned int |
mip_level | ) |
|
|
pure virtualnoexcept |
Schedules a download from the GPU.
- Parameters
-
mip_level | The mip level to download. |
◆ getHeight()
unsigned int ASGE::PixelBuffer::getHeight |
( |
| ) |
const |
|
inlinenoexcept |
Retrieves the height of the buffer.
- Returns
- The buffer's height.
Definition at line 158 of file PixelBuffer.hpp.
◆ getPixelData() [1/2]
virtual const std::byte* ASGE::PixelBuffer::getPixelData |
( |
| ) |
const |
|
pure virtualnoexcept |
Retrieves the pixel data as a pointer to an array of bytes.
The returned pointer is to the first byte in the pixel buffer array. The size of the buffer can be easily retrieved using the width and height functions. Each pixel's size is determined by the texture's BPP.
- Warning
- Accessing a pixel outside of the allocated buffer will lead to undefined behaviour. You should ensure all access is within the height * width * bpp bounds of the pixel buffer.
- Returns
- A pointer to the first pixel (constant) in the buffer.
◆ getPixelData() [2/2]
virtual std::byte* ASGE::PixelBuffer::getPixelData |
( |
| ) |
|
|
pure virtualnoexcept |
Retrieves the pixel data as a pointer to an array of bytes.
The returned pointer is to the first byte in the pixel buffer array. The size of the buffer can be easily retrieved using the width and height functions. Each pixel's size is determined by the texture's BPP.
- Warning
- Accessing a pixel outside of the allocated buffer will lead to undefined behaviour. You should ensure all access is within the height * width * bpp bounds of the pixel buffer.
- Returns
- A pointer to the first pixel in the buffer.
◆ getWidth()
unsigned int ASGE::PixelBuffer::getWidth |
( |
| ) |
const |
|
inlinenoexcept |
Retrieves the width of the buffer.
- Returns
- The buffer's width.
Definition at line 152 of file PixelBuffer.hpp.
◆ isBufferStale()
bool ASGE::PixelBuffer::isBufferStale |
( |
| ) |
const |
|
inlinenoexcept |
Checks to see if the buffer has changed but not sync'd.
- Returns
- Is the CPU and GPU out of sync.
Definition at line 146 of file PixelBuffer.hpp.
◆ upload() [1/2]
virtual void ASGE::PixelBuffer::upload |
( |
std::byte * |
data, |
|
|
unsigned int |
mip_level |
|
) |
| |
|
pure virtualnoexcept |
Signals an upload to the GPU to update the pixels.
- Parameters
-
[in] | data | A new range of pixels to upload. |
[in] | mip_level | The mip level to update. |
◆ upload() [2/2]
virtual void ASGE::PixelBuffer::upload |
( |
unsigned int |
mip_level | ) |
|
|
pure virtualnoexcept |
Signals an upload to the GPU to update the pixels.
- Parameters
-
[in] | mip_level | The mip level to update. |
The documentation for this class was generated from the following file: