Vertex DECLARATION & FVF errors

Started by
9 comments, last by Muhammad Haggag 19 years, 3 months ago
Hi friends... I've a strange error with this declaration: // Vertex shader declaration D3DVERTEXELEMENT9 g_FlameMeshDecl[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 }, { 0, 44, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 }, { 0, 60, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() }; The error I get out while debugging is: Direct3D9: Decl Validator: X281: (Element Error) (Decl Element [0]) Usage field contains value that is not a member of D3DDECLUSAGE. Value: 0x48. Aborting decl validation. Direct3D9: (ERROR) :Failed to create vertex declaration My vertex shader requires this type of vertex: // Structures struct appdata { float3 Position : POSITION; float4 UV : TEXCOORD0; float4 Tangent : TANGENT0; float4 Binormal : BINORMAL0; float4 Normal : NORMAL; }; Where am I wrong?! Do you understand where is the bug?! To know more info, take a look to this post... Thanks for help... [Edited by - GENTS on January 7, 2005 9:47:50 AM]
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Advertisement
Considering D3DDECLUSAGE has a hex value of 0, and non of those feilds has a hex value of 0x48, you must be corrupting memory somehow.

How are you actually creating your vertex decl object?
EvilDecl81
I do that:

LPD3DXBUFFER pBufferErrors = NULL;

if( FAILED( D3DXCreateEffectFromFile( g_pD3DDevice, PathFlameEffect,
NULL, // CONST D3DXMACRO* pDefines,
NULL, // LPD3DXINCLUDE pInclude,
dwShaderFlags, NULL, &g_pEffect, &pBufferErrors ))){
OutputDebugString( "Errore nel caricamento del file Flame.fx\n" );
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error", MB_OK|MB_ICONEXCLAMATION);
}

g_pEffect->GetVertexShader( "VertexShader", &g_FlameVS );

g_pD3DDevice->CreateVertexDeclaration( (D3DVERTEXELEMENT9*)fv, &g_FlameDecl );

But it fails...
Where is the bug!?
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Probably I miss some function like ID3DXEffectCompiler::CompileShader()?!
How should I compile my VertexShader and/or Pixel Shader function of my effect file and where is the bug in my vertex declaration?!

Thanks ^__^

----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Following other instructions I receive other errors:

Direct3D9: Decl Validator: X281: (Element Error) (Decl Element [0]) Usage field contains value that is not a member of D3DDECLUSAGE. Value: 0x48. Aborting decl validation.
Direct3D9: (ERROR) :Failed to create vertex declaration

Direct3D9: (WARN) :SetVertexDeclaration: NULL declaration pointer

Direct3D9: (ERROR) :Vertex shader declaration is not set

First-chance exception at 0x7c81eb33 in D3D_02.exe: Microsoft C++ exception: long @ 0x0012f914.
Direct3D9: (ERROR) :DrawPrimitive failed.


my code now is:

