PowerBlocks SDK
 
Loading...
Searching...
No Matches
gx_tev.h File Reference

TEV definitions. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  gx_tev_stage_t
 

Enumerations

enum  gx_tev_stage_id {
  GX_TEV_STAGE_0 , GX_TEV_STAGE_1 , GX_TEV_STAGE_2 , GX_TEV_STAGE_3 ,
  GX_TEV_STAGE_4 , GX_TEV_STAGE_5 , GX_TEV_STAGE_6 , GX_TEV_STAGE_7 ,
  GX_TEV_STAGE_8 , GX_TEV_STAGE_9 , GX_TEV_STAGE_10 , GX_TEV_STAGE_11 ,
  GX_TEV_STAGE_12 , GX_TEV_STAGE_13 , GX_TEV_STAGE_14 , GX_TEV_STAGE_15
}
 
enum  gx_tev_io_t {
  GX_TEV_IO_PREVIOUS = 0x0 , GX_TEV_IO_REGISTER_0 = 0x2 , GX_TEV_IO_REGISTER_1 = 0x4 , GX_TEV_IO_REGISTER_2 = 0x6 ,
  GX_TEV_IO_TEXTURE = 0x8 , GX_TEV_IO_RASTERIZER = 0xA , GX_TEV_IO_ONE = 0xC , GX_TEV_IO_HALF = 0xD ,
  GX_TEV_IO_CONSTANT = 0xE , GX_TEV_IO_ZERO = 0xF , GX_TEV_IO_ALPHA = 0x1
}
 
enum  gx_tev_scale_t { GX_TEV_SCALE_1 , GX_TEV_SCALE_2 , GX_TEV_SCALE_4 , GX_TEV_SCALE_HALF }
 
enum  gx_tev_bias_t { GX_TEV_BIAS_0 , GX_TEV_BIAS_ADD_HALF , GX_TEV_BIAS_SUB_HALF }
 
enum  gx_tev_compare_t {
  GX_TEV_COMPARE_R8_GREATER = 0x0 , GX_TEV_COMPARE_R8_EQUAL = 0x1 , GX_TEV_COMPARE_GR16_GREATER = 0x2 , GX_TEV_COMPARE_GR16_EQUAL = 0x3 ,
  GX_TEV_COMPARE_BGR24_GREATER = 0x4 , GX_TEV_COMPARE_BGR24_EQUAL = 0x5 , GX_TEV_COMPARE_RGB8_GT = 0x6 , GX_TEV_COMPARE_RGB8_EQ = 0x7 ,
  GX_TEV_COMPARE_A8_GREATER = 0x6 , GX_TEV_COMPARE_A8_EQUAL = 0x7
}
 

Functions

void gx_set_tev_stages (int count)
 Sets the number of tev stages.
 
void gx_initialize_tev_stage (gx_tev_stage_t *tev)
 Generates a empty TEV stage.
 
void gx_flash_tev_stage (gx_tev_stage_id id, const gx_tev_stage_t *tev)
 Flashes a TEV stage onto the BP.
 
void gx_set_tev_stage_color_input (gx_tev_stage_t *tev, gx_tev_io_t a, gx_tev_io_t b, gx_tev_io_t c, gx_tev_io_t d)
 Sets the color inputs to a TEV stage.
 
void gx_set_tev_stage_alpha_input (gx_tev_stage_t *tev, gx_tev_io_t a, gx_tev_io_t b, gx_tev_io_t c, gx_tev_io_t d)
 Sets the color inputs to a TEV stage.
 
void gx_set_tev_stage_color_output (gx_tev_stage_t *tev, gx_tev_io_t out, bool clamp)
 Sets the color output to a TEV stage.
 
void gx_set_tev_stage_alpha_output (gx_tev_stage_t *tev, gx_tev_io_t out, bool clamp)
 Sets the alpha output to a TEV stage.
 
void gx_set_tev_stage_color_biasing (gx_tev_stage_t *tev, bool subtract, gx_tev_bias_t bias, gx_tev_scale_t scale)
 Sets the TEV color stage into biasing mode.
 
void gx_set_tev_stage_color_comparison (gx_tev_stage_t *tev, gx_tev_compare_t comparison)
 Sets the TEV color stage into comparison mode.
 
