I want to have one buffer used for all dynamic properties but the amount of vertices in this could vary from just a few for an interface to the whole scene. As such if it's becomes initialized with only let's say the below.
offset = 120; //example situation. bd.ByteWidth = sizeof(VertexPositionColorTexture) * offset;
The above is 120 vertices, but if let's say the next time when I go to update. I need 160 vertices the buffer will only have space for 120 and will do one of the following.
- Crash with an access exception.
- Draw but it'll be missing those 40 excess vertices.
I update the Vertex Buffer by doing the following:
D3D11_MAPPED_SUBRESOURCE resource; ZeroMemory(&resource, sizeof(D3D11_MAPPED_SUBRESOURCE)); Engine::context->Map(dynamic_interfaces_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); memcpy(resource.pData, &vertsToDraw, sizeof(VertexPositionColorTexture) * offset); Engine::context->Unmap(dynamic_interfaces_buffer.Get(), 0);
The "offset" value changes with what ever data ends up being present. I update the existing "vertsToDraw" data as needed.
So if the title didn't make sense. I'm looking to edit the ByteWidth value that what stored in the ByteWidth of the description when the buffer was originally created. My only solution so far was to set the buffer to the maximum size I feel I would ever need then set the VertsToDraw array size to that same value. However then when I update I only update with the needed amount. I'm not sure if that causes a performance issue by having a buffer with a byteWidth of "32 Bytes" * "36,000 Vertices". When in many cases I might only use a few 1000 or less.
Another thought I had if the above is the only way was to create multiple buffer of various sizes and use which ever one fits the situation the best.
E.g. if it's 3828 vertices use a 4000 pre defined vertices buffer or if it's 18348 vertices use a 19000 pre defined buffer.
But i'm up for any solution if there's a better way to go about this i'm a bit new to DirectX.