Anonymous's picture

Vertex Array example

The Vertex array example (T02_Vertex_Arrays.cs) is missing the "Main" method in the example class file. I added it based one of the other examples, but the example does not display things.

Is this example in flux due to 0.9.1 development?

The reason I was looking at the Vertex array example is that while researching the share context issues I came accross several message boards indicating that OpenGL 3 will drop display lists from the spec and further indicated thet VA and VBO were both described as mechanisms to use in place of display lists.



Comment viewing options

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

I do not recall such a thing being specified in the OpenGL specification but I could very well be mistaken (the spec is huge!) You might wish to check there for confirmation.

If the exact behavior is not specified, then the result will be implementation-specific and you shouldn't rely on it. In this case, the safest approach would be to delay deletion until after a call to GL.Finish or SwapBuffers.

coder123's picture

Ok, thanks!
I'm currently revisiting this issue, and something in this thread caught my attention:

The Fiddler wrote:

Both Inertia and me have observed random crashes with unpinned arrays. The code sample above will work correctly as long as any of the following is true (ordered according to danger, with 1 being the least dangerous):
1. All GL.DrawElements calls finish within the fixed section.

So, have you ever experienced crashes with pinned arrays, when not using the GL.Finish workaround? I haven't, so if you have, I could use some info on the environment you've been testing in. That would help me reproduce the issue and probably understand it better.

Example code I'm talking about:

fixed(float* data = Data)
    GL.VertexPointer(..., (IntPtr)data);
    // No call to GL.Finish() here
the Fiddler's picture

Yes, I have experienced crashes with this exact code, for small datasets. (Large datasets may be stored in the large-object heap, with different GC characteristics - but portable applications cannot rely on this implementation detail).

The reason is that GL.DrawArrays may not read the pointer immediately. The driver is free to shuffle and optimize commands between sequence points, as long as the resulting image does not change. GL.Flush, GL.Finish and SwapBuffers introduce sequence points (i.e. commands prior to the sequence point are executed before commands after the sequence point). GL.Finish also introduces a sync point (i.e. all pending commands are executed immediately), which is the only way to guarantee that your "Data" variable is intact when GL.DrawArrays is executed.