private void Flush() { modelBuffer.Bind(); modelBuffer.SetData(itemPool, itemCount); foreach (var attribute in descriptor.AttributeFormats) { var value = attribute.Value; material.Program.Attribute(attribute.Key).VertexAttributePointer( value.ComponentCount, value.ComponentType, value.IsNormalized, value.Stride, value.Offset ); material.Program.Attribute(attribute.Key).EnableVertexAttributeArray(); } material.Program.Use(); if (material.Matrix4Uniforms != null) { foreach (var matrix in material.Matrix4Uniforms) { var m = matrix.Value; material.Program.Uniform(matrix.Key).Set(ref m); } } if (material.Int32Uniforms != null) { foreach (var pair in material.Int32Uniforms) { material.Program.Uniform(pair.Key).Set(pair.Value); } } indicesBuffer.Bind(); for (int i = 0; i < textureCount; i++) { material.Program.Uniform("uSampler" + i).Set(i); context.Textures[i] = textures[i]; } int offset = 0; int vertexCount = indicesCount; context.DrawElements(WebGLDrawMode.TRIANGLES, offset, WebGLType.UNSIGNED_SHORT, vertexCount); itemCount = 0; indicesCount = 0; textureCount = 0; Flushed?.Invoke(this, EventArgs.Empty); }
public RenderBatch(WebGLContext context, int elementCount) { this.context = context; this.descriptor = new TDescriptor(); itemPool = new DefaultVertexFormat[elementCount * descriptor.ElementVertexCount]; modelBuffer = context.CreateBuffer(BufferType.ARRAY_BUFFER, BufferUsage.STREAM_DRAW); modelBuffer.Bind(); modelBuffer.SetDataSize(itemPool.Length * descriptor.ByteSize); System.Console.WriteLine("Buffer size: " + itemPool.Length * descriptor.ByteSize); indicesBuffer = context.CreateBuffer(BufferType.ELEMENT_ARRAY_BUFFER, BufferUsage.STATIC_DRAW); indicesBuffer.Bind(); indicesBuffer.SetData(descriptor.CreateIndices(elementCount)); textures = new Texture2D[10]; }