NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
Simple Texture

Provides data structures for representing essential components of a texture. More...

Classes

struct  nnl::SPixel
 Represents a pixel with red, green, blue, and alpha color channels. More...
struct  nnl::STexture
 Represents a simple texture. More...

Enumerations

enum class  nnl::STextureFilter {
  nnl::STextureFilter::kNearest = 0 , nnl::STextureFilter::kLinear = 1 , nnl::STextureFilter::kNearestMipmapNearest = 4 , nnl::STextureFilter::kLinearMipmapNearest = 5 ,
  nnl::STextureFilter::kNearestMipmapLinear = 6 , nnl::STextureFilter::kLinearMipmapLinear = 7
}
 Specifies the filtering methods used for texture sampling. More...

Detailed Description

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

Class Documentation

◆ nnl::SPixel

struct 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].

Member Function Documentation

◆ 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.

Member Data Documentation

◆ a

u8 nnl::SPixel::a

Alpha channel [0, 255].

◆ b

u8 nnl::SPixel::b

Blue channel [0, 255].

◆ g

u8 nnl::SPixel::g

Green channel [0, 255].

◆ r

u8 nnl::SPixel::r

Red channel [0, 255].

◆ nnl::STexture

struct 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

Public Member Functions

void Resize (unsigned int new_width, unsigned int new_height)
 Resizes the texture.
void ExportPNG (const std::filesystem::path &path, bool flip=false) const
 Exports the texture to a PNG file.
Buffer ExportPNG (bool flip=false) const
 Exports the texture to a PNG file.
void FlipV ()
 Flips the texture vertically.
void AlignWidth ()
 Aligns the width to the next power of 2.
void AlignHeight ()
 Aligns the height to the next power of 2.
void QuantizeAlpha (unsigned int levels=256)
 Reduces alpha channel precision to the specified number of levels.
bool HasAlpha () const
 Checks if the texture contains any transparent pixels.

Static Public Member Functions

static STexture Import (const std::filesystem::path &path, bool flip=false)
 Constructs a texture from the specified file path.
static STexture Import (BufferView buffer, bool flip=false)
 Constructs a texture from the specified buffer.
static STexture GenerateChessPattern (unsigned int width=128, unsigned int height=128)
 Creates a chessboard pattern texture.

Public Attributes

std::string name
 An optional name for the texture.
unsigned int width = 0
 Width of the texture in pixels.
unsigned int height = 0
 Height of the texture in pixels.
STextureFilter min_filter = STextureFilter::kLinearMipmapNearest
 Texture sampling filter.
STextureFilter mag_filter = STextureFilter::kLinear
 Texture sampling filter.
std::vector< SPixelbitmap
 Pixel data of the texture.
SValue extras
 Any additional custom data.

Member Function Documentation

◆ 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
flipWhether 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
pathThe file path to save the texture image.
flipWhether 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
widthThe width of the chessboard texture. It must be a power of 2.
heightThe 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]

STexture nnl::STexture::Import ( BufferView buffer,
bool flip = false )
staticnodiscard

Constructs a texture from the specified buffer.

Loads texture data from common image formats (JPG, PNG, BMP, TGA)

Parameters
bufferThe file buffer containing an image.
flipSpecifies 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
pathThe file path to the texture image.
flipSpecifies 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
levelsNumber 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_widthThe new width for the texture.
new_heightThe new height for the texture.

Member Data Documentation

◆ bitmap

std::vector<SPixel> nnl::STexture::bitmap

Pixel data of the texture.

◆ extras

SValue nnl::STexture::extras

Any additional custom data.

◆ height

unsigned int nnl::STexture::height = 0

Height of the texture in pixels.

◆ mag_filter

STextureFilter nnl::STexture::mag_filter = STextureFilter::kLinear

Texture sampling filter.

◆ min_filter

Texture sampling 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.

Enumeration Type Documentation

◆ STextureFilter

enum class nnl::STextureFilter
strong

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.