citro3d
Data Structures | Functions
texture.h File Reference

Create and manipulate textures. More...

#include "types.h"

Go to the source code of this file.

Data Structures

struct  C3D_TexCube
 Cubemap texture data. More...
 
struct  C3D_Tex
 Texture data. More...
 
struct  C3D_TexInitParams
 Parameters for C3D_TexInitWithParams() More...
 

Functions

bool C3D_TexInitWithParams (C3D_Tex *tex, C3D_TexCube *cube, C3D_TexInitParams p)
 Initializes texture with specified parameters. More...
 
void C3D_TexLoadImage (C3D_Tex *tex, const void *data, GPU_TEXFACE face, int level)
 Copies raw texture data into C3D_Tex. More...
 
void C3D_TexGenerateMipmap (C3D_Tex *tex, GPU_TEXFACE face)
 Generates mipmaps for C3D_Tex using previously specified max level The max level should have been specified using C3D_TexInitMipmap() or C3D_TexInitWithParams() More...
 
void C3D_TexBind (int unitId, C3D_Tex *tex)
 Binds C3D_Tex to texture unit. More...
 
void C3D_TexFlush (C3D_Tex *tex)
 Flushes texture data from cache into memory. More...
 
void C3D_TexDelete (C3D_Tex *tex)
 Deletes texture data. More...
 
void C3D_TexShadowParams (bool perspective, float bias)
 Configues texunit0 shadow texture properties. More...
 
static int C3D_TexCalcMaxLevel (u32 width, u32 height)
 Calculates maximum mipmap level for given texture size. More...
 
static u32 C3D_TexCalcLevelSize (u32 size, int level)
 Calculates size of mipmap level. More...
 
static u32 C3D_TexCalcTotalSize (u32 size, int maxLevel)
 Calculates total size of mipmap texture data. More...
 
static bool C3D_TexInit (C3D_Tex *tex, u16 width, u16 height, GPU_TEXCOLOR format)
 Initializes standard 2D texture. More...
 
static bool C3D_TexInitMipmap (C3D_Tex *tex, u16 width, u16 height, GPU_TEXCOLOR format)
 Initializes standard 2D texture with mipmap Maximum miplevel is calculated using C3D_TexCalcMaxLevel() More...
 
static bool C3D_TexInitCube (C3D_Tex *tex, C3D_TexCube *cube, u16 width, u16 height, GPU_TEXCOLOR format)
 Initializes cubemap texture. More...
 
static bool C3D_TexInitVRAM (C3D_Tex *tex, u16 width, u16 height, GPU_TEXCOLOR format)
 Initializes 2D texture in VRAM. More...
 
static bool C3D_TexInitShadow (C3D_Tex *tex, u16 width, u16 height)
 Initializes 2D shadowmap texture. More...
 
static bool C3D_TexInitShadowCube (C3D_Tex *tex, C3D_TexCube *cube, u16 width, u16 height)
 Initializes shadowmap cubemap texture. More...
 
static GPU_TEXTURE_MODE_PARAM C3D_TexGetType (C3D_Tex *tex)
 Gets type of texture. More...
 
static void * C3D_TexGetImagePtr (C3D_Tex *tex, void *data, int level, u32 *size)
 Gets pointer to texture image. More...
 
static void * C3D_Tex2DGetImagePtr (C3D_Tex *tex, int level, u32 *size)
 Gets pointer to 2D texture image. More...
 
static void * C3D_TexCubeGetImagePtr (C3D_Tex *tex, GPU_TEXFACE face, int level, u32 *size)
 Gets pointer to cubemap texture image. More...
 
static void C3D_TexUpload (C3D_Tex *tex, const void *data)
 Copies raw texture data into standard 2D texture. More...
 
static void C3D_TexSetFilter (C3D_Tex *tex, GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter)
 Configures texture magnification and minification filters. More...
 
static void C3D_TexSetFilterMipmap (C3D_Tex *tex, GPU_TEXTURE_FILTER_PARAM filter)
 Configures texture mipmap minification filters. More...
 
static void C3D_TexSetWrap (C3D_Tex *tex, GPU_TEXTURE_WRAP_PARAM wrapS, GPU_TEXTURE_WRAP_PARAM wrapT)
 Configures texture wrapping options. More...
 
static void C3D_TexSetLodBias (C3D_Tex *tex, float lodBias)
 Configures texture level of detail bias used to select the correct mipmap during sampling. More...
 

