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?