Create, update, use and delete a renderbuffer object.
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var texture = new Texture(new TexImageBitmap(width, height),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                          new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                texture.Initialize();
                framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 0u);// 1
                this.BindingTexture = texture;
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            //framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + 1);// as in 1 in framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 1u);// 1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
예제 #2
0
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var texture = new Texture(TextureTarget.Texture2D,
                                      new NullImageFiller(width, height, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE),
                                      new SamplerParameters(
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureFilter.Linear,
                                          TextureFilter.Linear));

            texture.Initialize();
            this.BindingTexture = texture;
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var          framebuffer = new Framebuffer();

            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);                         //0
            framebuffer.Attach(texture);                             //1
            framebuffer.Attach(depthBuffer);                         // special
            framebuffer.SetDrawBuffers(GL.GL_COLOR_ATTACHMENT0 + 1); // as in 1 in framebuffer.Attach(texture);//1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();
            return(framebuffer);
        }
        private void Dispose(bool disposing)
        {
            if (this.disposedValue == false)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                }

                // Dispose unmanaged resources.
                {
                    Renderbuffer depthBuffer = this.depthBuffer;
                    if (depthBuffer != null)
                    {
                        depthBuffer.Dispose();
                    }
                }
                {
                    Renderbuffer[] array = this.colorBufferList.ToArray();
                    foreach (var item in array)
                    {
                        item.Dispose();
                    }
                }
                {
                    IntPtr context = GL.Instance.GetCurrentContext();
                    if (context != IntPtr.Zero)
                    {
                        glDeleteFramebuffers(this.frameBuffer.Length, this.frameBuffer);
                    }
                }
            }

            this.disposedValue = true;
        }
        private void Dispose(bool disposing)
        {
            if (this.disposedValue == false)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                }

                // Dispose unmanaged resources.
                {
                    Renderbuffer depthBuffer = this.depthBuffer;
                    if (depthBuffer != null)
                    {
                        depthBuffer.Dispose();
                    }
                }
                {
                    Renderbuffer[] array = this.colorBufferList.ToArray();
                    foreach (var item in array)
                    {
                        item.Dispose();
                    }
                }
                {
                    glDeleteFramebuffers(this.frameBuffer.Length, this.frameBuffer);
                }
            }

            this.disposedValue = true;
        }
예제 #5
0
        private void AttachDepthbuffer(Renderbuffer renderbuffer, FramebufferTarget target)
        {
            if (this.depthBuffer != null)
            {
                throw new Exception("Depth buffer already exists!");
            }

            glFramebufferRenderbuffer((uint)target, (uint)RenderbufferAttachment.DepthAttachment, OpenGL.GL_RENDERBUFFER, renderbuffer.Id);
            this.depthBuffer = renderbuffer;
        }
        /// <summary>
        /// Attach a <see cref="Renderbuffer"/> object as a color attachment to the currently bound framebuffer object.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="renderbuffer"></param>
        /// <param name="colorAttachmentLocation">ranges from 0 to <see cref="Framebuffer.maxColorAttachmentCount"/> - 1.</param>
        public void Attach(FramebufferTarget target, Renderbuffer renderbuffer, uint colorAttachmentLocation)
        {
            if (colorAttachmentLocation >= Framebuffer.maxColorAttachmentCount)
            {
                throw new IndexOutOfRangeException("Not enough attach points!");
            }

            glFramebufferRenderbuffer((uint)target, GL.GL_COLOR_ATTACHMENT0 + colorAttachmentLocation, GL.GL_RENDERBUFFER, renderbuffer.Id);

            this.colorBuffers[colorAttachmentLocation] = renderbuffer;
        }
        /// <summary>
        /// Attach a <see cref="Renderbuffer"/> object to the currently bound framebuffer object.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="renderbuffer"></param>
        /// <param name="location"></param>
        public void Attach(FramebufferTarget target, Renderbuffer renderbuffer, AttachmentLocation location)
        {
            switch (location)
            {
            case AttachmentLocation.Depth:
            {
                if (this.depthBuffer != null)
                {
                    throw new Exception("Depth buffer already exists!");
                }

                glFramebufferRenderbuffer((uint)target, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, renderbuffer.Id);

                this.depthBuffer = renderbuffer;
            }
            break;

            case AttachmentLocation.Stencil:
            {
                if (this.stencilBuffer != null)
                {
                    throw new Exception("Stencil buffer already exists!");
                }

                glFramebufferRenderbuffer((uint)target, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, renderbuffer.Id);

                this.stencilBuffer = renderbuffer;
            }
            break;

            case AttachmentLocation.DepthStencil:
            {
                if (this.depthBuffer != null)
                {
                    throw new Exception("Depth buffer already exists!");
                }
                if (this.stencilBuffer != null)
                {
                    throw new Exception("Stencil buffer already exists!");
                }

                glFramebufferRenderbuffer((uint)target, GL.GL_DEPTH_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, renderbuffer.Id);

                this.depthBuffer   = renderbuffer;
                this.stencilBuffer = renderbuffer;
            }
            break;

            default:
                throw new NotDealWithNewEnumItemException(typeof(AttachmentLocation));
            }
        }
