JamesWildDev's picture

VertexPointer, ColorPointer, etc. implementation

Hello.

I'm working with OpenTK and had an intermittent problem wherein sometimes things would fail to draw. I double checked my data and it was correct so I looked at how the VertexPointer method in particular was implemented. It appears to get a pointer from .NET/Mono for the array passed in, retain it just for the duration of passing it to GL, then discard it. This is a little misleading, and seems like the method should be marked unsafe.

On the other hand, I should stop being lazy and make this editor tool use VBOs!

Thanks for reading.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

It makes sense if you think about it. There is absolutely no way for OpenTK (or p/invoke in general) to determine how long it should pin a data pointer. The only one with that information is your application.

Three solutions:

  • use server-side storage (VBOs)
  • pin data buffers explicitly
  • allocate buffers in unmanaged memory.

Given that OpenGL 3.x and 4.x remove support for client-side storage, VBOs are the best solution.

JamesWildDev's picture

Oh yeah, the implementation's fine and makes perfect sense. But I think there should be an unsafe flag on methods that do this, to make it clearer to consumers of the API that it is not a "set and forget" method. I was expecting it to hold a reference to the array or copy it.

Thanks for developing this toolkit, the WinForms control is great.