lid6j86's picture

Lists to VBO?

I have a series of verticies in a list as

List<Coordinates<byte>> mVBOVertexBuffer

where coordinates holds an x, y, and z byte.

when I go to pass the list to bufferdata, I get this warning:

The type 'System.Collections.Generic.List>' must be a non-nullable value type in order to use it as parameter 'T2' in the generic type or method 'OpenTK.Graphics.OpenGL.GL.BufferData(OpenTK.Graphics.OpenGL.BufferTarget, System.IntPtr,ref T2, OpenTK.Graphics.OpenGL.BufferUsageHint)'

My question is this: Is there a way to get around this and push a list straight to a VBO via GL.BufferData(), or do I have to push this to a one-dimensional array?


Comment viewing options

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

Can I just sufficiently say mVBOVertexBuffer.ToArray() ? or should I pass it to an actual array first then pass the array?

AndyKorth's picture

A few notes, hopefully if I make any mistakes someone more experienced can correct me.

GL.BufferData is looking for a contiguous block of data, which is sent directly into video card memory. That data could be formatted in a variety of ways, it might be a mix of vertex positions, vertex colors, texture coordinates, and normals. OpenGL will trust that this raw block of data includes exactly what you tell it. It doesn't know how to navigate C# lists, as you suspected.

Additionally, your list is of Coordinates.. I'm hoping that's a struct even though it's generic.

I'd say it's fine to create the array via list.ToArray(); Either way you end up with an array. Although if you are changing that list of vertices regularly, you probably don't want to ToArray() each frame.

lid6j86's picture

yea it's a struct. I made it generic because I plan on preserving as much code as possible for future uses

amulware's picture

Be aware that ToArray() copies the entire list into a new and separate array, which can be quite a hit on the memory and also performance, if you do it too often.

If like me you care a lot about performance, I would advise you to just use an array in the first place, if possible of course.