Example #1
0
        private bool InitializeBuffers(Device device)
        {
            try
            {
                // Set the number of the vertices and indices in the vertex and index array, accordingly.
                VertexCount = 6;
                IndexCount  = 6;

                // Create the vertex array.
                var vertices = new TextureShader.Vertex[VertexCount];

                // Initialize vertex array to zeroes at first.
                foreach (var vertex in vertices)
                {
                    vertex.SetToZero();
                }

                // Create the index array.
                var indices = new int[IndexCount];

                // Load the index array with data.
                for (var i = 0; i < IndexCount; i++)
                {
                    indices[i] = i;
                }

                // Set up the description of the static vertex buffer.
                var vertexBuffer = new BufferDescription()
                {
                    Usage               = ResourceUsage.Dynamic,
                    SizeInBytes         = Utilities.SizeOf <TextureShader.Vertex>() * VertexCount,
                    BindFlags           = BindFlags.VertexBuffer,
                    CpuAccessFlags      = CpuAccessFlags.Write,
                    OptionFlags         = ResourceOptionFlags.None,
                    StructureByteStride = 0
                };

                // Create the vertex buffer.
                VertexBuffer = Buffer.Create(device, vertices, vertexBuffer);

                // Create the index buffer.
                IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        private bool InitializeBuffers(Device device)
        {
            try
            {
                // Set the number of the vertices and indices in the vertex and index array, accordingly.
                VertexCount = 6;
                IndexCount = 6;

                // Create the vertex array.
                var vertices = new TextureShader.Vertex[VertexCount];

                // Initialize vertex array to zeroes at first.
                foreach (var vertex in vertices)
                    vertex.SetToZero();

                // Create the index array.
                var indices = new int[IndexCount];

                // Load the index array with data.
                for (var i = 0; i < IndexCount; i++)
                    indices[i] = i;

                // Set up the description of the static vertex buffer.
                var vertexBuffer = new BufferDescription()
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<TextureShader.Vertex>() * VertexCount,
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                };

                // Create the vertex buffer.
                VertexBuffer = Buffer.Create(device, vertices, vertexBuffer);

                // Create the index buffer.
                IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return true;
            }
            catch
            {
                return false;
            }
        }