Skip to content

Commit b2db79f

Browse files
committed
Adding pixelMask example
1 parent 96b6851 commit b2db79f

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

src/samples/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SAMPLES = \
3131
gu/morph \
3232
gu/morphskin \
3333
gu/ortho \
34+
gu/pixelmask \
3435
gu/reflection \
3536
gu/rendertarget \
3637
gu/scissor \

src/samples/Makefile.samples

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ SAMPLES = \
2828
gu/morphskin \
2929
gu/mipmapping \
3030
gu/ortho \
31+
gu/pixelmask \
3132
gu/reflection \
3233
gu/rendertarget \
3334
gu/scissor \
35+
gu/pixelmask \
3436
gu/shadowprojection \
3537
gu/signals \
3638
gu/skinning \
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TARGET = pixelmask
2+
OBJS = pixelmask.o ../common/callbacks.o
3+
4+
INCDIR =
5+
CFLAGS = -Wall -O2
6+
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
7+
ASFLAGS = $(CFLAGS)
8+
9+
LIBDIR =
10+
LDFLAGS =
11+
LIBS = -lpspgu
12+
13+
EXTRA_TARGETS = EBOOT.PBP
14+
PSP_EBOOT_TITLE = PixelMask Sample
15+
16+
PSPSDK=$(shell psp-config --pspsdk-path)
17+
include $(PSPSDK)/lib/build.mak
18+
19+
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* PSP Software Development Kit - https://github.com/pspdev
3+
* -----------------------------------------------------------------------
4+
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
5+
*
6+
* PixelMask sample - Demonstrates sceGuPixelMask channel write-masking
7+
*/
8+
9+
#include <pspkernel.h>
10+
#include <pspdisplay.h>
11+
#include <pspdebug.h>
12+
#include <stdlib.h>
13+
#include <stdio.h>
14+
#include <math.h>
15+
#include <string.h>
16+
17+
#include <pspctrl.h>
18+
#include <pspgu.h>
19+
#include <psprtc.h>
20+
21+
#include "../common/callbacks.h"
22+
23+
PSP_MODULE_INFO("PixelMask Sample", 0, 1, 1);
24+
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
25+
26+
static unsigned int __attribute__((aligned(16))) list[1024];
27+
28+
#define BUF_WIDTH (512)
29+
#define SCR_WIDTH (480)
30+
#define SCR_HEIGHT (272)
31+
32+
#define COLOR_BLACK 0x00000000
33+
34+
typedef struct PixelMaskMode
35+
{
36+
const char *description;
37+
unsigned int mask;
38+
} PixelMaskMode;
39+
40+
#define TEXTURE_FORMAT GU_PSM_8888
41+
// In mask 0xAABBGGRR: 1-bits prevent writes to that bit, 0-bits allow writes.
42+
// Keep AA=0x00 so alpha writes remain enabled for all modes in this sample.
43+
static const PixelMaskMode modes[] = {
44+
{"Mask 0x00000000: All channels writable", 0x00000000},
45+
{"Mask 0x0000FFFF: Only Blue (+Alpha) writable", 0x0000FFFF}, // R=0xFF, G=0xFF, B=0x00, A=0x00
46+
{"Mask 0x00FF00FF: Only Green (+Alpha) writable", 0x00FF00FF}, // R=0xFF, G=0x00, B=0xFF, A=0x00
47+
{"Mask 0x00FFFF00: Only Red (+Alpha) writable", 0x00FFFF00}, // R=0x00, G=0xFF, B=0xFF, A=0x00
48+
};
49+
50+
// GU_PSM_8888, 8x8. Where the 2 first columns are red and the 2 last columns are green.
51+
static uint32_t __attribute__((aligned(16))) pixels[64] = {
52+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
53+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
54+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
55+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
56+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
57+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
58+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
59+
0xFF0000FF, 0xFF0000FF, 0xFF00FF00, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFF,
60+
};
61+
62+
struct Vertex
63+
{
64+
short u, v;
65+
short x, y, z;
66+
};
67+
68+
void blit()
69+
{
70+
struct Vertex *vertices = (struct Vertex *)sceGuGetMemory(2 * sizeof(struct Vertex));
71+
72+
vertices[0].u = 0;
73+
vertices[0].v = 0;
74+
vertices[0].x = 0;
75+
vertices[0].y = 0;
76+
vertices[0].z = 0;
77+
78+
vertices[1].u = 8;
79+
vertices[1].v = 8;
80+
vertices[1].x = SCR_WIDTH;
81+
vertices[1].y = SCR_HEIGHT;
82+
vertices[1].z = 0;
83+
84+
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
85+
}
86+
87+
int main(int argc, char *argv[])
88+
{
89+
int mode_index = 0;
90+
int frame_counter = 0;
91+
int drawFormat = GU_PSM_5650;
92+
93+
pspDebugScreenInit();
94+
setupCallbacks();
95+
96+
// Setup GU
97+
98+
void *fbp0 = guGetStaticVramBuffer(BUF_WIDTH, SCR_HEIGHT, drawFormat);
99+
void *fbp1 = guGetStaticVramBuffer(BUF_WIDTH, SCR_HEIGHT, drawFormat);
100+
101+
sceGuInit();
102+
103+
sceGuStart(GU_DIRECT, list);
104+
sceGuDrawBuffer(drawFormat, fbp0, BUF_WIDTH);
105+
sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, fbp1, BUF_WIDTH);
106+
sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2));
107+
sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT);
108+
sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
109+
sceGuEnable(GU_SCISSOR_TEST);
110+
sceGuEnable(GU_TEXTURE_2D);
111+
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
112+
113+
sceGuTexMode(TEXTURE_FORMAT, 0, 0, 0);
114+
sceGuTexImage(0, 8, 8, 8, pixels);
115+
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); // don't get influenced by any vertex colors
116+
sceGuTexFilter(GU_NEAREST, GU_NEAREST); // point-filtered sampling
117+
118+
sceGuFinish();
119+
sceGuSync(GU_SYNC_FINISH, GU_SYNC_WHAT_DONE);
120+
121+
sceDisplayWaitVblankStart();
122+
sceGuDisplay(GU_TRUE);
123+
124+
sceKernelDcacheWritebackAll();
125+
126+
pspDebugScreenInitEx(fbp0, drawFormat, 1);
127+
128+
while (running())
129+
{
130+
sceGuStart(GU_DIRECT, list);
131+
132+
sceGuClearColor(COLOR_BLACK);
133+
sceGuClear(GU_COLOR_BUFFER_BIT);
134+
135+
// Apply current pixel mask and draw color bars
136+
sceGuPixelMask(modes[mode_index].mask);
137+
blit();
138+
sceGuPixelMask(0);
139+
140+
sceGuFinish();
141+
sceGuSync(GU_SYNC_FINISH, GU_SYNC_WHAT_DONE);
142+
143+
// HUD text
144+
pspDebugScreenSetOffset((int)fbp0);
145+
pspDebugScreenSetXY(0, 0);
146+
pspDebugScreenPrintf("sceGuPixelMask demo\n");
147+
pspDebugScreenPrintf("%s\n", modes[mode_index].description);
148+
149+
sceDisplayWaitVblankStart();
150+
fbp0 = sceGuSwapBuffers();
151+
152+
// Rotate mode every ~2 seconds (assuming ~60 FPS)
153+
frame_counter++;
154+
if (frame_counter >= 120)
155+
{
156+
frame_counter = 0;
157+
mode_index = (mode_index + 1) % (sizeof(modes) / sizeof(modes[0]));
158+
}
159+
}
160+
161+
sceGuTerm();
162+
163+
sceKernelExitGame();
164+
return 0;
165+
}

0 commit comments

Comments
 (0)