Draw without Buffers

Started by
3 comments, last by Nathan Drake 8 years, 3 months ago

Hi guys,

based on this article, i wanna draw my stuff without buffers. it just shows that we can set IASetInputLayout(NULL) but it didn't say anything about how to set the IASetIndexBuffer and IASetIndexBuffer methods.


d3d11DevCon->IASetVertexBuffers(NULL, 0, 0, 0, 0);
d3d11DevCon->IASetIndexBuffer(NULL, 0, 0); //second argument can't be zero or null

is that matter to set something like DXGI_FORMAT_R32_UINT for second argument of IASetIndexBuffer and keep first argument as NULL ?

Advertisement

The input layout tells the IA stage which vertex buffers to read from -- so if the layout is NULL, it doesn't matter whether any vertex buffers are bound or not as they won't be used.

To "unbind" an index buffer, I use context.IASetIndexBuffer( 0, DXGI_FORMAT_R16_UINT, 0 );

However, the index buffer is only used if you use indexed draw calls (context.DrawIndexed / context.DrawIndexedInstanced). If you use one of these types of draws, then you must have an index buffer bound. If you use a non-indexed draw (context.Draw / context.DrawInstanced) then it doesn't matter if you've got an index buffer bound or not, as it won't be accessed.

IIRC you don't have to set the buffers to null. Having no input layout means that the device won't try to access the buffers anyway.

Niko Suni

Actually, they provide shader code at the beginning of the page.

It shows how you could generate specific vertex data using SV_VertexID.

Basically, the code below demonstrates how you could draw one triangle.


VSOut VSmain(VSIn input)
{
    VSOut output;

    if (input.vertexId == 0)
        output.pos = float4(0.0, 0.5, 0.5, 1.0);
    else if (input.vertexId == 2)
        output.pos = float4(0.5, -0.5, 0.5, 1.0);
    else if (input.vertexId == 1)
        output.pos = float4(-0.5, -0.5, 0.5, 1.0);

    output.color = clamp(output.pos, 0, 1);

    return output;
}

// On a C++ side

m_pD3D11Device->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_pD3D11Device->IASetInputLayout(NULL);

// Trigger the draw for one triangle. You are generating the data from VS using vertex id
m_pD3D11Device->Draw(3, 0);?

Specifying primitive topology allows you to understand vertex id order in vertex shader

?

IIRC you don't have to set the buffers to null. Having no input layout means that the device won't try to access the buffers anyway.

The input layout tells the IA stage which vertex buffers to read from -- so if the layout is NULL, it doesn't matter whether any vertex buffers are bound or not as they won't be used.

To "unbind" an index buffer, I use context.IASetIndexBuffer( 0, DXGI_FORMAT_R16_UINT, 0 );

However, the index buffer is only used if you use indexed draw calls (context.DrawIndexed / context.DrawIndexedInstanced). If you use one of these types of draws, then you must have an index buffer bound. If you use a non-indexed draw (context.Draw / context.DrawInstanced) then it doesn't matter if you've got an index buffer bound or not, as it won't be accessed.

Thank you so much for your complete answer

Actually, they provide shader code at the beginning of the page.

It shows how you could generate specific vertex data using SV_VertexID.

Basically, the code below demonstrates how you could draw one triangle.

VSOut VSmain(VSIn input)
{
VSOut output;

if (input.vertexId == 0)
output.pos = float4(0.0, 0.5, 0.5, 1.0);
else if (input.vertexId == 2)
output.pos = float4(0.5, -0.5, 0.5, 1.0);
else if (input.vertexId == 1)
output.pos = float4(-0.5, -0.5, 0.5, 1.0);

output.color = clamp(output.pos, 0, 1);

return output;
}
// On a C++ side

m_pD3D11Device->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_pD3D11Device->IASetInputLayout(NULL);

// Trigger the draw for one triangle. You are generating the data from VS using vertex id
m_pD3D11Device->Draw(3, 0);?

Specifying primitive topology allows you to understand vertex id order in vertex shader

?

the reason of asking was because it didn't mention anything about is that necessary to set IASetIndexBuffer and IASetVertexBuffer or not (because in the previous draw, i set both of these functions and i was worry that they might be used in my shaders.)

This topic is closed to new replies.

Advertisement