Ejemplo n.º 1
0
            static GraphicsBuffer CreateVertexBuffer(GraphicsContext graphicsContext, GraphicsHeap graphicsHeap, GraphicsBuffer vertexStagingBuffer, float aspectRatio)
            {
                var vertexBuffer  = graphicsHeap.CreateGraphicsBuffer(GraphicsBufferKind.Vertex, (ulong)(sizeof(IdentityVertex) * 3), (ulong)sizeof(IdentityVertex));
                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);
            }
Ejemplo n.º 2
0
            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);
            }
Ejemplo n.º 3
0
            static GraphicsMemoryRegion <GraphicsResource> CreateVertexBufferRegion(GraphicsContext graphicsContext, GraphicsBuffer vertexBuffer, GraphicsBuffer vertexStagingBuffer, float aspectRatio)
            {
                var vertexBufferRegion = vertexBuffer.Allocate(SizeOf <IdentityVertex>() * 4, alignment: 16);
                var pVertexBuffer      = vertexStagingBuffer.Map <IdentityVertex>(in vertexBufferRegion);

                pVertexBuffer[0] = new IdentityVertex {                         //
                    Position = new Vector3(-0.25f, 0.25f * aspectRatio, 0.0f),  //   y          in this setup
                    Color    = new Vector4(1.0f, 0.0f, 0.0f, 1.0f),             //   ^     z    the origin o
                };                                                              //   |   /      is in the middle
                                                                                //   | /        of the rendered scene
                pVertexBuffer[1] = new IdentityVertex {                         //   o------>x
                    Position = new Vector3(0.25f, 0.25f * aspectRatio, 0.0f),   //
                    Color    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f),             //   0 ----- 1
                };                                                              //   | \     |
                                                                                //   |   \   |
                pVertexBuffer[2] = new IdentityVertex {                         //   |     \ |
                    Position = new Vector3(0.25f, -0.25f * aspectRatio, 0.0f),  //   3-------2
                    Color    = new Vector4(0.0f, 0.0f, 1.0f, 1.0f),             //
                };

                pVertexBuffer[3] = new IdentityVertex {
                    Position = new Vector3(-0.25f, -0.25f * aspectRatio, 0.0f),
                    Color    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                };

                vertexStagingBuffer.UnmapAndWrite(in vertexBufferRegion);
                return(vertexBufferRegion);
            }
Ejemplo n.º 4
0
            static GraphicsMemoryRegion <GraphicsResource> CreateVertexBufferRegion(GraphicsContext graphicsContext, GraphicsBuffer vertexBuffer, GraphicsBuffer vertexStagingBuffer, float aspectRatio)
            {
                var vertexBufferRegion = vertexBuffer.Allocate(SizeOf <IdentityVertex>() * 3, alignment: 16);
                var pVertexBuffer      = vertexStagingBuffer.Map <IdentityVertex>(in vertexBufferRegion);

                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.UnmapAndWrite(in vertexBufferRegion);
                return(vertexBufferRegion);
            }