/// <summary> /// Sets the current render target. /// </summary> private void SetRenderTargetInternal(RenderTarget2D renderTarget, Color?clearColor = null, Double?clearDepth = null, Int32?clearStencil = null) { Ultraviolet.ValidateResource(renderTarget); var usage = renderTarget?.RenderTargetUsage ?? backBufferRenderTargetUsage; if (usage == RenderTargetUsage.PlatformContents) { usage = Capabilities.SupportsPreservingRenderTargetContentInHardware ? RenderTargetUsage.PreserveContents : RenderTargetUsage.DiscardContents; } var oglRenderTarget = (OpenGLRenderTarget2D)renderTarget; if (oglRenderTarget != this.renderTarget) { var targetName = gl.DefaultFramebuffer; var targetSize = Size2.Zero; if (oglRenderTarget != null) { oglRenderTarget.ValidateStatus(); targetName = oglRenderTarget.OpenGLName; targetSize = renderTarget.Size; } else { var currentWindow = Ultraviolet.GetPlatform().Windows.GetCurrent(); if (currentWindow != null) { targetSize = currentWindow.DrawableSize; } } OpenGLState.BindFramebuffer(targetName); if (this.renderTarget != null) { this.renderTarget.UnbindWrite(); } this.renderTarget = oglRenderTarget; if (this.renderTarget != null) { this.renderTarget.BindWrite(); } this.viewport = default(Viewport); SetViewport(new Viewport(0, 0, targetSize.Width, targetSize.Height)); if (usage == RenderTargetUsage.DiscardContents) { Clear(clearColor ?? Color.FromArgb(0xFF442288), clearDepth ?? 1.0, clearStencil ?? 0); } } }