0
votes

I have a simple rendering program I just made, but it refuses to draw anything but what I set the initial vertices to. Even if I call Map() and Unmap(), the geometry doesn't seem to change. I have a feeling it has to do with Map() and Unmap(), but I'm not sure. Right now, my initial vertex data consists of one triangle. Then I map the vertex buffer with a new set of vertices which consists of two triangles, but they aren't rendered. Only one triangle is rendered even though I pass in 6 for the vertex count in the draw function. Here is my setup code:

VertexData vertexData[] = 
{
    {0.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f},
    {0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f}
};

D3D11_BUFFER_DESC bd;
ZeroMemory(&bd,sizeof(bd));

bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VertexData)*256;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

D3D11_SUBRESOURCE_DATA vertexBufferData;
vertexBufferData.pSysMem = vertexData;
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;

_device->CreateBuffer(&bd, &vertexBufferData, &_renderBuffer);

Mapping function:

data is a vector containing six VertexData structs, for six vertices

D3D11_MAPPED_SUBRESOURCE ms;
ZeroMemory(&ms,sizeof(D3D11_MAPPED_SUBRESOURCE));
_deviceContext->Map(_renderBuffer,NULL,D3D11_MAP_WRITE_DISCARD,NULL,&ms);
memcpy(ms.pData,&data[0],sizeof(VertexData)*data.size());
_deviceContext->Unmap(_renderBuffer,NULL);

And here is my rendering code:

_deviceContext->ClearRenderTargetView(_backBuffer,D3DXCOLOR(0.0f,0.0f,0.0f,1.0f));
_deviceContext->Draw(6,0);
_swapChain->Present(0,0);

EDIT: Disabled backface culling, but the triangle is still not appearing.

Mapping Function

void Render::CopyDataToBuffers(std::vector<VertexData> data)
{
    D3D11_MAPPED_SUBRESOURCE ms;
    ZeroMemory(&ms,sizeof(D3D11_MAPPED_SUBRESOURCE));

    _deviceContext->Map(_renderBuffer,NULL,D3D11_MAP_WRITE_DISCARD,NULL,&ms);
    memcpy(ms.pData,&data[0],sizeof(VertexData)*data.size());
    _deviceContext->Unmap(_renderBuffer,NULL);
}

Calling of Mapping function

std::vector<VertexData> vertexDataVec;
vertexDataVec.push_back(vertexData[0]);
vertexDataVec.push_back(vertexData[1]);
vertexDataVec.push_back(vertexData[2]);
vertexDataVec.push_back(vertexData[3]);
vertexDataVec.push_back(vertexData[4]);
vertexDataVec.push_back(vertexData[5]);

Render::GetRender().CopyDataToBuffers(vertexDataVec);
1
Are you sure that the second triangle isn't just being removed by backface culling or something different? Have you debugged the application with PIX or the VS graphics debugger? - Nico Schertler
I haven't used the Visual Studio graphics debugger, but I have used NVIDIA Nsight a little bit. I will try debugging with VS when I get back. Also I didn't enable culling, is it enabled by default? - Nick Ellas
Can we take a look at data?, and how did you set the vertex/index buffer? - zdd
data is a function parameter, I will post the whole function for the mapping. - Nick Ellas

1 Answers

0
votes

To fix the problem, I just had to create a ID3D11RasterizerState and disable culling. Here is the structure:

ID3D11RasterizerState* rasterizerState = NULL;

D3D11_RASTERIZER_DESC rd =
{
        D3D11_FILL_SOLID,
        D3D11_CULL_NONE,
        TRUE,
        1,
        10.0F,
        1.0F,
        TRUE
};

_device->CreateRasterizerState(&rd,&rasterizerState);

_deviceContext->RSSetState(rasterizerState);