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 GraphicsTexture CreateTexture2D(GraphicsContext graphicsContext, GraphicsHeap graphicsHeap, GraphicsBuffer textureStagingBuffer) { const uint TextureWidth = 256; const uint TextureHeight = 256; const uint TextureSize = TextureWidth * TextureHeight; const uint CellWidth = TextureWidth / 8; const uint CellHeight = TextureHeight / 8; var texture2D = graphicsHeap.CreateGraphicsTexture(GraphicsTextureKind.TwoDimensional, TextureWidth, TextureHeight); var pTextureData = textureStagingBuffer.Map <uint>(); for (uint n = 0; n < TextureSize; n++) { var x = n % TextureWidth; var y = n / TextureWidth; if ((x / CellWidth % 2) == (y / CellHeight % 2)) { pTextureData[n] = 0xFF000000; } else { pTextureData[n] = 0xFFFFFFFF; } } textureStagingBuffer.Unmap(0..(int)TextureSize); graphicsContext.Copy(texture2D, textureStagingBuffer); return(texture2D); }
static GraphicsBuffer CreateVertexBuffer(GraphicsContext graphicsContext, GraphicsBuffer vertexStagingBuffer, float aspectRatio) { var vertexBuffer = graphicsContext.Device.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Vertex, GraphicsResourceCpuAccess.None, (ulong)(sizeof(IdentityVertex) * 3)); var pVertexBuffer = vertexStagingBuffer.Map <IdentityVertex>(); pVertexBuffer[0] = new IdentityVertex { Position = new Vector3(0.0f, 0.25f * aspectRatio, 0.0f), Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f) }; pVertexBuffer[1] = new IdentityVertex { Position = new Vector3(0.25f, -0.25f * aspectRatio, 0.0f), Color = new Vector4(0.0f, 1.0f, 0.0f, 1.0f) }; pVertexBuffer[2] = new IdentityVertex { Position = new Vector3(-0.25f, -0.25f * aspectRatio, 0.0f), Color = new Vector4(0.0f, 0.0f, 1.0f, 1.0f) }; vertexStagingBuffer.Unmap(0..(sizeof(IdentityVertex) * 3)); graphicsContext.Copy(vertexBuffer, vertexStagingBuffer); return(vertexBuffer); }
static GraphicsBuffer CreateIndexBuffer(GraphicsContext graphicsContext, GraphicsBuffer indexStagingBuffer) { var indexBuffer = graphicsContext.Device.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Index, GraphicsResourceCpuAccess.None, sizeof(ushort) * 6); 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); }
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); }