Check contents of a Vertex Buffer

Started by
26 comments, last by AussieSpoon 11 years, 3 months ago

Hello,

I am tringing to make a 2D sprite engine that uses a dynamic Vertex Buffer, but I can't tell if the way I'm adding vertex data to is is working. So I was wondering if there is any way I can use the Visual Studio 2010 debugger to find the value of each vetex in the Vertex buffer (to see if its being stored correctly)?

Just in case here is how I'm creating it:



//Called once during initialization 
if(FAILED( g_pd3dDevice->CreateVertexBuffer( s_nBatchSize * 4 * sizeof( SpriteVertex ), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
D3DFVF_SPRITEVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )

Here is how I'm putting data into it every frame:

SpriteVertex* pVertex;
		m_pVB->Lock(nRenderOffset, nSpritesToLock*4, (void**)&pVertex, 0);

//Use these variables to set the 4 verticies for each sprite (quad)
			//Set vertex 1
			pVertex->vPos = D3DXVECTOR3(vPos.x - 0.5f, vPos.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMin();
			pVertex->v1 = pTexture->GetTextureVMin();
			pVertex++;
			//Set vertex 2
			pVertex->vPos = D3DXVECTOR3(vPos.x+vSize.x - 0.5f, vPos.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMax();
			pVertex->v1 = pTexture->GetTextureVMin();
			pVertex++;
			//Set vertex 3
			pVertex->vPos = D3DXVECTOR3(vPos.x - 0.5f, vPos.y+vSize.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMin();
			pVertex->v1 = pTexture->GetTextureVMax();
			pVertex++;
			//Set vertex 
			pVertex->vPos = D3DXVECTOR3(vPos.x+vSize.x - 0.5f, vPos.y+vSize.y - 0.5f, fDepth);
			pVertex->Colour = tColour;
			pVertex->u1 = pTexture->GetTextureUMax();
			pVertex->v1 = pTexture->GetTextureVMax();
			pVertex++;
		}

m_pVB->Unlock();

This is using something Evil Steve posted here

Advertisement

I'm not sure of the corresponding action in the graphics debugger (you mean VS2012, right?) but in PIX you could take a frame snapshot, and then go back through and analyze the contents of any resource that was used during that frame. I think this should also be possible in the new version - but to be honest I haven't had a chance to use the new version yet...

Are you seeing behavior that makes you think it isn't working correctly? You should be able to build some test code and see if the corresponding rendered output is correct given a specific input pattern. Sometimes that is the best way I can find to test out my graphics related code.

[quote name='Jason Z' timestamp='1358130572' post='5021254']
Are you seeing behavior that makes you think it isn't working correctly?
[/quote]

Well all the values are what they should be, but I'm just having trouble finding what part of the process isn't working. Nothing draws to the screen when I call drawIndexedPrimitive but the code is too big to put up here (I think)

The only way I have used VB's previously was by creating an array then using memcpy(); but I don't see how I can create an array out of the for loop I had above?

Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

This, plus are there other 'normal' draw calls that are working properly? Or are none of them working as you expected?

If nothing draws make a PIX capture.
Find your drawcall for the sprite buffer then look at the mesh tab
In the mesh tab select the post VS tab and check whether the values there valid.
Also in the views above these tabs you can see what the vertex buffer looks like pre VS, post VS and what's in the viewport.

If stuff isn't showing up in the viewport then most likely one of your transforms or camera position is wrong or like mentioned above one of your renderderstates.
Also by clicking on one of the vertex numbers in the list you can debug the vertex or geometry shader associated with this draw call.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Put up a screenshot of all the PIX state values at the time of rendering.
Check the obvious: Is your viewport correct? Are your near/far planes correct? Is your culling correct? Is your depth negative when it should be positive or vice-versa? Is your world-view-project matrix orthogonal and correct? Is it of the correct handedness?

Post a PIX screenshot or 2 containing all of these values at the time of render.


L. Spiro

I've never used PIX, I have the SDK but have no idea how to use it? Do you mind explaining?

Yeah I havn't really touched the matrices, Stupid as this sounds I am just using the SetupMatracis(); from one of the SDK Tutorials, So it might be this.

How do I ensure the world view projection Matrix is Orthogonal and the correct handedness?

Currently I just have:


    D3DXMATRIXA16 matWorld;
    D3DXMatrixIdentity( &matWorld );
    D3DXMatrixRotationX( &matWorld, timeGetTime() / 1000.0f );
    g_pd3dDevice->SetTransform( D3DTS_WORLD,  &matWorld );

    D3DXVECTOR3 vEyePt( 0.0f, 0.0f, -70.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 800.0f / 600.0f, 1.0f, 100.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

All my depths are 0 (by default) , is this a problem?

I have :


g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

So I think it might be my matrices, so how do I ensure the world view projection Matrix is Orthogonal and the correct handedness?

Thanks

I've never used PIX, I have the SDK but have no idea how to use it? Do you mind explaining?
I just did: http://www.gamedev.net/topic/637219-particles-engine-and-slow-fps/#entry5021364

Also, your call to D3DXMatrixRotationX() is incorrect. It should be D3DXMatrixRotationZ().
Also your matrix is not orthogonal. Replace D3DXMatrixPerspectiveFovLH() with D3DXMatrixOrthoLH() or D3DXMatrixOrthoOffCenterLH().


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

See below

Running under Microsoft® Visual Studio® causes the working directory to be changed to that of the project. For now you should just manually override that via SetCurrentDirectory() at run-time so that the directories will be the same regardless of from where you start the application.

Since you didn’t actually step into Frame 150 or Frame 67 there is no information contained in either of your screen shots. Fix the resource problem first and try again—this time actually go to a render call.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement