コード例 #1
0
        private IRenderTarget PlatformApplyRenderTargets()
        {
            if (_currentRenderTargetBindings[0].RenderTarget is RenderTargetCube)
            {
                throw new NotImplementedException("RenderTargetCube not yet implemented.");
            }

            var renderTarget = _currentRenderTargetBindings[0].RenderTarget as RenderTarget2D;

            if (this.glRenderTargetFrameBuffer == 0)
            {
                glRenderTargetFrameBuffer = Framebuffer.Generate();
            }

            Framebuffer.Bind(GLFramebuffer, glRenderTargetFrameBuffer);
            Framebuffer.Texture2D(GLFramebuffer, GLColorAttachment0, TextureTarget.Texture2D, renderTarget.glTexture, 0);

            // Reverted this change, as per @prollin's suggestion
            Framebuffer.Renderbuffer(GLFramebuffer, GLDepthAttachment, GLRenderbuffer, renderTarget.glDepthBuffer);
            Framebuffer.Renderbuffer(GLFramebuffer, GLStencilAttachment, GLRenderbuffer, renderTarget.glStencilBuffer);

#if !GLES
            for (var i = 0; i < _currentRenderTargetCount; i++)
            {
                GL.BindTexture(TextureTarget.Texture2D, _currentRenderTargetBindings[i].RenderTarget.glTexture);
                GraphicsExtensions.CheckGLError();
                Framebuffer.Texture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext + i, TextureTarget.Texture2D, _currentRenderTargetBindings[i].RenderTarget.glTexture, 0);
            }

            GL.DrawBuffers(_currentRenderTargetCount, _drawBuffers);
            GraphicsExtensions.CheckGLError();
#endif

            // Test that the FBOs are attached and correct.
            var status = Framebuffer.CheckStatus(GLFramebuffer);
            if (status != GLFramebufferComplete)
            {
                string message = "Framebuffer Incomplete.";
                switch (status)
                {
                case FramebufferErrorCode.FramebufferIncompleteAttachment: message = "Not all framebuffer attachment points are framebuffer attachment complete."; break;

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

                case FramebufferErrorCode.FramebufferUnsupported: message = "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions."; break;
                    //case FramebufferErrorCode.FramebufferIncompleteDimensions : message = "Not all attached images have the same width and height."; break;
                }
                throw new InvalidOperationException(message);
            }

            // Reset the raster state because we flip vertices
            // when rendering offscreen and hence the cull direction.
            _rasterizerStateDirty = true;

            // Textures will need to be rebound to render correctly in the new render target.
            Textures.Dirty();

            return(renderTarget);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        private void PlatformApplyDefaultRenderTarget()
        {
            this.framebufferHelper.BindFramebuffer(this.glFramebuffer);

            //Reset the raster state beacuse we flip vertices when rendering offscreen and hence the cull direction;
            _rasterizerStateDirty = true;

            //Textures will need to be reound to render correctly in the new render target
            Textures.Dirty();
        }
コード例 #3
0
        private void PlatformApplyDefaultRenderTarget()
        {
            Framebuffer.Bind(GLFramebuffer, glFramebuffer);

            // Reset the raster state because we flip vertices
            // when rendering offscreen and hence the cull direction.
            _rasterizerStateDirty = true;

            // Textures will need to be rebound to render correctly in the new render target.
            Textures.Dirty();
        }
