Jump to content
  • Advertisement
Sign in to follow this  
Nathan Drake

Draw without Buffers

This topic is 989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Edited by Nathan Drake

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

?

Share this post


Link to post
Share on other sites

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.)

Edited by Nathan Drake

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!