3.c Vertex Arrays
Although it's really not recommended using them (besides for compiling to a Display List), Vertex Arrays can be safely used like this:
pseudocode:
float[] Positions; float[] Normals; unsafe { fixed (float* PositionsPointer = Positions) fixed (float* NormalsPointer = Normals) { GL.NormalPointer(..., NormalsPointer); GL.VertexPointer(..., PositionsPointer); GL.DrawArrays(...); GL.Finish(); // Force OpenGL to finsh drawing while the arrays are still pinned. } }
You must use the unsafe float* overloads for this to work, not the object overloads (which pin internally)
The important bit is that the pin between GL.*Pointer and GL.Draw* may not be released. For arrays smaller than 85000 Bytes it is also important to call GL.Finish in order for the CPU to wait until the GPU is done reading all pinned data. You might get away without the GL.Finish command for a very short VA or ones larger than 85000 Bytes, but once the pin is released the Garbage Collector is allowed to move or cleanup your array. This leads to difficult to trace access violations with medium sized VA (without waiting for OpenGL to finish processing it) and will randomly occur at frames where the GC kicks in.
GL.Finish will obviously kill performance, since you have a blocking statement executed, which forces CPU and GPU to work in sync and not taking advantage of parallel processing. That's why it's recommended to use Display Lists or Vertex Buffer Objects instead.
Please visit this discussion in the forum for more information.
- Printer-friendly version
- Login or register to post comments

