2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @file texenv.h
|
|
|
|
* @brief Configure texture combiner stages (TexEnv)
|
|
|
|
* @see https://www.khronos.org/opengl/wiki/Texture_Combiners
|
|
|
|
* @see https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTexEnv.xml
|
|
|
|
*/
|
2014-12-20 21:34:19 +01:00
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/// TexEnv stage configuration
|
2014-12-20 21:34:19 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
u16 srcRgb, srcAlpha;
|
2017-10-30 21:07:15 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
u32 opAll;
|
|
|
|
struct { u32 opRgb:12, opAlpha:12; };
|
|
|
|
};
|
2014-12-20 21:34:19 +01:00
|
|
|
u16 funcRgb, funcAlpha;
|
|
|
|
u32 color;
|
2015-09-10 13:47:16 +02:00
|
|
|
u16 scaleRgb, scaleAlpha;
|
2014-12-20 21:34:19 +01:00
|
|
|
} C3D_TexEnv;
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/// TexEnv operation mode
|
2017-10-30 21:07:15 +01:00
|
|
|
typedef enum
|
2014-12-20 21:34:19 +01:00
|
|
|
{
|
2024-01-17 03:31:31 +01:00
|
|
|
C3D_RGB = BIT(0), ///< RGB mode
|
|
|
|
C3D_Alpha = BIT(1), ///< Alpha mode
|
|
|
|
C3D_Both = C3D_RGB | C3D_Alpha, ///< Both
|
2017-10-30 21:07:15 +01:00
|
|
|
} C3D_TexEnvMode;
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the global TexEnv for a given stage.
|
|
|
|
* @param[in] id TexEnv stage between 0-5 to return.
|
|
|
|
* @return TexEnv of the given stage.
|
|
|
|
*/
|
2014-12-20 21:34:19 +01:00
|
|
|
C3D_TexEnv* C3D_GetTexEnv(int id);
|
2024-01-17 03:31:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the global TexEnv for a given stage.
|
|
|
|
* @param[in] id TexEnv stage between 0-5 to set.
|
|
|
|
* @param[in] env Pointer to user TexEnv.
|
|
|
|
*/
|
2014-12-20 21:34:19 +01:00
|
|
|
void C3D_SetTexEnv(int id, C3D_TexEnv* env);
|
2024-01-17 03:31:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Marks a TexEnv as needing to be updated.
|
|
|
|
* @note One must use this if they are continuing to use a TexEnv pointer they got from \ref C3D_GetTexEnv() after performing an action that flushes state.
|
|
|
|
* @param[in] env Pointer to a TexEnv struct.
|
|
|
|
*/
|
2017-04-26 16:34:59 +02:00
|
|
|
void C3D_DirtyTexEnv(C3D_TexEnv* env);
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Configures the stages where the GPU_PREVIOUS_BUFFER source value should be updated with the output of that stage.
|
|
|
|
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
|
|
|
* @param[in] mask Bitmask containing which stages update GPU_PREVIOUS_BUFFER (bitmask can be created using \ref GPU_TEV_BUFFER_WRITE_CONFIG())
|
|
|
|
*/
|
2015-09-10 13:47:16 +02:00
|
|
|
void C3D_TexEnvBufUpdate(int mode, int mask);
|
2024-01-17 03:31:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure the initial value of GPU_PREVIOUS_BUFFER. This value will be kept until it is updated; see \ref C3D_TexEnvBufUpdate().
|
|
|
|
* @param[in] color Color value.
|
|
|
|
*/
|
2015-09-10 13:47:16 +02:00
|
|
|
void C3D_TexEnvBufColor(u32 color);
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Resets a TexEnv to its default values.
|
|
|
|
* @param[out] env TexEnv to initialize.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvInit(C3D_TexEnv* env)
|
2014-12-20 21:34:19 +01:00
|
|
|
{
|
2017-10-30 21:07:15 +01:00
|
|
|
env->srcRgb = GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0);
|
|
|
|
env->srcAlpha = env->srcRgb;
|
|
|
|
env->opAll = 0;
|
|
|
|
env->funcRgb = GPU_REPLACE;
|
|
|
|
env->funcAlpha = env->funcRgb;
|
|
|
|
env->color = 0xFFFFFFFF;
|
|
|
|
env->scaleRgb = GPU_TEVSCALE_1;
|
|
|
|
env->scaleAlpha = GPU_TEVSCALE_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define _C3D_DEFAULT(x) = x
|
|
|
|
#else
|
|
|
|
#define _C3D_DEFAULT(x)
|
|
|
|
#endif
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets the input source of a TexEnv.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
|
|
|
* @param[in] s1 First source.
|
|
|
|
* @param[in] s2 Second source.
|
|
|
|
* @param[in] s3 Third source.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvSrc(C3D_TexEnv* env, C3D_TexEnvMode mode,
|
|
|
|
GPU_TEVSRC s1,
|
|
|
|
GPU_TEVSRC s2 _C3D_DEFAULT(GPU_PRIMARY_COLOR),
|
|
|
|
GPU_TEVSRC s3 _C3D_DEFAULT(GPU_PRIMARY_COLOR))
|
|
|
|
{
|
|
|
|
int param = GPU_TEVSOURCES((int)s1, (int)s2, (int)s3);
|
|
|
|
if ((int)mode & C3D_RGB)
|
2014-12-20 21:34:19 +01:00
|
|
|
env->srcRgb = param;
|
2017-10-30 21:07:15 +01:00
|
|
|
if ((int)mode & C3D_Alpha)
|
2014-12-20 21:34:19 +01:00
|
|
|
env->srcAlpha = param;
|
|
|
|
}
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Configures the operation to be applied to the input color of a TexEnv before the function is applied.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] o1 Operation to perform on the first source.
|
|
|
|
* @param[in] o2 Operation to perform on the second source.
|
|
|
|
* @param[in] o3 Operation to perform on the third source.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvOpRgb(C3D_TexEnv* env,
|
|
|
|
GPU_TEVOP_RGB o1,
|
|
|
|
GPU_TEVOP_RGB o2 _C3D_DEFAULT(GPU_TEVOP_RGB_SRC_COLOR),
|
|
|
|
GPU_TEVOP_RGB o3 _C3D_DEFAULT(GPU_TEVOP_RGB_SRC_COLOR))
|
2014-12-20 21:34:19 +01:00
|
|
|
{
|
2017-10-30 21:07:15 +01:00
|
|
|
env->opRgb = GPU_TEVOPERANDS((int)o1, (int)o2, (int)o3);
|
|
|
|
}
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Configures the operation to be applied to the input alpha of a TexEnv before the function is applied.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] o1 Operation to perform on the first source.
|
|
|
|
* @param[in] o2 Operation to perform on the second source.
|
|
|
|
* @param[in] o3 Operation to perform on the third source.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvOpAlpha(C3D_TexEnv* env,
|
|
|
|
GPU_TEVOP_A o1,
|
|
|
|
GPU_TEVOP_A o2 _C3D_DEFAULT(GPU_TEVOP_A_SRC_ALPHA),
|
|
|
|
GPU_TEVOP_A o3 _C3D_DEFAULT(GPU_TEVOP_A_SRC_ALPHA))
|
|
|
|
{
|
|
|
|
env->opAlpha = GPU_TEVOPERANDS((int)o1, (int)o2, (int)o3);
|
|
|
|
}
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets the combiner function to perform in this TexEnv.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
|
|
|
* @param[in] param Function to use.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvFunc(C3D_TexEnv* env, C3D_TexEnvMode mode, GPU_COMBINEFUNC param)
|
|
|
|
{
|
|
|
|
if ((int)mode & C3D_RGB)
|
2014-12-20 21:34:19 +01:00
|
|
|
env->funcRgb = param;
|
2017-10-30 21:07:15 +01:00
|
|
|
if ((int)mode & C3D_Alpha)
|
2014-12-20 21:34:19 +01:00
|
|
|
env->funcAlpha = param;
|
|
|
|
}
|
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets the value of the GPU_CONSTANT source for a TexEnv stage.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] color RGBA color value to apply.
|
|
|
|
*/
|
2014-12-20 21:34:19 +01:00
|
|
|
static inline void C3D_TexEnvColor(C3D_TexEnv* env, u32 color)
|
|
|
|
{
|
|
|
|
env->color = color;
|
|
|
|
}
|
2015-09-10 13:47:16 +02:00
|
|
|
|
2024-01-17 03:31:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Configures the scaling to be applied to the output of a TexEnv.
|
|
|
|
* @param[out] env Pointer to TexEnv struct.
|
|
|
|
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
|
|
|
* @param[in] param Scale factor to apply.
|
|
|
|
*/
|
2017-10-30 21:07:15 +01:00
|
|
|
static inline void C3D_TexEnvScale(C3D_TexEnv* env, int mode, GPU_TEVSCALE param)
|
2015-09-10 13:47:16 +02:00
|
|
|
{
|
|
|
|
if (mode & C3D_RGB)
|
|
|
|
env->scaleRgb = param;
|
|
|
|
if (mode & C3D_Alpha)
|
|
|
|
env->scaleAlpha = param;
|
|
|
|
}
|
2017-10-30 21:07:15 +01:00
|
|
|
|
|
|
|
#undef _C3D_DEFAULT
|