locked
Merging two vertex buffers RRS feed

  • Question

  • I have created two different vertex and index buffers for two different objects. Then I merged those two vertex vertex and index buffers into one vertex and index buffer and send them to input assembler ,I drawed them one by one,But just the first object is being drawn ,the second not.When I use two different buffers everything is Ok but with one large vertex buffer not. Am I missing something in my code, or have I done something wrong? What to do to draw them both.

    Here is some part of my code :

    ID3D11Buffer * mPiramidVertex;
    ID3D11Buffer* mPiramidIndex;
    ID3D11Buffer*secondVertex;
    ID3D11Buffer* secondIndex;
    ...
        
         
    UINT stride[] = { sizeof(Vertex), sizeof(Vertex) };
    	UINT offset[] = { 0,0 };
    	ID3D11Buffer* twoBufers[2] = { mPiramidVertex,secondVertex };
    	ID3D11Buffer* twoindices[2] = { mPiramidIndex,secondIndex };
    mdevicecontexct->IASetVertexBuffers(0, 2, twoBufers, stride, offset);//merging vertex buffers
    	mdevicecontexct->IASetIndexBuffer(*twoindices, DXGI_FORMAT_R32_UINT, 0);//merging index buffers
    
    XMMATRIX view  = XMLoadFloat4x4(&mView);
    	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
    
    D3DX11_TECHNIQUE_DESC Desc;
        mTech->GetDesc( &Desc );
    
        for(UINT p = 0; p < Desc.Passes; ++p)
        {
    	
    		XMMATRIX world = XMLoadFloat4x4(&mWorld);
    		XMMATRIX worldViewProj = world*view*proj;
    		mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
            mTech->GetPassByIndex(p)->Apply(0, mdevicecontexct);
    		
    		mdevicecontexct->DrawIndexed(18, 0, 0);//first object has 18 indices and 5 vertices.
    		mdevicecontexct->RSSetState(fillSolid);
    
    
    		world = XMMatrixTranslation(0.0f, 1.0f, 0.0f);
    		worldViewProj = world*view*proj;
            mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
    		mTech->GetPassByIndex(p)->Apply(0, mdevicecontexct);
    
    		mdevicecontexct->DrawIndexed(36, 18, 5);//second object has 36 indices and 8 vertices.
    		mdevicecontexct->RSSetState(fillSolid);
        }
    
    	HRESULT(mSwapChain->Present(0, 0));


    Admir


    • Edited by admiri92 Monday, December 8, 2014 11:00 PM
    Monday, December 8, 2014 10:59 PM

Answers

  • Maybe there are some misconception on index buffer here:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff476453(v=vs.85).aspx

    Calling this method using a buffer that is currently bound for writing (i.e. bound to the stream output pipeline stage) will effectively bind NULL instead because a buffer cannot be bound as both an input and an output at the same time.

    Best Regards,
    Please remember to mark the replies as answers if they help

    • Marked as answer by admiri92 Wednesday, December 10, 2014 11:04 PM
    Tuesday, December 9, 2014 7:47 AM

All replies

  • Maybe there are some misconception on index buffer here:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff476453(v=vs.85).aspx

    Calling this method using a buffer that is currently bound for writing (i.e. bound to the stream output pipeline stage) will effectively bind NULL instead because a buffer cannot be bound as both an input and an output at the same time.

    Best Regards,
    Please remember to mark the replies as answers if they help

    • Marked as answer by admiri92 Wednesday, December 10, 2014 11:04 PM
    Tuesday, December 9, 2014 7:47 AM
  • Maybe there are some misconception on index buffer here:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ff476453(v=vs.85).aspx

    Calling this method using a buffer that is currently bound for writing (i.e. bound to the stream output pipeline stage) will effectively bind NULL instead because a buffer cannot be bound as both an input and an output at the same time.

    Best Regards,
    Please remember to mark the replies as answers if they help


    Yes, you are right , the error was at trying two bind two vertex/index buffers at one time.

    Admir

    Wednesday, December 10, 2014 11:04 PM