예제 #8
0
        private Framebuffer CreatePickFramebuffer(int width, int height)
        {
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var          framebuffer = new Framebuffer();

            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);
            framebuffer.Attach(depthBuffer);
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
예제 #9
0
        private Renderbuffer AttachDepthbuffer(FramebufferTarget target)
        {
            if (this.depthBuffer != null)
            {
                throw new Exception("Depth buffer already exists!");
            }

            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(this.Width, this.Height, DepthComponentType.DepthComponent24);

            glFramebufferRenderbuffer((uint)target, (uint)RenderbufferAttachment.DepthAttachment, GL.GL_RENDERBUFFER, depthBuffer.Id);

            this.depthBuffer = depthBuffer;

            return(depthBuffer);
        }
예제 #10
0
        private Renderbuffer AttachColorbuffer(FramebufferTarget target)
        {
            if (nextColorAttachmentIndex >= attachment_id.Length)
            {
                throw new IndexOutOfRangeException("Not enough attach points!");
            }

            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(this.Width, this.Height, GL.GL_RGBA);

            glFramebufferRenderbuffer((uint)target, attachment_id[nextColorAttachmentIndex++], GL.GL_RENDERBUFFER, colorBuffer.Id);

            this.colorBufferList.Add(colorBuffer);

            return(colorBuffer);
        }
예제 #11
0
        /// <summary>
        /// Attach a render buffer.
        /// <para>Bind() this framebuffer before invoking this method.</para>
        /// </summary>
        /// <param name="renderbuffer"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public void Attach(Renderbuffer renderbuffer, FramebufferTarget target = FramebufferTarget.Framebuffer)
        {
            switch (renderbuffer.BufferType)
            {
            case RenderbufferType.DepthBuffer:
                AttachDepthbuffer(renderbuffer, target);
                break;

            case RenderbufferType.ColorBuffer:
                AttachColorbuffer(renderbuffer, target);
                break;

            default:
                throw new NotImplementedException();
            }
        }
예제 #12
0
        /// <summary>
        /// Attach a render buffer.
        /// <para>Bind() this framebuffer before invoking this method.</para>
        /// </summary>
        /// <param name="renderbuffer"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public void Attach(Renderbuffer renderbuffer, FramebufferTarget target = FramebufferTarget.Framebuffer)
        {
            switch (renderbuffer.BufferType)
            {
            case RenderbufferType.DepthBuffer:
                AttachDepthbuffer(renderbuffer, target);
                break;

            case RenderbufferType.ColorBuffer:
                AttachColorbuffer(renderbuffer, target);
                break;

            default:
                throw new Exception("Unexpected Renderbuffer type!");
            }
        }
예제 #13
0
        private static Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);
            framebuffer.Bind();
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_RGBA, RenderbufferType.ColorBuffer);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, 0u);// 0
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24, RenderbufferType.DepthBuffer);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return framebuffer;
        }
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            Renderbuffer colorbuffer = framebuffer.Attach(RenderbufferType.ColorBuffer);      //0
            Texture      texture     = framebuffer.Attach(TextureAttachment.ColorAttachment); //1
            Renderbuffer depthbuffer = framebuffer.Attach(RenderbufferType.DepthBuffer);      // special

            framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + 1);                           // as in 1 in framebuffer.Attach(TextureAttachment.ColorAttachment);//1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            this.BindingTexture = texture;

            return(framebuffer);
        }
예제 #15
0
        /// <summary>
        /// Attach a renderbuffer.
        /// </summary>
        /// <param name="renderbuffer"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public Renderbuffer Attach(RenderbufferType renderbuffer, FramebufferTarget target = FramebufferTarget.Framebuffer)
        {
            Renderbuffer result = null;

            switch (renderbuffer)
            {
            case RenderbufferType.DepthBuffer:
                result = AttachDepthbuffer(target);
                break;

            case RenderbufferType.ColorBuffer:
                result = AttachColorbuffer(target);
                break;

            default:
                throw new Exception("Unexpected RenderbufferType!");
            }

            return(result);
        }
예제 #16
0
        private Framebuffer CreatePickFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_RGBA);
                // attach the renderbufer as first color buffer attachment.
                const uint colorAttachmentLocation = 0;
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, colorAttachmentLocation);
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
예제 #17
0
        private void AttachColorbuffer(Renderbuffer renderbuffer, FramebufferTarget target)
        {
            if (nextColorAttachmentIndex >= attachment_id.Length)
            {
                throw new IndexOutOfRangeException("Not enough attach points!");
            }
            if (this.colorBufferList.Count > 0)
            {
                if (this.Width != renderbuffer.Width ||
                    this.Height != renderbuffer.Height)
                {
                    throw new Exception("Size not match!");
                }
            }

            glFramebufferRenderbuffer((uint)target, attachment_id[nextColorAttachmentIndex++], OpenGL.GL_RENDERBUFFER, renderbuffer.Id);
            this.colorBufferList.Add(renderbuffer);
            this.Width  = renderbuffer.Width;
            this.Height = renderbuffer.Height;
        }
예제 #18
0
        private static Framebuffer CreateFramebuffer(int width, int height, ContextGenerationParams parameters)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var  renderbuffer            = new Renderbuffer(width, height, GL.GL_RGBA);
                uint colorAttachmentLocation = 0;
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, colorAttachmentLocation);// 0
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            if (parameters.StencilBits > 0)
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_STENCIL_INDEX8);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Stencil);
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }