1
我想繪製一些在彼此頂部的二維正方形。DrawIndexedInstanced()影響其他幾何
第一方是800×600像素,以0爲中心,0 第二組方格的各30×30個像素,移動圍繞在所述第一2D方形
的頂部對於第一方,我我試圖使用簡單的索引幾何來呈現它。
我試過渲染每個單獨的,它的工作原理。但是,當我試圖同時渲染兩個圖形時,即使我首先渲染第一個方塊,但第二個方塊的實例似乎會通過移動800 x 600方塊來匹配實例緩衝區中的第一個實例正方形,即使我從電路板切換到每個方塊時通過新的頂點緩衝區。以下是我的渲染代碼:
void Render()
{
FLOAT color[] = {0.3f, 0.4f, 0.5f, 1.0f};
m_d3dImmediateContext->ClearRenderTargetView(m_d3dRenderTargetView, color);
m_d3dImmediateContext->ClearDepthStencilView(m_d3dDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
m_d3dImmediateContext->IASetInputLayout(m_d3dInputLayout);
m_d3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UINT stride = sizeof(Vertex);
UINT offset = 0;
m_d3dImmediateContext->IASetVertexBuffers(0, 1, &m_d3dBoardVBuffer, &stride, &offset);
m_d3dImmediateContext->IASetIndexBuffer(m_d3dIBuffer, DXGI_FORMAT_R32_UINT, 0);
m_d3dImmediateContext->VSSetShader(m_d3dVShader, NULL, 0);
m_d3dImmediateContext->PSSetShader(m_d3dPShader, NULL, 0);
m_d3dImmediateContext->VSSetConstantBuffers(0, 1, &m_d3dCBPerObject);
m_d3dImmediateContext->PSSetSamplers(0, 1, &m_samLinear);
m_d3dImmediateContext->PSSetShaderResources(0, 1, &m_d3dBoardSRV);
XMMATRIX worldViewProj = m_world * m_view * m_proj;
XMStoreFloat4x4(&m_cbPerObject.WorldViewProj, worldViewProj);
D3D11_MAPPED_SUBRESOURCE mappedResource;
m_d3dImmediateContext->Map(m_d3dCBPerObject, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
CopyMemory(mappedResource.pData, &m_cbPerObject, sizeof(struct CBPerObject));
m_d3dImmediateContext->Unmap(m_d3dCBPerObject, 0);
m_d3dImmediateContext->DrawIndexed(m_indexCount, 0, 0);
UINT blockStride[2] = {sizeof(Vertex), sizeof(Instance)};
UINT blockOffset[2] = {0, 0};
ID3D11Buffer *vBuffers[2] = {m_d3dBlockVBuffer, m_d3dBlockInstVBuffer};
m_d3dImmediateContext->IASetVertexBuffers(0, 2, vBuffers, blockStride, blockOffset);
m_d3dImmediateContext->IASetIndexBuffer(m_d3dIBuffer, DXGI_FORMAT_R32_UINT, 0);
m_d3dImmediateContext->VSSetShader(m_d3dVShader, NULL, 0);
m_d3dImmediateContext->PSSetShader(m_d3dPShader, NULL, 0);
m_d3dImmediateContext->VSSetConstantBuffers(0, 1, &m_d3dCBPerObject);
m_d3dImmediateContext->PSSetSamplers(0, 1, &m_samLinear);
m_d3dImmediateContext->PSSetShaderResources(0, 1, &m_d3dBlockSRV);
worldViewProj = m_world * m_view * m_proj;
XMStoreFloat4x4(&m_cbPerObject.WorldViewProj, worldViewProj);
D3D11_MAPPED_SUBRESOURCE mappedResource2;
m_d3dImmediateContext->Map(m_d3dCBPerObject, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource2);
CopyMemory(mappedResource2.pData, &m_cbPerObject, sizeof(struct CBPerObject));
m_d3dImmediateContext->Unmap(m_d3dCBPerObject, 0);
m_d3dImmediateContext->DrawIndexedInstanced(m_indexCount, 4, 0, 0, 0);
m_d3dSwapChain->Present(0, 0);
}
我在做一些根本不正確的事情嗎?董事會是800×600平方米,塊是30×30平方米。在主板上,我想基本渲染多個方塊。