public virtual void Cleanup() { Context?.ClearState(); Context?.Flush(); BackBuffer?.Dispose(); BackBuffer = null; ZBuffer?.Dispose(); ZBuffer = null; RenderTargetViewRef?.Dispose(); RenderTargetViewRef = null; DepthStencilSRVRef?.Dispose(); DepthStencilSRVRef = null; DepthStencilViewRef?.Dispose(); DepthStencilViewRef = null; FactoryDWrite?.Dispose(); FactoryDWrite = null; Factory2D?.Dispose(); Factory2D = null; RenderTarget2D?.Dispose(); RenderTarget2D = null; Context?.Dispose(); DeviceRef?.Dispose(); DeviceRef = null; }
public void Dispose() { GL.DeleteFramebuffer(Id); DepthBuffer.Dispose(); BackBuffer.Dispose(); REngine.CheckGLError(); }
protected void ResizeSwapChain() { Device.PrintLiveObjects(); Debug.WriteLine("===="); foreach (var resource in Device.PresenterResources) { resource.Dispose(); } for (int i = 0; i < BackBufferCount; i++) { BackBuffers[i].Dispose(); } BackBuffer.Dispose(); Device.PrintLiveObjects(); NativeSwapChain.ResizeBuffers( BackBufferCount, Description.Width, Description.Height, Format.B8G8R8A8_UNorm, SwapChainFlags.None); BackBuffer.Initialize(NativeSwapChain.GetBackBuffer <Resource>(BackBufferIndex)); for (int i = 0; i < BackBufferCount; i++) { BackBuffers[i].Initialize(NativeSwapChain.GetBackBuffer <Resource>(i)); } foreach (var resource in Device.PresenterResources) { resource.Recreate(); } }
//--------------------// #region Dispose protected override void OnDispose() { Log.Info("Disposing engine\nLast framerate: " + Performance.Fps); // Dispose scenes and views ExtraRender = null; foreach (var view in Views) { view.Scene.Dispose(); } base.OnDispose(); // Shutdown music Music?.Dispose(); // Dispose cached assets Cache?.Dispose(); // Dispose default meshes SimpleSphere?.Dispose(); SimpleBox?.Dispose(); // Dispose Direct3D device BackBuffer?.Dispose(); Device?.Dispose(); // Dispose DirectSound objects //_listener?.Dispose(); AudioDevice?.Dispose(); _direct3D?.Dispose(); // Dispose debug window _debugForm?.Dispose(); }
public void Dispose() { BackBufferRTV.Dispose(); BackBuffer.Dispose(); SwapChain.Dispose(); Device.Dispose(); DeviceContext.Dispose(); }
private void DestroyBuffers() { ImmediateContext.OutputMerger.SetRenderTargets((RenderTargetView)null); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); }
public void Dispose() { RenderTargetView.Dispose(); BackBuffer.Dispose(); DeviceContext.Dispose(); D11Device.Dispose(); _swapChain.Dispose(); factory.Dispose(); }
public virtual void UpdateDevice(GameContainer container) { DeviceContext = container.DeviceContext; Resource.UpdateDevice(container); BackBuffer?.Dispose(); BackBuffer = null; //BackBuffer = new Bitmap1(container.DeviceContext, container.D2D1BackBuffer.PixelSize); }
public void Dispose() { Window.Dispose(); Device.Dispose(); SwapChain.Dispose(); BackBuffer.Dispose(); RenderTargetView.Dispose(); Texture.Dispose(); TextureShaderResourceView.Dispose(); }
public void DestroyBuffers() { if (BackBuffer != null) { ImmediateContext.OutputMerger.SetRenderTargets((RenderTargetView)null); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); BackBuffer = null; } }
public void Dispose() { VertexBuffer.Dispose(); RenderView.Dispose(); Device.ImmediateContext.ClearState(); Device.ImmediateContext.Flush(); Device.ImmediateContext.Dispose(); Device.Dispose(); SwapChain.Dispose(); VertexShader.Dispose(); PixelShader.Dispose(); InputLayout.Dispose(); BackBuffer.Dispose(); Factory.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_dynamicRenderEventPublisher != null) { _dynamicRenderEventPublisher.Cancel(); _dynamicRenderEventPublisher.Dispose(); _dynamicRenderEventPublisher = null; } if (_vtkRenderWindow != null) { _vtkRenderWindow.Dispose(); _vtkRenderWindow = null; } if (_vtkRenderer != null) { _vtkRenderer.Dispose(); _vtkRenderer = null; } if (_sceneGraphRoot != null) { _sceneGraphRoot.Dispose(); _sceneGraphRoot = null; } if (_imageBuffer != null) { _imageBuffer.Dispose(); _imageBuffer = null; } if (_overlayBuffer != null) { _overlayBuffer.Dispose(); _overlayBuffer = null; } if (_finalBuffer != null) { _finalBuffer.Dispose(); _finalBuffer = null; } } }
/// <summary> /// Copies any current content to the back buffer so that drawing should occur on the /// back buffer (instead of the fore-buffer). Calling draw methods without /// calling this may cause exceptions. /// </summary> /// <param name="preserve">Boolean, true if the front buffer content should be copied to the back buffer /// where drawing will be taking place.</param> public void StartDrawing(bool preserve) { Bitmap backBuffer = new Bitmap(BufferRectangle.Width, BufferRectangle.Height); if (Buffer != null && preserve && Buffer.Width == backBuffer.Width && Buffer.Height == backBuffer.Height) { Graphics g = Graphics.FromImage(backBuffer); g.DrawImageUnscaled(Buffer, 0, 0); } if (BackBuffer != null && BackBuffer != Buffer) { BackBuffer.Dispose(); } BackBuffer = backBuffer; OnStartDrawing(); }
/// <summary> /// Resets the engine /// </summary> private void Reset() { // Set flag to prevent infinite loop of resets _isResetting = true; #region Cleanup Log.Info("Clearing Direct3D resources"); BackBuffer.Dispose(); DeviceLost?.Invoke(); #endregion #region Wait // Wait in case the device isn't ready to be reset while (Device.TestCooperativeLevel() == ResultCode.DeviceLost) { Thread.Sleep(100); WinForms.Application.DoEvents(); } // Catch internal driver errors var result = Device.TestCooperativeLevel(); if (result != ResultCode.DeviceNotReset && result != ResultCode.Success) { throw new Direct3D9Exception(result); } #endregion #region Reset Log.Info("Resetting Direct3D device"); Log.Info("Presentation parameters:\n" + PresentParams); Device.Reset(PresentParams); // Setup the default values for the Direct3D device and restore resources SetupTextureFiltering(); RenderViewport = Device.Viewport; BackBuffer = Device.GetBackBuffer(0, 0); DeviceReset?.Invoke(); State.Reset(); Performance.Reset(); #endregion _isResetting = NeedsReset = false; }
public void Shutdown() { // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception. _swapChain?.SetFullscreenState(false, null); _alphaEnableBlendingState?.Dispose(); _alphaEnableBlendingState = null; _alphaDisableBlendingState?.Dispose(); _alphaDisableBlendingState = null; BackBuffer?.Dispose(); BackBuffer = null; _depthDisabledStencilState?.Dispose(); _depthDisabledStencilState = null; _rasterState?.Dispose(); _rasterState = null; DepthStencilView?.Dispose(); DepthStencilView = null; _depthStencilState?.Dispose(); _depthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; _renderTargetView?.Dispose(); _renderTargetView = null; DeviceContext?.Dispose(); DeviceContext = null; Device?.Dispose(); Device = null; BackBuffer?.Dispose(); BackBuffer = null; _swapChain?.Dispose(); _swapChain = null; }
public void Dispose() { if (IsDisposed) { return; } if (RenderContext != null) { RenderContext.Dispose(); } if (BackBuffer != null) { BackBuffer.Dispose(); } if (DepthStencilBuffer != null) { DepthStencilBuffer.Dispose(); } //if (Factory != null) //Factory.Dispose(); if (swapChain != null) { swapChain.Dispose(); } GraphicsObject[] created = CreatedObjects.ToArray(); for (int i = 0; i < created.Length; i++) { if (!created[i].IsDisposed) { Log.Warning("{0} was not disposed! Created at:\r\n{1}", created[i].GetType().Name, created[i].CreationStack); created[i].Dispose(); } } CreatedObjects.Clear(); if (Device != null) { Device.Dispose(); } IsDisposed = true; }
/// <inheritdoc /> public override void Destroy() { base.Destroy(); lock (Renderer.Locker) { CanRender = false; _bloomEffect.Destroy(); _ambientOcclusion.Destroy(); RenderHandle = IntPtr.Zero; lock (Locker) { LayerCollectors.Clear(); } Constants.Dispose(); RenderTarget2D?.Dispose(); BackBuffer?.Dispose(); Buffer0?.Dispose(); Buffer1?.Dispose(); Buffer2?.Dispose(); Buffer3?.Dispose(); BufferDownscaleHalf0?.Dispose(); BufferDownscaleHalf1?.Dispose(); BufferDownscaleQuarter0?.Dispose(); BufferDownscaleQuarter1?.Dispose(); DepthStencilBuffer?.Dispose(); SwapChain?.Dispose(); BackBuffer = null; Buffer0 = null; Buffer1 = null; Buffer2 = null; Buffer3 = null; } }
public void UnloadDirect3D() { if (!Ready) { return; } TextureCache.Dispose(); DefaultTextureView.Dispose(); DefaultTexture.Dispose(); SampleState.Dispose(); DefaultEffect.Dispose(); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); Device.Dispose(); }
protected override void WindowResize(int width, int height) { base.WindowResize(width, height); Device.ImmediateContext.ClearState(); _renderTarget2D.Dispose(); BackBuffer.Dispose(); RenderView.Dispose(); _surface?.Dispose(); SwapChain.ResizeBuffers(1, 0, 0, Format.R8G8B8A8_UNorm, SwapChainFlags.None); BackBuffer = Resource.FromSwapChain <Texture2D>(SwapChain, 0); RenderView = new RenderTargetView(Device, BackBuffer); _surface = BackBuffer.QueryInterface <Surface>(); _renderTarget2D = new RenderTarget(Factory2D, _surface, new RenderTargetProperties(new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied))); }
public void ExitAndRelease() { try { D2Ddevice.ImmediateContext.ClearState(); //设备即时上下文清理状态 D2Ddevice.ImmediateContext.Flush(); //设备即时上下文刷新 D2Ddevice.Dispose(); //设备销毁 D2Ddevice.Dispose(); //设备销毁 SwapChain.Dispose(); //基础交换链销毁 DXGIFactory.Dispose(); //基础工厂销毁 BackBufferView.Dispose(); //后备缓冲视图销毁 BackBuffer.Dispose(); //后备缓冲销毁 } catch (Exception) { return; } }
/// <inheritdoc /> protected override void Dispose(bool disposing) { if (disposing) { if (Buffer != BackBuffer && Buffer != null) { Buffer.Dispose(); Buffer = null; } if (BackBuffer != null) { BackBuffer.Dispose(); BackBuffer = null; } BufferEnvelope = null; BufferRectangle = Rectangle.Empty; IsInitialized = false; } base.Dispose(disposing); }
/// <summary> /// Updates the backbuffer /// </summary> public void UpdateBackBuffer() { if (BackBuffer != null) { BackBuffer.Dispose(); } Size size = GetSize(); BackBuffer = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb); Graphics gfx = Graphics.FromImage(BackBuffer); gfx.Clear(BackColor); if (_useHatch) { using (HatchBrush brush = new HatchBrush(_hatchStyle, _hatchForeColor, _hatchBackColor)) { gfx.FillRectangle(brush, new Rectangle(Point.Empty, size)); } } Point origin = GetOrigin(); if (_image != null && !UseCanvas) { gfx.DrawImage(ImageAlpha != 1 ? BitmapTransparency(_image, ImageAlpha) : _image, origin); } OnAfterDrawOnBackbuffer(ref gfx, ref origin); if (gfx != null) { gfx.Dispose(); } // Flip to screen Invalidate(); }
private void DisposeBuffers() { BackBuffer.Dispose(); BackBuffer = default; }
public DX11(RenderForm form, CoreSettings coreSettings) { _form = form; sw = Stopwatch.StartNew(); LoadedTexturesByName = new Dictionary <string, ShaderResourceView>(); LoadedTexturesByPtrs = new Dictionary <IntPtr, ShaderResourceView>(); var swapChainDesc = new SwapChainDescription { Usage = Usage.RenderTargetOutput, OutputHandle = form.Handle, BufferCount = 1, IsWindowed = true, Flags = SwapChainFlags.AllowModeSwitch, SwapEffect = SwapEffect.Discard, SampleDescription = new SampleDescription(1, 0), ModeDescription = new ModeDescription { Format = Format.R8G8B8A8_UNorm, Width = form.Width, Height = form.Height, Scaling = DisplayModeScaling.Unspecified, RefreshRate = new Rational(60, 1), ScanlineOrdering = DisplayModeScanlineOrder.Unspecified } }; Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, new[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_0 }, swapChainDesc, out var device, out var swapChain); D11Device = device; DeviceContext = device.ImmediateContext; _swapChain = swapChain; factory = swapChain.GetParent <Factory>(); factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll); BackBuffer = Resource.FromSwapChain <Texture2D>(swapChain, 0); RenderTargetView = new RenderTargetView(device, BackBuffer); using (new PerformanceTimer("Init ImGuiRender")) { ImGuiRender = new ImGuiRender(this, form, coreSettings); } using (new PerformanceTimer("Init SpriteRender")) { SpritesRender = new SpritesRender(this, form, coreSettings); } InitStates(); form.UserResized += (sender, args) => { RenderTargetView?.Dispose(); BackBuffer.Dispose(); swapChain.ResizeBuffers(1, form.Width, form.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None); BackBuffer = Resource.FromSwapChain <Texture2D>(swapChain, 0); RenderTargetView = new RenderTargetView(device, BackBuffer); ImGuiRender.Resize(form.Bounds); ImGuiRender.UpdateConstantBuffer(); SpritesRender.ResizeConstBuffer(BackBuffer.Description); var descp = BackBuffer.Description; Viewport.Height = form.Height; Viewport.Width = form.Width; DeviceContext.Rasterizer.SetViewport(Viewport); DeviceContext.OutputMerger.SetRenderTargets(RenderTargetView); }; ImGuiDebug = new DebugInformation("ImGui"); SpritesDebug = new DebugInformation("Sprites"); SwapchainDebug = new DebugInformation("Swapchain"); // Core.DebugInformations.Add(ImGuiDebug); // Core.DebugInformations.Add(ImGuiInputDebug); // Core.DebugInformations.Add(SpritesDebug); // Core.DebugInformations.Add(SwapchainDebug); }
public virtual void Dispose() { BackBuffer?.Dispose(); BackBuffer = null; Resource.Dispose(); }
/// <summary> /// Resizes the GBuffer. /// </summary> internal void Resize(Device device) { UpdateProjectionMatrix(); RebuildFrustum(_frustumCulling); CanRender = false; var newWidth = Math.Max(1, (int)_viewportSize.x); var newHeight = Math.Max(1, (int)_viewportSize.y); RenderTarget2D?.Dispose(); RenderTarget2D = null; Renderer.Context2D.Target = null; _surface?.Dispose(); BackBuffer?.Dispose(); Buffer0?.Dispose(); Buffer1?.Dispose(); Buffer2?.Dispose(); Buffer3?.Dispose(); DepthStencilBuffer?.Dispose(); Viewport = new ViewportF(0, 0, ViewportSize.x, ViewportSize.y); try { SwapChain.ResizeBuffers(RenderConstants.FrameCount, newWidth, newHeight, RenderConstants.BackBufferFormat, SwapChainFlags.None); } catch (SharpDXException e) { Logger.Error(e); throw; } var backBufferTexture = Resource.FromSwapChain <Texture2D>(SwapChain, 0); BackBuffer = new Texture(backBufferTexture); Buffer0 = CreateCameraBuffer("Buffer0", 1f, RenderConstants.BackBufferFormat); Buffer1 = CreateCameraBuffer("Buffer1", 1f, Format.R8G8B8A8_UNorm); Buffer2 = CreateCameraBuffer("Buffer2", 1f, Format.R16G16B16A16_Float); Buffer3 = CreateCameraBuffer("Buffer3", 1f, Format.R8G8B8A8_UNorm); BufferDownscaleHalf0 = CreateCameraBuffer("BufferDownsampleHalf0", 1 / 2f, Format.R8G8B8A8_UNorm); BufferDownscaleHalf1 = CreateCameraBuffer("BufferDownsampleHalf1", 1 / 2f, Format.R8G8B8A8_UNorm); BufferDownscaleQuarter0 = CreateCameraBuffer("BufferDownsampleQuarter0", 1 / 4f, Format.R8G8B8A8_UNorm); BufferDownscaleQuarter1 = CreateCameraBuffer("BufferDownsampleQuarter1", 1 / 4f, Format.R8G8B8A8_UNorm); var depthStencilBuffer = new Texture2D(Renderer.Device, new Texture2DDescription { Format = Format.R24G8_Typeless, ArraySize = 1, MipLevels = 1, Width = newWidth, Height = newHeight, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); DepthStencilBuffer = new Texture(depthStencilBuffer, new DepthStencilViewDescription { Format = Format.D24_UNorm_S8_UInt, Dimension = DepthStencilViewDimension.Texture2D }, new ShaderResourceViewDescription { Format = Format.R24_UNorm_X8_Typeless, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MostDetailedMip = 0, MipLevels = -1 } }); _surface = BackBuffer.QueryInterface <Surface>(); _surface.DebugName = "BackBufferSurface"; try { RenderTarget2D = new Bitmap1(Renderer.Context2D, _surface, new BitmapProperties1(new PixelFormat(_surface.Description.Format, AlphaMode.Premultiplied), 96, 96, BitmapOptions.Target | BitmapOptions.CannotDraw)); } catch (Exception) { _surface.Dispose(); RenderTarget2D?.Dispose(); Logger.Info("An exception occured while creating the GUI surface render target."); throw; } lock (Locker) { foreach (var collector in LayerCollectors) { collector.Target = RenderTarget2D; } } lock (PostEffectsLocker) { foreach (var effect in PostEffects) { effect.UpdateSize(this); } } var cb = Constants; cb.Data.ScreenParams.X = newWidth; cb.Data.ScreenParams.Y = newHeight; cb.Data.ScreenParams.Z = AspectRatio; cb.Data.ScreenParams.W = FieldOfView * 0.5f / newHeight; NeedsResize = false; CanRender = true; //Logger.Trace("Camera resized."); }
public override void InitRenderTarget() { BackBuffer?.Dispose(); RenderTargetViewRef?.Dispose(); DepthStencilSRVRef?.Dispose(); ZBuffer?.Dispose(); DepthStencilViewRef?.Dispose(); RenderTarget2D?.Dispose(); SwapChainRef.ResizeBuffers(1, Width, Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None); using (Surface surface = SwapChainRef.GetBackBuffer <Surface>(0)) { RenderTarget2D = new RenderTarget(Factory2D, surface, RenderTarget2DProperites); } RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; BackBuffer = SwapChainRef.GetBackBuffer <Texture2D>(0); BackBuffer.DebugName = "BackBuffer"; RenderTargetViewRef = new RenderTargetView(DeviceRef, BackBuffer); RenderTargetViewRef.DebugName = "BackBufferRenderTargetView"; ZBufferTextureDescription.Width = Width; ZBufferTextureDescription.Height = Height; ZBuffer = new Texture2D(DeviceRef, ZBufferTextureDescription); ZBuffer.DebugName = "ZBuffer"; DepthStencilViewRef = new DepthStencilView(DeviceRef, ZBuffer, new DepthStencilViewDescription { Format = Format.D32_Float, Dimension = MSamplesCount > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D, Flags = DepthStencilViewFlags.None, }); DepthStencilViewRef.DebugName = "ZBufferDepthStencilView"; ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription() { Format = Format.R32_Float, }; if (MSamplesCount > 1) { SRVDesc.Dimension = ShaderResourceViewDimension.Texture2DMultisampled; SRVDesc.Texture2DMS = new ShaderResourceViewDescription.Texture2DMultisampledResource(); } else { SRVDesc.Dimension = ShaderResourceViewDimension.Texture2D; SRVDesc.Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MostDetailedMip = 0, MipLevels = 1, }; } DepthStencilSRVRef = new ShaderResourceView(DeviceRef, ZBuffer, SRVDesc); DepthStencilSRVRef.DebugName = "ZBufferDepthStencilSRV"; SetUpViewport(); OnInitRenderTarget?.Invoke(); }