Page 1 of 1
Question about KOS PVR sprites on Dreamcast
Posted: Sun May 26, 2013 9:08 am
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?
Re: Question about KOS PVR sprites on Dreamcast
Posted: Sun May 26, 2013 11:10 am
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.
Re: Question about KOS PVR sprites on Dreamcast
Posted: Sun May 26, 2013 11:28 am
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));
}
Re: Question about KOS PVR sprites on Dreamcast
Posted: Sun May 26, 2013 11:44 am
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.
Re: Question about KOS PVR sprites on Dreamcast
Posted: Sun May 26, 2013 2:20 pm
by Light-Dark
Thank you sir! You have helped me greatly today :D!