Interface AdvancedFbo

All Superinterfaces:
AutoCloseable, org.lwjgl.system.NativeResource
All Known Implementing Classes:
AdvancedFboImpl, VanillaAdvancedFboWrapper

public interface AdvancedFbo extends org.lwjgl.system.NativeResource

A framebuffer that has more capabilities than the vanilla Minecraft RenderTarget.

In order to resize, NativeResource.free() must be called and a new framebuffer should be created. Multiple color buffers of different types and depth attachments can be added.

Draw buffers are set automatically, but the default can be retrieved with getDrawBuffers() to effectively reset it. The draw buffers are set once by default and must be reset back if modified.

See Also:
  • Method Details

    • create

      void create()
      Creates the framebuffer and all attachments.
    • clear

      void clear()
      Clears the buffers in this framebuffer.
    • bind

      void bind(boolean setViewport)
      Binds this framebuffer for read and draw requests.
      Parameters:
      setViewport - Whether to set the viewport to fit the bounds of this framebuffer
    • bindRead

      void bindRead()
      Binds this framebuffer for read requests.
    • bindDraw

      void bindDraw(boolean setViewport)
      Binds this framebuffer for draw requests.
      Parameters:
      setViewport - Whether to set the viewport to fit the bounds of this framebuffer
    • getMainFramebuffer

      static AdvancedFbo getMainFramebuffer()
      Gets the main framebuffer.
      Returns:
      main framebuffer
    • unbind

      static void unbind()
      Binds the main Minecraft framebuffer for writing and reading.
    • unbindRead

      static void unbindRead()
      Binds the main Minecraft framebuffer for reading.
    • unbindDraw

      static void unbindDraw()
      Binds the main Minecraft framebuffer for drawing.
    • draw

      default void draw()
      Draws this framebuffer to the screen.
    • resolveToFbo

      default void resolveToFbo(int id, int width, int height, int mask, int filtering)
      Resolves this framebuffer to the framebuffer with the specified id as the target.
      Parameters:
      id - The id of the framebuffer to copy into
      width - The width of the framebuffer being copied into
      height - The height of the framebuffer being copied into
      mask - The buffers to copy into the provided framebuffer
      filtering - The filter to use if this framebuffer and the provided framebuffer are different sizes
    • resolveToAdvancedFbo

      default void resolveToAdvancedFbo(AdvancedFbo target)
      Resolves this framebuffer to the provided advanced framebuffer as the target.
      Parameters:
      target - The target framebuffer to copy data into
    • resolveToAdvancedFbo

      default void resolveToAdvancedFbo(AdvancedFbo target, int mask, int filtering)
      Resolves this framebuffer to the provided advanced framebuffer as the target.
      Parameters:
      target - The target framebuffer to copy data into
      mask - The buffers to copy into the provided framebuffer
      filtering - The filter to use if this framebuffer and the provided framebuffer are different sizes
    • resolveToFramebuffer

      default void resolveToFramebuffer(com.mojang.blaze3d.pipeline.RenderTarget target)
      Resolves this framebuffer to the provided minecraft framebuffer as the target.
      Parameters:
      target - The target framebuffer to copy data into
    • resolveToFramebuffer

      default void resolveToFramebuffer(com.mojang.blaze3d.pipeline.RenderTarget target, int mask, int filtering)
      Resolves this framebuffer to the provided minecraft framebuffer as the target.
      Parameters:
      target - The target framebuffer to copy data into
      mask - The buffers to copy into the provided framebuffer
      filtering - The filter to use if this framebuffer and the provided framebuffer are different sizes
    • resolveToScreen

      default void resolveToScreen()
      Resolves this framebuffer to the window framebuffer as the target.
    • resolveToScreen

      default void resolveToScreen(int mask, int filtering)
      Resolves this framebuffer to the window framebuffer as the target.
      Parameters:
      mask - The buffers to copy into the provided framebuffer
      filtering - The filter to use if this framebuffer and the provided framebuffer are different sizes
    • getId

      int getId()
      Returns:
      The id of this framebuffer or -1 if it has been deleted
    • getWidth

      int getWidth()
      Returns:
      The width of this framebuffer
    • getHeight

      int getHeight()
      Returns:
      The height of this framebuffer
    • getColorAttachments

      int getColorAttachments()
      Returns:
      The amount of color attachments in this framebuffer
    • getClearMask

      int getClearMask()
      Returns:
      The mak used while clearing the buffer
    • getDrawBuffers

      int[] getDrawBuffers()
      Returns:
      The names of the default draw buffer state
    • hasColorAttachment

      boolean hasColorAttachment(int attachment)
      Checks to see if the provided attachment has been added to this framebuffer.
      Parameters:
      attachment - The attachment to check
      Returns:
      Whether there is a valid attachment in the specified slot
    • hasDepthAttachment

      boolean hasDepthAttachment()
      Returns:
      Whether there is a depth attachment added to this framebuffer
    • getColorAttachment

      AdvancedFboAttachment getColorAttachment(int attachment)
      Checks the attachments for the specified slot. If the amount of attachments is unknown, use hasColorAttachment(int) to verify before calling this.
      Parameters:
      attachment - The attachment to get
      Returns:
      The attachment in the specified attachment slot
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot
    • isColorTextureAttachment

      default boolean isColorTextureAttachment(int attachment)
      Checks to see if the provided attachment has been added to this framebuffer and is a texture attachment.
      Parameters:
      attachment - The attachment to check
      Returns:
      Whether there is a valid attachment in the specified slot
    • isMutableColorTextureAttachment

      default boolean isMutableColorTextureAttachment(int attachment)
      Checks to see if the provided attachment has been added to this framebuffer and is a mutable texture attachment.
      Parameters:
      attachment - The attachment to check
      Returns:
      Whether there is a valid attachment in the specified slot
    • isColorRenderAttachment

      default boolean isColorRenderAttachment(int attachment)
      Checks to see if the provided attachment has been added to this framebuffer and is a render attachment.
      Parameters:
      attachment - The attachment to check
      Returns:
      Whether there is a valid attachment in the specified slot
    • getColorTextureAttachment

      default AdvancedFboTextureAttachment getColorTextureAttachment(int attachment)
      Retrieves the attachment for the specified slot. If the attachment is not known to be an AdvancedFboTextureAttachment, use isColorTextureAttachment(int) before calling this.
      Parameters:
      attachment - The attachment to get
      Returns:
      The texture attachment in the specified attachment slot
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboTextureAttachment
    • setColorAttachmentTexture

      default void setColorAttachmentTexture(int attachment, int textureId)
      Updates the 2D texture attachment reference for the specified slot. If the attachment is not known to be an AdvancedFboMutableTextureAttachment, use isMutableColorTextureAttachment(int) before calling this.
      Parameters:
      attachment - The attachment to modify
      textureId - The id of the texture to draw into
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboMutableTextureAttachment
    • setColorAttachmentTexture

      default void setColorAttachmentTexture(int attachment, int textureId, int layer)

      Updates the texture attachment reference for the specified slot. if the attachment is not known to be an AdvancedFboMutableTextureAttachment, use isMutableColorTextureAttachment(int) before calling this.

      The framebuffer must be bound before calling this

      Parameters:
      attachment - The attachment to modify
      textureId - The id of the texture to draw into
      layer - The texture layer to attach. For cubemaps this is the attachment face
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboMutableTextureAttachment
    • getColorRenderAttachment

      default AdvancedFboRenderAttachment getColorRenderAttachment(int attachment)
      Retrieves the attachment for the specified slot. If the attachment is not known to be an AdvancedFboRenderAttachment, use isColorRenderAttachment(int) before calling this.
      Parameters:
      attachment - The attachment to get
      Returns:
      The render attachment in the specified attachment slot
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboRenderAttachment
    • getDepthAttachment

      AdvancedFboAttachment getDepthAttachment()
      Returns:
      The depth attachment of this framebuffer
      Throws:
      IllegalArgumentException - If there is no depth attachment in this framebuffer
    • isDepthTextureAttachment

      default boolean isDepthTextureAttachment()
      Returns:
      Whether a depth texture attachment has been added to this framebuffer
    • isDepthMutableTextureAttachment

      default boolean isDepthMutableTextureAttachment()
      Returns:
      Whether a mutable depth texture attachment has been added to this framebuffer
    • isDepthRenderAttachment

      default boolean isDepthRenderAttachment()
      Returns:
      Whether a depth render attachment has been added to this framebuffer
    • getDepthTextureAttachment

      default AdvancedFboTextureAttachment getDepthTextureAttachment()
      Retrieves a depth buffer texture attachment. If the attachment is not known to be a AdvancedFboTextureAttachment, use isDepthTextureAttachment() before calling this.
      Returns:
      The texture attachment in the specified attachment slot
      Throws:
      IllegalArgumentException - If there is no depth attachment in this framebuffer, or it is not an AdvancedFboTextureAttachment
    • setDepthAttachmentTexture

      default void setDepthAttachmentTexture(int textureId)
      Updates the 2D depth texture attachment reference for the specified slot. If the attachment is not known to be an AdvancedFboMutableTextureAttachment, use isMutableColorTextureAttachment(int) before calling this.
      Parameters:
      textureId - The id of the texture to draw into
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboMutableTextureAttachment
    • setDepthAttachmentTexture

      default void setDepthAttachmentTexture(int textureId, int layer)

      Updates the depth texture attachment reference for the specified slot. If the attachment is not known to be an AdvancedFboMutableTextureAttachment, use isMutableColorTextureAttachment(int) before calling this.

      The framebuffer must be bound before calling this

      Parameters:
      textureId - The id of the texture to draw into
      layer - The texture layer to attach. For cubemaps this is the attachment face
      Throws:
      IllegalArgumentException - If there is no attachment in the specified attachment slot, or it is not an AdvancedFboMutableTextureAttachment
    • getDepthRenderAttachment

      default AdvancedFboRenderAttachment getDepthRenderAttachment()
      Retrieves a depth buffer render attachment. If the attachment is not known to be a AdvancedFboRenderAttachment, use isDepthRenderAttachment() before calling this.
      Returns:
      The render attachment in the specified attachment slot
      Throws:
      IllegalArgumentException - If there is no depth attachment in this framebuffer, or it is not an AdvancedFboRenderAttachment
    • toRenderTarget

      com.mojang.blaze3d.pipeline.RenderTarget toRenderTarget()
      Returns:
      A RenderTarget that uses this advanced fbo as the target
    • withSize

      static AdvancedFbo.Builder withSize(int width, int height)
      Creates a new AdvancedFbo with the provided width and height.
      Parameters:
      width - The width of the canvas
      height - The height of the canvas
      Returns:
      A builder to construct a new FBO
    • copy

      static AdvancedFbo.Builder copy(AdvancedFbo parent)
      Creates a copy of the provided AdvancedFbo.
      Parameters:
      parent - The parent to copy attachments from
      Returns:
      A builder to construct a new FBO
    • copy

      static AdvancedFbo.Builder copy(com.mojang.blaze3d.pipeline.RenderTarget parent)
      Creates a copy of the provided RenderTarget.
      Parameters:
      parent - The parent to copy attachments from
      Returns:
      A builder to construct a new FBO