Hi there,
I'm struggling a bit with this as it's a little new to me. I've come across this in my project and was wondering exactly what it's doing?
Here's a struct definition which contains the un-ordered map. The struct MeshGeometry has some COM pointers in it that will (presumably) point to filled vertex and index buffers later. I've left some of the details out for clarity:
So that's the struct where the unordered_map data member is first defined. The SubmeshGeometry struct has the following definition:Code:struct MeshGeometry { // Give it a name so we can look it up by name. std::string Name; // System memory copies. Use Blobs because the vertex/index format can be generic. // It is up to the client to cast appropriately. Microsoft::WRL::ComPtr<ID3DBlob> VertexBufferCPU = nullptr; Microsoft::WRL::ComPtr<ID3DBlob> IndexBufferCPU = nullptr; Microsoft::WRL::ComPtr<ID3D12Resource> VertexBufferGPU = nullptr; Microsoft::WRL::ComPtr<ID3D12Resource> IndexBufferGPU = nullptr; Microsoft::WRL::ComPtr<ID3D12Resource> VertexBufferUploader = nullptr; Microsoft::WRL::ComPtr<ID3D12Resource> IndexBufferUploader = nullptr; // Data about the buffers. UINT VertexByteStride = 0; UINT VertexBufferByteSize = 0; DXGI_FORMAT IndexFormat = DXGI_FORMAT_R16_UINT; UINT IndexBufferByteSize = 0; // A MeshGeometry may store multiple geometries in one vertex/index buffer. // Use this container to define the Submesh geometries so we can draw // the Submeshes individually. std::unordered_map<std::string, SubmeshGeometry> DrawArgs; .... rest omitted (just a few member functions) }
And here's the code used to run this stuff in the .cpp file:Code:// Defines a subrange of geometry in a MeshGeometry. This is for when multiple // geometries are stored in one vertex and index buffer. It provides the offsets // and data needed to draw a subset of geometry stores in the vertex and index // buffers so that we can implement the technique described by Figure 6.3. struct SubmeshGeometry { UINT IndexCount = 0; UINT StartIndexLocation = 0; INT BaseVertexLocation = 0; // Bounding box of the geometry defined by this submesh. // This is used in later chapters of the book. DirectX::BoundingBox Bounds; };
So a MeshGeometry can hold buffers that actually contain several individual objects such as a box, a sphere and a cylinder. When we only want to draw one of them we need only a portion of the MeshGeometry - which is the SubmeshGeometry.Code:SubmeshGeometry submesh; submesh.IndexCount = (UINT)indices.size(); submesh.StartIndexLocation = 0; submesh.BaseVertexLocation = 0; mBoxGeo->DrawArgs["box"] = submesh;
So it seems the map takes the Submesh declaration and somehow ties it to a portion of the MeshGeometry struct. It seems to do this however with an std::string, which I found a bit weird. I know there's a lot of API stuff in here but it's the C++ stuff I'm concerned about. Namely how the unordered_map ties data to struct and does so using a string.
So when this is done can I sort of "access" the unordered_map in the MeshGeometry struct and retrieve Submesh data from it?
That would make sense actually, because some of this data is needed later on (functions not shown here) to tell the GPU which part of the buffer to draw from, so you can pick out which specific shape you want to draw.
Still a bit shaky on it though, so I'd appreciate some input on the C++ only parts of it. I understand this is not the place to be requesting info about the API parts.
Thanks![]()


Reply With Quote