
GL.BufferData<T>()
Posted Wednesday, 24 March, 2010 - 10:03 by iliak inHi
I make a BufferObject class to handle generic VBO (index buffer using uint, texture buffer using floats, normal buffer using floats...). Here's the code :
/// <summary> /// Stores user datas in graphic card's memory /// </summary> public class BufferObject<T> : IDisposable { /// <summary> /// Apply updates /// </summary> public void Apply() { if (!Display.Capabilities.HasVBO) return; try { GL.BindBuffer(BufferTarget.ArrayBuffer, Handle); GL.BufferData<T>(BufferTarget.ArrayBuffer, (IntPtr)(Count * ElementSize), Buffer.ToArray(), BufferUsageHint.StaticDraw); } catch (Exception e) { bool er = GL.IsBuffer(Handle); Trace.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } }
I have the following error on the GL.BufferData line : The type 'T' 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, T2[], OpenTK.Graphics.OpenGL.BufferUsageHint)'.
Any idea ?


Comments
Re: GL.BufferData<T>()
Add the
structgeneric constraint:This is not enough to ensure that T is blittable but it is better than nothing.
OpenTK.BlittableValueTypeprovides additional checks to ensure that T is a valid type for OpenGL interop at runtime.Re: GL.BufferData<T>()
Ok, thanks !