Beispiel #1
0
        protected override void InitD3D(out IntPtr d3DDevicePtr)
        {
            LoadDxgiDll();
            var scd = new SwapChainDescription
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription {
                    Format = DXGI_FORMAT_R8G8B8A8_UNORM
                },
                Usage             = DXGI_USAGE_RENDER_TARGET_OUTPUT,
                OutputHandle      = Form.Handle,
                SampleDescription = new SampleDescription {
                    Count = 1
                },
                IsWindowed = true
            };

            unsafe
            {
                IntPtr pSwapChain        = IntPtr.Zero;
                IntPtr pDevice           = IntPtr.Zero;
                IntPtr pImmediateContext = IntPtr.Zero;
                int    ret = D3D11CreateDeviceAndSwapChain((void *)IntPtr.Zero, D3D_DRIVER_TYPE_HARDWARE, (void *)IntPtr.Zero, 0, (void *)IntPtr.Zero, 0, D3D11_SDK_VERSION, &scd, &pSwapChain, &pDevice, (void *)IntPtr.Zero, &pImmediateContext);
                _swapChain   = pSwapChain;
                _device      = pDevice;
                d3DDevicePtr = pImmediateContext;

                if (ret >= 0)
                {
                    _swapchainRelease     = GetDelegate <VTableFuncDelegate>(GetVTableFuncAddress(_swapChain, VTableIndexes.DXGISwapChainRelease));
                    _deviceRelease        = GetDelegate <VTableFuncDelegate>(GetVTableFuncAddress(_device, VTableIndexes.D3D11DeviceRelease));
                    _deviceContextRelease = GetDelegate <VTableFuncDelegate>(GetVTableFuncAddress(d3DDevicePtr, VTableIndexes.D3D11DeviceContextRelease));
                }
            }
        }
Beispiel #2
0
        protected override void InitD3D(out IntPtr d3DDevicePtr)
        {
            _pD3D = Direct3DCreate9(D3D9SdkVersion);
            if (_pD3D == IntPtr.Zero)
            {
                throw new Exception("Failed to create D3D.");
            }

            var parameters = new D3DPresentParameters
            {
                Windowed         = true,
                SwapEffect       = 1,
                BackBufferFormat = 0
            };

            var createDevicePtr = GetVTableFuncAddress(_pD3D, VTableIndexes.Direct3D9CreateDevice);
            var createDevice    = GetDelegate <CreateDeviceDelegate>(createDevicePtr);

            if (createDevice(_pD3D, 0, 1, Form.Handle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, ref parameters, out d3DDevicePtr) < 0)
            {
                throw new Exception("Failed to create device.");
            }
            _d3DDeviceRelease = GetDelegate <VTableFuncDelegate>(GetVTableFuncAddress(D3DDevicePtr, VTableIndexes.Direct3DDevice9Release));
            _d3DRelease       = GetDelegate <VTableFuncDelegate>(GetVTableFuncAddress(_pD3D, VTableIndexes.Direct3D9Release));
        }