Пример #1
0
        void generateQuad()
        {
            // Setup vertices for a single uv-mapped quad made from two triangles
            VertexData[] quadCorners =
            {
                new VertexData
                {
                    pos    = new Vector3(1f, 1f, 0f),
                    uv     = new Vector2(1.0f, 1.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },

                new VertexData
                {
                    pos    = new Vector3(-1.0f, 1.0f, 0f),
                    uv     = new Vector2(0.0f, 1.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },

                new VertexData
                {
                    pos    = new Vector3(-1.0f, -1.0f, 0f),
                    uv     = new Vector2(0.0f, 0.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },


                new VertexData
                {
                    pos    = new Vector3(1.0f, -1.0f, 0f),
                    uv     = new Vector2(1.0f, 0.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },
            };

            // Setup indices
            var indices = new uint[] { 0, 1, 2, 2, 3, 0 };

            indexCount = (uint)indices.Length;

            var device = mManager.Configuration.Device;

            Debug.Assert(device != null);

            // Create buffers
            // For the sake of simplicity we won't stage the vertex data to the gpu memory

            // Vertex buffer
            {
                var bufferSize = (uint)(Marshal.SizeOf <VertexData>() * quadCorners.Length);
                vertexBuffer = new BufferInfo(
                    mManager.Configuration.Partition,
                    MgBufferUsageFlagBits.VERTEX_BUFFER_BIT,
                    MgMemoryPropertyFlagBits.HOST_VISIBLE_BIT | MgMemoryPropertyFlagBits.HOST_COHERENT_BIT,
                    bufferSize);
                vertexBuffer.SetData <VertexData>(bufferSize, quadCorners, 0, quadCorners.Length);
            }


            // Index buffer
            {
                var bufferSize = indexCount * sizeof(uint);
                indexBuffer = new BufferInfo(
                    mManager.Configuration.Partition,
                    MgBufferUsageFlagBits.INDEX_BUFFER_BIT,
                    MgMemoryPropertyFlagBits.HOST_VISIBLE_BIT | MgMemoryPropertyFlagBits.HOST_COHERENT_BIT,
                    bufferSize);
                indexBuffer.SetData(bufferSize, indices, 0, (int)indexCount);
            }
        }