Jump to content
  • Advertisement
Sign in to follow this  
doesnotcompute

OpenGL Emulating DrawPrimitiveUP/DrawIndexedPrimitiveUP with OpenGL

This topic is 2753 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

I'm trying to add support in my opengl renderer, for what DX9 calls "user primitives". This basically means, the user passes an array of vertex data (and index data in the indexed case) that they want drawn as a list of triangles. Once the DrawUserPrimitives call returns, they should be able to do whatever they want with the original pointer/arrays they passed.

I could implement this with immediate mode but I'm trying to not use any deprecated functionality, so what I originally came up with was this:


void DrawUserIndexedPrimitives(vertexDeclaration, vertexArray, indexArray)
{
foreach vertexElement in vertexDeclaration
{
glEnableVertexAttribArray vertexElement
glVertexAttribPointer vertexArray + vertexElementOffset
}

glDrawElements indexArray
}



I'm getting strange behavior (missing and corrupted triangles) with this though, which I'm thinking is because the driver is actually storing the values of my pointers and not copying the data, so if reuse or delete the arrays it ends up using bad vertex/index data when it gets around to actually rendering the triangles.

Does anyone know if this is actually the case? I can't seem to find any documentation on how this is implemented (whether it will make a copy or not).

If this *is* the case, then I'm thinking of using dynamic draw vertex/index buffers to hold the user primitive data instead. But this leads to a similar uncertainty about when it's safe to discard the contents of the buffer. Can I safely discard it after I issue the DrawElements call, should I do it at the end of the frame?

EDIT: Gah, or it could be me making typos... nevermind.

Share this post


Link to post
Share on other sites
Advertisement
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!