Sign in to follow this  
anders211

How to access the vertex and indices buffer data in graphic memory card?

Recommended Posts

I have in CreateVertexBuffer flag D3DUSAGE_DYNAMIC and D3DPOOL_DEFAULT.
I have in Lock method of vertex and index buffer flag D3DLOCK_DISCARD.
The effect is that at the scene I have the rendered figure which I want.

But I don't know how can I access back again the vertex buffer and index buffer data?
I thought that I can do it with the aid of once again Lock method but with flag D3DLOCK_READONLY.


[i]vector<NormalVertex2> verts(numVertices);
vb->Lock(0, numVertices*sizeof(NormalVertex2), (void**)&verts, D3DLOCK_READONLY);
vb->Unlock();

vector<WORD> indices(numTriangles*3);
ib->Lock(0, numTriangles*3*sizeof(WORD), (void**)&indices, D3DLOCK_READONLY);
ib->Unlock();[/i]


But the effect is that verts has all the same some amazing big values and indices vector consists of all zeros.
So how can I access the vertices and indexed buffer once again?

For example for texture I can access data properly with D3DLOCKED_RECT and LockRect method and it works great. Is there something equivalent for vertex and index buffer???
[i]vector<DWORD> textureData(numCellsPerCol*numCellsPerRow);
D3DLOCKED_RECT lockedRect;
pTex->LockRect(0, &lockedRect, 0, D3DLOCK_READONLY);
DWORD* imageData = (DWORD*)lockedRect.pBits;
for(i32 i=0; i<numCellsPerCol; i++)
for(i32 j=0; j<numCellsPerRow; j++)
textureData[i*numCellsPerRow +j] = imageData[i * lockedRect.Pitch/4+j];
pTex->UnlockRect(0);[/i]


Thanks in advance for a little help.

Share this post


Link to post
Share on other sites
Frankly speaking I have been learning DirectX since about quite not so long and there are matters which I am not sure. I want it because the question is:
Is a good way to keep saved data also in memory (RAM I suppose) or there is no need to keep data on the memory because You have a possibility to get them from vertex (index) buffer which You used to save data in graphic memory card... I believe that if You don't change very often position of vertices in this part of message loop which is responsible for present the scene, the best way is not to save data twice (on RAM memory and graphic memory card). Nevertheless I would like to get to know is there any way to get back data from vertex (index) buffer like in IDirect3DTexture9 object example from the previous e-mail?

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