コード例 #4
0
        private IRenderTarget PlatformApplyRenderTargets()
        {
            var glFramebuffer = 0;

            if (!this.glFramebuffers.TryGetValue(this._currentRenderTargetBindings, out glFramebuffer))
            {
                this.framebufferHelper.GenFramebuffer(out glFramebuffer);
                this.framebufferHelper.BindFramebuffer(glFramebuffer);
                var renderTargetBinding = this._currentRenderTargetBindings[0];
                var renderTarget        = renderTargetBinding.RenderTarget as RenderTarget2D;
                this.framebufferHelper.FramebufferRenderbuffer((int)FramebufferAttachment.DepthAttachment, renderTarget.glDepthBuffer, 0);
                this.framebufferHelper.FramebufferRenderbuffer((int)FramebufferAttachment.StencilAttachment, renderTarget.glStencilBuffer, 0);
                for (var i = 0; i < this._currentRenderTargetCount; ++i)
                {
                    renderTargetBinding = this._currentRenderTargetBindings[i];
                    renderTarget        = renderTargetBinding.RenderTarget as RenderTarget2D;
                    var attachement = (int)(FramebufferAttachment.ColorAttachment0 + i);
                    if (renderTarget.glColorBuffer != renderTarget.glTexture)
                    {
                        this.framebufferHelper.FramebufferRenderbuffer(attachement, renderTarget.glColorBuffer, 0);
                    }
                    else
                    {
                        this.framebufferHelper.FramebufferTexture2D(attachement, (int)renderTarget.glTarget, renderTarget.glTexture, 0, renderTarget.MultiSampleCount);
                    }
                }

#if DEBUG
                this.framebufferHelper.CheckFramebufferStatus();
#endif
                this.glFramebuffers.Add((RenderTargetBinding[])_currentRenderTargetBindings.Clone(), glFramebuffer);
            }
            else
            {
                this.framebufferHelper.BindFramebuffer(glFramebuffer);
            }
#if !GLES
            GL.DrawBuffers(this._currentRenderTargetCount, this._drawBuffers);
#endif

            // Reset the raster state because we flip vertices
            // when rendering offscreen and hence the cull direction.
            _rasterizerStateDirty = true;

            // Textures will need to be rebound to render correctly in the new render target.
            Textures.Dirty();

            return(_currentRenderTargetBindings[0].RenderTarget as IRenderTarget);
        }
コード例 #5
0
        private IRenderTarget PlatformApplyRenderTargets()
        {
            if (!this.glFramebuffers.TryGetValue(this._currentRenderTargetBindings, out WebGLFramebuffer glFramebuffer))
            {
                this.framebufferHelper.GenFramebuffer(out glFramebuffer);
                this.framebufferHelper.BindFramebuffer(glFramebuffer);
                var renderTargetBinding = this._currentRenderTargetBindings[0];
                var renderTarget        = renderTargetBinding.RenderTarget as IRenderTarget;
                this.framebufferHelper.FramebufferRenderbuffer(gl.DEPTH_ATTACHMENT, renderTarget.GLDepthBuffer, 0);
                this.framebufferHelper.FramebufferRenderbuffer(gl.STENCIL_ATTACHMENT, renderTarget.GLStencilBuffer, 0);
                for (var i = 0; i < this._currentRenderTargetCount; ++i)
                {
                    renderTargetBinding = this._currentRenderTargetBindings[i];
                    renderTarget        = renderTargetBinding.RenderTarget as IRenderTarget;
                    var attachement = gl.COLOR_ATTACHMENT0 + i;

                    this.framebufferHelper.FramebufferTexture2D(attachement, (int)renderTarget.GetFramebufferTarget(renderTargetBinding), renderTarget.GLTexture, 0, renderTarget.MultiSampleCount);
                }

                this.glFramebuffers.Add((RenderTargetBinding[])_currentRenderTargetBindings.Clone(), glFramebuffer);
            }
            else
            {
                this.framebufferHelper.BindFramebuffer(glFramebuffer);
            }

            if (_drawBuffersExtension != null)
            {
                var tmp = new double[(int)_currentRenderTargetCount];
                for (int i = 0; i < this._currentRenderTargetCount; i++)
                {
                    tmp[i] = _drawBuffers[i];
                }
                _drawBuffersExtension.drawBuffersWEBGL(tmp);
            }

            // Reset the raster state because we flip vertices
            // when rendering offscreen and hence the cull direction.
            _rasterizerStateDirty = true;

            // Textures will need to be rebound to render correctly in the new render target.
            Textures.Dirty();

            return(_currentRenderTargetBindings[0].RenderTarget as IRenderTarget);
        }