Sign in to follow this  
Beco

ProcessVertices()

Recommended Posts

Beco    162
Hello! Could somebody give me a great tutorial on ProcessVertices()? I can't get it work correctly. I've been searching for a long time but I can't find any useable. Thx

Share this post


Link to post
Share on other sites
don    431
What isn't working for you? It's pretty straightforward. It will only work with software vertex processing though.

Share this post


Link to post
Share on other sites
Beco    162
Does this mean that I have to create my device with D3DCREATE_SOFTWARE_VERTEXPROCESSING flag? Here is the problematic part of a sample code.



// Creating D3D device
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice );

// ...

// Rendering part

LPDIRECT3DVERTEXBUFFER9 pVB = NULL;

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

g_pd3dDevice->BeginScene();

g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );

setShaderConstants();

g_pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration );
g_pd3dDevice->SetVertexShader( g_pVertexShader );

g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );

int nVertices = 4;

// Begin process vertices
g_pd3dDevice->CreateVertexBuffer( nVertices * 16, D3DUSAGE_SOFTWAREPROCESSING, D3DFVF_XYZRHW, D3DPOOL_DEFAULT, &pVB, NULL );

g_pd3dDevice->ProcessVertices( 0, 0, nVertices, pVB, g_pVertexDeclaration, D3DPV_DONOTCOPYDATA);

VOID* pVertices;
if( FAILED( pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
return;
pVB->Unlock();
// End process vertices

g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );



I know that it makes no sense in this way, it's only a test program so if I can get it work and understand it I can port it to my code. Running this code processvertices causes an unhandled exception error. In another test apllication it didn't crash but I can't get back anything.
I'm new in shaders and a little bit confused in many points, mainly in creating the destination vertex buffer and the parameters of ProcessVertices(). I'm also not sure that setting stream source and shader is correct in this way.

Thx help

Share this post


Link to post
Share on other sites
don    431
The sample code that you posted is so messed up I don't know where to start to help you.

You could start by doing the sensible thing and added error checking to test the return value from each of the D3D API calls that you're making. If all of the calls are succeeding and you're still getting an exception in ProcessVertices, then run your app under the debug version of the D3D runtime and crank up the error reporting through the DirectX Control Panel applet.

If you still need help after doing these things, simplify your sample code to nothing more than creating a source VB containing only vertex position data (D3DFVF_XYZ) and an output buffer containing only transformed position data (D3DFVF_XYZRHW) and then go from there.

I've used ProcessVertices a lot over the years, but only with the fixed function pipeline.


Share this post


Link to post
Share on other sites
Beco    162
Yes, the code is messed up a bit because it makes no sense in this way. Maybe it is because I didn't tell anything about my program. I'm creating a D3D analyser application and I want to get the transformed screen coordinates of an arbitrary program. So my purpose is to catch the content of the vertex buffers and
transform them "manually". I already have everything except those transformed by shaders and I have heard that I can do it with processvertices. I don't want to
render anything from the output buffer I only want to read them out. The problem is that I still don't know how.

It's true that the code I made above is a big mess. It was only a sample for me to get to know how this function works. Here is antoher one, I hope it's a little bit cleaner. The most problematic parts are the parameters of Processvertices() and CreateVertexbuffer for the destination buffer. I'm also not sure that the output vertex declaration is correct.


struct Vertex
{
float x, y, z;
DWORD color;
};

#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE )

Vertex g_quadVertices[] =
{
{ -1.0f,-1.0f, 0.0f, 0xffffff00, },
{ 1.0f,-1.0f, 0.0f, 0xff00ff00, },
{ 1.0f, 1.0f, 0.0f, 0xffff0000, },
{ -1.0f, 1.0f, 0.0f, 0xff0000ff, }
};

// Creating device
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice );

//...
// Initializing source vertex buffer and fill it with data
g_pd3dDevice->CreateVertexBuffer( 4*sizeof(Vertex), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL );
void *pVertices = NULL;

g_pVertexBuffer->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0 );
memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices) );
g_pVertexBuffer->Unlock();

// Initializing destination vertex buffer
g_pd3dDevice->CreateVertexBuffer( 4 * 16, D3DUSAGE_SOFTWAREPROCESSING, D3DFVF_XYZRHW, D3DPOOL_DEFAULT, &g_pDestBuffer, NULL);

//...
// Initializing source vertex declaration
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};

g_pd3dDevice->CreateVertexDeclaration( decl,
&g_pVertexDeclaration );

// Initializing destination vertex declaration
D3DVERTEXELEMENT9 declDest[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 },
D3DDECL_END()
};

g_pd3dDevice->CreateVertexDeclaration( declDest,
&g_pDestDeclaration );

// ...
// Transorm vertices

g_pd3dDevice->SetVertexDeclaration(
g_pVertexDeclaration );
g_pd3dDevice->SetVertexShader( g_pVertexShader );

g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );

g_pd3dDevice->ProcessVertices( 0, 0, 4,
g_pDestBuffer, g_pDestDeclaration, 0);

VOID* pVertices;
VOID* pData= new BYTE[100];
if( FAILED( g_pDestBuffer->Lock( 0, 0,
(void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy(pData, pVertices, 80);
g_pDestBuffer->Unlock();



If I leave the
g_pd3dDevice->SetVertexDeclaration(g_pVertexDeclaration );
line the program doesn't crash, but pData is full with 0. Otherwise processvertices causes an unhandled exception error.

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