public unsafe void LoadSubData(IntPtr offset, IntPtr data, int size) { if (size < 0) { throw new ArgumentException("Size cannot be less than zero."); } if (this.bufferSize == 0) { throw new InvalidOperationException(string.Format( "Cannot update {0}, because its storage was not initialized yet.", typeof(NativeGraphicsBuffer).Name)); } if ((uint)offset + size > this.bufferSize) { throw new ArgumentException(string.Format( "Cannot update {0} with offset {1} and size {2}, as this exceeds the internal " + "storage size {3}.", typeof(NativeGraphicsBuffer).Name, offset, size, this.bufferSize)); } NativeGraphicsBuffer prevBound = GetBound(this.type); Bind(this.type, this); uint target = ToOpenTKBufferType(this.type); GraphicsBackend.GL.BufferSubData(target, (uint)offset, TypedArray <Uint8ClampedArray, byte> .From(new Span <byte>(data.ToPointer(), size))); Bind(this.type, prevBound); }
public unsafe void LoadData(IntPtr data, int size) { if (size < 0) { throw new ArgumentException("Size cannot be less than zero."); } NativeGraphicsBuffer prevBound = GetBound(this.type); Bind(this.type, this); uint target = ToOpenTKBufferType(this.type); if (data == IntPtr.Zero || size == 0) { // ToDo //GraphicsBackend.GL.BufferData(target, null, WebGLRenderingContextBase.STREAM_DRAW); } else { GraphicsBackend.GL.BufferData(target, TypedArray <Uint8ClampedArray, byte> .From(new Span <byte>(data.ToPointer(), size)), WebGLRenderingContextBase.STREAM_DRAW); } this.bufferSize = size; Bind(this.type, prevBound); }
public static void Bind(GraphicsBufferType type, NativeGraphicsBuffer buffer) { if (GetBound(type) == buffer) { return; } SetBound(type, buffer); uint target = ToOpenTKBufferType(type); GraphicsBackend.GL.BindBuffer(target, buffer != null ? buffer.Handle : null); }
private static void SetBound(GraphicsBufferType type, NativeGraphicsBuffer buffer) { if (type == GraphicsBufferType.Vertex) { boundVertex = buffer; } else if (type == GraphicsBufferType.Index) { boundIndex = buffer; } else { return; } }
public void SetupEmpty(int size) { if (size < 0) { throw new ArgumentException("Size cannot be less than zero."); } NativeGraphicsBuffer prevBound = GetBound(this.type); Bind(this.type, this); uint target = ToOpenTKBufferType(this.type); GraphicsBackend.GL.BufferData(target, (ulong)size, WebGLRenderingContextBase.STREAM_DRAW); this.bufferSize = size; Bind(this.type, prevBound); }
void IGraphicsBackend.Render(IReadOnlyList <DrawBatch> batches) { if (batches.Count == 0) { return; } this.RetrieveActiveShaders(batches); this.SetupSharedParameters(this.renderOptions.ShaderParameters); int drawCalls = 0; DrawBatch lastRendered = null; for (int i = 0; i < batches.Count; i++) { DrawBatch batch = batches[i]; VertexDeclaration vertexType = batch.VertexBuffer.VertexType; // Bind the vertex buffer we'll use. Note that this needs to be done // before setting up any vertex format state. NativeGraphicsBuffer vertexBuffer = batch.VertexBuffer.NativeVertex as NativeGraphicsBuffer; NativeGraphicsBuffer.Bind(GraphicsBufferType.Vertex, vertexBuffer); bool first = (i == 0); bool sameMaterial = lastRendered != null && lastRendered.Material.Equals(batch.Material); // Setup vertex bindings. Note that the setup differs based on the // materials shader, so material changes can be vertex binding changes. if (lastRendered != null) { this.FinishVertexFormat(lastRendered.Material, lastRendered.VertexBuffer.VertexType); } this.SetupVertexFormat(batch.Material, vertexType); // Setup material when changed. if (!sameMaterial) { this.SetupMaterial( batch.Material, lastRendered != null ? lastRendered.Material : null); } // Draw the current batch this.DrawVertexBatch( batch.VertexBuffer, batch.VertexRanges, batch.VertexMode); drawCalls++; lastRendered = batch; } // Cleanup after rendering NativeGraphicsBuffer.Bind(GraphicsBufferType.Vertex, null); NativeGraphicsBuffer.Bind(GraphicsBufferType.Index, null); if (lastRendered != null) { this.FinishMaterial(lastRendered.Material); this.FinishVertexFormat(lastRendered.Material, lastRendered.VertexBuffer.VertexType); } if (this.renderStats != null) { this.renderStats.DrawCalls += drawCalls; } this.FinishSharedParameters(); }