Commit 2dfc064e authored by chili's avatar chili
Browse files

indexed triangle drawing

parent 61f3e9ba
......@@ -124,6 +124,9 @@ void Graphics::DrawTestTriangle()
{ 0.0f,0.5f,255,0,0,0 },
{ 0.5f,-0.5f,0,255,0,0 },
{ -0.5f,-0.5f,0,0,255,0 },
{ -0.3f,0.3f,0,255,0,0 },
{ 0.3f,0.3f,0,0,255,0 },
{ 0.0f,-0.8f,255,0,0,0 },
};
vertices[0].color.g = 255;
wrl::ComPtr<ID3D11Buffer> pVertexBuffer;
......@@ -137,11 +140,35 @@ void Graphics::DrawTestTriangle()
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = vertices;
GFX_THROW_INFO( pDevice->CreateBuffer( &bd,&sd,&pVertexBuffer ) );
// Bind vertex buffer to pipeline
const UINT stride = sizeof( Vertex );
const UINT offset = 0u;
pContext->IASetVertexBuffers( 0u,1u,pVertexBuffer.GetAddressOf(),&stride,&offset );
// create index buffer
const unsigned short indices[] =
{
0,1,2,
0,2,3,
0,4,1,
2,1,5,
};
wrl::ComPtr<ID3D11Buffer> pIndexBuffer;
D3D11_BUFFER_DESC ibd = {};
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.Usage = D3D11_USAGE_DEFAULT;
ibd.CPUAccessFlags = 0u;
ibd.MiscFlags = 0u;
ibd.ByteWidth = sizeof( indices );
ibd.StructureByteStride = sizeof( unsigned short );
D3D11_SUBRESOURCE_DATA isd = {};
isd.pSysMem = indices;
GFX_THROW_INFO( pDevice->CreateBuffer( &ibd,&isd,&pIndexBuffer ) );
// bind index buffer
pContext->IASetIndexBuffer( pIndexBuffer.Get(),DXGI_FORMAT_R16_UINT,0u );
// create pixel shader
......@@ -200,7 +227,7 @@ void Graphics::DrawTestTriangle()
pContext->RSSetViewports( 1u,&vp );
GFX_THROW_INFO_ONLY( pContext->Draw( (UINT)std::size( vertices ),0u ) );
GFX_THROW_INFO_ONLY( pContext->DrawIndexed( (UINT)std::size( indices ),0u,0u ) );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment