A proper way to draw

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

Moderators: cheriff, TyRaNiD

Post Reply
sigutis
Posts: 7
Joined: Sat Mar 21, 2009 6:02 pm

A proper way to draw

Post by sigutis »

I have written some code for my game. But I have a feeling that its working too slow. Could you guys comment this please?

Code: Select all

/*This is my vertex structure*/
typedef struct
{
	unsigned short u, v;
	unsigned int color;
	 short x, y, z;
	unsigned short useless; //for a 16bit struct
} Vertex;

/*In the main loop*/
/*-------------------------------------*/
guStart();
	
//clean screen
sceGuClearColor(0xff554433);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

sceKernelDcacheWritebackAll();
		sceGuTexImage(0, Alien->textureWidth, Alien->textureHeight, Alien->textureWidth, (void*) Alien->data);
		Vertex* vertices = (Vertex*)sceGuGetMemory(mobsterCount *2 * sizeof(Vertex));

/*Filling the vertex buffer*/
int mix=0,miny=0,maxx=60,maxy=60;
		for &#40;i=0,h=0;i<mobsterCount;i++,h+=2&#41;
		&#123;
			vertices&#91;h&#93;.u = minx; 
			vertices&#91;h&#93;.v = miny;
			vertices&#91;h&#93;.color = 0;
			vertices&#91;h&#93;.x = mobsters&#91;i&#93;.x;
			vertices&#91;h&#93;.y = mobsters&#91;i&#93;.y;
			vertices&#91;h&#93;.z = 0;

			vertices&#91;h+1&#93;.u = minx+maxx; 
			vertices&#91;h+1&#93;.v = miny+maxy;
			vertices&#91;h+1&#93;.color = 0;
			vertices&#91;h+1&#93;.x = mobsters&#91;i&#93;.x+maxx;
			vertices&#91;h+1&#93;.y = mobsters&#91;i&#93;.y+maxy;
			vertices&#91;h+1&#93;.z = 0;
		&#125;
sceGuDrawArray&#40;GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_8888|GU_VERTEX_16BIT|GU_TRANSFORM_2D,mobsterCount*2,0,vertices&#41;;

sceGuFinish&#40;&#41;;
sceGuSync&#40;0,0&#41;;
sceDisplayWaitVblankStart&#40;&#41;;
sceGuSwapBuffers&#40;&#41;;
This fragment draws mobsterCount number of 60x60 images. Is this a proper blitting? I am realy not satistfied with the drawing speed, but I would like to skip swizzling and cache manipulation.
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

Here are some ideas:
- Take sceKernelDcacheWritebackAll(); out of the mainloop
- Don't call sceGuTexImage if the texture didn't change since the last draw call
- Remove the color component from the vertex data, use sceGuColor or similar instead
- Cut the textures to 32x32 or use swizzling on 64x64
- Use 5551 or 5650 textures instead of 8888.
- Remove texture filtering, use GU_NEAREST
- Store your texture in vram instead of main memory
- Make sure you're not drawing something that is outside of the visible area of the screen, it looks like you're drawing the entire mobster list.
- Turn off blending
(+[__]%)
Post Reply