Welcome! Log In Create A New Profile

Advanced

Vertex Attribute Table

Posted by dancinninja 
Vertex Attribute Table
November 25, 2010 10:31PM
I am having some trouble with the vertex attribute table. In the documentation (seen here) it says that you can specify different vertex attributes ahead of time and call them when you need them, like so:

GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
// Vertex Attribute 0
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
// Vertex Attribute 1
GX_SetVtxAttrFmt(GX_VTXFMT1, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT1, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);

Then in my rendering code I call it like so:

// Only colors
GX_Begin(GX_QUADS, GX_VTXFMT1, 4);
	GX_Position3f32(0, 0, 0);
	GX_Color4u8(0xff, 0x00, 0x00, 0xff);
	GX_Position3f32(1, 2, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
	GX_Position3f32(1, 1, 0);
	GX_Color4u8(0x00, 0xff, 0x00, 0xff);
	GX_Position3f32(2, 1, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
GX_End();

//...

// Colors and normals
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
	GX_Position3f32(5, 5, 0);
	GX_Normal3f32(0, 1, 0);
	GX_Color4u8(0xff, 0x00, 0x00, 0xff);
	GX_Position3f32(8, 7, 0);
	GX_Normal3f32(0, 0, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
	GX_Position3f32(7, 7, 0);
	GX_Normal3f32(1, 0, 0);
	GX_Color4u8(0x00, 0xff, 0x00, 0xff);
	GX_Position3f32(7, 8, 0);
	GX_Normal3f32(1, 1, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
GX_End();

This just hangs. If I only use one (say VTXFMT0) then it all works just peachy. What am I doing wrong?

Thanks!
Re: Vertex Attribute Table
November 25, 2010 11:08PM
You set the vertex description to pos, normal and color but vtx1 is only pos and color?? Just a guess, I'm no GX guru.

Have you tried something like



GX_ClearVtxDesc( );
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);

GX_Begin(GX_QUADS, GX_VTXFMT1, 4);
	GX_Position3f32(0, 0, 0);
	GX_Color4u8(0xff, 0x00, 0x00, 0xff);
	GX_Position3f32(1, 2, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
	GX_Position3f32(1, 1, 0);
	GX_Color4u8(0x00, 0xff, 0x00, 0xff);
	GX_Position3f32(2, 1, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
GX_End();


GX_ClearVtxDesc( );

GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);


GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
	GX_Position3f32(5, 5, 0);
	GX_Normal3f32(0, 1, 0);
	GX_Color4u8(0xff, 0x00, 0x00, 0xff);
	GX_Position3f32(8, 7, 0);
	GX_Normal3f32(0, 0, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
	GX_Position3f32(7, 7, 0);
	GX_Normal3f32(1, 0, 0);
	GX_Color4u8(0x00, 0xff, 0x00, 0xff);
	GX_Position3f32(7, 8, 0);
	GX_Normal3f32(1, 1, 0);
	GX_Color4u8(0xff, 0xff, 0xff, 0xff);
GX_End(); 

Re: Vertex Attribute Table
November 26, 2010 12:30AM
Scanff, I could kiss you. That did the trick! Thank you so much!
Re: Vertex Attribute Table
November 26, 2010 12:33AM
;) welcome ... which reminds me I need to spend sometime on desmume soon.
Re: Vertex Attribute Table
November 27, 2010 07:07PM
Couldn't you set GX_VA_NRM to GX_NONE before using VTXFMT1 and then back to GX_DIRECT when you use VTXFMT0, rather than clearing all descriptors and setting POS and CLR0 each time?
Re: Vertex Attribute Table
November 28, 2010 12:35AM
That's an interesting point you bring up. I could do that after I render stuff. I wonder what would be faster.
Re: Vertex Attribute Table
December 02, 2010 08:51AM
As tueidj said, trying to avoid clearing all vertex descriptors and setting them again is a good idea. It's good for two reasons:
-Before every draw, the GP must collapse all state-changing commands and execute them, so avoiding these commands will save you GPU time
-Sending less commands also saves you space in the command FIFO.
Sorry, only registered users may post in this forum.

Click here to login