The blit sample

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

The blit sample

Post by sigutis »

I have a question about this function in the blit example.

Code: Select all

void advancedBlit(int sx, int sy, int sw, int sh, int dx, int dy, int slice)
{
	int start, end;

	// blit maximizing the use of the texture-cache

	for &#40;start = sx, end = sx+sw; start < end; start += slice, dx += slice&#41;
	&#123;
		struct Vertex* vertices = &#40;struct Vertex*&#41;sceGuGetMemory&#40;2 * sizeof&#40;struct Vertex&#41;&#41;;
		int width = &#40;start + slice&#41; < end ? slice &#58; end-start;

		vertices&#91;0&#93;.u = start; vertices&#91;0&#93;.v = sy;
		vertices&#91;0&#93;.color = 0;
		vertices&#91;0&#93;.x = dx; vertices&#91;0&#93;.y = dy; vertices&#91;0&#93;.z = 0;

		vertices&#91;1&#93;.u = start + width; vertices&#91;1&#93;.v = sy + sh;
		vertices&#91;1&#93;.color = 0;
		vertices&#91;1&#93;.x = dx + width; vertices&#91;1&#93;.y = dy + sh; vertices&#91;1&#93;.z = 0;

		sceGuDrawArray&#40;GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_4444|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices&#41;;
	&#125;
&#125;
What is the role of the variable

Code: Select all

slice
here?

And should I create vertices for all of my objects and use sceGuDrawArray 1 time or can I just call this function many times? What would be the perfomance impact?

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

Post by Torch »

Its drawing an array of pixels with the GU at once. i.e. one vertical line at a time. Slice is the current vertical line its drawing from your source image.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Not quite. It's more than one vertical line. It's because the texture cache inside the GU is limited. Depending on the pixel format, the cache will only hold from 128x128 for 16 color LUT mode to 32x64 for 32 bit ARGB. If you try to draw wider than what fits in the cache, the GU will stall while the cache reloads, and since that would happen on every line, your rendering speed would plummet. So you only make it "slice" wide so that all the lines fit in the cache for much faster rendering speed. Slice has been chosen for 32 bit modes, but you can change that if you use different pixel formats. I do in Basilisk 2. Just seach ps2dev for texture cache for a more complete explanation as well as the exact size that fits in the cache.
Post Reply