Detailed Description

Create and manipulate textures.

Function Documentation

◆ C3D_Tex2DGetImagePtr()

static void* C3D_Tex2DGetImagePtr ( C3D_Tex tex,
int  level,
u32 size 
)
inlinestatic

Gets pointer to 2D texture image.

Parameters
[in]texPointer to C3D_Tex.
[in]levelSpecifies mipmap level.
[out]sizeCan be used to get the size of the image data.
Returns
Pointer to raw image data.

◆ C3D_TexBind()

void C3D_TexBind ( int  unitId,
C3D_Tex tex 
)

Binds C3D_Tex to texture unit.

Note
The 3DS has 3 normal texture units (IDs 0 through 2).
Parameters
[in]unitIdSpecifies texture unit.
[in]texPointer to C3D_Tex.

◆ C3D_TexCalcLevelSize()

static u32 C3D_TexCalcLevelSize ( u32  size,
int  level 
)
inlinestatic

Calculates size of mipmap level.

Parameters
[in]sizeSize of original texture.
[in]levelMipmap level.
Returns
Calculated level size.

◆ C3D_TexCalcMaxLevel()

static int C3D_TexCalcMaxLevel ( u32  width,
u32  height 
)
inlinestatic

Calculates maximum mipmap level for given texture size.

Parameters
[in]widthWidth of texture.
[in]heightHeight of texture.
Returns
Calculated maximum mipmap level.

◆ C3D_TexCalcTotalSize()

static u32 C3D_TexCalcTotalSize ( u32  size,
int  maxLevel 
)
inlinestatic

Calculates total size of mipmap texture data.

Parameters
[in]sizeSize of original texture.
[in]maxLevelMaximum mipmap level.
Returns
Calculated total size.

◆ C3D_TexCubeGetImagePtr()

static void* C3D_TexCubeGetImagePtr ( C3D_Tex tex,
GPU_TEXFACE  face,
int  level,
u32 size 
)
inlinestatic

Gets pointer to cubemap texture image.

Parameters
[in]texPointer to C3D_Tex.
[in]faceSpecifies the cubemap texture face.
[in]levelSpecifies mipmap level.
[out]sizeCan be used to get the size of the image data.
Returns
Pointer to raw image data.

◆ C3D_TexDelete()

void C3D_TexDelete ( C3D_Tex tex)

Deletes texture data.

Parameters
[in]texPointer to C3D_Tex.

◆ C3D_TexFlush()

void C3D_TexFlush ( C3D_Tex tex)

Flushes texture data from cache into memory.

Parameters
[in]texPointer to C3D_Tex.
See also
GSPGPU_FlushDataCache()

◆ C3D_TexGenerateMipmap()

void C3D_TexGenerateMipmap ( C3D_Tex tex,
GPU_TEXFACE  face 
)

Generates mipmaps for C3D_Tex using previously specified max level The max level should have been specified using C3D_TexInitMipmap() or C3D_TexInitWithParams()

Note
Does not support generating mipmaps for VRAM textures.
Parameters
[in,out]texPointer to C3D_Tex.
[in]faceSpecifies texture face.

◆ C3D_TexGetImagePtr()

static void* C3D_TexGetImagePtr ( C3D_Tex tex,
void *  data,
int  level,
u32 size 
)
inlinestatic

Gets pointer to texture image.

Parameters
[in]texPointer to C3D_Tex.
[in]dataPointer texture face.
[in]levelSpecifies mipmap level.
[out]sizeCan be used to get the size of the image data.
Returns
Pointer to raw image data.

◆ C3D_TexGetType()

static GPU_TEXTURE_MODE_PARAM C3D_TexGetType ( C3D_Tex tex)
inlinestatic

Gets type of texture.

Parameters
[in]texPointer to C3D_Tex.

◆ C3D_TexInit()

static bool C3D_TexInit ( C3D_Tex tex,
u16  width,
u16  height,
GPU_TEXCOLOR  format 
)
inlinestatic

Initializes standard 2D texture.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
[in]formatSpecifies texture format.
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitCube()

static bool C3D_TexInitCube ( C3D_Tex tex,
C3D_TexCube cube,
u16  width,
u16  height,
GPU_TEXCOLOR  format 
)
inlinestatic

Initializes cubemap texture.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[out]cubePointer to C3D_TexCube.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
[in]formatSpecifies texture format.
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitMipmap()

