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

Classes

struct  nnl::texture::TextureData
 Structure representing image data of a texture. More...
struct  nnl::texture::Texture
 Structure representing a texture. More...
struct  nnl::texture::ConvertParam
 Structure to hold parameters for texture conversion. More...

Typedefs

using nnl::texture::TextureContainer = std::vector<Texture>
 Type alias for a container of textures.

Enumerations

enum class  nnl::texture::TextureFormat : u16 {
  nnl::texture::TextureFormat::kCLUT8 = 5 , nnl::texture::TextureFormat::kCLUT4 = 4 , nnl::texture::TextureFormat::kRGBA8888 = 3 , nnl::texture::TextureFormat::kRGBA4444 = 2 ,
  nnl::texture::TextureFormat::kRGBA5551 = 1 , nnl::texture::TextureFormat::kRGB565 = 0
}
 Enumeration of texture formats. More...
enum class  nnl::texture::ClutFormat : u8 { nnl::texture::ClutFormat::kRGBA8888 = 3 , nnl::texture::ClutFormat::kRGBA4444 = 2 , nnl::texture::ClutFormat::kRGBA5551 = 1 , nnl::texture::ClutFormat::kRGB565 = 0 }
 Enumeration of color formats used in Color Lookup Tables (CLUT). More...
enum class  nnl::texture::TextureFilter : u8 {
  nnl::texture::TextureFilter::kNearest = 0 , nnl::texture::TextureFilter::kLinear = 1 , nnl::texture::TextureFilter::kNearestMipmapNearest = 4 , nnl::texture::TextureFilter::kLinearMipmapNearest = 5 ,
  nnl::texture::TextureFilter::kNearestMipmapLinear = 6 , nnl::texture::TextureFilter::kLinearMipmapLinear = 7
}
 Enumeration of texture filtering methods. More...

Functions

std::vector< STexturennl::texture::Convert (const TextureContainer &texture_container, bool mipmaps=false)
 Converts a container of textures to a simplified representation.
TextureContainer nnl::texture::Convert (std::vector< STexture > &&images, const ConvertParam &texture_params={})
 Converts a vector of simplified textures into the in-game format.
bool nnl::texture::IsOfType (BufferView buffer)
 Tests if the provided file is a texture container.
TextureContainer nnl::texture::Import (BufferView buffer)
 Parses a binary file and converts it to a structured texture container.
Buffer nnl::texture::Export (const TextureContainer &texture_container)
 Converts a texture container to its binary file representation.

Variables

constexpr unsigned int nnl::texture::kMinDimension = 1
 Minimum allowed width and height of a texture in pixels.
constexpr unsigned int nnl::texture::kMinByteBufferWidth = 16
 Minimum width of a texture buffer in bytes (as expected by the GE). The actual pixel width can be smaller than this.
constexpr unsigned int nnl::texture::kMaxDimension = 1024
 Maximum allowed width and height of a texture in pixels.
constexpr std::size_t nnl::texture::kMaxMipMapLvl = 7
 The maximum number of mipmap levels that can be used.
constexpr std::size_t nnl::texture::kMaxTextureLvl = 1 + kMaxMipMapLvl
 The maximum number of texture levels.

Detailed Description


Class Documentation

◆ nnl::texture::TextureData

struct nnl::texture::TextureData

Structure representing image data of a texture.

It can be used to represent both the main texture level and its mipmaps.

Note
For proper functionality, both texture width and height must be powers of 2, especially when mipmapping is used. The PSP's GE can only load textures in powers of 2. If the height is not a power of 2 (a practice often used in UI textures to save space), it's rounded up and extra garbage data is loaded. If width is not a power of 2 (which is the case for few invalid textures), it's rounded down and part of the texture is discarded.
See also
nnl::texture::Texture

Public Attributes

u16 width = 0
 Width of the texture in pixels. It must be a power of 2.
u16 height = 0
u16 buffer_width = 0
Buffer bitmap_buffer
 Raw bitmap data. Its interpretation depends on the texture_format.

Member Data Documentation

◆ bitmap_buffer

Buffer nnl::texture::TextureData::bitmap_buffer

Raw bitmap data. Its interpretation depends on the texture_format.

◆ buffer_width

u16 nnl::texture::TextureData::buffer_width = 0

Width of the bitmap_buffer in pixels. It must be greater than or equal to the width. The buffer width in bytes must be a multiple of 16. For example, in a CLUT4 texture, this value must be at least 32 pixels.

◆ height

u16 nnl::texture::TextureData::height = 0

