-
Notifications
You must be signed in to change notification settings - Fork 4
4. Initializing a vertex buffer
theproadam edited this page Apr 23, 2020
·
4 revisions
To maximize performance, renderXF uses its own unmanaged buffers. To make things easier, renderXF accepts a pre existing float array which stores the vertex data.
//Load vertex data into an array
float[] vertexpoints = LoadVertexData();
//Create a buffer compatible with renderXF
GLBuffer myBuffer = new GLBuffer(vertexpoints, Stride, MemoryLocation.Heap);
WARNING: It is extremely important to make sure the stride value is correct. If it is not, renderXF may crash.
GLBuffers will self dispose, however this may take up to a few seconds after runtime. To dispose instantly, just call the Dispose() function.
if (myBuffer != null)
myBuffer.Dispose();
renderXF can store the buffer in the heap, or the stack. Storing the buffer on the stack is experimental and is easily subject to random stack overflow errors. It is recommended to store all buffers in heap memory.
//Buffer allocated in the heap
GLBuffer heap_Buffer = new GLBuffer(vertexpoints, Stride, MemoryLocation.Heap);
//Buffer allocated in the stack
GLBuffer stackBuffer = new GLBuffer(vertexpoints, Stride, MemoryLocation.Stack);
It is also possible to get the true memory address via the GetAddress() function.
IntPtr addr = myBuffer.GetAddress();
float* fldr = (float*)myBuffer.GetAddress();
This can be useful for things such as creating a separate normal buffer, then getting its its normal values per face via float pointer.
- Initializing the renderer
- Setting the transform data
- Blitting and clearing the viewport
- Initializing a vertex buffer
- Creating a shader
- Drawing an object
- Screen space shaders
- Blitting bitmaps
- Loading a texture
- Creating a framebuffer
- Displaying a texture