void ResetDevice() { devBB.Dispose(); ResetHandlers.Reset(); for (; ;) { var result = dev.TestCooperativeLevel(); if (result.IsSuccess) { break; } if (result.Code == -2005530519) // D3DERR_DEVICENOTRESET { try { var pp = MakePresentParameters(); dev.Reset(pp); break; } catch { } } System.Threading.Thread.Sleep(100); } ResetHandlers.Restore(); devBB = dev.GetBackBuffer(0, 0); }
public void RefreshControlSwapChain(GLControlWrapper_SlimDX9 control) { if (control.SwapChain != null) { control.SwapChain.Dispose(); control.SwapChain = null; } ResetHandlers.Remove(control, "SwapChain"); var pp = new PresentParameters { BackBufferWidth = Math.Max(8, control.ClientSize.Width), BackBufferHeight = Math.Max(8, control.ClientSize.Height), BackBufferCount = 1, BackBufferFormat = Format.X8R8G8B8, DeviceWindowHandle = control.Handle, Windowed = true, PresentationInterval = control.Vsync ? PresentInterval.One : PresentInterval.Immediate }; control.SwapChain = new SwapChain(dev, pp); ResetHandlers.Add(control, "SwapChain", () => { control.SwapChain.Dispose(); control.SwapChain = null; }, () => RefreshControlSwapChain(control)); }
void RestoreRenderTarget(RenderTarget rt) { var tw = rt.Texture2d.Opaque as TextureWrapper; int w = rt.Texture2d.IntWidth; int h = rt.Texture2d.IntHeight; var d3dtex = new d3d9.Texture(dev, w, h, 1, d3d9.Usage.RenderTarget, d3d9.Format.A8R8G8B8, d3d9.Pool.Default); tw.Texture = d3dtex; //i know it's weird, we have to re-add ourselves to the list //bad design.. ResetHandlers.Add(rt, "RenderTarget", () => ResetRenderTarget(rt), () => RestoreRenderTarget(rt)); }
public RenderTarget CreateRenderTarget(int w, int h) { var d3dtex = new d3d9.Texture(dev, w, h, 1, d3d9.Usage.RenderTarget, d3d9.Format.A8R8G8B8, d3d9.Pool.Default); var tw = new TextureWrapper() { Texture = d3dtex }; var tex = new Texture2d(this, tw, w, h); RenderTarget rt = new RenderTarget(this, tw, tex); ResetHandlers.Add(rt, "RenderTarget", () => ResetRenderTarget(rt), () => RestoreRenderTarget(rt)); return(rt); }
void ResetDevice() { ResetHandlers.Reset(); for (;;) { var pp = MakePresentParameters(); try { dev.Reset(pp); } catch { } if (dev.TestCooperativeLevel().IsSuccess) { break; } System.Threading.Thread.Sleep(100); } ResetHandlers.Restore(); }
void IDisposable.Dispose() { ResetHandlers.Reset(); DestroyDevice(); d3d.Dispose(); }