static GraphicsBuffer CreateVertexBuffer(GraphicsContext graphicsContext, GraphicsHeap graphicsHeap, GraphicsBuffer vertexStagingBuffer, float aspectRatio) { var vertexBuffer = graphicsHeap.CreateGraphicsBuffer(GraphicsBufferKind.Vertex, (ulong)(sizeof(TextureVertex) * 3), (ulong)sizeof(TextureVertex)); var pVertexBuffer = vertexStagingBuffer.Map <TextureVertex>(); pVertexBuffer[0] = new TextureVertex { Position = new Vector3(0.0f, 0.25f * aspectRatio, 0.0f), UV = new Vector2(0.5f, 1.0f), }; pVertexBuffer[1] = new TextureVertex { Position = new Vector3(0.25f, -0.25f * aspectRatio, 0.0f), UV = new Vector2(1.0f, 0.0f), }; pVertexBuffer[2] = new TextureVertex { Position = new Vector3(-0.25f, -0.25f * aspectRatio, 0.0f), UV = new Vector2(0.0f, 0.0f), }; vertexStagingBuffer.Unmap(0..(sizeof(TextureVertex) * 3)); graphicsContext.Copy(vertexBuffer, vertexStagingBuffer); return(vertexBuffer); }
static GraphicsBuffer CreateConstantBuffer(GraphicsHeap graphicsHeap) { var constantBuffer = graphicsHeap.CreateGraphicsBuffer(GraphicsBufferKind.Constant, 256, 64); var pConstantBuffer = constantBuffer.Map <Matrix4x4>(); pConstantBuffer[0] = Matrix4x4.Identity; constantBuffer.Unmap(0..sizeof(Matrix4x4)); return(constantBuffer); }
static GraphicsBuffer CreateIndexBuffer(GraphicsContext graphicsContext, GraphicsHeap graphicsHeap, GraphicsBuffer indexStagingBuffer) { var indexBuffer = graphicsHeap.CreateGraphicsBuffer(GraphicsBufferKind.Index, sizeof(ushort) * 6, sizeof(ushort)); var pIndexBuffer = indexStagingBuffer.Map <ushort>(); pIndexBuffer[0] = 0; pIndexBuffer[1] = 1; pIndexBuffer[2] = 2; pIndexBuffer[3] = 0; pIndexBuffer[4] = 2; pIndexBuffer[5] = 3; indexStagingBuffer.Unmap(0..(sizeof(ushort) * 6)); graphicsContext.Copy(indexBuffer, indexStagingBuffer); return(indexBuffer); }