Jump to content
  • Advertisement
Sign in to follow this  

MDX for .NET 2.0 (How to use GraphicsBuffer)

This topic is 4505 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, Here is the peace of code I try to make work :
    // create the vertex and index buffer
    VertexBuffer  ^ vertexBuffer  = gcnew VertexBuffer(m_D3DDevice, 4 * sizeof(CustomVertex::PositionColored), Usage::None, CustomVertex::PositionColored::Format, Pool::Managed, nullptr);
    IndexBuffer   ^ indexBuffer   = gcnew IndexBuffer(m_D3DDevice, 6 * sizeof(short), Usage::None, Pool::Managed, true, nullptr);

    // try to fill the vertex buffer >_<
    // first, I lock it to a GraphicsBuffer (no doc on that one :/)
    GraphicsBuffer ^ lockedBuffer = vertexBuffer->Lock(0, 0, LockFlags::None);

    // the lockedBuffer->Write() needs a cli::array<unsigned char, 1> ^ as a parameter, so I create on, big enough for all the vertices
    cli::array<unsigned char> ^ vertices = gcnew cli::array<unsigned char> (4 * sizeof(CustomVertex::PositionColored));

    // and here is the problem : How do I fill this cli::array now ????
    // ....

    // write the content into the buffer and unlock

    // do the same for the indices (if I can do it for the vertices, it's the same)

    // set my buffers and draw
    m_D3DDevice->VertexFormat = CustomVertex::PositionColored::Format;
    m_D3DDevice->Indices      = indexBuffer;
    m_D3DDevice->SetStreamSource(0, vertexBuffer, 0);
    m_D3DDevice->DrawIndexedPrimitives(PrimitiveType::TriangleList, 0, 0, 4, 0, 2);

So, my problem is : 1) is it the correct method to fill a buffer with managed DirectX, C++, and with the 2.0 runtime ? 2) if it's the correct method, then, how do I fill this cli::array ??? It's unsigned char, because the GraphicsBuffer::Write() method requires unsigned chars !! So how can I add my vertices ? Thx in advance for any answer / pointer to a good tutorial / whatever could help me ^^ (And i'm using managed C++, not C#. And .NET 2.0, not 1.X !) [Edited by - paic on March 16, 2006 8:36:45 AM]

Share this post

Link to post
Share on other sites
The graphics buffer should be a generic, in MDX2.0. I'm assuming you're referencing version 2.0 of MDX, though you didn't mention.

I use:

GraphicsBuffer<MyVertexStruct> gBuffer;
gBuffer = vBuffer.Lock<MyVertexStruct>(....);

and then write each vertex using: gBuffer = whatever;

I'm assuming CLI acts the same way about this.

Also note, there seem to be two versions of the GraphicsBuffer. You need the one that is in the Generics namespace.

Hope this helps.

Share this post

Link to post
Share on other sites
Thx 1000 times !
And do you mind telling me where did you find this information ????? (I never thought there would be 2 versions of GraphicsBuffer !)

Share this post

Link to post
Share on other sites
I got tipped off by someone, though I can't quite remember who it was. One of the regulars here - so I bet he's reading this. Thanks again :).

Anyhow, I understood this feature was added in one of the later releases of MDX2.0, so someone who's been following the release info would see that they added it.

Also, if you're interested, the non-generic GraphicsBuffer should have a GetBuffer<>() method, that returns a generic buffer with the type you give it, so that's an option too (I was using this before I found out about the newer type).

Hope this helps :).

Share this post

Link to post
Share on other sites
It's still prerelease I think so they haven't fully documented it. Remember the generic version of GraphicsBuffer is in DirectX::Generic.

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!