Esempio n. 1
0
        /// <summary>
        /// Resizes this <see cref="Framebuffer2D"/>.
        /// </summary>
        /// <param name="width">The new width for the <see cref="Framebuffer2D"/>.</param>
        /// <param name="height">The new height for the <see cref="Framebuffer2D"/>.</param>
        /// <remarks>This resizes all the framebuffer attachments.</remarks>
        public void Resize(uint width, uint height)
        {
            if (width == Width && height == Height)
            {
                return;
            }

            // We go through all the texture attachments and resize them.
            for (int i = 0; i < Framebuffer.textureAttachments.Count; i++)
            {
                if (!(Framebuffer.textureAttachments[i].Texture is Texture2D tex2d))
                {
                    throw new InvalidOperationException("This framebuffer contains non-Texture2D texture attachments, a Resize2D operation is invalid");
                }
                tex2d.RecreateImage(width, height);
            }

            // We go through all the renderbuffer attachments and resize them.
            for (int i = 0; i < Framebuffer.renderbufferAttachments.Count; i++)
            {
                // We can't resize renderbuffers, so we dispose them and create new ones.
                FramebufferRenderbufferAttachment att = Framebuffer.renderbufferAttachments[i];
                Framebuffer.TryDetachRenderbuffer(att.AttachmentPoint, out att);
                att.Renderbuffer.Dispose();
                Framebuffer.Attach(new RenderbufferObject(Framebuffer.GraphicsDevice, width, height, att.Renderbuffer.Format, att.Renderbuffer.Samples), att.AttachmentPoint);
            }

            Framebuffer.UpdateFramebufferData();
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to detach a <see cref="RenderbufferObject"/> attached to the specified point.
        /// </summary>
        /// <param name="point">The attachment point to check.</param>
        /// <param name="attachment">The detached <see cref="RenderbufferObject"/> attachment, if the method returned true.</param>
        /// <returns>Returns whether the operation succeded.</returns>
        public bool TryDetachRenderbuffer(FramebufferAttachmentPoint point, out FramebufferRenderbufferAttachment attachment)
        {
            for (int i = 0; i < renderbufferAttachments.Count; i++)
            {
                if (renderbufferAttachments[i].AttachmentPoint == point)
                {
                    GraphicsDevice.Framebuffer = this;
                    GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, (FramebufferAttachment)point, RenderbufferTarget.Renderbuffer, 0);
                    attachment = renderbufferAttachments[i];
                    renderbufferAttachments.RemoveAt(i);
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a <see cref="RenderbufferObject"/> attachment from this <see cref="FramebufferObject"/>.
        /// </summary>
        /// <param name="attachmentPoint">The point to look for a renderbuffer attachment at.</param>
        /// <param name="attachment">The attachment found.</param>
        /// <returns>Whether a renderbuffer attachment was found at the specified attachment point.</returns>
        public bool TryGetRenderbufferAttachment(FramebufferAttachmentPoint attachmentPoint, out FramebufferRenderbufferAttachment attachment)
        {
            for (int i = 0; i < renderbufferAttachments.Count; i++)
            {
                if (renderbufferAttachments[i].AttachmentPoint == attachmentPoint)
                {
                    attachment = renderbufferAttachments[i];
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }