Dynamic Buffers

Started by
13 comments, last by Funkymunky 22 years ago
Alright I''m getting desperate with these things. I''ve posted this question before, but noone ever replies with a solution. I need a dynamic Index buffer. Does this mean I need a dynamic vertex buffer too, even if that is going to remain the same? I can''t get this damn thing working. here is my basic code for a dynamix index buffer, which does not work. #define D3DFVF_DROVERTS (D3DFVF_XYZ | D3DFVF_DIFFUSE) struct DROVertex { D3DXVECTOR3 position; D3DCOLOR color; }; DROVertex verts[4]; IDirect3DVertexBuffer8 *vbuffer; WORD *indices; IDirect3DIndexBuffer8 *ibuffer; // fill in verts device->CreateVertexBuffer(4*sizeof(DROVertex), D3DUSAGE_SOFTWAREPROCESSING, D3DFVF_DROVERTS, D3DPOOL_DEFAULT, &vbuffer) DROVertex *pVertices; if(vbuffer->Lock(0, sizeof(verts), (BYTE**)&pVertices, 0)) for(int i=0; i<4; i++) { pVertices.position = verts.position; pVertices.color = verts.color; } vbuffer->Unlock(); indices = new WORD[4]; device->CreateIndexBuffer(4*sizeof(WORD), D3DUSAGE_WRITEONLY | D3DUSAGE_DONOTCLIP | D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer) // from here, every 2 seconds i change from 3-4 indices, and draw a triangle fan so it should switch from a triangle to a quad if you catch my drift WORD *pIndices; ibuffer->Lock(0, 3*sizeof(WORD), (BYTE**)&pIndices, D3DLOCK_NOSYSLOCK | D3DLOCK_DISCARD); for(int i=0; i<3; i++) pIndices = indices; ibuffer->Unlock(); // then come render time, I do a drawindexed primitive call, with D3DPT_TRIANGLEFAN and the # of vertices indexed and the # of triangles to draw. Doesnt work. Help?! Please?!?! </i>
Advertisement
Show the DIP code, please. The provided code looks ok so far. BTW: use the debug runtime and watch the debug spew may also help.

Bjørn.
We are boki. The rest is known.
device->BeginScene();
device->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);

device->SetStreamSource(0, vbuffer, sizeof(DROVertex));
device->SetVertexShader(D3DFVF_DROVERTS);
device->SetIndices(ibuffer, 0);
if(on)
device->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, 0, 3, 0, 1);
else
device->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, 0, 4, 0, 2);


Edited by - Funkymunky on July 28, 2001 3:22:55 PM
Hm, looks ok.

Some other thing to check (in no particular order):
- return values of the functions (test at least for D3D_OK in debug build)
- order of vertices (or current cull mode)
- colour of the vertices (not white and alpha set to 0xFF)
- type of device (e.g. software processing vbs wont be usable in hw mode)
- ensure that you know whether the locks succeed or not

Bjørn.
We are boki. The rest is known.
Perhaps being a little bit more specific than "It doesn''t work" will get you more replies!!! - **how** doesn''t it work ? - do you get a crash ?, do you get corrupt graphics ?, do you get an error code back from any calls ?

0. Make sure you''re running with the DEBUG version of the D3D runtime (you get the option when you install the SDK) and make sure you set the slider in the control panel to maximum when you have problems - It should be your first stop particularly if things "just don''t work"

1. You create the vertex buffer with a software vertex processing flag set indicating that all the t&l of that buffer will be done with the CPU... but you don''t set that for the index buffer!! - specify the same processing type for all buffers used in the same DrawPrim call.

2. You use D3DPOOL_DEFAULT which can imply VIDEO memory on a T&L device (even with software vertex processing) - Change it to system if you''re explicitly specifying software vertex processing.

3. Same goes for the DONOTCLIP flag - D3D and the drivers do extra temporary buffer creation based on that flag, particularly with software VP [The PSGP] (to store outcodes etc):
a. Only specify DONOTCLIP if you''re 100% certain every vertex falls within the screen/guardband - otherwise you''ll get artefacts.

4. You don''t need a dynamic vertex buffer with a dynamic index buffer.

5. You shouldn''t be calling DISCARD for every lock!!! - that''ll just chew up video memory - you need to use the correct combination of DISCARD and NOOVERWRITE - look at the DirectX FAQ on MSDN for the correct usage pattern.

6. Performance Note: Creating 4 vertex/index buffers is going to be pretty wasteful - group all stuff using the same format which is used around the same time into single big buffers!

7. Performance Note: Passing less than 20 polygons to a DrawPrimitive call should be considered extremely bad practice - on T&L cards, passing less than 200 per call is bad!

8. All of that assumes its not something simpler and elsewhere like transformation matrices or texture states (how hard have you checked)

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

1) Yes, I''ve been running with DEBUG runtimes. slider to max.
2) I don''t have a T&L device
3) ok. i took out DONOTCLIP
4) cool
5) I know: this is a test program because i can''t get a dynamic index buffer working. How will calling discard every time i update the buffer chew up video memory? It returns a pointer to a new memory area, clearing up the old.
6) i know, test prog
7) yes
8) i''ve checked harder than a bull on viagra

all that said, i did find a returned error. My DrawIndexedPrimitive call returns D3DERR_INVALIDCALL, which is about generic as it gets. Everything else is fine, locks, rendercalls...except me. I''m still angry as hell at Microsoft for making this such a pain in the ass. Any more suggestions?
quote:Original post by Funkymunky
all that said, i did find a returned error. My DrawIndexedPrimitive call returns D3DERR_INVALIDCALL, which is about generic as it gets. Everything else is fine, locks, rendercalls...except me. I''m still angry as hell at Microsoft for making this such a pain in the ass. Any more suggestions?

G''day!

I don''t see anything in the code that should make it fail. It could be as simple as bad test data, or your ''on'' flag could be set wrong.

I can honestly say that I''ve never seen an INVALIDCALL without something being dumped to the debug spew.



Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
hhmmm...what does "Stream 0 stride should match the stride, implied by the current vertex shader"

friends don''t let friends code while under the influence of prescription drugs. Damn i wrote this crap like a crackhead....not..that...crack....is.....prescribed......
"Stream 0 stride should match the stride, implied by the current vertex shader" means that the size of your vertex structure is not the same as the one d2d expected - even thought it seems to be...

Try to align DROVertex to 4 bytes (via pragma pack( push, 4 ) and an accompaning pragma pack( pop ) after the struct).

Bjørn.
We are boki. The rest is known.
No way i must have messed up somewhere else, i''ve never had to do that.

This topic is closed to new replies.

Advertisement