Question about KOS PVR sprites on Dreamcast

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Question about KOS PVR sprites on Dreamcast

Post by Light-Dark »

I'm just wondering, what is the difference between using a polygon or using a sprite in PVR? how would I go about using PVR sprites, is there any examples?
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Question about KOS PVR sprites on Dreamcast

Post by Falco Girgis »

This topic is poorly named. I almost didn't check it out, because I have never used a KOS sprite... We wrote our own driver for this, because KOS originally didn't support them. I know KOS 2.0.0 supports this, but I have no idea how to use it.
Light-Dark wrote:I'm just wondering, what is the difference between using a polygon or using a sprite in PVR?
A "polygon" on the PVR is a triangle strip. In order to render a quadrilateral with a triangle strip, you must use 4 vertices (two triangles). Each vertex is a 32-bit structure containing x, y, z coordinates; a, r, g, b color data; u, v coordinates; and a PVR vertex command.

The "sprite" is actually an optimized hardware sprite structure supported by the PVR. Rather than submitting four 32-bit vertices to render a single sprite, you submit a single 64-bit vertex, and the hardware is able to extrapolate the rest of the data. The biggest key differences in the data structure is that there is no floating point z coordinate for the fourth vertex and the color of the sprite is submitted in the header (rather than individually for each vertex).

This means that you must resubmit a polygon header to change colors, and that the hardware sprites must be colored uniformly (no gourad shading). However, you are submitting half of the amount of data to the PVR using this method, so you should be able to get higher throughput.
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: Question about KOS PVR sprites on Dreamcast

Post by Light-Dark »

Thank you, and to draw a sprite would it be along the lines of this?

Code: Select all

void Draw_Tr_Sprite(const float x,const float y,const float z,const float w,const float h,const Color4 &clr)
{
	pvr_sprite_cxt_t cxt;
	pvr_sprite_hdr_t hdr;
	hdr.argb = PVR_PACK_COLOR(clr.a,clr.r,clr.g,clr.b);
	hdr.oargb = 0;
	pvr_sprite_col_t spr;

	pvr_sprite_cxt_col(&cxt,PVR_LIST_TR_POLY);
	pvr_sprite_compile(&hdr,&cxt);
	pvr_prim(&hdr,sizeof(hdr));

	spr.ax = x;
	spr.ay = y;
	spr.az = z;

	spr.bx = x+w;
	spr.by = y;
	spr.bz = z;

	spr.cx = x;
	spr.cy = y+h;
	spr.cz = z;

	spr.dx = x+w;
	spr.dy = y+h;
	spr.dz = z;

	pvr_prim(&spr,sizeof(spr));

}

<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Re: Question about KOS PVR sprites on Dreamcast

Post by Tvspelsfreak »

You may have to set the color after pvr_sprite_compile. I'm not sure if it overwrites the argb/oargb fields.
Also, since sprites are essentially quads, you'll have to set the coordinates in clockwise (or counter-clockwise if you've changed the cull setting) order, not in a 'Z' order like it's done with a triangle strip.
And there is no dz field. All sprites are planar, so "dz" is automatically calculated by the PVR.

You can't submit a color in the header and expect your sprites to be colored unless you have a VERY recent version of KOS though. There's a bug where the wrong texture env is used for sprites. See my response in this thread.

EDIT: That last remark only applies to textured sprites though.
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: Question about KOS PVR sprites on Dreamcast

Post by Light-Dark »

Thank you sir! You have helped me greatly today :D!
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
Post Reply