Drawing multiple objects

Started by
3 comments, last by romashka911 5 years, 6 months ago

Hi everyone!

I have some problem in drawing multiple objects. If i load and draw only one model, it draws correctly, but if i add more objects, some of them draw partially, and i have warning ID3D11DeviceContext::DrawIndexed: Index buffer has not enough space! [ EXECUTION WARNING #359: DEVICE_DRAW_INDEX_BUFFER_TOO_SMALL].

If i draw only one model, i don't have this warning.

For each model in render function i do following actions:


deviceContext->PSSetSamplers(0, 1, &m_samplerState);
deviceContext->IASetInputLayout(m_layout);
deviceContext->VSSetShader(m_vertexShader, NULL, 0);
deviceContext->PSSetShader(m_pixelShader, NULL, 0);
deviceContext->DrawIndexed(indexDrawAmount, indexStart, 0);

unsigned int stride;
unsigned int offset;

stride = sizeof(VertexType);
offset = 0;
deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, offset);
deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

deviceContext->PSSetSamplers(0, 0, NULL);
deviceContext->IASetInputLayout(NULL);
deviceContext->VSSetShader(NULL, NULL, 0);
deviceContext->PSSetShader(NULL, NULL, 0);

Each model has it's own vertex and index buffers, which being initialized when i load .obj file.

Each index is unsigned int.

When i'm trying to use Graphics Debugger in Visual Studio, i catch unhandled exception in line


deviceContext->DrawIndexed(indexDrawAmount, indexStart, 0);

 

dx11 2018-10-05 18-44-58-83.bmp

Advertisement

Well, warning is self explanatory - there is something wrong with your index buffer.

Do both models work if you load and draw only one of them?

Do both models work if you load both of them but draw only one of them?

Do you really set your vertex/index buffers *after* you issue the draw call?

Mistake was foolish - calling DrawIndexed before setting buffers

This topic is closed to new replies.

Advertisement