void gx_set_tev_stage_alpha_biasing (gx_tev_stage_t *tev, bool subtract, gx_tev_bias_t bias, gx_tev_scale_t scale)
 Sets the TEV alpha stage into biasing mode.
 
void gx_set_tev_stage_alpha_comparison (gx_tev_stage_t *tev, gx_tev_compare_t comparison)
 Sets the TEV alpha stage into comparison mode.
 
void gx_flash_tev_register_color (gx_tev_io_t reg, int r, int g, int b, int a)
 Set the value of one of the TEVs internal registers.
 

Detailed Description

TEV definitions.

Though the TEV is really part of the BP. The TEV registers have been made their own header. So that their functions are organized.

Diagram of a TEV Stage:

                                                                                    /|     +------------+
                                                                                   / |>----| PREVIOUS   |

+------—+ 8 +----------------------—+ / | +---------—+ | INPUT A |>-/–| | / | +------—+ | | | | +---------—+ | | | |>-—| REGISTER 1 | +------—+ 8 | COLOR MIXER | +------------—+ +----—+ 11 | | +---------—+ | INPUT B |>-/–| mix(a, b, c) |>-—| ADD & SCALE |>-—| CLAMP |>-/–| | +------—+ | (a * (1.0 - c) + b * c) | | ((c+d+b) * s) | +----—+ | | +---------—+ | | +------------—| | |>-—| REGISTER 2 | +------—+ 8 | | | | | +---------—+ | INPUT C |>-/–| | | \ | +------—+ +----------------------—+ | \ | +---------—+ | \ |>-—| REGISTER 3 | +------—+ 11 | | +---------—+ | INPUT D |—/-------------------------------------—+ +------—+

Notes:

  • Each of the inputs, A-D, are selectable.
  • Inputs are truncated to 8 bits, except for D that is a signed 11 bits, [-1024, 1023]
  • The addition is input D, additional bias, then scale is set to be 0.5, 1, 2, or 4
  • If clamping is enabled, color values are capped [0, 255], otherwise [-1024, 1023]
  • You can save the output to 1 of 4 TEV registers, or just use the tev previous register.
  • TEV previous becomes the pixels color at the end of the TEV pipeline.
  • TEVs default mode is biasing mode, it can be in compare mode too. No mixing, It just says, if operation on input A and B is true, pass C, otherwise, 0. It still adds D as a bias.
Author
Samuel Fitzsimons (rainbain)
Date
2025 @license MIT (see LICENSE file)

Function Documentation

◆ gx_flash_tev_register_color()

void gx_flash_tev_register_color ( gx_tev_io_t reg,
int r,
int g,
int b,
int a )
extern

Set the value of one of the TEVs internal registers.

The TEV's internal registers can be used to store constant colors if wanted. Only GX_TEV_IO_REGISTER_0, GX_TEV_IO_REGISTER_1, and GX_TEV_IO_REGISTER_2 are valid.

Parameters
colorRegister to put it into.
rRed value [0, 255], or a signed 11 bit value [-1024, 1024]
gGreen value [0, 255], or a signed 11 bit value [-1024, 1024]
bBlue value [0, 255], or a signed 11 bit value [-1024, 1024]
aAlpha value [0, 255], or a signed 11 bit value [-1024, 1024]

◆ gx_flash_tev_stage()

void gx_flash_tev_stage ( gx_tev_stage_id id,
const gx_tev_stage_t * tev )
extern

Flashes a TEV stage onto the BP.

Copys TEV stages onto the BP.

Parameters
idTEV stage id.
tevPointer to TEV stage.

◆ gx_initialize_tev_stage()

void gx_initialize_tev_stage ( gx_tev_stage_t * tev)
extern

Generates a empty TEV stage.

It will just pass rasterizer/color value.

Parameters
tevTEV stage to set.

◆ gx_set_tev_stage_alpha_biasing()

void gx_set_tev_stage_alpha_biasing ( gx_tev_stage_t * tev,
bool subtract,
gx_tev_bias_t bias,
gx_tev_scale_t scale )
extern

Sets the TEV alpha stage into biasing mode.