Height of the texture in pixels. It generally should be a power of 2. However, it may not always be the case for UI textures.

◆ width

u16 nnl::texture::TextureData::width = 0

Width of the texture in pixels. It must be a power of 2.

◆ nnl::texture::Texture

struct nnl::texture::Texture

Structure representing a texture.

This struct encapsulates all the necessary information for a texture. It can store both the main texture level and its mipmaps.

See also
nnl::texture::TextureContainer

Public Attributes

Buffer clut_buffer
utl::static_vector< TextureData, kMaxTextureLvltexture_data
TextureFormat texture_format = TextureFormat::kCLUT8
 Format of the texture data.
bool swizzled = true
TextureFilter min_filter = TextureFilter::kLinearMipmapNearest
 Minification filter method for texture sampling.
TextureFilter mag_filter = TextureFilter::kLinear
ClutFormat clut_format = ClutFormat::kRGBA8888
 Format of the CLUT data.

Member Data Documentation

◆ clut_buffer

Buffer nnl::texture::Texture::clut_buffer

Color Look Up Table. It's used when texture_format is set to one of the CLUT formats.

◆ clut_format

ClutFormat nnl::texture::Texture::clut_format = ClutFormat::kRGBA8888

Format of the CLUT data.

◆ mag_filter

TextureFilter nnl::texture::Texture::mag_filter = TextureFilter::kLinear

Magnification filter method for texture sampling: kLinear or kNearest.

◆ min_filter

TextureFilter nnl::texture::Texture::min_filter = TextureFilter::kLinearMipmapNearest

Minification filter method for texture sampling.

◆ swizzled

bool nnl::texture::Texture::swizzled = true

Indicates whether the texture data is reorganized for more efficient use by the GE

◆ texture_data

utl::static_vector<TextureData, kMaxTextureLvl> nnl::texture::Texture::texture_data

Stores various levels of the texture. Index 0 contains the full-resolution base texture, with subsequent indices storing mipmaps. Limited to 8 levels in total.

◆ texture_format

TextureFormat nnl::texture::Texture::texture_format = TextureFormat::kCLUT8

Format of the texture data.

◆ nnl::texture::ConvertParam

struct nnl::texture::ConvertParam

Structure to hold parameters for texture conversion.

This structure encapsulates various parameters that control the behavior of texture conversion from a simplified representation to the in-game format.

See also
nnl::texture::Convert

Public Attributes

TextureFormat texture_format = TextureFormat::kCLUT8
 The format the texture will be converted to.
ClutFormat clut_format = ClutFormat::kRGBA8888
bool clut_dither = true
unsigned int max_mipmap_lvl = kMaxMipMapLvl
 The maximum number of mipmap levels to generate.
bool gen_small_mipmap = false
unsigned int max_width_height = kMaxDimension / 2
bool swizzle = true

Member Data Documentation

◆ clut_dither

bool nnl::texture::ConvertParam::clut_dither = true

Whether dithering should be applied to the texture if a CLUT format is used. This may give an illusion of a greater color variety.

◆ clut_format

ClutFormat nnl::texture::ConvertParam::clut_format = ClutFormat::kRGBA8888

The format the color lookup table will use (if texture_format uses it).

◆ gen_small_mipmap

bool nnl::texture::ConvertParam::gen_small_mipmap = false

Whether to generate mipmaps with width that is smaller than the minimum buffer width.

◆ max_mipmap_lvl

unsigned int nnl::texture::ConvertParam::max_mipmap_lvl = kMaxMipMapLvl

The maximum number of mipmap levels to generate.

◆ max_width_height

unsigned int nnl::texture::ConvertParam::max_width_height = kMaxDimension / 2

Maximum dimensions for the texture; larger textures will be resized.

◆ swizzle

bool nnl::texture::ConvertParam::swizzle = true

Whether to reorganize the texture data for more efficient use.

See also
nnl::texture::SwizzleFromMem

◆ texture_format

TextureFormat nnl::texture::ConvertParam::texture_format = TextureFormat::kCLUT8

The format the texture will be converted to.

Typedef Documentation

◆ TextureContainer

Type alias for a container of textures.

Note
This struct usually stores only a portion of the data required by an asset to function properly. Its binary representation must be used as part of various larger containers that may also include UI configs, text, models and other data.
See also
nnl::asset::Asset
nnl::asset::Asset3D
nnl::asset::BitmapText
nnl::model::Model

Enumeration Type Documentation

◆ ClutFormat

enum class nnl::texture::ClutFormat : u8
strong

Enumeration of color formats used in Color Lookup Tables (CLUT).