// Initialize vertices for rendering a quad
FLAMEVERT fv[] =
{
// pX pY pZ |---tex---|tX tY tZ tW bX bY bZ bW nX nY nZ nW
{ -400, 200, -200, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -400, 0, -50, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -200, 200, -200, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -200, 0, -50, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
};

// Create a big square for rendering the stencilbuffer contents
g_pD3DDevice->CreateVertexBuffer( 4*sizeof(FLAMEVERT),
D3DUSAGE_WRITEONLY, 0,
D3DPOOL_DEFAULT, &g_FlameVB, NULL );

// lock and unlock the vertex buffer to fill it with memcpy
VOID* pVertices;
if( FAILED( g_FlameVB->Lock( 0, sizeof (fv), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, fv, sizeof (fv));
g_FlameVB->Unlock();

g_pD3DDevice->CreateVertexDeclaration( (D3DVERTEXELEMENT9*)fv, &g_FlameDecl );

Why doesn't it work?!
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
What a stupid!!!
That's an idiot error!!!

// Vertex shader declaration
D3DVERTEXELEMENT9 g_FlameMeshDecl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 2 },
{ 0, 44, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 3 },
{ 0, 60, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END()
};

// Initialize vertices for rendering a quad
FLAMEVERT fv[] =
{
// pX pY pZ |---tex---|tX tY tZ tW bX bY bZ bW nX nY nZ nW
{ -400, 200, -200, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -400, 0, -50, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -200, 200, -200, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
{ -200, 0, -50, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, },
};

// Create a big square for rendering the stencilbuffer contents
g_pD3DDevice->CreateVertexBuffer( 4*sizeof(FLAMEVERT),
D3DUSAGE_WRITEONLY, 0,
D3DPOOL_DEFAULT, &g_FlameVB, NULL );

// lock and unlock the vertex buffer to fill it with memcpy
VOID* pVertices;
if( FAILED( g_FlameVB->Lock( 0, sizeof (fv), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, fv, sizeof (fv));
g_FlameVB->Unlock();

g_pD3DDevice->CreateVertexDeclaration( g_FlameMeshDecl, &g_FlameDecl );


It's now ok...

But I receive a new error 'cause the Flame.fx effect file wants a float4 NORMAL, but Vertex Declaration usage wants a float3 normal... How to solve this error?!

Direct3D9: Decl Validator: X284: (Element Error) (Decl Element [3]) Declaration can't map to fixed function FVF because a usage+index pair (D3DDECLUSAGE_BINORMAL,3) that is not valid for fixed function appears between two vertex elements that have usage+index pairs valid for fixed function. For a vertex declaration to map to fixed function, all individual elements that are valid for fixed function must appear contiguously starting from the first element. Remaining elements at the end do not have to be valid for fixed function, as long as there are few enough that they can be aliased internally to texcoord(n), texcoord(n+1) etc. up to max. texcoord7 (thereby appearing to conform to an FVF, although the aliased values should not be used).
First-chance exception at 0x7c81eb33 in D3D_02.exe: Microsoft C++ exception: long @ 0x0012f958.
Direct3D9: (ERROR) :DrawPrimitive failed.

----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
I thinks that this is a problem with BINORMAL and due to the fact that I've undeclared any FVF...

Do you have an idea?!

How could I solve this problem?!

THANKS ^__^
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
I do like this:

// Create a big square for rendering
g_pD3DDevice->CreateVertexBuffer( 4*sizeof(FLAMEVERT),
D3DUSAGE_WRITEONLY, 0,
D3DPOOL_DEFAULT, &g_FlameVB, NULL );

and then while rendering:

g_pD3DDevice->SetFVF(0);
g_pD3DDevice->SetVertexDeclaration(g_FlameDecl);

Where g_FlameDecl and FLAMEVERT are those posted above...

I've also tried to use float3, but with no changes...
It still get out same errors...

Direct3D9: Decl Validator: X284: (Element Error) (Decl Element [3]) Declaration can't map to fixed function FVF because a usage+index pair (D3DDECLUSAGE_BINORMAL,0) that is not valid for fixed function appears between two vertex elements that have usage+index pairs valid for fixed function. For a vertex declaration to map to fixed function, all individual elements that are valid for fixed function must appear contiguously starting from the first element. Remaining elements at the end do not have to be valid for fixed function, as long as there are few enough that they can be aliased internally to texcoord(n), texcoord(n+1) etc. up to max. texcoord7 (thereby appearing to conform to an FVF, although the aliased values should not be used).
First-chance exception at 0x7c81eb33 in D3D_02.exe: Microsoft C++ exception: long @ 0x0012f958.
Direct3D9: (ERROR) :DrawPrimitive failed.

Is there a way to solve this problem?!

Thanks for help!
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
is there NO solution for this type of error?!
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
I've tried your solution but it still doesn't works...

Now my new code looks like this:

Declarations:
// Vertex shader declarationD3DVERTEXELEMENT9 g_FlameMeshDecl[] ={{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },{ 0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },{ 0, 48, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },D3DDECL_END()};IDirect3DVertexShader9      *g_FlameVS   = NULL;IDirect3DVertexDeclaration9 *g_FlameDecl = NULL;struct FLAMEVERT{    FLOAT pX, pY, pZ;	FLOAT nX, nY, nZ;    FLOAT tex1U, tex1V, tex1W;	FLOAT tX, tY, tZ;	FLOAT bX, bY, bZ;};// Structuresstruct appdata {    float3 Position	: POSITION;    float3 Normal	: NORMAL;    float3 UV		: TEXCOORD0;    float3 Tangent	: TANGENT0;    float3 Binormal	: BINORMAL0;    };


Init()
	D3DXCreateTextureFromFile(g_pD3DDevice, PathFlameTexture1 , &g_FlameTexture1 );	D3DXCreateTextureFromFile(g_pD3DDevice, PathFlameTexture2 , &g_FlameTexture2 );	g_pD3DDevice->CreateVertexDeclaration( g_FlameMeshDecl, &g_FlameDecl );	// Initialize vertices for rendering a quad	FLAMEVERT fv[] =	{		// pX    pY   pZ   nX nY nZ |--tex--|  tX tY tZ  bX bY bZ		{ -400, 200, -50,  0, 0, 1,  0, 0, 1,   0, 1, 0, 1, 0, 0,},		{ -400,   0, -50,  0, 0, 1,  1, 0, 1,   0, 1, 0, 1, 0, 0,},		{ -200, 200, -50,  0, 0, 1,  0, 1, 1,   0, 1, 0, 1, 0, 0,},		{ -200,   0, -50,  0, 0, 1,  1, 1, 1,   0, 1, 0, 1, 0, 0,},	};	// Create a big square for rendering     g_pD3DDevice->CreateVertexBuffer( 4*sizeof(FLAMEVERT),									   0, 0,                                       D3DPOOL_DEFAULT, &g_FlameVB, NULL );    // lock and unlock the vertex buffer to fill it with memcpy    VOID* pVertices;    if( FAILED( g_FlameVB->Lock( 0, sizeof (fv), (void**)&pVertices, 0 ) ) )        return E_FAIL;    memcpy( pVertices, fv, sizeof (fv));    g_FlameVB->Unlock();	dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT | D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;	if( FAILED( D3DXCreateEffectFromFile( g_pD3DDevice, PathFlameEffect, 					NULL, // CONST D3DXMACRO* pDefines,					NULL, // LPD3DXINCLUDE pInclude,					dwShaderFlags, NULL, &g_pEffect, &pBufferErrors  ))){			OutputDebugString( "Errore nel caricamento del file Flame.fx\n" );			LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();			SetError("FX Creation Error");			MessageBox(NULL, (const char*)pCompilErrors, "Fx Creation Error", MB_OK|MB_ICONEXCLAMATION);		}		if( FAILED( g_pEffect->SetFloat( "noiseFreq", 0.1f ) ))			OutputDebugString( "Impossibile assegnare noiseFreq\n" );		if( FAILED( g_pEffect->SetFloat( "noiseStrength", 1.0f ) ))			OutputDebugString( "Impossibile assegnare noiseStrength\n" );		if( FAILED( g_pEffect->SetFloat( "timeScale", 1.0f ) ))			OutputDebugString( "Impossibile assegnare timeScale\n" );		D3DXVECTOR3 noiseScale = D3DXVECTOR3(0.5, 0.5, 0.5);		D3DXVECTOR3 noiseAnim = D3DXVECTOR3(0.4, -1.9, 0.8);		if( FAILED( g_pEffect->SetValue( "noiseScale", noiseScale, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare noiseScale\n" );		if( FAILED( g_pEffect->SetValue( "noiseAnim", noiseAnim, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare noiseAnim\n" );		D3DXCOLOR flameColor = D3DXCOLOR(0.3, 0.2, 0.2, 1.0);		D3DXVECTOR3 flameScale = D3DXVECTOR3(0.25, -0.18, 0.12);		D3DXVECTOR3 flameTrans = D3DXVECTOR3(0.0, -0.1, 0.0);		if( FAILED( g_pEffect->SetValue( "flameColor", &flameColor, sizeof(D3DXCOLOR) ) ))			OutputDebugString( "Impossibile assegnare flameColor\n" );		if( FAILED( g_pEffect->SetValue( "flameScale", flameScale, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare flameScale\n" );		if( FAILED( g_pEffect->SetValue( "flameTrans", flameTrans, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare flameTrans\n" );		if( FAILED( g_pEffect->SetTexture( "noiseTexture", g_FlameTexture1 ) ))			OutputDebugString( "Impossibile assegnare noiseTexture\n" );		if( FAILED( g_pEffect->SetTexture( "flameTexture", g_FlameTexture2 ) ))			OutputDebugString( "Impossibile assegnare flameTexture\n" );


Render()
  // Begin 3D scene  g_pD3DDevice->BeginScene();    UINT cPasses=0; 		// Apply the technique contained in the effect 		if( SUCCEEDED( g_pEffect->SetTechnique("ps20") ) ){					ticks = (float)GetTickCount()/1000.0f;			g_pEffect->SetFloat( "ticks", ticks );			g_pD3DDevice->GetTransform( D3DTS_WORLD, &mWorld );			g_pD3DDevice->GetTransform( D3DTS_VIEW, &mView );			g_pD3DDevice->GetTransform( D3DTS_PROJECTION, &mProj );			mWorldViewProjection = mWorld * mView * mProj;			g_pEffect->SetMatrix( "wvp", &mWorldViewProjection );			g_pEffect->SetMatrix( "world", &mWorld );					g_pEffect->Begin(&cPasses, 0);					for (iPass = 0; iPass < cPasses; iPass++)			{					    g_pEffect->BeginPass(iPass);							    // Render the mesh with the applied technique				g_pD3DDevice->SetVertexDeclaration(g_FlameDecl);				g_pD3DDevice->SetStreamSource( 0, g_FlameVB, 0, sizeof(FLAMEVERT) );				g_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );						    g_pEffect->EndPass();			}			g_pEffect->End();		}		else			SetError("Errore nell'impostare la Technique ps20");			  // End 3D scene  g_pD3DDevice->EndScene();  


I've not anymore errors, but the effect still doesn't work... I can't see anything moving as a flame on my screen, sigh sob!!!

Is there any error?!

Thanks for replies
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -

This topic is closed to new replies.

Advertisement