예제 #1
0
        private void InitVertexBuffer()
        {
            Cube cube = new Cube();

            IntPtr verticesData = Marshal.AllocCoTaskMem(Marshal.SizeOf(cube.Vertices));
            Marshal.StructureToPtr(cube.Vertices, verticesData, true);

            BufferDescription bufferDesc = new BufferDescription()
            {
                Usage = Usage.Default,
                ByteWidth = (uint)Marshal.SizeOf(cube.Vertices),
                BindFlags = BindFlag.VertexBuffer,
                CpuAccessFlags = 0,
                MiscFlags = 0
            };

            SubresourceData InitData = new SubresourceData()
            {
                SysMem = verticesData
            };

            //D3DBuffer buffer = null;
            vertexBuffer = device.CreateBuffer(bufferDesc, InitData);

            // Set vertex buffer
            uint stride = (uint)Marshal.SizeOf(typeof(SimpleVertex));
            uint offset = 0;
            device.IA.SetVertexBuffers(
                0,
                new D3DBuffer[] { vertexBuffer },
                new uint[] { stride },
                new uint[] { offset });
            Marshal.FreeCoTaskMem(verticesData);
        }
예제 #2
0
        private void InitIndexBuffer()
        {
            Cube cube = new Cube();

            IntPtr indicesData = Marshal.AllocCoTaskMem(Marshal.SizeOf(cube.Indices));
            Marshal.StructureToPtr(cube.Indices, indicesData, true);

            BufferDescription bufferDesc = new BufferDescription()
            {
                Usage = Usage.Default,
                ByteWidth = (uint)Marshal.SizeOf(cube.Indices),
                BindFlags = BindFlag.IndexBuffer,
                CpuAccessFlags = 0,
                MiscFlags = 0
            };

            SubresourceData initData = new SubresourceData()
            {
                SysMem = indicesData
            };

            indexBuffer = device.CreateBuffer(bufferDesc, initData);
            device.IA.SetIndexBuffer(indexBuffer, Format.R32_UINT, 0);
            Marshal.FreeCoTaskMem(indicesData);
        } 
예제 #3
0
        private void InitIndexBuffer()
        {
            Cube cube = new Cube();

            IntPtr indicesData = Marshal.AllocCoTaskMem(Marshal.SizeOf(cube.Indices));
            Marshal.StructureToPtr(cube.Indices, indicesData, true);

            BufferDescription bufferDesc = new BufferDescription()
            {
                Usage = Usage.Default,
                ByteWidth = (uint)Marshal.SizeOf(cube.Indices),
                BindingOptions = BindingOptions.IndexBuffer,
                CpuAccessOptions = CpuAccessOptions.None,
                MiscellaneousResourceOptions = MiscellaneousResourceOptions.None
            };

            SubresourceData initData = new SubresourceData()
            {
                SystemMemory = indicesData
            };

            indexBuffer = device.CreateBuffer(bufferDesc, initData);
            device.IA.IndexBuffer = new IndexBuffer(indexBuffer, Format.R32UInt, 0);
            Marshal.FreeCoTaskMem(indicesData);
        }