static bool C3D_TexInitMipmap ( C3D_Tex tex,
u16  width,
u16  height,
GPU_TEXCOLOR  format 
)
inlinestatic

Initializes standard 2D texture with mipmap Maximum miplevel is calculated using C3D_TexCalcMaxLevel()

Parameters
[out]texPointer to uninitialized C3D_Tex.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
[in]formatSpecifies texture format.
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitShadow()

static bool C3D_TexInitShadow ( C3D_Tex tex,
u16  width,
u16  height 
)
inlinestatic

Initializes 2D shadowmap texture.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitShadowCube()

static bool C3D_TexInitShadowCube ( C3D_Tex tex,
C3D_TexCube cube,
u16  width,
u16  height 
)
inlinestatic

Initializes shadowmap cubemap texture.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[out]cubePointer to C3D_TexCube.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitVRAM()

static bool C3D_TexInitVRAM ( C3D_Tex tex,
u16  width,
u16  height,
GPU_TEXCOLOR  format 
)
inlinestatic

Initializes 2D texture in VRAM.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[in]widthSpecifies width of texture. (must be a power of 2)
[in]heightSpecifies height of texture. (must be a power of 2)
[in]formatSpecifies texture format.
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexInitWithParams()

bool C3D_TexInitWithParams ( C3D_Tex tex,
C3D_TexCube cube,
C3D_TexInitParams  p 
)

Initializes texture with specified parameters.

Parameters
[out]texPointer to uninitialized C3D_Tex.
[out]cubePointer to C3D_TexCube. (Only used if texture type is cubemap)
[in]pParameters. See C3D_TexInitParams.
Returns
True if texture was initialized successfully, otherwise false.

◆ C3D_TexLoadImage()

void C3D_TexLoadImage ( C3D_Tex tex,
const void *  data,
GPU_TEXFACE  face,
int  level 
)

Copies raw texture data into C3D_Tex.

Parameters
[out]texPointer to C3D_Tex.
[in]dataPointer to raw texture data.
[in]faceSpecifies texture face.
[in]levelSpecifies mipmap level.

◆ C3D_TexSetFilter()

static void C3D_TexSetFilter ( C3D_Tex tex,
GPU_TEXTURE_FILTER_PARAM  magFilter,
GPU_TEXTURE_FILTER_PARAM  minFilter 
)
inlinestatic

Configures texture magnification and minification filters.

Parameters
[out]texPointer to C3D_Tex.
[in]magFilterSpecifies the filtering to use when magnifying the the texture.
[in]minFilterSpecifies the filtering to use when minifying the the texture.

◆ C3D_TexSetFilterMipmap()

static void C3D_TexSetFilterMipmap ( C3D_Tex tex,
GPU_TEXTURE_FILTER_PARAM  filter 
)
inlinestatic

Configures texture mipmap minification filters.

Parameters
[out]texPointer to C3D_Tex.
[in]filterSpecifies the filtering to use when minifying the the mipmap.

◆ C3D_TexSetLodBias()

static void C3D_TexSetLodBias ( C3D_Tex tex,
float  lodBias 
)
inlinestatic

Configures texture level of detail bias used to select the correct mipmap during sampling.

Parameters
[out]texPointer to C3D_Tex.
[in]lodBiasSpecifies the texture level of detail bias.

◆ C3D_TexSetWrap()

static void C3D_TexSetWrap ( C3D_Tex tex,
GPU_TEXTURE_WRAP_PARAM  wrapS,
GPU_TEXTURE_WRAP_PARAM  wrapT 
)
inlinestatic

Configures texture wrapping options.

Parameters
[out]texPointer to C3D_Tex.
[in]wrapSSpecifies the texture wrapping mode for texture coordinate S (aka U).
[in]wrapTSpecifies the texture wrapping mode for texture coordinate T (aka V).

◆ C3D_TexShadowParams()

void C3D_TexShadowParams ( bool  perspective,
float  bias 
)

Configues texunit0 shadow texture properties.

Parameters
[in]perspectiveTODO
[in]biasTODO

◆ C3D_TexUpload()

static void C3D_TexUpload ( C3D_Tex tex,
const void *  data 
)
inlinestatic

Copies raw texture data into standard 2D texture.

Parameters
[out]texPointer to C3D_Tex.
[in]dataPointer to raw texture data.