Skip to content

Commit

Permalink
clipping: simplify texture coordinate transformation
Browse files Browse the repository at this point in the history
Instead of scaling the coordinates by -1 on the Y axis, modify the
texture data by flipping it vertically. This allows us to use
guMtxTransApply() function, which is way faster than guMtxConcat().
  • Loading branch information
mardy committed Aug 7, 2024
1 parent 28c1a36 commit 22245d1
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ POSSIBILITY OF SUCH DAMAGE.

static GXTexObj s_clip_texture;
static uint8_t s_clip_texels[32] ATTRIBUTE_ALIGN(32) = {
0x0f, 0x00, 0x00, 0x00,
/* We only are about the top-left 2x2 corner, that is (given that pixels
* are 4 bits wide) the first and the fourth byte only.
* Note how the positive pixel value is set on the bottom right corner,
* since in OpenGL the y coordinate grows upwards, but the t texture
* coordinate grows downwards. */
0x00, 0x00, 0x00, 0x00,
/* There are six more rows, but we don't care about their contents: we only
* care about the top-left 2x2 corner */
0x0f, 0x00, 0x00, 0x00,
};

static void load_clip_texture(u8 tex_map)
Expand Down Expand Up @@ -103,12 +106,7 @@ static bool setup_tev(int *stages, int *tex_coords, int tex_maps, int *tex_mtxs,
* centre of our texture is (0.5, 0.5), therefore we need to map the zero
* point to that. We do that by translating the texture coordinates by 0.5.
*/
const static Mtx trans = {
{ 1, 0, 0, 0.5},
{ 0, -1, 0, 0.5},
{ 0, 0, 0, 1}, /* row is unused */
};
guMtxConcat(trans, m, m);
guMtxTransApply(m, m, 0.5, 0.5, 0);
GX_LoadTexMtxImm(m, tex_mtx, GX_MTX2x4);

GX_SetTexCoordGen(tex_coord, GX_TG_MTX2x4, GX_TG_POS, tex_mtx);
Expand Down

0 comments on commit 22245d1

Please sign in to comment.