Пример #1
0
        public override unsafe void Init(ScreenData data)
        {
            GraphicalConfiguration config = new GraphicalConfiguration
            {
                ForceFullscreenAsWindowed = false,
                ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER.DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
                VSyncCount = 0,
                BackBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM,
                DepthStencilFormat = DXGI_FORMAT_D32_FLOAT,
                FullscreenScalingStrategy = DXGI_MODE_SCALING.DXGI_MODE_SCALING_UNSPECIFIED,
                MultiSamplingStrategy = new DXGI_SAMPLE_DESC(1, 0),
                RequiredDirect3DLevel = D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_1,
                ScalingStrategy = DXGI_SCALING.DXGI_SCALING_NONE,
                SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_DISCARD
            };

            DeviceManager.Initialize(config, data);
            _renderer.Init(config, DeviceManager.Manager.Device);
        }
Пример #2
0
 public abstract void Init(GraphicalConfiguration config, ID3D12Device *device);
Пример #3
0
        public override void Init(GraphicalConfiguration config, ID3D12Device *device)
        {
            bool z = new RgbaColor() == new RgbaColor();

            _pipelineManager = new PipelineManager(ComPtr <ID3D12Device> .CopyFromPointer(device));
            _allocator       = new GpuAllocator(ComPtr <ID3D12Device> .CopyFromPointer(device));

            var verticesDesc = new GpuResourceDesc(
                GpuResourceFormat.Buffer((ulong)sizeof(Vertex) * 3),
                GpuMemoryType.CpuWriteOptimized,
                D3D12_RESOURCE_STATE_GENERIC_READ,
                GpuAllocFlags.ForceAllocateComitted
                );

            //var triangleVertices = stackalloc Vertex[3] {
            //    new Vertex
            //    {
            //        Position = new Vector3(0.0f, 0.25f, 0.0f),
            //        Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f)
            //    },
            //    new Vertex
            //    {
            //        Position = new Vector3(0.25f, -0.25f, 0.0f),
            //        Color = new Vector4(0.0f, 1.0f, 0.0f, 1.0f)
            //    },
            //    new Vertex
            //    {
            //        Position = new Vector3(-0.25f, -0.25f, 0.0f),
            //        Color = new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
            //    },
            //};

            var cubeVertices = stackalloc Vertex[8]
            {
                new Vertex(new Vector3(-0.5f, -0.5f, -0.5f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f)),
                new Vertex(new Vector3(-0.5f, -0.5f, 0.5f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)),
                new Vertex(new Vector3(-0.5f, 0.5f, -0.5f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f)),
                new Vertex(new Vector3(-0.5f, 0.5f, 0.5f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f)),
                new Vertex(new Vector3(0.5f, -0.5f, -0.5f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f)),
                new Vertex(new Vector3(0.5f, -0.5f, 0.5f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f)),
                new Vertex(new Vector3(0.5f, 0.5f, -0.5f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f)),
                new Vertex(new Vector3(0.5f, 0.5f, 0.5f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f))
            };

            var cubeIndices = stackalloc ushort[36]
            {
                0,
                2,
                1, // -x
                1,
                2,
                3,

                4,
                5,
                6, // +x
                5,
                7,
                6,

                0,
                1,
                5, // -y
                0,
                5,
                4,

                2,
                6,
                7, // +y
                2,
                7,
                3,

                0,
                4,
                6, // -z
                0,
                6,
                2,

                1,
                3,
                7, // +z
                1,
                7,
                5,
            };

            var vertices = _allocator.AllocateVertexBuffer <Vertex>(8, GpuMemoryType.CpuWriteOptimized, GpuAllocFlags.ForceAllocateComitted);
            var indices  = _allocator.AllocateIndexBuffer <ushort>(36, GpuMemoryType.CpuWriteOptimized, GpuAllocFlags.ForceAllocateComitted);

            vertices.Resource.Map(0);
            Unsafe.CopyBlock(vertices.Resource.CpuAddress, cubeVertices, (uint)sizeof(Vertex) * 8);
            vertices.Resource.Unmap(0);

            indices.Resource.Map(0);
            Unsafe.CopyBlock(indices.Resource.CpuAddress, cubeIndices, (uint)sizeof(ushort) * 36);
            indices.Resource.Unmap(0);

            _vertexBuffer = vertices;
            _indexBuffer  = indices;

            _rootSig = RootSignature.Create(device, default, default);