/// <summary> /// Sets up all necessary native resources for this RenderTarget. /// </summary> protected void SetupNativeRes() { foreach (var target in this.targets.Where(t => t != null).Res()) { if (target.ContentWidth == 0 || target.ContentHeight == 0) { Logs.Core.WriteError("Error initializing '{0}' because '{1}' has a dimension of zero.", this, target); return; } } if (this.native == null) { this.native = DualityApp.GraphicsBackend.CreateRenderTarget(); } INativeTexture[] targets = this.targets .Select(t => t.Res != null ? t.Res.Native : null) .ToArray(); try { this.native.Setup(targets, this.multisampling, this.depthBuffer); } catch (Exception e) { Logs.Core.WriteError("Error initializing RenderTarget {0}:{1}{2}", this, Environment.NewLine, LogFormat.Exception(e)); } }
/// <summary> /// Frees up any native resources that this RenderTarget might have occupied. /// </summary> protected void FreeNativeRes() { if (this.native != null) { this.native.Dispose(); this.native = null; } }
/// <summary> /// Sets up all necessary native resources for this RenderTarget. /// </summary> protected void SetupNativeRes() { if (this.native == null) { this.native = DualityApp.GraphicsBackend.CreateRenderTarget(); } INativeTexture[] targets = this.targets .Select(t => t.Res != null ? t.Res.Native : null) .ToArray(); try { this.native.Setup(targets, this.multisampling); } catch (Exception e) { Log.Core.WriteError("Error initializing RenderTarget {0}:{2}{1}", this.FullName, Log.Exception(e), Environment.NewLine); } }
/// <summary> /// Retrieves the rendering targets pixel data from video memory in the Rgba8 format. /// As a storage array type, either byte or <see cref="ColorRgba"/> is recommended. /// </summary> /// <param name="renderTarget"></param> /// <param name="buffer">The target buffer to store transferred pixel data in.</param> /// <param name="dataLayout">The desired color layout of the specified buffer.</param> /// <param name="dataElementType">The desired color element type of the specified buffer.</param> /// <param name="targetIndex">The target texture lists index to read from.</param> /// <param name="x">The x position of the rectangular area to read.</param> /// <param name="y">The y position of the rectangular area to read.</param> /// <param name="width">The width of the rectangular area to read. Defaults to the rendering targets width.</param> /// <param name="height">The height of the rectangular area to read. Defaults to the rendering targets height.</param> public static void GetData <T>( this INativeRenderTarget renderTarget, T[] buffer, ColorDataLayout dataLayout, ColorDataElementType dataElementType, int targetIndex, int x, int y, int width, int height) where T : struct { using (PinnedArrayHandle pinned = new PinnedArrayHandle(buffer)) { renderTarget.GetData( pinned.Address, dataLayout, dataElementType, targetIndex, x, y, width, height); } }