I set up the wievport, swapchain, DX11 device, etc., then create a vertex buffer and set it as active
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX) * 3;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
hr = dev->CreateBuffer(&bd, NULL, &pVBuffer);
UINT stride = sizeof(VERTEX);
UINT offset = 0;
devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
Then, in the main frame function, create and update an array of three vertices...
devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
static float r = 0.5;
static float h = 0;
h += 0.001;
if (h >= 2 * D3DX_PI)
{
h = 0;
}
vertices[0] = { r*cos(-(D3DX_PI / 6) + h), r*sin(-(D3DX_PI / 6) + h), 0.0, D3DXCOLOR(1.0, 0.0, 0.0, 1.0) };
vertices[1] = { r*cos((D3DX_PI / 2) + h), r*sin((D3DX_PI / 2) + h), 0.0, D3DXCOLOR(0.0, 1.0, 0.0, 1.0) };
vertices[2] = { r*cos(7 * (D3DX_PI / 6) + h), r*sin(7 * (D3DX_PI / 6) + h), 0.0, D3DXCOLOR(0.0, 0.0, 1.0, 1.0) };
And fill the buffer, which is already active
fillBuffer<VERTEX[]>(dev, devcon, &pVBuffer, vertices, sizeof(VERTEX)*3);
...
template <typename T> HRESULT fillBuffer(ID3D11Device *dev, ID3D11DeviceContext *devcon, ID3D11Buffer **ppOut, T pIn, UINT vSize)
{
HRESULT hr;
D3D11_MAPPED_SUBRESOURCE ms;
hr = devcon->Map(*ppOut, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
if (FAILED(hr))
return hr;
memcpy(ms.pData, pIn, vSize);
devcon->Unmap(*ppOut, NULL);
return S_OK;
}
Then I draw the triangle and present the frame
devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
devcon->Draw(3, 0);
return swapchain->Present(0, 0);
And voilà.
Admittedly, if I try to use the shader I was working on, the output image is exactly the same, but I tried cleaning every part of the code where the shader is used or set up and it still works. I even renamed the .hlsl file and recompiled everything to be sure. Could it be a caching/partial compilation issue?