DirectX 11 Drawing multiple instances of the same object

Started by
1 comment, last by Muzzy A 10 years ago

I'm trying to set up Direct X 11 and I have a cube that I'm trying to render multiple times in different places. The problem is only the last one being drawn gets rendered.

Here is how I set my constant buffers


struct objData
{
    Matrix4x4 world;
    Matrix4x4 viewProj;
};

// I do this for every object
void CRenderer::setPerObjectData( const Matrix4x4& world,const Matrix4x4& viewProj )
{
    D3D11* d3d = g_Engine->getD3D();
 
    objData d = { world,viewProj };
 
    D3D11_MAPPED_SUBRESOURCE edit;
    d3d->getDeviceContext()->Map(_pObjectData, 0, D3D11_MAP_WRITE_DISCARD, 0, &edit);

    memcpy(edit.pData, &d, sizeof( objData ) );

    d3d->getDeviceContext()->Unmap(_pObjectData, 0);
 
    // '_pObjectData' is the same buffer for all the objects being rendered
    d3d->getDeviceContext()->VSSetConstantBuffers(0, 1, &_pObjectData);
}
Advertisement

We cannot tell you anything by looking at that code. We need vshader, buffers creation the draw call

A random tutorial about instancing: http://www.braynzarsoft.net/index.php?p=D3D11Instancing

Well this Tutorial explains everything I need. Thanks for the post.

This topic is closed to new replies.

Advertisement