Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Texture.hpp
1/*
2Copyright (C) 2016-2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_TEXTURE_H
17#define AEONGAMES_TEXTURE_H
18#include <cstdint>
19#include <string>
20#include <functional>
21#include <vector>
23#include "aeongames/Resource.hpp"
24
25namespace AeonGames
26{
32 class Texture : public Resource
33 {
34 public:
39 enum class Format : uint32_t
40 {
41 Unknown = 0,
45 };
46
57
58 DLL ~Texture();
66 DLL void Resize ( uint32_t aWidth, uint32_t aHeight, const uint8_t* aPixels = nullptr, Format aFormat = Format::Unknown, Type aType = Type::Unknown );
76 DLL void WritePixels ( int32_t aXOffset, int32_t aYOffset, uint32_t aWidth, uint32_t aHeight, Format aFormat, Type aType, const uint8_t* aPixels );
81 DLL void LoadFromMemory ( const void* aBuffer, size_t aBufferSize ) final;
83 DLL void Unload() final;
85 DLL uint32_t GetWidth() const;
87 DLL uint32_t GetHeight() const;
89 DLL Format GetFormat() const;
91 DLL Type GetType() const;
93 DLL const std::vector<uint8_t>& GetPixels() const;
94 private:
95 std::vector<uint8_t> mPixels{};
96 uint32_t mWidth{};
97 uint32_t mHeight{};
98 Format mFormat{};
99 Type mType{};
100 };
101
108 DLL bool RegisterImageDecoder ( const std::string& aMagick, const std::function < bool ( Texture&, size_t, const void* ) > & aDecoder );
113 DLL bool UnregisterImageDecoder ( const std::string& aMagick );
120 DLL bool DecodeImage ( Texture& aTexture, const void* aBuffer, size_t aBufferSize );
126 DLL bool DecodeImage ( Texture& aTexture, const std::string& aFileName );
133 static constexpr size_t GetPixelSize ( Texture::Format aFormat, Texture::Type aType )
134 {
135 return ( aFormat == Texture::Format::Unknown || aType == Texture::Type::Unknown ) ? 0 :
136 ( ( aFormat == Texture::Format::RGB ) ? 3 : 4 ) * ( ( aType == Texture::Type::UNSIGNED_BYTE ) ? 1 : 2 );
137 }
138}
139#endif
Platform-specific macros, includes, and DLL export/import definitions.
Base class for loadable engine resources.
Definition Resource.hpp:33
Represents a 2D texture image resource.
Definition Texture.hpp:33
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.
Definition Texture.cpp:46
DLL void Unload() final
Releases all texture data and resets the texture to an empty state.
Definition Texture.cpp:102
DLL uint32_t GetWidth() const
Returns the texture width in pixels.
Definition Texture.cpp:75
DLL Format GetFormat() const
Returns the pixel format.
Definition Texture.cpp:83
DLL const std::vector< uint8_t > & GetPixels() const
Returns a reference to the raw pixel data.
Definition Texture.cpp:92
Type
Pixel component data type.
Definition Texture.hpp:51
@ UNSIGNED_INT_8_8_8_8_REV
Packed 32-bit unsigned integer with reversed byte order.
Definition Texture.hpp:55
@ UNSIGNED_SHORT
16-bit unsigned integer per channel.
Definition Texture.hpp:54
@ Unknown
Unspecified or invalid type.
Definition Texture.hpp:52
@ UNSIGNED_BYTE
8-bit unsigned integer per channel.
Definition Texture.hpp:53
DLL ~Texture()
Destructor.
Format
Pixel channel layout format.
Definition Texture.hpp:40
@ BGRA
4-channel blue, green, red, alpha.
Definition Texture.hpp:44
@ Unknown
Unspecified or invalid format.
Definition Texture.hpp:41
@ RGB
3-channel red, green, blue.
Definition Texture.hpp:42
@ RGBA
4-channel red, green, blue, alpha.
Definition Texture.hpp:43
DLL Type GetType() const
Returns the pixel component type.
Definition Texture.cpp:87
DLL void LoadFromMemory(const void *aBuffer, size_t aBufferSize) final
Loads texture data from a raw memory buffer.
Definition Texture.cpp:97
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.
Definition Texture.cpp:63
DLL uint32_t GetHeight() const
Returns the texture height in pixels.
Definition Texture.cpp:79
<- This is here just for the literals
Definition AABB.hpp:31
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.
Definition Texture.cpp:26
DLL bool UnregisterImageDecoder(const std::string &aMagick)
Unregisters a previously registered image decoder.
Definition Texture.cpp:31
DLL bool DecodeImage(Texture &aTexture, const void *aBuffer, size_t aBufferSize)
Decodes image data from a memory buffer into a Texture.
Definition Texture.cpp:36
STL namespace.