Пример #1
0
        public Framebuffer(int width, int height, bool depth, bool interpol)
        {
            FramebufferTexture texture = new FramebufferTexture();
            texture.setFormat(OpenGL.GL_RGBA16F, width, height, OpenGL.GL_RGBA, false, interpol);

            setup(texture, depth);
        }
Пример #2
0
        public void addColorAttachment(uint internalfmt, uint format, bool mipmap, bool interpol)
        {
            FramebufferTexture texture = new FramebufferTexture();

            texture.setFormat(internalfmt, m_width, m_height, format, mipmap, interpol);

            addColorAttachment(texture);
        }
Пример #3
0
        public Framebuffer(int width, int height, bool depth, bool interpol)
        {
            FramebufferTexture texture = new FramebufferTexture();

            texture.setFormat(OpenGL.GL_RGBA16F, width, height, OpenGL.GL_RGBA, false, interpol);

            setup(texture, depth);
        }
Пример #4
0
        private void setup(FramebufferTexture color0, bool depth)
        {
            m_width  = color0.width();
            m_height = color0.height();

            /* Create render buffer object for depth buffering */
            if (depth)
            {
                m_depth = new FramebufferTexture();
                m_depth.setFormat(OpenGL.GL_DEPTH_COMPONENT24, m_width, m_height, OpenGL.GL_DEPTH_COMPONENT, false, false);
            }
            else
            {
                m_depth = null;
            }

            /* Create and bind new FBO */
            glGenFramebuffers(1, framebufferId);
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, framebufferId[0]);

            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER_EXT,
                                   attachment_id[m_color.Count], OpenGL.GL_TEXTURE_2D, color0.glID(), 0);
            m_color.Add(color0);

            if (m_depth != null)
            {
                glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER_EXT,
                                       OpenGL.GL_DEPTH_ATTACHMENT_EXT, OpenGL.GL_TEXTURE_2D, m_depth.glID(), 0);
            }

            uint result = glCheckFramebufferStatus(OpenGL.GL_FRAMEBUFFER_EXT);

            if (result != OpenGL.GL_FRAMEBUFFER_COMPLETE_EXT)
            {
                throw new Exception("Failed to create frame buffer object!");
            }

            useAllAttachments();

            /* Uibind FBO */
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, 0);
        }
Пример #5
0
        public void addColorAttachment(FramebufferTexture tex)
        {
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, framebufferId[0]);
            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER_EXT,
                                   attachment_id[m_color.Count], tex.glTarget(), tex.glID(), 0);
            uint result = glCheckFramebufferStatus(OpenGL.GL_FRAMEBUFFER_EXT);

            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, 0);

            if (result != OpenGL.GL_FRAMEBUFFER_COMPLETE_EXT)
            {
                throw new Exception("Failed to attach extra color buffer!");
            }

            m_color.Add(tex);

            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, framebufferId[0]);
            useAllAttachments();
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, 0);
        }
Пример #6
0
        public void swapColorAttachment(Framebuffer other, int index)
        {
            FramebufferTexture tmp = m_color[index];

            m_color[index]       = other.m_color[index];
            other.m_color[index] = tmp;

            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, framebufferId[0]);
            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER_EXT,
                                   attachment_id[index], m_color[index].glTarget(), m_color[index].glID(), 0);
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, 0);

            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, other.framebufferId[0]);
            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER_EXT,
                                   attachment_id[index], other.m_color[index].glTarget(), other.m_color[index].glID(), 0);
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER_EXT, 0);

            ErrorCode error = (ErrorCode)OpenGL.GetError();

            if (error != ErrorCode.NoError)
            {
                throw new Exception(string.Format("OpenGL Error: {0}", error));
            }
        }
Пример #7
0
 public Framebuffer(FramebufferTexture color0, bool depth)
 {
     setup(color0, depth);
 }
Пример #8
0
 public Framebuffer(FramebufferTexture color0, bool depth)
 {
     setup(color0, depth);
 }
Пример #9
0
        private void setup(FramebufferTexture color0, bool depth)
        {
            this.Width = color0.Width;
            this.Height = color0.Width;

            /* Create render buffer object for depth buffering */
            if (depth)
            {
                m_depth = new FramebufferTexture();
                m_depth.setFormat(OpenGL.GL_DEPTH_COMPONENT24, this.Width, this.Height, OpenGL.GL_DEPTH_COMPONENT, false, false);
            }
            else
            {
                m_depth = null;
            }

            /* Create and bind new FBO */
            glGenFramebuffers(1, framebufferId);
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebufferId[0]);

            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER,
                attachment_id[m_color.Count], OpenGL.GL_TEXTURE_2D, color0.TextureId, 0);
            m_color.Add(color0);

            if (m_depth != null)
            {
                glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER,
                    OpenGL.GL_DEPTH_ATTACHMENT, OpenGL.GL_TEXTURE_2D, m_depth.TextureId, 0);
            }

            uint result = glCheckFramebufferStatus(OpenGL.GL_FRAMEBUFFER);

            if (result != OpenGL.GL_FRAMEBUFFER_COMPLETE)
            {
                throw new Exception("Failed to create frame buffer object!");
            }

            useAllAttachments();

            /* Uibind FBO */
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, 0);
        }
Пример #10
0
        public void addColorAttachment(uint internalfmt, uint format, bool mipmap, bool interpol)
        {
            FramebufferTexture texture = new FramebufferTexture();

            texture.setFormat(internalfmt, this.Width, this.Height, format, mipmap, interpol);

            addColorAttachment(texture);
        }
Пример #11
0
        public void addColorAttachment(FramebufferTexture tex)
        {
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebufferId[0]);
            glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER,
                attachment_id[m_color.Count], tex.TextureTarget, tex.TextureId, 0);
            uint result = glCheckFramebufferStatus(OpenGL.GL_FRAMEBUFFER);
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, 0);

            if (result != OpenGL.GL_FRAMEBUFFER_COMPLETE)
            {
                throw new Exception("Failed to attach extra color buffer!");
            }

            m_color.Add(tex);

            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebufferId[0]);
            useAllAttachments();
            glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, 0);
        }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="color0"></param>
 /// <param name="depth"></param>
 public Framebuffer(FramebufferTexture color0, bool depth)
 {
     InitFramebufferExtensions();
     setup(color0, depth);
 }