DX11-Reuse or Create a new Buffer?

Started by
4 comments, last by andur 14 years, 1 month ago
Hi, so I get at a point where I can render a cube, yay. Now my program loads an .OBJ file to a vposnormaltex layout struct array. I want know how I render new stuff every time I want. Should I reuse the buffer? Or should I Create a new one(using the same ID3D11Buffer)? I notice theres this HRESULT SetPrivateData( REFGUID guid, UINT DataSize, const void *pData ); that the ID3D11Buffer inherits, but Im not sure what I should do..
Advertisement
Quote:Original post by Icebone1000
Hi, so I get at a point where I can render a cube, yay. Now my program loads an .OBJ file to a vposnormaltex layout struct array.

I want know how I render new stuff every time I want. Should I reuse the buffer? Or should I Create a new one(using the same ID3D11Buffer)?

A buffer can contain any number of objects in any particular formats you want. Just as long as you have allocated enough space for it. The important thing is that you don't create buffers that are too large (a few meg is usually good), and that you properly specify their usage so that they can be placed in the best locations for them (static geometry should not be specified with dynamic/cpu read and write, for instance).
Quote:
I notice theres this
HRESULT SetPrivateData(
REFGUID guid,
UINT DataSize,
const void *pData
);
that the ID3D11Buffer inherits, but Im not sure what I should do..

That does not do what you think it does.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

The thing is that the data I want render are set at running time, my app have a open .obj menu item..Everytime a .obj file is opened I want to display the object(Im not considering yet display all .obj opened, just one by one now to make easier).

What my app do at start is set a cube, create a vertexbuffer(subresource = cube), bind it to the input assembly, and render.

What should I do when the .obj is readed?:
-Create a new dx buffer, point the vposnormaltex array, bind it to the IA?

-Re-set the dx buffer, that is alredy binded to the IA(dont know if this is how things works, I remember something like this on DX9, using 'lock' to bring GPU stuff to mem, re-set and sending back)?

Keep the array of geometry, a pointer to the vertrex buffer, the topology type and the layout together in a class or structure.

For each of these, on every frame, you just set the input type, set the vertex buffer and render everything.

Ideally, you should keep state changes to a minimum. I suppose if your input layout is always the same, you can set it once but realistically this never really happens once you get past the initial stages.

I would suggest trying whatever works for you and when you know more, take a look at the performance considerations documentation on MSDN.
Thanks for the info.

But I still dont know if theres a way to re-set an alredy created buffer or if I can recreate it every time I want change the data on it.

My program specificaly have 4 types of input layout( pos, posnorm, postex, postexnorm ), witch also means I have to recompile also another effect file.. heres the approach Im taking everytime a file is opened:

OPENFILENAME openFile = {0};...if( GetOpenFileName( &openFile ) ){std::ifstream File;File.open( openFile.lpstrFile,std::ios::in|std::ios::_Nocreate );if( File.is_open() ){							myOBJ.OBJReadDataFromFileStream( File );							myOBJ.OBJTransformDataToDXLayout();switch( myOBJ.OBJGetOBJType() ){case 0x00:if( DXInitEffect( TEXT("BasicTr.fx"), g_pEffect, g_pETech, g_pEPass, g_pDevice ) != S_OK ){MB( " dxerror", "effect load fail", MB_E );									}break;case 0xff:if( DXInitEffect( TEXT("BasicTransformLightTex.fx"), g_pEffect, g_pETech, g_pEPass, g_pDevice ) != S_OK ){MB( " dxerror", "effect load fail", MB_E );}break;case 0xf0:if( DXInitEffect( TEXT("BasicTransformLight.fx"), g_pEffect, g_pETech, g_pEPass, g_pDevice ) != S_OK ){MB( " dxerror", "effect load fail", MB_E );}break;case 0x0f:if( DXInitEffect( TEXT("BasicTransformTex.fx"), g_pEffect, g_pETech, g_pEPass, g_pDevice ) != S_OK ){MB( " dxerror", "effect load fail", MB_E );}break;}if( DXSetBufferResources(	g_pDevice, g_pVB, g_pIB, myOBJ.OBJGetDXVBData(), myOBJ.OBJGetDXVBDataSize() ) != S_OK ){	MB( " dxerror", "set buff", MB_E );}if( DXInitInputAssemble(	g_pDevice,g_pDIContext,myOBJ.OBJGetDXInputLayout(), myOBJ.OBJGetDXLayoutNumElms(), g_pEPass,g_pInputLayout, &g_pVB, 1, myOBJ.OBJGetDXStride(),	&g_pIB, 1 ) != S_OK ){MB( " dxerror", "init ia", MB_E );							}DXSetSCBVariablesInitialValues();//reset matrices and set textureiVcount = myOBJ.OBJGetDXVCount();bStuffToRender = TRUE;File.close();}//is open

Its working fine...but I really dont know how I would do on a game( I dont know many things in fact...)
Is normal an app call a million times pass->apply() and dc->Draw()?

I cant imagine how would be manage the transformation matrices for a bunch of different objects... And how would be sprite animation? On OpenGL what I was used to do is change the texcoord everytime, pretty automatic..cant see any similar way of doing this on DX.
Use the map function on your device context to edit the contents of a buffer.

This topic is closed to new replies.

Advertisement