In biasing mode, the formula is like (mix(a, b, c) +- d + bias) * scale This in contrary to compare mode where the formula is d + (a compare b ? c : 0)

Parameters
tevTEV stage to modify.
subtractIf set, the d value will be subtracted
biasBias value, -0.5, 0, 0.5.
scaleScale. 0.5, 1, 2, or 4

◆ gx_set_tev_stage_alpha_comparison()

void gx_set_tev_stage_alpha_comparison ( gx_tev_stage_t * tev,
gx_tev_compare_t comparison )
extern

Sets the TEV alpha stage into comparison mode.

In biasing mode, the formula is like (mix(a, b, c) +- d + bias) * scale This in contrary to compare mode where the formula is `d + (a compare b ? c : 0)

Parameters
tevTEV stage to modify.
comparisonComparison mode to use.

◆ gx_set_tev_stage_alpha_input()

void gx_set_tev_stage_alpha_input ( gx_tev_stage_t * tev,
gx_tev_io_t a,
gx_tev_io_t b,
gx_tev_io_t c,
gx_tev_io_t d )
extern

Sets the color inputs to a TEV stage.

Sets the alpha inputs to a TEV stage

In this you can not use GX_TEV_INPUT_ONE and GX_TEV_INPUT_HALF.

GX_TEV_INPUT_ALPHA will not do anything.

Parameters
tevTEV stage to modify.
input_aInput A's alpha value
input_bInput B's alpha value
input_cInput C's alpha value
input_dInput D's 11 bit signed value

◆ gx_set_tev_stage_alpha_output()

void gx_set_tev_stage_alpha_output ( gx_tev_stage_t * tev,
gx_tev_io_t out,
bool clamp )
extern

Sets the alpha output to a TEV stage.

Sets the alpha output to a TEV stage

Parameters
tevTEV stage to modify.
outOutput Destination
clampClamp the output [0, 255] or else [-1024, 1023]

◆ gx_set_tev_stage_color_biasing()

void gx_set_tev_stage_color_biasing ( gx_tev_stage_t * tev,
bool subtract,
gx_tev_bias_t bias,
gx_tev_scale_t scale )
extern

Sets the TEV color stage into biasing mode.

In biasing mode, the formula is like (mix(a, b, c) +- d + bias) * scale This in contrary to compare mode where the formula is d + (a compare b ? c : 0)

Parameters
tevTEV stage to modify.
subtractIf set, the d value will be subtracted
biasBias value, -0.5, 0, 0.5.
scaleScale. 0.5, 1, 2, or 4

◆ gx_set_tev_stage_color_comparison()

void gx_set_tev_stage_color_comparison ( gx_tev_stage_t * tev,
gx_tev_compare_t comparison )
extern

Sets the TEV color stage into comparison mode.

In biasing mode, the formula is like (mix(a, b, c) +- d + bias) * scale This in contrary to compare mode where the formula is d + (a compare b ? c : 0)

Parameters
tevTEV stage to modify.
comparisonComparison mode to use.

◆ gx_set_tev_stage_color_input()

void gx_set_tev_stage_color_input ( gx_tev_stage_t * tev,
gx_tev_io_t a,
gx_tev_io_t b,
gx_tev_io_t c,
gx_tev_io_t d )
extern

Sets the color inputs to a TEV stage.

Sets the color inputs to a TEV stage

Setting the GX_TEV_INPUT_ALPHA bit on a input, will instead use the alpha channel for that input.

Parameters
tevTEV stage to modify.
input_aInput A's RGB8 value
input_bInput B's RGB8 value
input_cInput C's RGB8 value
input_dInput D's 11 bit signed value

◆ gx_set_tev_stage_color_output()

void gx_set_tev_stage_color_output ( gx_tev_stage_t * tev,
gx_tev_io_t out,
bool clamp )
extern

Sets the color output to a TEV stage.

Sets the color output to a TEV stage

Parameters
tevTEV stage to modify.
outOutput Destination
clampClamp the output [0, 255] or else [-1024, 1023]

◆ gx_set_tev_stages()

void gx_set_tev_stages ( int count)
extern

Sets the number of tev stages.

Sets the number of TEV stages the hardware will process.

Parameters
countTEV Stage count 1 to 16