Assume that I need to render static picture (100 stars). I generate star data (position, color, size) to std::vector stars;
Then I create a class for D3D rendering, which consist a buffer:
CGalaxyMapRenderer
{
…
CComPtr<ID3D11Buffer> m_spStarBuffer;
}
In ctor I initialize it in this way:
CGalaxyMapRenderer::CGalaxyMapRenderer(const std::vector<SStarData>& vecData)
{
…
const CD3D11_BUFFER_DESC vertexBuffDescr((UINT)(sizeof(SStarData)*stars.size()), D3D11_BIND_VERTEX_BUFFER); //Constant buffer?
D3D11_SUBRESOURCE_DATA initVertexData = {0};
initVertexData.pSysMem = &stars[0];
spDevice->CreateBuffer(&vertexBuffDescr, &initVertexData, &m_spStarBuffer);
…
}
After that I may destroy std::vector, as it is no longer needed.
The questions are:
spDevice->CreateBuffer(&vertexBuffDescr, &initVertexData, &m_spStarBuffer));
Where memory allocation will take place for this peace of code?
Will it be graphic memory or current process memory?
When I no longer need to render a galaxy map (for example, when I want to move to next level, where no galaxy map required), I am going to destroy CGalaxyMapRenderer. There will be automatic destruction of m_spStarBuffer in dtor. The question is: is it enough to clear all the buffer resources? Or should I make some additional steps in order to make memory free?
As to first question it should be on the process heap graphic memory is only used when needed in general: http://msdn.microsoft.com/en-us/library/ff476501(v=vs.85).aspx
As to second question I'm hoping by automatic destruction you mean that m_spStarBuffer is a smart pointer. Here's a simple example of creating a vertex buffer: http://msdn.microsoft.com/en-us/library/ff476899(v=VS.85).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With