This code works fine:
Vertex cubeVertices[] =
{
{XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3(-0.5f, -0.5f, 0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3(-0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3( 0.5f, -0.5f, 0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3( 0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
{XMFLOAT3( 0.5f, 0.5f, 0.5f), XMFLOAT3(0.0f, 0.133f, 0.333f)},
};
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
vertexBufferData.pSysMem = cubeVertices;
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
//THE PROBLEM IS HERE
//if I use sizeof(m_Vertices) it no longer works.
//I still don't understand though because m_Vertices should still be in scope
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&vertexBufferDesc,
&vertexBufferData,
&m_vertexBuffer));
It draws a lovely cube on my screen.
This code does not work:
GeometryGenerator generator;
GeometryGenerator::MeshData cubeData;
generator.CreateCube(cubeData);
//I thought it might be a scope problem
//m_Vertices is a std::Vector<Vertex>
m_Vertices.resize(cubeData.Vertices.size());
for(size_t i = 0; i < cubeData.Vertices.size(); ++i)
{
m_Vertices[i].pos = cubeData.Vertices[i].Position;
m_Vertices[i].color = XMFLOAT3(0.0f, 0.133f, 0.333f);
}
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
vertexBufferData.pSysMem = &m_Vertices[0];
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
//THE PROBLEM IS HERE
//if I use sizeof(m_Vertices) it no longer works.
//I still don't understand though because m_Vertices should still be in scope
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(m_Vertices), D3D11_BIND_VERTEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&vertexBufferDesc,
&vertexBufferData,
&m_vertexBuffer));
The screen clears to my clear color but no shapes draw on the screen.
I thought &m_Vertices[0] is equivalent to an array? I've checked the values in debug and both the array and my CreateCube function produce the same data.