Package graphics

Class Framebuffer

java.lang.Object
graphics.Framebuffer

public class Framebuffer extends Object
This class is heavily inspired from TheCherno's Hazel Engine's Framebuffer API

An encapsulation of an OpenGL Framebuffer

Author:
VoxelRifts
  • Constructor Details

    • Framebuffer

      public Framebuffer(int width, int height, FramebufferSpec spec)
      Default Framebuffer constructor
      Parameters:
      width - int: width of the fbo
      height - int: height of the fbo
      spec - FramebufferSpec: Specification of the framebuffer
  • Method Details

    • createDefault

      public static Framebuffer createDefault()
      Factory method to create an instance that manages the default framebuffer
      Returns:
      Framebuffer
    • createWithColorAttachment

      public static Framebuffer createWithColorAttachment()
      Factory method to create an instance that has one simple color attachment
      Returns:
      Framebuffer
    • createHalfResWithColorAttachment

      public static Framebuffer createHalfResWithColorAttachment()
      Factory method to create an instance that is half the size of the screen and has one simple color attachment
      Returns:
      Framebuffer
    • resizeAll

      public static void resizeAll(EventData.WindowResizeEventData data)
      Resize all Framebuffers created via the createWithColorAttachment() or createHalfResWithColorAttachment() methods
    • unbind

      public static void unbind()
      Unbinds the framebuffer i.e. binds the default framebuffer
    • clean

      public static void clean()
      Deletes all Framebuffers

      Called after the X is pressed

    • isDefault

      public boolean isDefault()
      Checks if the fbo is a wrapper around the default one. Required because created wrapper has no attachments stored in colorAttachmentTextures
      Returns:
      if the framebuffer instance is a wrapper around the
    • getColorAttachment

      public Texture getColorAttachment(int i)
      Get a color texture attachment id from the framebuffer
      Parameters:
      i - index of the texture attachment required
      Returns:
      the color attachment texture id at the index
    • getDepthAttachment

      public Texture getDepthAttachment()
      Get the depth attachment texture from this framebuffer
      Returns:
      the depth attachment texture id
    • blitColorBuffersToScreen

      public void blitColorBuffersToScreen()
      Copies all data from the color texture attachments of this framebuffer to the texture attachments of the default Framebuffer. OpenGL provides a function, glBlitFramebuffer for this
    • blitEntireFboToScreen

      public void blitEntireFboToScreen()
      Copies all data from the ALL texture attachments of this framebuffer to the texture attachments of the default Framebuffer. OpenGL provides a function, glBlitFramebuffer for this
    • resize

      public void resize(int width, int height)
      Resize the Framebuffer to a specific size it will regenerate the entire framebuffer
      Parameters:
      width - int: new width
      height - int new height
    • bind

      public void bind()
      Binds the framebuffer
    • delete

      public void delete()
      Deletes the texture attachments and the framebuffer
    • getWidth

      public int getWidth()
      Get the width of this Framebuffer
      Returns:
      width of the Framebuffer
    • getHeight

      public int getHeight()
      Get the height of this Framebuffer
      Returns:
      height of the Framebuffer