public void SetRenderTargets(params RenderTargetBinding[] renderTargets) { // Checking for redundant SetRenderTargets... if (renderTargets == null && RenderTargetCount == 0) { return; } else if (renderTargets != null && renderTargets.Length == RenderTargetCount) { bool isRedundant = true; for (int i = 0; i < renderTargets.Length; i += 1) { if (renderTargets[i].RenderTarget != renderTargetBindings[i].RenderTarget || renderTargets[i].CubeMapFace != renderTargetBindings[i].CubeMapFace) { isRedundant = false; } } if (isRedundant) { return; } } Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length); if (renderTargets == null || renderTargets.Length == 0) { GLDevice.SetRenderTargets(null, null, 0, DepthFormat.None); RenderTargetCount = 0; // Set the viewport to the size of the backbuffer. Viewport = new Viewport(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight); // Set the scissor rectangle to the size of the backbuffer. ScissorRectangle = new Rectangle(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight); if (PresentationParameters.RenderTargetUsage == RenderTargetUsage.DiscardContents) { Clear(DiscardColor); } } else { uint[] glTarget = new uint[renderTargets.Length]; OpenGLDevice.GLenum[] glTargetFace = new OpenGLDevice.GLenum[renderTargets.Length]; for (int i = 0; i < renderTargets.Length; i += 1) { glTarget[i] = renderTargets[i].RenderTarget.texture.Handle; if (renderTargets[i].RenderTarget is RenderTarget2D) { glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_2D; } else { glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)renderTargets[i].CubeMapFace; } } IRenderTarget target = renderTargets[0].RenderTarget as IRenderTarget; GLDevice.SetRenderTargets( glTarget, glTargetFace, target.DepthStencilBuffer, target.DepthStencilFormat ); Array.Copy(renderTargets, renderTargetBindings, renderTargets.Length); RenderTargetCount = renderTargets.Length; // Set the viewport to the size of the first render target. Viewport = new Viewport(0, 0, target.Width, target.Height); // Set the scissor rectangle to the size of the first render target. ScissorRectangle = new Rectangle(0, 0, target.Width, target.Height); if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents) { Clear(DiscardColor); } } }