Here is my original code that writes to vram for my game:
Code: Select all
int video_copy_screen(s_screen* src)
{
char *sp;
Color *dp;
int width, height;
// Determine width and height
width = screen_w;
if(width > src->width) width = src->width;
height = screen_h;
if(height > src->height) height = src->height;
if(!width || !height) return 0;
// Copy to linear video ram
sp = src->data;
dp = getVramDisplayBuffer()+((SCREEN_WIDTH-screen_w)/2)+((SCREEN_HEIGHT-screen_h)/2)*LINESIZE;
do{
int x;
for(x=0;x<width;x++) {
dp[x] = palette[((int)(sp[x])) & 0xFF];
}
sp += src->width;
dp += SCREEN_PITCH;
}while(--height);
if(pspFpsEnabled) getFPS();
return 1;
}
Code: Select all
int video_copy_screen(s_screen* src)
{
char *sp;
Color *dp;
int width, height;
Image* image = (Image*) malloc(sizeof(Image));
if (!image) return 0;
// Determine width and height
width = screen_w;
if(width > src->width) width = src->width;
height = screen_h;
if(height > src->height) height = src->height;
if(!width || !height) return 0;
image->imageWidth = width;
image->imageHeight = height;
image->textureWidth = getNextPower2(width);
image->textureHeight = getNextPower2(height);
image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
if (!image->data) return 0;
memset(image->data, 0, image->textureWidth * image->textureHeight * sizeof(Color));
sp = src->data;
dp = image->data + ((SCREEN_WIDTH-screen_w)/2)+((SCREEN_HEIGHT-screen_h)/2) * image->textureWidth;
do{
int x;
for(x=0;x<width;x++) {
dp[x] = palette[sp[x]];
}
sp += src->width;
dp += image->textureWidth;
}while(--height);
if(pspFpsEnabled) getFPS();
blitImageToScreen(0, 0, 480, 272, image, 0, 0);
flipScreen();
freeImage(image);
return 1;
}
Can some guide me in properly using the GU to get better performance than the original code.
blitImageToScreen, getNextPower2, flipScreen and freeImage is based on graphics.c from luaplayer.
s_screen is a struct that contains two ints for width and height and char array for the data.