I need to get some things straight I guess. Today I have been busy porting my 2D GFX functions to use the GU instead of writing directly to VRAM (and use a doublebuffer technique). as example I took the "blit" demo from the PSPSDK samples directory. This one renders a flat 480x272 texture to the screen. I got this all nicely working, only there was one downside, the animation of my stuff wasn't 100% smooth. Someone suggested I might needed to flush the caches using sceKernelDcacheWritebackAll(); But this didn't change a thing..
Then I read on this forum about texture swizzling. I enabled swizzling in sceGuTexMode(); and took the example function from [here] (thanks chp). Now comes my actual problem, I don't know how to use this function properly. it requires a input and output pointer which are chars. My texture is in raw 16bit format..
My code looks (shortened) like this:
Code: Select all
static unsigned short __attribute__((aligned(16))) pixels[512*272]; // display buffer
static unsigned int __attribute__((aligned(16))) list[262144];
// Setup GU
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_5551,(void*)0,512);
sceGuDispBuffer(480,272,(void*)0x88000,512);
sceGuDepthBuffer((void*)0x110000,512);
sceGuOffset(2048 - (480/2),2048 - (272/2));
sceGuViewport(2048,2048,480,272);
sceGuDepthRange(0xc350,0x2710);
sceGuScissor(0,0,480,272);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFrontFace(GU_CW);
sceGuEnable(GU_TEXTURE_2D);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(1);
struct Vertex* vertices;
unsigned short *texture;
texture = malloc(sizeof(pixels));
// swizzle texture
swizzle(texture, &pixels, 480*2, 272); // pixel width = 2 bytes, so x2
sceGuStart(GU_DIRECT,list);
// setup the source buffer as a 512x512 texture, but only copy 480x272
sceGuTexMode(GU_PSM_5551,0,0,GU_TRUE);
sceGuTexImage(0,512,512,512,texture);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
sceGuTexFilter(GU_NEAREST,GU_NEAREST);
sceGuTexScale(1.0f/512.0f,1.0f/512.0f); // scale UVs to 0..1
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
for (j = 0; j < 480; j = j+SLICE_SIZE) {
vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
vertices[0].u = j; vertices[0].v = 0;
vertices[0].color = 0;
vertices[0].x = j; vertices[0].y = 0; vertices[0].z = 0;
vertices[1].u = j+SLICE_SIZE; vertices[1].v = 272;
vertices[1].color = 0;
vertices[1].x = j+SLICE_SIZE; vertices[1].y = 272; vertices[1].z = 0;
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5551|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
}
sceGuFinish();
sceGuSync(0,0);
Any help would be highly appreciated!