c++ - (DirectX 11) Dynamic Vertex/Index Buffers implementation with constant scene content changes -
For the first time (with me) delving into un-managed DirectX 11 and there is an issue, though, on forums Frequently I still leave the questions with me.
I am developing as an app in which objects are added to the scenes over time. On each render loop, I want to collect all corners in the scene and they should reuse a single top and index buffer for performance and best practice. My question is in relation to the use of dynamic vertical and index buffers when visual content changes, so I can not fully understand their correct usage.
Vertex Buffer Descriptration. Usage = D3D11_USAGE_DYNAMIC; Vertex buffer decryption. Binduflags = D3D11_BIIBSFTEXBUFFER; Vertex bufferDelication CPUAvailability Flags = D3D11_CPU_ACCESS_WRITE; Summit Buffer Descriptration Mixflag = 0; Vertex buffer description Structure biastrade = 0; Will I make a buffer when the scene starts and should anyway update their contents in every frame? If so, what should be the size of the byte size in buffer details? And how do I get started with it?
Or, should I first show the size of the scene (frame 1) as the shape of the current size? If so, when I add any other object to this scene, do I need to recreate the buffer and change the bitwidth of buffer details to the new top number? If my view updates your uppercase on each frame, then using a dynamic buffer will lose its purpose in this way ...
I am testing to start buffer for the first time. , And from there, using the map / unmount on each frame. I start by filling out a vector list with all the visible objects and then update this kind of resource:
Zero view :: submission () {(...) std :: Vector & lt; VERTEX & gt; TotalVertices; Std :: vector & lt; Integer & gt; TotalIndices; Int totalVertexCount = 0; Int totalIndexCount = 0; (SizeEiterator = Model.Bijin (); SizeItterator! = Model.and (); ++ SizeEtyterator) {Model * CurrentModel = (* Size indicator); // Total presentations are filled here ...} // The total edition and total index at this point are all the visual data (ifVertexBufferSet) {// This is where it copies the new corner of buffer // This is causing flicker in full screen ... D3D11_MAPPED_SUBRESOURCE Resource; Reference- & gt; Map (peak buffer, 0, d3d 11_MAP_WRITE_DISCARD, 0, and resource); Memcpy (source.pData, & amp; total version [0], sizeof (total version)); Reference- & gt; Unmatched (Vertexbuffer, 0); } Else {// it is run in the first frame but what if new corners are added to the scenario? Vertex buffer decryption. Bitwidth = size (VATXX) * total vertex count; UINT Stride = Psychophuff (Veertex); UINT offset = 0; D3D11_SUBRESOURCE_DATA resource data; Zoramori (and resource data, size (resource data)); ResourceData.pSysMem = & amp; Total edition [0]; Device-> CreateBuffer (& amp; vertexBufferDescription; & Resource Data, & amp; vertexBuffer); Reference-> IASetVertexBuffers (0, 1, & vertexBuffer, and elongation, and offset); IsVertexBufferSet = true; } At the end of the render loop, while keeping track of the corner buffer position for each object, I eventually invoke Draw ():
< Code> context-> Draw (object vertex calculation, current offset); } My current implementation is causing my whole scene to be flicker. But there is no memory leak, if I am using the Map / Unmatched API, then there is nothing to do with it?
In addition to this, when will buffer-> release () begin to be ideal? Tips or code sample would be great! thank you in advanced!
In the top buffer on memcpy you do the following:
memcpy (Source.pData, and the conclave, [0], size (total version)); Size (total current) only one std :: vector < VERTEX & gt; Which is what you want. Try the following code:
memcpy (resource.pData, & amp; totalVertices [0], sizeof (VERTEX) * totalVertices.size ()); In addition you do not appear to call IASetVertexBuffers , when VerttexBufferSet is true, make sure that you do this.
Comments
Post a Comment