Sign in to follow this  
janta

DrawPrimitiveUP, vertex stride and FVF

Recommended Posts

Hello GDNet, My question is very simple: Does the vertex stride passed as the last parameter of DrawPrimitiveUP have to match the size that would be computed from the FVF code passed to the SetFVF function ? I ask because I have a vertex struct with 2 texture coordinates:
struct HUDVertex
{
	float	x, y, z, w;
	uint32	uiCol;
	float	u0, v0;
	float	u1, v1;
};
but I don't always use both, and I thought that I could just be done with disabling the second texture sampler and using the appropriate FVF:
if(use2Textures)
{
    SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
    SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
else
{
    SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX2);
    /* Set sampler/stages states properly */
}
/* ... */
DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(HUDVertex));
Everything is fine with 2 textures, but when I use only one texture, then what is rendered depends on the values of u1 and v1. I expected they would just be ignored. I've tried to use D3DFVF_TEX2 but that did not fix my issue either. Explanation/Help would be much appreciated. AFAIK the directX 9 help for c++ in the latest SDK release does not adress my question. Thank you.

Share this post


Link to post
Share on other sites
Are you using the debug runtimes? Any interesting debug output? I seem to recall DrawPrimitiveUP giving a warning about the vertex stride not matching the stride computed from the FVF, and if you're not getting that it could be worthwhile double checking all the parameters.

The second set of texture coordinates should certainly be getting ignored. You could also try using a vertex declaration instead of an FVF, and see if that solves your problem.

Share this post


Link to post
Share on other sites
I think the warning was when the stride was larger than the FVF, and it was something about older drivers not being able to handle this properly. Newer cards shouldn't have any trouble. (Newer as in including shader 1.1 cards).

Specifying tex2 shouldn't hurt though. It's not going to actually sample a texture if the texture stages are disable and don't refer to TEXCOORDINDEX 1.

As you're having trouble with both these cases, I think your bug lies elsewhere.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this