public async Task RenderFrame() { await _context.ClearColorAsync(0, 0, 0, 1); await _context.ClearAsync(BufferBits.COLOR_BUFFER_BIT); Buffer.BlockCopy(spriteEngine.vertices, 0, byteArr, 0, byteArr.Length); await _context.BufferDataAsync(BufferType.ARRAY_BUFFER, byteArr, BufferUsageHint.DYNAMIC_DRAW); // this matrix will convert from pixels to clip space Matrix4x4 myMatrix = Matrix4x4.CreateOrthographic(_canvasReference.Width, _canvasReference.Height, 1, -1); // this matrix will translate our quad to dstX, dstY Matrix4x4 transMatrix = Matrix4x4.CreateTranslation(transVector); myMatrix = Matrix4x4.Multiply(myMatrix, transMatrix); // Set the matrix. await _context.UniformMatrixAsync(u_matrix_location, false, new float[16] { myMatrix.M11, myMatrix.M12, myMatrix.M13, myMatrix.M14, myMatrix.M21, myMatrix.M22, myMatrix.M23, myMatrix.M24, myMatrix.M31, myMatrix.M32, myMatrix.M33, myMatrix.M34, myMatrix.M41, myMatrix.M42, myMatrix.M43, myMatrix.M44 }); await _context.DrawArraysAsync(Primitive.TRIANGLES, 0, 6 *spriteEngine.spriteCount); spriteEngine.spriteCount = 0; }
public async static Task <VBO> BuildAsync(WebGLContext gl, int count, float[] data) { var dataBuffer = await gl.CreateBufferAsync(); await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, dataBuffer); await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, data, BufferUsageHint.STATIC_DRAW); return(new VBO(gl, count, data, dataBuffer)); }
private static async void InitStaticBuffer(WebGLContext gl) { vertexBuffer = await gl.CreateBufferAsync(); await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, vertexBuffer); { var vertexArrayDef = new[] { -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, }; await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, vertexArrayDef, BufferUsageHint.STATIC_DRAW); await gl.EnableVertexAttribArrayAsync(shader.PositionAttributeLocaltion); await gl.VertexAttribPointerAsync(shader.PositionAttributeLocaltion, 2, DataType.FLOAT, false, sizeof(float) * 2, 0); } texBuffer = await gl.CreateBufferAsync(); await gl.BindBufferAsync(BufferType.ARRAY_BUFFER, texBuffer); { var texArrayDef = new[] { 0, 0, 1, 0, 1, 1, 0, 1 }; await gl.BufferDataAsync(BufferType.ARRAY_BUFFER, texArrayDef, BufferUsageHint.STATIC_DRAW); await gl.EnableVertexAttribArrayAsync(shader.TexturePositionAttributeLocaltion); await gl.VertexAttribPointerAsync(shader.TexturePositionAttributeLocaltion, 2, DataType.FLOAT, false, sizeof(float) * 2, 0); } }
public async Task <GLBuffer <TBufferObject, TBufferType> > ConsumeAndBindBufferAsync(TBufferObject obj) { ResetObject(); var buffer = await _context.CreateBufferAsync(); await _context.BindBufferAsync(_bufferType, buffer); // select await _context.BufferDataAsync(_bufferType, GetBuffer(obj), _bufferUsageHint); await PostProcessBufferAsync(obj, buffer); LastState = LastStateType.Success; GLObjectValue = buffer; return(this); }