/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTargetView"/> class. /// </summary> /// <param name="resource">The resource to bind to the view.</param> /// <param name="format">The format of the view.</param> protected GorgonRenderTargetView(GorgonResource resource, BufferFormat format) : base(resource, format) { switch (resource.ResourceType) { case ResourceType.Buffer: _bufferTarget = (GorgonRenderTargetBuffer)resource; break; case ResourceType.Texture1D: _1DTarget = (GorgonRenderTarget1D)resource; break; case ResourceType.Texture2D: _2DTarget = (GorgonRenderTarget2D)resource; if (_2DTarget.IsSwapChain) { _swapChain = (GorgonSwapChain)_2DTarget; } break; case ResourceType.Texture3D: _3DTarget = (GorgonRenderTarget3D)resource; break; } }
private Surface(int width, int height) { _target = CreateEmptyTarget(width, height); this.Width = width; this.Height = height; }
private Surface(string Filename) { if (!System.IO.File.Exists(Filename)) { throw new System.IO.FileNotFoundException("The file could not be found!", Filename); } GorgonLibrary.IO.GorgonImageCodec Codec = null; if (Filename.EndsWith(".png", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecPNG(); } if (Filename.EndsWith(".bmp", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecBMP(); } if (Filename.EndsWith(".jpg", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecJPEG(); } if (Filename.EndsWith(".jpeg", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecJPEG(); } if (Filename.EndsWith(".tga", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecTGA(); } if (Filename.EndsWith(".dds", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecDDS(); } if (Filename.EndsWith(".gif", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecGIF(); } if (Filename.EndsWith(".tif", true, System.Globalization.CultureInfo.CurrentCulture)) { Codec = new GorgonLibrary.IO.GorgonCodecTIFF(); } if (Codec == null) { throw new System.IO.FileLoadException("The file contains an invalid extension!", Filename); } _target = Program.GameLogic.Graphics.Textures.FromFile <GorgonRenderTarget2D>("Nondescript_Texture", Filename, Codec); Width = _target.Settings.Width; Height = _target.Settings.Height; }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> private void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { Settings.Window.ParentChanged -= Window_ParentChanged; if (_topLevelControl != null) { _topLevelControl.ParentChanged -= Window_ParentChanged; } if (_parentForm != null) { _parentForm.ResizeBegin -= _parentForm_ResizeBegin; _parentForm.ResizeEnd -= _parentForm_ResizeEnd; _parentForm.Activated -= _parentForm_Activated; _parentForm.Deactivate -= _parentForm_Deactivate; } Settings.Window.Resize -= Window_Resize; if (_renderTarget != null) { _renderTarget.Dispose(); _renderTarget = null; } Gorgon.Log.Print("GorgonSwapChain '{0}': Removing D3D11 swap chain...", LoggingLevel.Simple, Name); if (GISwapChain != null) { // Always go to windowed mode before destroying the swap chain. GISwapChain.SetFullscreenState(false, null); GISwapChain.Dispose(); } if (Graphics != null) { Graphics.RemoveTrackedObject(this); } GISwapChain = null; } Graphics = null; _disposed = true; }
/// <summary> /// Function to create any resources bound to the swap chain. /// </summary> /// <param name="targetReseat">The swap chain needs to be re-seated in slot 0 of the render target list.</param> /// <param name="depthReseat">The depth/stencil view needs to be re-seated.</param> private void CreateResources(bool targetReseat = false, bool depthReseat = false) { Gorgon.Log.Print("GorgonSwapChain '{0}': Creating D3D11 render target view...", LoggingLevel.Intermediate, Name); if (_renderTarget == null) { _renderTarget = new GorgonRenderTarget2D(Graphics, Name + "_Internal_Render_Target_" + Guid.NewGuid(), new GorgonRenderTarget2DSettings { AllowUnorderedAccessViews = (Settings.Flags & SwapChainUsageFlags.AllowUnorderedAccessView) == SwapChainUsageFlags.AllowUnorderedAccessView, ArrayCount = 1, DepthStencilFormat = Settings.DepthStencilFormat, Width = Settings.Width, Height = Settings.Height, Format = Settings.Format, TextureFormat = Settings.Format, Multisampling = Settings.Multisampling, IsTextureCube = false, MipCount = 1, ShaderViewFormat = BufferFormat.Unknown }); } else { // Readjust target settings. _renderTarget.Settings.Width = Settings.Width; _renderTarget.Settings.Height = Settings.Height; _renderTarget.Settings.DepthStencilFormat = Settings.DepthStencilFormat; _renderTarget.Settings.Format = Settings.Format; _renderTarget.Settings.Multisampling = Settings.Multisampling; } // Initialize (or reinitialize) the target. _renderTarget.InitializeSwapChain(this); // Re-seat the target/depth stencil. if ((targetReseat) && (depthReseat)) { Graphics.Output.SetRenderTarget(_renderTarget, DepthStencilBuffer); } else if (depthReseat) { Graphics.Output.DepthStencilView = DepthStencilBuffer; } else if (targetReseat) { Graphics.Output.SetRenderTarget(_renderTarget, Graphics.Output.DepthStencilView); } }
/// <summary> /// Function to retrieve the render target view for a render target. /// </summary> /// <param name="target">Render target to evaluate.</param> /// <returns>The render target view for the swap chain.</returns> public static GorgonRenderTargetView ToRenderTargetView(GorgonRenderTarget2D target) { return(target == null ? null : target._defaultRenderTargetView); }