19#include "aeongames/Texture.hpp"
52 mPixels.resize ( aWidth * aHeight * GetPixelSize ( mFormat, mType ) );
53 if ( aPixels !=
nullptr )
55 memcpy ( mPixels.data(), aPixels, mPixels.size() );
59 memset ( mPixels.data(), 0, mPixels.size() );
66 assert ( mType == aType && mFormat == aFormat );
67 uint8_t* cursor = mPixels.data() + ( ( aYOffset * mWidth ) + aXOffset );
68 size_t pixel_size = GetPixelSize ( mFormat, mType );
69 for (
size_t i = 0; i < aHeight; ++i )
71 memcpy ( cursor, aPixels + ( i * pixel_size * aWidth ), pixel_size * aWidth );
static bool Decode(T &aOutput, uint32_t aId)
Decodes a resource identified by its CRC32 id.
static bool RegisterDecoder(const std::string &aMagick, const std::function< bool(T &, size_t, const void *) > &aDecoder)
Registers a decoder function for the given magic byte sequence.
static bool UnregisterDecoder(const std::string &aMagick)
Unregisters the decoder for the given magic byte sequence.
Represents a 2D texture image resource.
DLL void Resize(uint32_t aWidth, uint32_t aHeight, const uint8_t *aPixels=nullptr, Format aFormat=Format::Unknown, Type aType=Type::Unknown)
Resizes the texture and optionally replaces pixel data.
DLL void Unload() final
Releases all texture data and resets the texture to an empty state.
DLL uint32_t GetWidth() const
Returns the texture width in pixels.
DLL Format GetFormat() const
Returns the pixel format.
DLL const std::vector< uint8_t > & GetPixels() const
Returns a reference to the raw pixel data.
Type
Pixel component data type.
@ Unknown
Unspecified or invalid type.
DLL ~Texture()
Destructor.
Format
Pixel channel layout format.
@ Unknown
Unspecified or invalid format.
DLL Type GetType() const
Returns the pixel component type.
DLL void LoadFromMemory(const void *aBuffer, size_t aBufferSize) final
Loads texture data from a raw memory buffer.
DLL void WritePixels(int32_t aXOffset, int32_t aYOffset, uint32_t aWidth, uint32_t aHeight, Format aFormat, Type aType, const uint8_t *aPixels)
Writes pixel data into a sub-region of the texture.
DLL uint32_t GetHeight() const
Returns the texture height in pixels.
<- This is here just for the literals
DLL bool RegisterImageDecoder(const std::string &aMagick, const std::function< bool(Texture &, size_t, const void *) > &aDecoder)
Registers an image decoder for a specific file magic identifier.
DLL bool UnregisterImageDecoder(const std::string &aMagick)
Unregisters a previously registered image decoder.
DLL bool DecodeImage(Texture &aTexture, const void *aBuffer, size_t aBufferSize)
Decodes image data from a memory buffer into a Texture.