コード例 #1
0
ファイル: SimpleBlur.cs プロジェクト: rboissel/ratchet-opengl
        void RegenerateFramebuffer()
        {
            // Create our renderbuffer

            _FramebufferColorBuffer = _Context.GenTexture();
            _FramebufferColorBuffer.BindTexture(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D);
            _FramebufferColorBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_MIN_FILTER, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_NEAREST);
            _FramebufferColorBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_MAG_FILTER, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_NEAREST);
            _FramebufferColorBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_WRAP_S, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_CLAMP_TO_BORDER);
            _FramebufferColorBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_WRAP_T, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_CLAMP_TO_BORDER);
            _FramebufferColorBuffer.TexImage2D(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, 0, Ratchet.Drawing.OpenGL.glTexture.InternalFormat.GL_RGBA, Width, Height, 0, Ratchet.Drawing.OpenGL.glTexture.Format.GL_RGBA, Ratchet.Drawing.OpenGL.glTexture.Type.GL_UNSIGNED_BYTE, null);

            Ratchet.Drawing.OpenGL.glTexture depthBuffer = _Context.GenTexture();
            depthBuffer.BindTexture(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D);
            depthBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_MIN_FILTER, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_NEAREST);
            depthBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_MAG_FILTER, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_NEAREST);
            depthBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_WRAP_S, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_CLAMP_TO_BORDER);
            depthBuffer.TexParameter(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, Ratchet.Drawing.OpenGL.glTexture.Parameter.GL_TEXTURE_WRAP_T, Ratchet.Drawing.OpenGL.glTexture.ParameterValue.GL_CLAMP_TO_BORDER);
            depthBuffer.TexImage2D(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D, 0, Ratchet.Drawing.OpenGL.glTexture.InternalFormat.GL_DEPTH_COMPONENT, Width, Height, 0, Ratchet.Drawing.OpenGL.glTexture.Format.GL_DEPTH_COMPONENT, Ratchet.Drawing.OpenGL.glTexture.Type.GL_UNSIGNED_BYTE, null);


            if (_Framebuffer != null)
            {
                _Framebuffer.Dispose();
            }
            _Framebuffer = _Context.GenFramebuffer();
            _Framebuffer.BindFramebuffer(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_FRAMEBUFFER);
            _Context.Viewport(0, 0, Width, Height);
            _Framebuffer.AttachTexture(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_FRAMEBUFFER, Ratchet.Drawing.OpenGL.glFramebuffer.Attachment.GL_COLOR_ATTACHMENT0, _FramebufferColorBuffer, 0);
            _Framebuffer.AttachTexture(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_FRAMEBUFFER, Ratchet.Drawing.OpenGL.glFramebuffer.Attachment.GL_DEPTH_ATTACHMENT, depthBuffer, 0);
            _Context.DrawBuffers(new Ratchet.Drawing.OpenGL.glContext.DrawBufferMode[] { Ratchet.Drawing.OpenGL.glContext.DrawBufferMode.GL_COLOR_ATTACHMENT0 });
            _Framebuffer.UnbindFramebuffer(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_FRAMEBUFFER);
        }