3

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:

  1. 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?

  2. 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?

ToughDev
  • 117
  • 1
  • 5

1 Answers1

2

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

AJG85
  • 15,849
  • 13
  • 42
  • 50
  • The question was about where exactly memory is allocates in CreateBuffer() call. Is it in process memory or Video Card on-board memory? – ToughDev Jun 01 '11 at 09:11
  • I could be wrong but as I said in first sentence it should be in process memory ... things are only swapped into video memory when they need to be rendered. You can check by using psapi if you need to http://msdn.microsoft.com/en-us/library/ms684884(v=vs.85).aspx – AJG85 Jun 01 '11 at 15:16