in Shared/Rendering/MarkerRenderer.cpp [136:243]
void MarkerRenderer::CreateDeviceDependentResources()
{
if (nullptr == _slateMaterial)
{
_slateMaterial =
std::make_unique<SlateMaterial>(
_deviceResources);
}
_slateMaterial->CreateDeviceDependentResources();
{
const CD3D11_BUFFER_DESC constantBufferDesc(sizeof(SlateModelConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
ASSERT_SUCCEEDED(
_deviceResources->GetD3DDevice()->CreateBuffer(
&constantBufferDesc,
nullptr,
&_modelConstantBuffer
)
);
}
// Once all shaders are loaded, create the mesh.
{
// Load mesh vertices. Each vertex has a position and a color.
// Note that the cube size has changed from the default DirectX app
// template. Windows Holographic is scaled in meters.
const float sx = _markerSize, sy = _markerSize, sz = _markerSize;
static const std::array<VertexPositionColorTexture, 8> cubeVertices =
{ {
{ { -sx, -sy, -sz },{ 1.0f, 0.0f, 0.0f },{ 0.0f, 1.0f } },
{ { -sx, -sy, sz },{ 0.0f, 1.0f, 0.0f },{ 0.0f, 1.0f } },
{ { -sx, sy, -sz },{ 0.0f, 0.0f, 1.0f },{ 0.0f, 0.0f } },
{ { -sx, sy, sz },{ 0.0f, 1.0f, 0.0f },{ 0.0f, 0.0f } },
{ { sx, -sy, -sz },{ 1.0f, 0.0f, 1.0f },{ 1.0f, 1.0f } },
{ { sx, -sy, sz },{ 0.0f, 1.0f, 0.0f },{ 1.0f, 1.0f } },
{ { sx, sy, -sz },{ 0.0f, 0.0f, 1.0f },{ 1.0f, 0.0f } },
{ { sx, sy, sz },{ 0.0f, 1.0f, 0.0f },{ 1.0f, 0.0f } },
} };
D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
vertexBufferData.pSysMem = cubeVertices.data();
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
const CD3D11_BUFFER_DESC vertexBufferDesc(
static_cast<uint32_t>(sizeof(VertexPositionColorTexture) * cubeVertices.size()),
D3D11_BIND_VERTEX_BUFFER);
ASSERT_SUCCEEDED(
_deviceResources->GetD3DDevice()->CreateBuffer(
&vertexBufferDesc,
&vertexBufferData,
&_vertexBuffer
)
);
// Load mesh indices. Each trio of indices represents
// a triangle to be rendered on the screen.
// For example: 2,1,0 means that the vertices with indexes
// 2, 1, and 0 from the vertex buffer compose the
// first triangle of this mesh.
// Note that the winding order is clockwise by default.
constexpr std::array<unsigned short, 36> cubeIndices =
{ {
2,1,0, // -x
2,3,1,
6,4,5, // +x
6,5,7,
0,1,5, // -y
0,5,4,
2,6,7, // +y
2,7,3,
0,4,6, // -z
0,6,2,
1,3,7, // +z
1,7,5,
} };
_indexCount = static_cast<uint32_t>(cubeIndices.size());
D3D11_SUBRESOURCE_DATA indexBufferData = { 0 };
indexBufferData.pSysMem = cubeIndices.data();
indexBufferData.SysMemPitch = 0;
indexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC indexBufferDesc(
static_cast<uint32_t>(sizeof(unsigned short) * cubeIndices.size()),
D3D11_BIND_INDEX_BUFFER);
ASSERT_SUCCEEDED(
_deviceResources->GetD3DDevice()->CreateBuffer(
&indexBufferDesc,
&indexBufferData,
&_indexBuffer
)
);
}
_loadingComplete = true;
}