Beispiel #1
0
            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);
            }
Beispiel #2
0
            static GraphicsMemoryRegion <GraphicsResource> CreateVertexBufferRegion(GraphicsContext graphicsContext, GraphicsBuffer vertexBuffer, GraphicsBuffer vertexStagingBuffer, float aspectRatio)
            {
                var vertexBufferRegion = vertexBuffer.Allocate(SizeOf <TextureVertex>() * 3, alignment: 16);
                var pVertexBuffer      = vertexStagingBuffer.Map <TextureVertex>(in vertexBufferRegion);

                pVertexBuffer[0] = new TextureVertex {
                    Position = new Vector3(0.0f, 0.25f * aspectRatio, 0.0f),
                    UV       = new Vector2(1.0f, 0.0f)
                };

                pVertexBuffer[1] = new TextureVertex {
                    Position = new Vector3(0.25f, -0.25f * aspectRatio, 0.0f),
                    UV       = new Vector2(0.0f, 1.0f)
                };

                pVertexBuffer[2] = new TextureVertex {
                    Position = new Vector3(-0.25f, -0.25f * aspectRatio, 0.0f),
                    UV       = new Vector2(0.0f, 0.0f)
                };

                vertexStagingBuffer.UnmapAndWrite(in vertexBufferRegion);
                return(vertexBufferRegion);
            }