PNG Images with Alpha effect slows down the script

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

PNG Images with Alpha effect slows down the script

Post by Pihas »

PNG Images with Alpha effect slows down the script i blit images after while true and use "mouse" in it. And if i blit 2 images one on other it slow down "mouse" movement
while(1)
{

...

/////////////////////////////////////////////////////////////////////////////////
if ((x < 58 && y < 58) && (pad.Buttons & PSP_CTRL_CROSS)) {
pco = 1;
}
if(pco == 1)
{
blitAlphaImageToScreen(0 ,0 , 480, 246, pc, 0, 0);
if (x > 99 && x < 276 && y > 69 && y < 120)
{
blitImageToScreen(0 ,0 , 185, 60, hover, 100, 68);
}
if (x > 276 && x < 465 && y > 69 && y < 120)
{
blitImageToScreen(0 ,0 , 185, 60, hover, 286, 68);
}
blitAlphaImageToScreen(0 ,0 , 77, 50, ms, 105, 73);
printTextScreen(185, 90, "Memory Stick", black);
blitAlphaImageToScreen(0 ,0 , 70, 57, umd, 290, 70);
printTextScreen(362, 90, "UMD", black);
if(x > 420 && x < 472 && y < 18)
{
blitAlphaImageToScreen(0 ,0 , 42, 16, close, 431, 2);
if (pad.Buttons & PSP_CTRL_CROSS)
{
pco = 0;
}
}
}
/////////////////////////////////////////////////////////////////////////////////

...

blitAlphaImageToScreen(0 ,0 , 32, 32, cursor, x, y);



sceDisplayWaitVblankStart();
flipScreen();

...

}

... - means cutted script


Something
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

An alpha blit has to read the existing pixels and perform a multiply per pixel, so it's bound to be slower than a straight blit which doesn't.

Jim
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

It looks like your using the graphics.c from LUAPlayer. This is very inefficient because each function call is a complete independent blitting process. You should learn to use the GU functions yourself.
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

Post by Pihas »

So what is the esiest way to use it without graphic.c ? :/ Becouse Gui have a lot of functions.... Or where is samples with it ? Found that some of people uses OSLib if i will use it would i have same problem?
Pihas
Posts: 53
Joined: Sat Oct 25, 2008 10:26 pm
Location: Lithuania
Contact:

Post by Pihas »

void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy)
{
if (!initialized) return;

sceKernelDcacheWritebackInvalidateAll();
guStart();
sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data);
float u = 1.0f / ((float)source->textureWidth);
float v = 1.0f / ((float)source->textureHeight);
sceGuTexScale(u, v);

int j = 0;
while (j < width) {
Vertex* vertices = (Vertex*) sceGuGetMemory(2 * sizeof(Vertex));
int sliceWidth = 64;
if (j + sliceWidth > width) sliceWidth = width - j;
vertices[0].u = sx + j;
vertices[0].v = sy;
vertices[0].x = dx + j;
vertices[0].y = dy;
vertices[0].z = 0;
vertices[1].u = sx + j + sliceWidth;
vertices[1].v = sy + height;
vertices[1].x = dx + j + sliceWidth;
vertices[1].y = dy + height;
vertices[1].z = 0;
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
j += sliceWidth;
}
sceGuFinish();
sceGuSync(0, 0);

}

I use blitAlphaImageToScreen function after while true how to optimize this :/ tried to cut sceGuSync(0, 0); sceGuFinish(); to main.c but i had the same problem :/
Post Reply