/// <summary> /// Construct an ElementBufferObject. /// </summary> /// <param name="elementType"> /// The <see cref="DrawElementsType"/> that specify how vertices are interpreted. /// </param> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> public ElementBuffer(DrawElementsType elementType, MapBufferUsageMask usageMask) : base(BufferTarget.ElementArrayBuffer, usageMask) { try { ElementsType = elementType; // Determine ElementsType and default RestartIndexKey switch (elementType) { case DrawElementsType.UnsignedByte: ItemSize = 1; RestartIndexKey = 0x000000FF; break; case DrawElementsType.UnsignedShort: ItemSize = 2; RestartIndexKey = 0x0000FFFF; break; case DrawElementsType.UnsignedInt: ItemSize = 4; RestartIndexKey = 0xFFFFFFFF; break; default: throw new ArgumentException("type not supported", "elementType"); } } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }
/// <summary> /// Construct an ElementBufferObject. /// </summary> /// <param name="elementType"> /// /// </param> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> protected ElementBuffer(Type elementType, MapBufferUsageMask usageMask) : base(BufferTarget.ElementArrayBuffer, usageMask) { try { // Determine ElementsType and default RestartIndexKey switch (Type.GetTypeCode(elementType)) { case TypeCode.Byte: ElementsType = DrawElementsType.UnsignedByte; ItemSize = 1; RestartIndexKey = 0x000000FF; break; case TypeCode.UInt16: ElementsType = DrawElementsType.UnsignedShort; ItemSize = 2; RestartIndexKey = 0x0000FFFF; break; case TypeCode.UInt32: ElementsType = DrawElementsType.UnsignedInt; ItemSize = 4; RestartIndexKey = 0xFFFFFFFF; break; default: throw new ArgumentException("type not supported", nameof(elementType)); } } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }
/// <summary> /// Construct a Buffer determining its type, data usage and transfer mode. /// </summary> /// <param name="type"> /// A <see cref="BufferTarget"/> that specify the buffer object type. /// </param> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> protected Buffer(BufferTarget type, MapBufferUsageMask usageMask) { // Store the buffer object type Target = type; // Store the buffer data usage hints Hint = UsageMaskToHint(usageMask); // Guess appropriate storage flags _UsageMask = usageMask; }
/// <summary> /// Construct an ArrayBufferObjectBase. /// </summary> /// <param name="bufferTarget"> /// A <see cref="BufferTarget"/> that specify the buffer target. /// </param> /// <param name="itemSize"> /// A <see cref="uint"/> that specifies the size of a single item, in bytes. /// </param> /// <param name="usageMask"> /// A <see cref="MapBufferUsageMask"/> that specifies the data buffer usage mask. /// </param> protected ArrayBufferBase(BufferTarget bufferTarget, uint itemSize, MapBufferUsageMask usageMask) : base(bufferTarget, usageMask) { if (itemSize == 0) { throw new ArgumentException("invalid", nameof(itemSize)); } ItemSize = itemSize; }
/// <summary> /// Construct a immutable Buffer determining its type, data usage and storage mode. /// </summary> /// <param name="type"> /// A <see cref="BufferTarget"/> that specify the buffer object type. /// </param> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> protected Buffer(BufferTarget type, MapBufferUsageMask usageMask) { // Store the buffer object type Target = type; // Store the buffer usage mask UsageMask = usageMask; // Let be immutable Immutable = true; // Guess appropriate hint flags // Note: this flag is not actually used when buffer is immutable Hint = BufferUsage.StaticDraw; }
/// <summary> /// Construct an immutable ArrayBufferInterleaved specifying its item layout on GPU side. /// </summary> /// <param name="usageMask"> /// A <see cref="MapBufferUsageMask"/> that specifies the data buffer usage mask. /// </param> public ArrayBufferInterleaved(MapBufferUsageMask usageMask) : base(BufferTarget.ArrayBuffer, (uint)Marshal.SizeOf(typeof(T)), usageMask) { try { // Detect interleaved fields using reflection (cached) List <InterleavedSectionBase> typeSections = ScanTypeSections(); // Get array sections for this instance _InterleavedSections = typeSections.ConvertAll(item => new InterleavedSection(this, item)); } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }
/// <summary> /// Get the <see cref="BufferHint"/> corresponding to a <see cref="MapBufferUsageMask"/>. /// </summary> /// <param name="hint"></param> /// <returns></returns> private static BufferUsage UsageMaskToHint(MapBufferUsageMask usageMask) { BufferUsage hint = BufferUsage.StaticDraw; // Common usage: map for writing before rendering if ((usageMask & MapBufferUsageMask.MapWriteBit) != 0) { hint = BufferUsage.DynamicDraw; } // Common usage: transform feedback if ((usageMask & MapBufferUsageMask.MapReadBit) != 0) { hint = BufferUsage.DynamicRead; } return(hint); }
/// <summary> /// Create an <see cref="UniformBuffer"/> useful for backing with a buffer object the specified uniform block. /// </summary> /// <param name="uniformBlockName"></param> /// <param name="usageMask"></param> /// <returns></returns> public UniformBuffer CreateUniformBlock(string uniformBlockName, MapBufferUsageMask usageMask) { UniformBlockBinding uniformBlockBinding = GetUniformBlock(uniformBlockName); if (uniformBlockBinding == null) { throw new ArgumentException("no uniform block with such name", "uniformBlockName"); } UniformBuffer uniformBuffer = new UniformBuffer(usageMask); // Allocate client storage uniformBuffer.Create(uniformBlockBinding.DataSize); // Map uniform names with MapUniformBlock(uniformBlockName, uniformBuffer); return(uniformBuffer); }
/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on GPU side. /// </summary> /// <param name="usageMask"> /// A <see cref="MapBufferUsageMask"/> that specifies the data buffer usage mask. /// </param> public ArrayBufferObjectInterleaved(MapBufferUsageMask usageMask) : base(usageMask) { try { // Determine array item size ItemSize = (uint)Marshal.SizeOf(typeof(T)); // Detect interleaved fields using reflection (cached) List <InterleavedSectionBase> typeSections = ScanTypeSections(); // Get array sections for this instance _InterleavedSections = typeSections.ConvertAll(delegate(InterleavedSectionBase item) { return(new InterleavedSection(this, item)); }); } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }
public static void NamedBufferStorageEXT(uint buffer, IntPtr offset, uint size, IntPtr clientBuffer, MapBufferUsageMask flags) { Debug.Assert(Delegates.pglNamedBufferStorageExternalEXT != null, "pglNamedBufferStorageExternalEXT not implemented"); Delegates.pglNamedBufferStorageExternalEXT(buffer, offset, size, clientBuffer, (uint)flags); LogCommand("glNamedBufferStorageExternalEXT", null, buffer, offset, size, clientBuffer, flags); DebugCheckErrors(null); }
/// <summary> /// Construct an ShaderStorageBuffer. /// </summary> /// <param name="usageMask"> /// A <see cref="MapBufferUsageMask"/> that specifies the data buffer usage mask. /// </param> public ShaderStorageBuffer(MapBufferUsageMask usageMask) : base(BufferTarget.ShaderStorageBuffer, usageMask) { }
public static void BufferStorage(BufferTarget target, uint size, object data, MapBufferUsageMask flags) { GCHandle pin_data = GCHandle.Alloc(data, GCHandleType.Pinned); try { BufferStorage(target, size, pin_data.AddrOfPinnedObject(), flags); } finally { pin_data.Free(); } }
public static void BufferStorage(BufferTarget target, uint size, IntPtr data, MapBufferUsageMask flags) { Debug.Assert(Delegates.pglBufferStorage != null, "pglBufferStorage not implemented"); Delegates.pglBufferStorage((int)target, size, data, (uint)flags); LogCommand("glBufferStorage", null, target, size, data, flags); DebugCheckErrors(null); }
/// <summary> /// Construct an ElementBufferObject. /// </summary> /// <param name="elementType"> /// The <see cref="DrawElementsType"/> that specify how vertices are interpreted. /// </param> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> public ElementBuffer(DrawElementsType elementType, MapBufferUsageMask usageMask) : base(BufferTarget.ElementArrayBuffer, GetItemSize(elementType), usageMask) { ElementsType = elementType; RestartIndexKey = GetDefaultRestartIndex(elementType); }
/// <summary> /// Construct an UniformBufferObject. /// </summary> /// <param name="usageMask"> /// An <see cref="MapBufferUsageMask"/> that specify the buffer storage usage mask. /// </param> public UniformBuffer(MapBufferUsageMask usageMask) : base(BufferTarget.UniformBuffer, usageMask) { }