XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

Modifying Vertex Buffer Issue

Last post 04-27-2008 3:54 PM by Nick Korn. 6 replies.
  • 04-26-2008 3:41 PM

    Modifying Vertex Buffer Issue

    I am having an issue modifying a vertex buffer once I have sent it to the GPU.  I know I need to Map() and Unmap() the vertex buffer but I do not understand what is required to set the vertex buffer description in order to allow this.  My current setup works but as you will read below it does not function perfectly.

    My current code for setting up the vertex buffer is below.  When I run my program with this code I receive some debug input from DX10:
    D3D10: ERROR: ID3D10Device::IASetVertexBuffers: A Buffer trying to be bound to slot 0 did not have the appropriate bind flag set at creation time to allow the Buffer to be bound as a VertexBuffer. [ STATE_SETTING ERROR #238: IASETVERTEXBUFFERS_INVALIDBUFFER ]

    Setup code:
    D3D10_BUFFER_DESC bd; 
    bd.Usage =/* D3D10_USAGE_DEFAULT;*/D3D10_USAGE_DYNAMIC;
    bd.ByteWidth = sizeof(VertexPositionColor) * bb_numVertices;
    bd.BindFlags = D3D10_BIND_CONSTANT_BUFFER;//D3D10_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = /*0;*/D3D10_CPU_ACCESS_WRITE;
    bd.MiscFlags = 0;

    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = vertices;
    hr = Device->CreateBuffer(&bd, &InitData, &bb_VertexBuffer);

    Modification code:
    VertexPositionColor *pData = NULL;
      if(SUCCEEDED(bb_VertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, reinterpret_cast<void**>(&pData))))
      {
        memcpy(pData, vertices, sizeof(VertexPositionColor) * bb_numVertices);
        bb_VertexBuffer->Unmap();
      }

    I originally through the bind flag should be the commented out code but when I run that hr gives me E_INVALIDARG.

    Thank you for all your help.
  • 04-26-2008 5:32 PM In reply to

    Re: Modifying Vertex Buffer Issue

    you should set BindFlag to D3D10_BIND_VERTEX_BUFFER i believe
  • 04-26-2008 5:44 PM In reply to

    Re: Modifying Vertex Buffer Issue

    I may have been a little confusing in my wording.  I originally thought it should be D3D10_BIND_VERTEX_BUFFER but I receive E_INVALIDARGS as the result when I use that value.
  • 04-26-2008 6:05 PM In reply to

    Re: Modifying Vertex Buffer Issue

    And what does debug input say in this case?

     

    I see that you dont initialize all fields of D3D10_SUBRESOURCE_DATA (pitches), so this can be  reason of failure.

  • 04-26-2008 8:49 PM In reply to

    Re: Modifying Vertex Buffer Issue

    The dubug input I receive is:

    D3D10: ERROR: ID3D10Device::IASetVertexBuffers: A Buffer trying to be bound to slot 0 did not have the appropriate bind flag set at creation time to allow the Buffer to be bound as a VertexBuffer. [ STATE_SETTING ERROR #238: IASETVERTEXBUFFERS_INVALIDBUFFER ]

    What should be filled in with the D3D10_SUBRESOURCE_DATA?  When I read the documentation for that struct the two pitch values described state they are only used for texture resrouces.
  • 04-27-2008 6:22 AM In reply to

    Re: Modifying Vertex Buffer Issue

    Well this message means that you didn`t set D3D10_BIND_VERTEX_BUFFER as a bind flag for your vertex buffer, i asked  what dx10 says if you set this flag, because you have said before that it does not work for you either. I have no problems with vertex buffers at all, they are bound as required, and can be locked if you use D3D10_USAGE_DYNAMIC plus some cpu flag when creating a buffer. And from my point of view you are doing everything correct besides the bind flag,where you try to bind the vertex buffer as a constant buffer.
  • 04-27-2008 3:54 PM In reply to

    Re: Modifying Vertex Buffer Issue

    Thank you for your help.

    After my 3rd attempt at using D3D10_BIND_VERTEX_BUFFER as the bind flag everything is working fine.  Not positive as to what my issue was.
Page 1 of 1 (7 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG