Reputation: 4089
I am trying to port an application with some OpenTK (C# Opengl implementation) to XNA/MonoGame and I have come to a buffer, but I cannot figure out how to port this because there does not seem to be any direct equivilant of the buffer functions. I am trying to port this code:
public void RefillVBO()
{
if (positions == null) return;
if (hasBuf)
GL.DeleteBuffers(3, buf);
GL.GenBuffers(3, buf);
GL.BindBuffer(BufferTarget.ArrayBuffer, buf[0]);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(positions.Length * sizeof(float)), positions, BufferUsageHint.StaticDraw);
if (normals != null)
{
GL.BindBuffer(BufferTarget.ArrayBuffer, buf[1]);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * sizeof(float)), normals, BufferUsageHint.StaticDraw);
}
GL.BindBuffer(BufferTarget.ElementArrayBuffer, buf[2]);
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(elementsLength * sizeof(int)), elements, BufferUsageHint.StaticDraw);
hasBuf = true;
}
Could anyone please translate this for me and possibly explain what is going on because I have no idea?
Also, is there any porting guide or something for this because there are literally hundreds of other errors related to "Gl" functions.
Upvotes: 0
Views: 109
Reputation: 32587
In XNA you usually create a struct type that contains the vertex' data (e.g. position, normal...). Based on that type you create a VertexDeclaration
that tells the GPU how to interpret the data. Finally you create a VertexBuffer
and set the data. Optionally you can create an index buffer.
Take a look at these links:
How To: Create and Use a Custom Vertex
Improving performance by using VertexBuffers and IndexBuffers
Upvotes: 1