Edit: Solved, see posts bellow :D.
I am having trouble when using OpenTK.Half (OpenTK v1.1) instead of floats when using them in vertex buffers for vertex attributes.
My program runs just fine when using VertexAttribPointerType.Float, but fails with VertexAttribPointerType.HalfFloat
I am using the buffers in this way (VB.net):
Dim BytesPerValue as Interger= OpenTK.Half.SizeInBytes 'this should be 2, right? Buffers(i) = GL.GenBuffer() GL.BindBuffer(BufferTarget.ArrayBuffer, Buffers(i)) GL.BufferData(BufferTarget.ArrayBuffer, CType(max_primitive_count * primitive_dimensions * BytesPerValue, IntPtr), IntPtr.Zero, BufferUsageHint.StreamDraw) 'Then for the update and drawing part I do : 'n_primitives is the number of primitives to be updated and drawn, passed as an argument in the method. Data is a Byte array (read description in the bottom) GL.BindBuffer(BufferTarget.ArrayBuffer, Buffers(CurrentBufferIndex)) Dim pointr = GL.MapBufferRange(BufferTarget.ArrayBuffer, IntPtr.Zero, n_primitives * PrimitiveDimensions * BytesPerValue, BufferAccessMask.MapWriteBit) SyncLock Me 'protecting Data Runtime.InteropServices.Marshal.Copy(Data, 0, pointr, n_primitives * PrimitiveDimensions * BytesPerValue) End SyncLock GL.UnmapBuffer(BufferTarget.ArrayBuffer) GL.VertexAttribPointer(AttributeIndex, PrimitiveDimensions, VertexAttribPointerType.HalfFloat, False, 0, 0) '... some other buffers code GL.DrawArrays(PrimitiveType.Points, 0, Count) 'where count is the number of points to draw (same as n_primitives)
Data is a byte array. It contains the HalfFloat binary values (obtained via Half.GetBytes()), packed. This means, you can read or write a "half" every 2 bytes. Data.Length is (max_primitives*primitive_dimensions*bytespervalue)
The way I put data in the Data array is:
Dim b = Half.GetBytes(value)
Array.Copy(b, 0, Data, index * BytesPerValue, BytesPerValue)
'where index is the index of the "half" value in the array, and "value" is a "Half" number.
I repeat. This works well when using BytesPerValue = "SIzeOfSingle"(should be 4), VertexAttribPointerType.Float, and filling the Data with BitConverter.GetBytes(CSng(value))
I tried using another "Half" (half float) implementation for .net, but the result is the same.
Does anyone has an example of how to properly use half precision floats with OpenGL in Opentk? The answer to " do you really need half floats in your application?" in my case is:" Yes, I do, just because". So asking something alike wont solve any problem. I am aware of the precision issues of a Half, and by my calculations, that shouldn't be a problem in this case.