Exemplo n.º 1
0
        internal void ApplyRenderTargets(RenderTargetBinding[] renderTargets)
        {
            RenderTargetBinding[] renderTargetBindingArray = this._currentRenderTargetBindings;
            this._currentRenderTargetBindings = renderTargets;
            bool flag;

            if (this._currentRenderTargetBindings == null || this._currentRenderTargetBindings.Length == 0)
            {
                GraphicsExtensions.BindFramebuffer(FramebufferTarget.Framebuffer, this.glFramebuffer);
                flag          = true;
                this.Viewport = new Viewport(0, 0, this.PresentationParameters.BackBufferWidth, this.PresentationParameters.BackBufferHeight);
            }
            else
            {
                if (this._currentRenderTargetBindings[0].RenderTarget is RenderTargetCube)
                {
                    throw new NotImplementedException("RenderTargetCube not yet implemented.");
                }
                RenderTarget2D renderTarget = this._currentRenderTargetBindings[0].RenderTarget as RenderTarget2D;
                if ((int)this.glRenderTargetFrameBuffer == 0)
                {
                    GraphicsExtensions.GenFramebuffers(1, out this.glRenderTargetFrameBuffer);
                }
                Threading.BlockOnUIThread((Action)(() =>
                {
                    GraphicsExtensions.BindFramebuffer(FramebufferTarget.Framebuffer, this.glRenderTargetFrameBuffer);
                    GraphicsExtensions.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, renderTarget.glTexture, 0);
                    if (renderTarget.DepthStencilFormat != DepthFormat.None)
                    {
                        GraphicsExtensions.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, renderTarget.glDepthStencilBuffer);
                        if (renderTarget.DepthStencilFormat == DepthFormat.Depth24Stencil8)
                        {
                            GraphicsExtensions.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, RenderbufferTarget.Renderbuffer, renderTarget.glDepthStencilBuffer);
                        }
                        else
                        {
                            GraphicsExtensions.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, RenderbufferTarget.Renderbuffer, 0U);
                        }
                    }
                    else
                    {
                        GraphicsExtensions.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, 0U);
                    }
                    FramebufferErrorCode local_0 = GraphicsExtensions.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                    if (local_0 == FramebufferErrorCode.FramebufferComplete)
                    {
                        return;
                    }
                    string local_1 = "Framebuffer Incomplete (" + (object)local_0 + ") : ";
                    switch (local_0)
                    {
                    case FramebufferErrorCode.FramebufferIncompleteAttachment:
                        local_1 = local_1 + "Not all framebuffer attachment points are framebuffer attachment complete.";
                        break;

                    case FramebufferErrorCode.FramebufferIncompleteMissingAttachment:
                        local_1 = local_1 + "No images are attached to the framebuffer.";
                        break;

                    case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
                        local_1 = local_1 + "Not all attached images have the same width and height.";
                        break;

                    case FramebufferErrorCode.FramebufferUnsupported:
                        local_1 = local_1 + "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.";
                        break;
                    }
                    throw new InvalidOperationException(local_1);
                }));
                this.Viewport = new Viewport(0, 0, renderTarget.Width, renderTarget.Height);
                flag          = renderTarget.RenderTargetUsage == RenderTargetUsage.DiscardContents;
            }
            if (flag)
            {
                this.Clear(GraphicsDevice.DiscardColor);
            }
            if (renderTargetBindingArray != null)
            {
                for (int index = 0; index < renderTargetBindingArray.Length; ++index)
                {
                    Texture renderTarget = renderTargetBindingArray[index].RenderTarget;
                    if (renderTarget.LevelCount > 1)
                    {
                        if (!(renderTarget is RenderTarget2D))
                        {
                            throw new NotImplementedException();
                        }
                        (renderTarget as RenderTarget2D).GenerateMipmaps();
                    }
                }
            }
            this._rasterizerStateDirty = true;
        }