Last active
December 23, 2015 02:09
-
-
Save unknownbrackets/6565511 to your computer and use it in GitHub Desktop.
partial stencil test (messy)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <common.h> | |
#include <pspdisplay.h> | |
#include <pspgu.h> | |
#include <pspgum.h> | |
#include <common.h> | |
#include <pspkernel.h> | |
#include "commands.h" | |
u8 *fbp0 = 0; | |
u8 *dbp0 = fbp0 + 512 * 272 * sizeof(u32); | |
unsigned int __attribute__((aligned(16))) list[262144]; | |
typedef struct { | |
u32 color; | |
u16 x, y, z; | |
} VertexColor; | |
__attribute__((aligned(16))) VertexColor vertices[256]; | |
inline VertexColor makeVertex(u32 c, u16 x, u16 y, u16 z) { | |
VertexColor v; | |
v.color = c; | |
v.x = x; | |
v.y = y; | |
v.z = z; | |
return v; | |
} | |
void displayBuffer(const char *reason) { | |
unsigned int *fb = (unsigned int *)sceGeEdramGetAddr(); | |
unsigned short *db = (unsigned short *)((u8 *)sceGeEdramGetAddr() + (intptr_t)dbp0); | |
checkpoint("%s: COLOR= %08x %08x %08x %08x", reason, fb[0], fb[1], fb[2], fb[3]); | |
checkpoint("%s: DEPTH= %04x %04x %04x %04x", reason, db[0], db[1], db[2], db[3]); | |
} | |
void testStencilClear() { | |
sceGuStart(GU_DIRECT, list); | |
sceGuClearColor(0xCCCCCC); | |
sceGuClearStencil(0xCC); | |
sceGuClearDepth(0xCCCC); | |
sceGuClear(GU_COLOR_BUFFER_BIT | GU_STENCIL_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); | |
sceGuFinish(); | |
sceKernelDcacheWritebackInvalidateAll(); | |
sceGuSync(GU_SYNC_WAIT, GU_SYNC_WHAT_DONE); | |
sceGuSync(0, 0); | |
displayBuffer("Stencil cleared"); | |
sceGuStart(GU_DIRECT, list); | |
sceGuDisable(GU_STENCIL_TEST); | |
sceGuDisable(GU_DEPTH_TEST); | |
sceGuClearColor(0xBBBBBB); | |
sceGuClearStencil(0xBB); | |
sceGuClearDepth(0xBBBB); | |
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); | |
sceGuFinish(); | |
sceKernelDcacheWritebackInvalidateAll(); | |
sceGuSync(GU_SYNC_WAIT, GU_SYNC_WHAT_DONE); | |
sceGuSync(0, 0); | |
displayBuffer("Color/depth cleared, no stencil test"); | |
sceGuStart(GU_DIRECT, list); | |
sceGuStencilFunc(GU_ALWAYS, 0, 0); | |
sceGuStencilOp(GU_INCR, GU_DECR, GU_ZERO); | |
sceGuEnable(GU_STENCIL_TEST); | |
sceGuDisable(GU_DEPTH_TEST); | |
sceGuClearColor(0xAAAAAA); | |
sceGuClearStencil(0xAA); | |
sceGuClearDepth(0xAAAA); | |
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); | |
sceGuFinish(); | |
sceKernelDcacheWritebackInvalidateAll(); | |
sceGuSync(GU_SYNC_WAIT, GU_SYNC_WHAT_DONE); | |
sceGuSync(0, 0); | |
displayBuffer("Color/depth cleared, with stencil test"); | |
sceGuStart(GU_DIRECT, list); | |
sceGuStencilFunc(GU_ALWAYS, 0, 0); | |
sceGuStencilOp(GU_INCR, GU_DECR, GU_ZERO); | |
sceGuEnable(GU_STENCIL_TEST); | |
sceGuDepthOffset(0); | |
sceGuDepthMask(GU_FALSE); | |
sceGuDepthFunc(GU_ALWAYS); | |
sceGuEnable(GU_DEPTH_TEST); | |
sceGuClearColor(0x999999); | |
sceGuClearStencil(0x99); | |
sceGuClearDepth(0x9999); | |
sceGuClear(GU_COLOR_BUFFER_BIT | GU_STENCIL_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); | |
sceGuFinish(); | |
sceKernelDcacheWritebackInvalidateAll(); | |
sceGuSync(GU_SYNC_WAIT, GU_SYNC_WHAT_DONE); | |
sceGuSync(0, 0); | |
displayBuffer("Stencil cleared, with depth and stencil test"); | |
} | |
void testStencilOp() { | |
sceGuStart(GU_DIRECT, list); | |
sceGuStencilFunc(GU_NEVER, 0, 0); | |
sceGuStencilOp(GU_INCR, GU_DECR, GU_ZERO); | |
//sceGuEnable(GU_STENCIL_TEST); | |
sceGuDisable(GU_STENCIL_TEST); | |
sceGuDepthOffset(0); | |
sceGuDepthMask(GU_FALSE); | |
sceGuDepthFunc(GU_ALWAYS); | |
//sceGuEnable(GU_DEPTH_TEST); | |
sceGuDisable(GU_DEPTH_TEST); | |
int i = 0; | |
vertices[i++] = makeVertex(0xFFFFFF00, 0, 0, 0); | |
vertices[i++] = makeVertex(0xFFFFFF00, 400, 200, 1); | |
sceGuColor(0xFFFFFF00); | |
sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, vertices); | |
sceGuFinish(); | |
sceKernelDcacheWritebackInvalidateAll(); | |
sceGuSync(GU_SYNC_WAIT, GU_SYNC_WHAT_DONE); | |
sceGuSync(0, 0); | |
displayBuffer("Stencil test attempt"); | |
} | |
void init() { | |
sceGuInit(); | |
sceGuStart(GU_DIRECT, list); | |
sceGuDrawBuffer(GU_PSM_8888, fbp0, 512); | |
sceGuDispBuffer(480, 272, fbp0, 512); | |
sceGuDepthBuffer(dbp0, 512); | |
sceGuDepthRange(65535, 0); | |
sceGuScissor(0, 0, 480, 272); | |
sceGuEnable(GU_SCISSOR_TEST); | |
sceGuFinish(); | |
sceGuSync(0, 0); | |
sceDisplayWaitVblankStart(); | |
sceGuDisplay(1); | |
memset(sceGeEdramGetAddr(), 0x11, 512 * 272 * sizeof(u32)); | |
memset(((u8 *)sceGeEdramGetAddr() + (intptr_t)dbp0), 0x11, 512 * 272 * sizeof(u16)); | |
displayBuffer("Initial"); | |
} | |
extern "C" int main(int argc, char *argv[]) { | |
init(); | |
checkpoint("framebuf: %08x", sceDisplaySetFrameBuf(sceGeEdramGetAddr(), 512, 3, PSP_DISPLAY_SETBUF_IMMEDIATE)); | |
checkpoint("dispmode: %08x", sceDisplaySetMode(0, 480, 272)); | |
testStencilClear(); | |
testStencilOp(); | |
for (int i = 0; i < 300; i++) { | |
sceDisplayWaitVblankStart(); | |
} | |
sceGuTerm(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment