Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 27 Jan 2013
Offline Last Active Feb 06 2013 11:05 PM

Topics I've Started

How to Bind Multiple Shapes/Models to One Vertex Buffer?

28 January 2013 - 04:00 PM

If I have two Vertex Arrays, one for Square, and one for Triangle; what is the best way to bind them to the VertexBuffer?

  1. Is this possible with objects that have different numbers of Vertices?
  2. Is this possible with objects that have different buffer element descriptions, (one with float4 position data, and another with float3 and texcoords, etc).

I have about 100 static model templates that I would like to bind to the vertex buffer, and a few thousand instances associated with those models in an instance buffer.


I can DrawInstanced/Indexed and point to the appropriate pointer in the vertex buffer for reading, (I think), so I am just trying to figure out the best way to get the vertices into the vertex buffer in the first place.




Currently, I am binding one Shape, (a triangle), to the subresource like this:


ModelRenderer::StaticBufferDescription.ByteWidth = bufferSize;
ModelRenderer::StaticBufferDescription.BindFlags = D3D11_BIND_VERTEX_BUFFER;

ModelRenderer::StaticSubResourceData.SysMemPitch = 0;
ModelRenderer::StaticSubResourceData.SysMemSlicePitch = 0;
ModelRenderer::StaticSubResourceData.pSysMem = model->GetVertices();

& ModelRenderer::StaticBufferDescription,
& ModelRenderer::StaticSubResourceData,
& ModelRenderer::StaticBuffer);

Device Context and Vertex Buffer with Many Vertex and Pixel Shaders

27 January 2013 - 09:49 PM



I have tried to phrase my question in multiple ways, mostly because I don't think I understand the complexity of this particular topic, so thanks for your patience!


Yet another rephrase:

1. Can I write Vertex Data to the VertexBuffer for two different objects, (square, triangle), with either the same or different input layout?
2. Can they both use different vertex shaders, pixel shaders, and textures?

3. Could I write a sort of Shader Selector in HLSL that reads a parameter from the input element and dynamically chooses a different pixel shader or texture?


Related C++ Code


When I create an input layout, can I do this without specifying an actual Vertex Shader, or somehow specify more than one?



    result = NS::DeviceManager::Device->CreateInputLayout(
    & NS::ModelRenderer::StaticInputLayout


When I set the VertexShader and PixelShader, how do I associate them with a particular model in my VertexBuffer?  Is it possible to set more than one of each?


DeviceManager::DeviceContext->VSSetShader(ModelRenderer::StaticVertexShader.Get(), nullptr, 0);
DeviceManager::DeviceContext->PSSetShader(ModelRenderer::StaticPixelShader.Get(), nullptr, 0);