Exemple #1
1
        public RenderContainer(SwapChainDescription swapChainDescription, RenderControl control)
        {
            try
            {
                _swapChainDescription = swapChainDescription;

                using (Factory1 factory = new Factory1())
                using (Adapter adapter = factory.GetAdapter(0))
                {
                    Device11 = new Dx11ChainedDevice(adapter, _swapChainDescription);
                    Device10 = new Dx10Device(adapter);
                }

                GraphicsDevice = new GenericGraphicsDevice(Device11.Device);
                SpriteBatch = new SpriteBatch(GraphicsDevice);

                Reset(control.Width, control.Height);

                control.Resize += OnRenderControlResize;
            }
            catch
            {
                Dispose();
                throw;
            }
        }
        public override void Hook()
        {
            DebugMessage("Hook: Begin");

            // Determine method addresses in Direct3D10.Device, and DXGI.SwapChain
            if (_d3d10_1VTblAddresses == null)
            {
                _d3d10_1VTblAddresses = new List<IntPtr>();
                _dxgiSwapChainVTblAddresses = new List<IntPtr>();
                DebugMessage("Hook: Before device creation");
                using (var factory = new Factory1())
                {
                    using (
                        var device = new Device1(factory.GetAdapter(0), DeviceCreationFlags.None,
                            FeatureLevel.Level_10_1))
                    {
                        DebugMessage("Hook: Device created");
                        _d3d10_1VTblAddresses.AddRange(GetVTblAddresses(device.NativePointer,
                            D3D10_1_DEVICE_METHOD_COUNT));

                        using (var renderForm = new RenderForm())
                        {
                            using (
                                var sc = new SwapChain(factory, device,
                                    DXGI.CreateSwapChainDescription(renderForm.Handle)))
                            {
                                _dxgiSwapChainVTblAddresses.AddRange(GetVTblAddresses(sc.NativePointer,
                                    DXGI.DXGI_SWAPCHAIN_METHOD_COUNT));
                            }
                        }
                    }
                }
            }

            // We will capture the backbuffer here
            DXGISwapChain_PresentHook = new Hook<DXGISwapChain_PresentDelegate>(
                _dxgiSwapChainVTblAddresses[(int) DXGI.DXGISwapChainVTbl.Present],
                new DXGISwapChain_PresentDelegate(PresentHook),
                this);

            // We will capture target/window resizes here
            DXGISwapChain_ResizeTargetHook = new Hook<DXGISwapChain_ResizeTargetDelegate>(
                _dxgiSwapChainVTblAddresses[(int) DXGI.DXGISwapChainVTbl.ResizeTarget],
                new DXGISwapChain_ResizeTargetDelegate(ResizeTargetHook),
                this);

            /*
             * Don't forget that all hooks will start deactivated...
             * The following ensures that all threads are intercepted:
             * Note: you must do this for each hook.
             */
            DXGISwapChain_PresentHook.Activate();

            DXGISwapChain_ResizeTargetHook.Activate();

            Hooks.Add(DXGISwapChain_PresentHook);
            Hooks.Add(DXGISwapChain_ResizeTargetHook);
        }
Exemple #3
0
 public static Dx10Device CreateDefaultAdapter()
 {
     using (Factory1 factory = new Factory1())
     using (Adapter adapter = factory.GetAdapter(0))
         return new Dx10Device(adapter);
 }