/// <summary> /// Initializes a new instance of the OpenGLRenderTarget2D class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="width">The render target's width in pixels.</param> /// <param name="height">The render target's height in pixels.</param> /// <param name="usage">A <see cref="RenderTargetUsage"/> value specifying whether the /// render target's data is discarded or preserved when it is bound to the graphics device.</param> /// <param name="buffers">The collection of render buffers to attach to the target.</param> public OpenGLRenderTarget2D(UltravioletContext uv, Int32 width, Int32 height, RenderTargetUsage usage, IEnumerable <RenderBuffer2D> buffers = null) : base(uv) { Contract.EnsureRange(width > 0, nameof(width)); Contract.EnsureRange(height > 0, nameof(height)); var framebuffer = 0u; uv.QueueWorkItem(state => { using (OpenGLState.ScopedCreateFramebuffer(out framebuffer)) { if (buffers != null) { foreach (OpenGLRenderBuffer2D buffer in buffers) { AttachRenderBuffer(buffer); } } } }).Wait(); this.width = width; this.height = height; this.framebuffer = framebuffer; this.renderTargetUsage = usage; }