Provides data structures for representing essential components of a texture.
More...
Provides data structures for representing essential components of a texture.
This file defines structures that facilitate the conversion between common image formats (such as JPG and PNG) and in-game texture formats.
- See also
- nnl::STexture
-
nnl::texture::Texture
◆ nnl::SPixel
Represents a pixel with red, green, blue, and alpha color channels.
- See also
- nnl::STexture
Public Member Functions |
| | operator u32 () const |
| | Converts the pixel into a single 32-bit ABGR color.
|
Public Attributes |
| u8 | r |
| | Red channel [0, 255].
|
| u8 | g |
| | Green channel [0, 255].
|
| u8 | b |
| | Blue channel [0, 255].
|
| u8 | a |
| | Alpha channel [0, 255].
|
◆ operator u32()
| nnl::SPixel::operator u32 |
( |
| ) |
const |
|
inline |
Converts the pixel into a single 32-bit ABGR color.
- Returns
- A 32-bit unsigned integer representing the color.
◆ nnl::STexture
Represents a simple texture.
This struct defines essential components of a texture. It serves as an intermediary representation for image data, facilitating the conversion between common image formats (such as JPG and PNG) and in-game texture formats.
- See also
- nnl::texture::Texture
-
nnl::texture::Convert
-
nnl::STexture::Import
-
nnl::STexture::ExportPNG
◆ AlignHeight()
| void nnl::STexture::AlignHeight |
( |
| ) |
|
Aligns the height to the next power of 2.
If the texture height is not a power of 2, this method extends it to the next power of 2, placing the original texture on a bigger canvas. This may be useful since the GE supports only power of 2 textures.
◆ AlignWidth()
| void nnl::STexture::AlignWidth |
( |
| ) |
|
Aligns the width to the next power of 2.
If the texture width is not a power of 2, this method extends it to the next power of 2, placing the original texture on a bigger canvas. This may be useful since the GE supports only power of 2 textures.
◆ ExportPNG() [1/2]
| Buffer nnl::STexture::ExportPNG |
( |
bool | flip = false | ) |
const |
|
nodiscard |
Exports the texture to a PNG file.
- Parameters
-
| flip | Whether to flip the image vertically during exporting. |
- Returns
- A Buffer containing the exported texture data.
◆ ExportPNG() [2/2]
| void nnl::STexture::ExportPNG |
( |
const std::filesystem::path & | path, |
|
|
bool | flip = false ) const |
Exports the texture to a PNG file.
- Parameters
-
| path | The file path to save the texture image. |
| flip | Whether to flip the image vertically during exporting. |
◆ FlipV()
| void nnl::STexture::FlipV |
( |
| ) |
|
Flips the texture vertically.
◆ GenerateChessPattern()
| STexture nnl::STexture::GenerateChessPattern |
( |
unsigned int | width = 128, |
|
|
unsigned int | height = 128 ) |
|
staticnodiscard |
Creates a chessboard pattern texture.
This static method generates a chessboard pattern texture of the specified width and height.
- Parameters
-
| width | The width of the chessboard texture. It must be a power of 2. |
| height | The height of the chessboard texture. It must be a power of 2. |
- Returns
- A new STexture object representing the chessboard pattern.
◆ HasAlpha()
| bool nnl::STexture::HasAlpha |
( |
| ) |
const |
Checks if the texture contains any transparent pixels.
- Returns
- True if the texture has transparent pixels.
◆ Import() [1/2]
Constructs a texture from the specified buffer.
Loads texture data from common image formats (JPG, PNG, BMP, TGA)
- Parameters
-
| buffer | The file buffer containing an image. |
| flip | Specifies whether to vertically flip the image during loading. |
◆ Import() [2/2]
| STexture nnl::STexture::Import |
( |
const std::filesystem::path & | path, |
|
|
bool | flip = false ) |
|
staticnodiscard |
Constructs a texture from the specified file path.
Loads texture data from common image formats (JPG, PNG, BMP, TGA)
- Parameters
-
| path | The file path to the texture image. |
| flip | Specifies whether to vertically flip the image during loading. |
◆ QuantizeAlpha()
| void nnl::STexture::QuantizeAlpha |
( |
unsigned int | levels = 256 | ) |
|
Reduces alpha channel precision to the specified number of levels.
This may be useful for optimizing textures for CLUT formats.
- Parameters
-
| levels | Number of alpha levels (1-256). Default 256 (no change). 1 makes the image fully opaque. |
◆ Resize()
| void nnl::STexture::Resize |
( |
unsigned int | new_width, |
|
|
unsigned int | new_height ) |
Resizes the texture.
- Parameters
-
| new_width | The new width for the texture. |
| new_height | The new height for the texture. |
◆ bitmap
| std::vector<SPixel> nnl::STexture::bitmap |
Pixel data of the texture.
◆ extras
Any additional custom data.
◆ height
| unsigned int nnl::STexture::height = 0 |
Height of the texture in pixels.
◆ mag_filter
◆ min_filter
◆ name
| std::string nnl::STexture::name |
An optional name for the texture.
◆ width
| unsigned int nnl::STexture::width = 0 |
Width of the texture in pixels.
◆ STextureFilter
Specifies the filtering methods used for texture sampling.
- See also
- nnl::STexture
-
https://registry.khronos.org/OpenGL-Refpages/es2.0/xhtml/glTexParameter.xml
| Enumerator |
|---|
| kNearest | Nearest-neighbor filtering.
|
| kLinear | Linear filtering.
|
| kNearestMipmapNearest | Nearest filtering with mipmap selection.
|
| kLinearMipmapNearest | Linear filtering with mipmap selection.
|
| kNearestMipmapLinear | Nearest filtering with mipmap selection.
|
| kLinearMipmapLinear | Linear filtering with mipmap selection.
|