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

Started by
2 comments, last by 21st Century Moose 12 years, 2 months ago
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.


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();



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???
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);



Thanks in advance for a little help.
Advertisement
My first question would be; why do you want to?

If you have filled the buffer already you should have the data laying around after all...
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?
It's advisable to keep them in memory anyway - or to at least have some way of recreating them (such as loading them from a model) - as you're going to need them if you get a lost device.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement