Beispiel #1
0
        public void Dispose()
        {
            if (postprocessingEnabled)
            {
                gl.DeleteRenderbuffersEXT(1, glRenderBufferArray);
                gl.DeleteTextures(1, glFrameBufferTexArray);
                gl.DeleteFramebuffersEXT(1, glFrameBufferArray);

                postShader.Dispose();
                postShader = null;
            }
        }
Beispiel #2
0
        private void UpdatePostProcessing(bool enabled)
        {
            if (!postprocessingEnabled && enabled)
            {
                // Setup back buffer
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.GenTextures(1, glFrameBufferTexArray);
                fboTexture = glFrameBufferTexArray[0];
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, fboTexture);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);
                gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA,
                    viewportSize.Width, viewportSize.Height, 0,
                    OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, null);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

                // Setup depth buffer
                gl.GenRenderbuffersEXT(1, glRenderBufferArray);
                rboDepth = glRenderBufferArray[0];
                gl.BindRenderbufferEXT(OpenGL.GL_RENDERBUFFER, rboDepth);
                gl.RenderbufferStorageEXT(OpenGL.GL_RENDERBUFFER, OpenGL.GL_DEPTH_COMPONENT16,
                    viewportSize.Width, viewportSize.Height);
                gl.BindRenderbufferEXT(OpenGL.GL_RENDERBUFFER, 0);

                // Setup framebuffer
                gl.GenFramebuffersEXT(1, glFrameBufferArray);
                fbo = glFrameBufferArray[0];
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, fbo);
                gl.FramebufferTexture2DEXT(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_COLOR_ATTACHMENT0_EXT,
                    OpenGL.GL_TEXTURE_2D, fboTexture, 0);
                gl.FramebufferRenderbufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_DEPTH_ATTACHMENT_EXT,
                    OpenGL.GL_RENDERBUFFER, rboDepth);

                uint fboStatus = gl.CheckFramebufferStatusEXT(OpenGL.GL_FRAMEBUFFER_EXT);

                if (gl.CheckFramebufferStatusEXT(OpenGL.GL_FRAMEBUFFER_EXT) != OpenGL.GL_FRAMEBUFFER_COMPLETE_EXT)
                {
                    postprocessingEnabled = false;

                    gl.DeleteRenderbuffersEXT(1, glRenderBufferArray);
                    gl.DeleteTextures(1, glFrameBufferTexArray);
                    gl.DeleteFramebuffersEXT(1, glFrameBufferArray);

                    return;
                }

                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0);

                // Setup post-processing shader
                postShader = new Shader(gl, ManifestResourceLoader.LoadTextFile(@"Resources\Shaders\screen.vert"),
                    ManifestResourceLoader.LoadTextFile(@"Resources\Shaders\screen.frag"), null);

                if (!postShader.Compiled)
                {
                    throw new Exception(postShader.CompilerOutput);
                }

                postprocessingEnabled = true;
            }
            else if (postprocessingEnabled && !enabled)
            {
                gl.DeleteRenderbuffersEXT(1, glRenderBufferArray);
                gl.DeleteTextures(1, glFrameBufferTexArray);
                gl.DeleteFramebuffersEXT(1, glFrameBufferArray);

                postShader.Dispose();
                postShader = null;

                postprocessingEnabled = false;
            }
        }
Beispiel #3
0
        private void UpdatePostProcessing(bool enabled)
        {
            if (!postprocessingEnabled && enabled)
            {
                // Setup back buffer
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.GenTextures(1, glFrameBufferTexArray);
                fboTexture = glFrameBufferTexArray[0];
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, fboTexture);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
                gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);
                gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA,
                    viewportSize.Width, viewportSize.Height, 0,
                    OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, null);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

                // Setup depth buffer
                gl.GenRenderbuffersEXT(1, glRenderBufferArray);
                rboDepth = glRenderBufferArray[0];
                gl.BindRenderbufferEXT(OpenGL.GL_RENDERBUFFER, rboDepth);
                gl.RenderbufferStorageEXT(OpenGL.GL_RENDERBUFFER, OpenGL.GL_DEPTH_COMPONENT16,
                    viewportSize.Width, viewportSize.Height);
                gl.BindRenderbufferEXT(OpenGL.GL_RENDERBUFFER, 0);

                // Setup framebuffer
                gl.GenFramebuffersEXT(1, glFrameBufferArray);
                fbo = glFrameBufferArray[0];
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, fbo);
                gl.FramebufferTexture2DEXT(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_COLOR_ATTACHMENT0_EXT,
                    OpenGL.GL_TEXTURE_2D, fboTexture, 0);
                gl.FramebufferRenderbufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_DEPTH_ATTACHMENT_EXT,
                    OpenGL.GL_RENDERBUFFER, rboDepth);

                uint fboStatus = gl.CheckFramebufferStatusEXT(OpenGL.GL_FRAMEBUFFER_EXT);

                if (gl.CheckFramebufferStatusEXT(OpenGL.GL_FRAMEBUFFER_EXT) != OpenGL.GL_FRAMEBUFFER_COMPLETE_EXT)
                {
                    postprocessingEnabled = false;

                    gl.DeleteRenderbuffersEXT(1, glRenderBufferArray);
                    gl.DeleteTextures(1, glFrameBufferTexArray);
                    gl.DeleteFramebuffersEXT(1, glFrameBufferArray);

                    return;
                }

                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0);

                // Setup post-processing shader
                postShader = new Shader(gl, ManifestResourceLoader.LoadTextFile(@"Resources\Shaders\screen.vert"),
                    ManifestResourceLoader.LoadTextFile(@"Resources\Shaders\screen.frag"), null);

                if (!postShader.Compiled)
                {
                    throw new Exception(postShader.CompilerOutput);
                }

                postprocessingEnabled = true;
            }
            else if (postprocessingEnabled && !enabled)
            {
                gl.DeleteRenderbuffersEXT(1, glRenderBufferArray);
                gl.DeleteTextures(1, glFrameBufferTexArray);
                gl.DeleteFramebuffersEXT(1, glFrameBufferArray);

                postShader.Dispose();
                postShader = null;

                postprocessingEnabled = false;
            }
        }