Skip to content

Commit

Permalink
gpu/texture-flip rectangle test
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Feb 21, 2021
1 parent 072a2f2 commit 7adb9f0
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ IMAGES = common \
gpu/mask-bit \
gpu/quad \
gpu/rectangles \
gpu/texture-flip \
gpu/texture-overflow \
gpu/transparency \
gpu/triangle \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lines | Draws lines using different modes - for verifying Bre
mask-bit | Check Mask bit behavior during VRAM copy operations
quad | Semi-transparent polygon commands - for testing fill rules and transparency handling
rectangles | Draws all combinations of Rectangle commands
texture-flip | Check gp0_e1.13 and gp0_e1.12 texture flip behaviour
texture-overflow | Draws textured rectangle with UV overflowing VRAM width
transparency | Draws rectangles with 4 semi-transparent blending modes
triangle | Draws Gouroud shaded equilateral triangle
Expand Down
3 changes: 3 additions & 0 deletions gpu/texture-flip/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TARGET = texture-flip.elf

include ../../common-test.mk
128 changes: 128 additions & 0 deletions gpu/texture-flip/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include <common.h>

#define SCR_W 320
#define SCR_H 240

const int texPageX = 640;
const int texPageY = 0;

uint16_t lastTpage = 0;
void setTextureFlip(bool flipY, bool flipX) {
DR_TPAGE e;
setDrawTPage(&e, /* Drawing to display area */ 1, /* dithering */ 0, getTPage(/* bits = 15bit */ 2, /* transparencyMode */0, texPageX, texPageY));
e.code[0] |= (flipX << 12);
e.code[0] |= (flipY << 13);
lastTpage = e.code[0];
DrawPrim(&e);
}

void drawRectangle(int x, int y, int w, int h) {
SPRT s;
setSprt(&s);
setSemiTrans(&s, 0);
setRGB0(&s, 128, 128, 128 );
s.x0 = x;
s.y0 = y;
s.w = w;
s.h = h;
s.u0 = 0;
s.v0 = 0;
DrawPrim(&s);
}

void drawQuad(int x, int y, int w, int h) {
POLY_FT4 p;
setPolyFT4(&p);
setSemiTrans(&p, 0);
setRGB0(&p, 128, 128, 128 );
setClut(&p, 0, 0); // Not used
p.tpage = lastTpage;

p.x0 = x; p.y0 = y;
p.x1 = x+w; p.y1 = y;
p.x2 = x; p.y2 = y+h;
p.x3 = x+w; p.y3 = y+h;

p.u0 = 0; p.v0 = 0;
p.u1 = w; p.v1 = 0;
p.u2 = 0; p.v2 = h;
p.u3 = w; p.v3 = h;
DrawPrim(&p);
}

int main() {
initVideo(SCR_W, SCR_H);
printf("\ngpu/texture-flip\n");
printf("VRAM contents:\n"
"0,0 \n"
"┌--------------------------------------------------------┐\n"
"|┌--------┐ ┌--------┐ ┌---------┐ |\n"
"|| | | | | | |\n"
"|| Rect | | Rect | | texture | |\n"
"|| normal | | x-flip | | | |\n"
"|| | | | | | |\n"
"|| | | | | | |\n"
"│└--------┘ └--------┘ └---------┘ |\n"
"| |\n"
"│┌--------┐ ┌--------┐ ┌--┐ ┌--┐ |\n"
"|| | | | | r| | r| 64x64rect |\n"
"|| Rect | | Rect | └--┘ └--┘ 2nd flipped |\n"
"|| y-flip | | x&y | |\n"
"|| | | flip | ┌--┐ ┌--┐ 64x64 quad |\n"
"|| | | | | q| | q| 2nd flipped |\n"
"|└--------┘ └--------┘ └--┘ └--┘(should be the same)|\n"
"└--------------------------------------------------------┘\n"
" 1023, 1023\n\n");

clearScreenColor(0xff, 0xff, 0xff);

const int W = 256;
const int H = 256;
// Make texture
for (int i = 0; i < 0xffff; i++) {
int x = texPageX + i % W;
int y = texPageY + i / W;
vramPut(x, y, i);
}

// 0x0 - normal
setTextureFlip(0, 0);
drawRectangle(0, 0, W, H);

// 260x0 - x flipped
setTextureFlip(0, 1);
drawRectangle(260, 0, W, H);

// 260x0 - y flipped
setTextureFlip(1, 0);
drawRectangle(0, 260, W, H);

// 260x260 - x&&y flipped
setTextureFlip(1, 1);
drawRectangle(260, 260, W, H);


// 640x260 - normal (small rect)
setTextureFlip(0, 0);
drawRectangle(640, 260, 64, 64);

// 640x260 - x&&y flipped (small rect)
setTextureFlip(1, 1);
drawRectangle(714, 260, 64, 64);


// Check polygons as well, just to be sure
// 640x260 - normal (small polygon)
setTextureFlip(0, 0);
drawQuad(640, 334, 64, 64);

// 640x260 - x&&y flipped (small polygon)
setTextureFlip(1, 1);
drawQuad(714, 334, 64, 64);

printf("Done.\n");
for (;;) {
VSync(0);
}
return 0;
}
Binary file added gpu/texture-flip/vram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7adb9f0

Please sign in to comment.