Jump to content
  • Advertisement
Sign in to follow this  
GENTS

Vertex DECLARATION & FVF errors

This topic is 5060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!?

Share this post


Link to post
Share on other sites
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 ^__^

Share this post


Link to post
Share on other sites
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?!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ^__^

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
I've tried your solution but it still doesn't works...

Now my new code looks like this:

Declarations:

// Vertex shader declaration
D3DVERTEXELEMENT9 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;
};

// Structures
struct 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

Share this post


Link to post
Share on other sites

This topic is 5060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!