See also
nnl::texture::Texture
Enumerator
kRGBA8888 

32-bit color format. 8 bits per channel.

kRGBA4444 

16-bit color format. 4 bits per channel.

kRGBA5551 

16-bit color format. 1 bit for the alpha channel.

kRGB565 

16-bit color format. No alpha channel.

◆ TextureFilter

enum class nnl::texture::TextureFilter : u8
strong

Enumeration of texture filtering methods.

This enum defines various texture filtering methods that can be applied when rendering textures larger or smaller than their original size.

The filtering methods include options that can be used for both magnification and minification, as well as mipmapping.

These values map directly to what the GE expects.

See also
nnl::texture::Texture
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.

◆ TextureFormat

enum class nnl::texture::TextureFormat : u16
strong

Enumeration of texture formats.

This enum defines the various texture formats that can be used to store texture data. The values correspond to what is expected by the GE. Technically, there are a few more formats available, but they are not used by the games and are rare in general.

See also
nnl::texture::Texture
Enumerator
kCLUT8 

8 bit indices that refer to a color lookup table with up to 256 colors.

kCLUT4 

4 bit indices that refer to a color lookup table with up to 16 colors.

kRGBA8888 

32-bit color format with 8 bits per channel. No CLUT.

kRGBA4444 

16-bit color format with 4 bits per channel. No CLUT.

kRGBA5551 

16-bit color format. No CLUT.

kRGB565 

16-bit color format. No CLUT.

Function Documentation

◆ Convert() [1/2]

std::vector< STexture > nnl::texture::Convert ( const TextureContainer & texture_container,
bool mipmaps = false )

Converts a container of textures to a simplified representation.

This function takes a TextureContainer containing multiple in-game textures and converts each texture into a simplified representation.

Parameters
texture_containerThe input container holding the textures to be converted.
mipmapsA flag indicating whether mipmaps should be extracted as well.
Returns
A vector of STexture objects representing the converted textures.
See also
nnl::STexture

◆ Convert() [2/2]

TextureContainer nnl::texture::Convert ( std::vector< STexture > && images,
const ConvertParam & texture_params = {} )

Converts a vector of simplified textures into the in-game format.

This function takes a vector of STexture images and converts them into a TextureContainer, applying the specified conversion parameters.

Parameters
imagesA vector of STexture objects representing the textures to be converted.
texture_paramsA ConvertParam object specifying the conversion settings for each texture.
Returns
A TextureContainer object containing the converted textures.
Note
Use std::move when passing an existing object.

◆ Export()

Buffer nnl::texture::Export ( const TextureContainer & texture_container)
nodiscard

Converts a texture container to its binary file representation.

This function takes a TextureContainer object and converts it into the binary format.

Parameters
texture_containerThe TextureContainer object to be converted.
Returns
A buffer containing the binary representation of the texture container.

◆ Import()

TextureContainer nnl::texture::Import ( BufferView buffer)

Parses a binary file and converts it to a structured texture container.

This function takes a binary representation of a texture container, parses its contents, and converts them into a TextureContainer vector for easier access and manipulation.

Parameters
bufferThe binary file to be processed.
Returns
A TextureContainer object representing the converted data.
See also
nnl::texture::IsOfType
nnl::texture::Export

◆ IsOfType()

bool nnl::texture::IsOfType ( BufferView buffer)

Tests if the provided file is a texture container.

This function takes a file buffer and checks whether it corresponds to the in-game texture container format.

Parameters
bufferThe file buffer to be tested.
Returns
Returns true if the file is identified as a texture container.
See also
nnl::texture::Import

Variable Documentation

◆ kMaxDimension

unsigned int nnl::texture::kMaxDimension = 1024
constexpr

Maximum allowed width and height of a texture in pixels.

The GE supports a maximum width of only 512 pixels. However, emulators can handle textures up to 1024 pixels in width and height.

◆ kMaxMipMapLvl

std::size_t nnl::texture::kMaxMipMapLvl = 7
constexpr

The maximum number of mipmap levels that can be used.

◆ kMaxTextureLvl

std::size_t nnl::texture::kMaxTextureLvl = 1 + kMaxMipMapLvl
constexpr

The maximum number of texture levels.

◆ kMinByteBufferWidth

unsigned int nnl::texture::kMinByteBufferWidth = 16
constexpr

Minimum width of a texture buffer in bytes (as expected by the GE). The actual pixel width can be smaller than this.

◆ kMinDimension

unsigned int nnl::texture::kMinDimension = 1
constexpr

Minimum allowed width and height of a texture in pixels.