DX11顶点未绘制超过一定数量

时间:2017-08-01 01:43:02

标签: c++ graphics directx-11

我正在尝试渲染全屏细分网格。它可以按照预期的方式工作,最多可以达到大约250x250个顶点,但是在此之后,它会在上半部分之后切断(取决于我设置网格的细分方式)。

我有一个顶点和索引向量,我以编程方式填充为三角形列表。我怀疑它可能与顶点缓冲区的缓冲区大小有关,因为顶点/索引的数量似乎是正确的,但是当我尝试增加字节宽度分配时,我得到了内存访问冲突。

顶点数据结构定义如下:

struct SimpleVertex
{
    XMFLOAT3 Pos;
    XMFLOAT2 Tex;
};

要初始化缓冲区,我使用:

D3D11_BUFFER_DESC bd;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;

...

D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &(meshVertices[0]);

...

D3D11_INPUT_ELEMENT_DESC meshLayout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

顶点缓冲区:

...
bd.ByteWidth = sizeof(SimpleVertex) * (UINT)(meshVertices.size());
...
hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, &g_pMeshVertexBuffer);

索引缓冲区:

...
bd.ByteWidth = sizeof(WORD) * (UINT)(meshIndices.size());
...
hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, &g_pMeshIndexBuffer);

画出电话:

void RenderMesh(){
    g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);

    UINT stride = sizeof(SimpleVertex);
    UINT offset = 0;

    g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pMeshVertexBuffer, &stride, &offset);
    g_pImmediateContext->IASetInputLayout(g_pMeshVertexLayout);
    g_pImmediateContext->IASetIndexBuffer(g_pMeshIndexBuffer, DXGI_FORMAT_R16_UINT, 0);

    g_pImmediateContext->VSSetShader(g_pMeshVertexShader, nullptr, 0);
    g_pImmediateContext->PSSetShader(g_pMeshPixelShader, nullptr, 0);
    g_pImmediateContext->PSSetSamplers(0, 1, &g_pSamplerLinear);

    g_pImmediateContext->DrawIndexed(numMeshIndices, 0, 0);
}

非常感谢任何帮助。

0 个答案:

没有答案