Class TextureAllocator

java.lang.Object
dev.pfaff.altargui.texture.TextureAllocator
All Implemented Interfaces:
AutoCloseable

public final class TextureAllocator extends Object implements AutoCloseable

Arrays: | 1 | 2 | 3 |
Active: | D | U* | U |

States:

  1. D clean for drawing
  2. U accepting uploads
  3. U* finishing upload

When a buffer with state U* is finished, it transitions to state D, the previous buffer transitions to state U, and the next buffer transitions to state U*. Thanks to this model, the states of all three buffers may be represented using a single 2-bit index.

|---|---|---|
| A | B | C |
|---|---|---|

Initial state:

  • A) Drawing
  • B) Finishing (nothing)
  • C) Uploading

Next state, triggered on job submission to C:

  • A) Uploading
  • B) Drawing
  • C) Finishing (at least 1 job)

Next state, triggered on job completion in C:

  • A) Finishing (possibly nothing)
  • B) Uploading
  • C) Drawing

Next state, triggered on job completion in A (if any) and job submission to B:

  • A) Drawing
  • B) Finishing (possibly nothing)
  • C) Uploading
  • Field Details

    • TBS_COUNT

      public static final byte TBS_COUNT
      See Also:
    • MAX_TEXTURE_SIZE

      public static final int MAX_TEXTURE_SIZE
    • UNIT

      public static final int UNIT
      The minimum allocation size in pixels. Herein we often measure in "units" rather than pixels for efficiency.
  • Constructor Details

    • TextureAllocator

      public TextureAllocator(int size, int initialLayers)
      Parameters:
      size - the width and height of each layer.
  • Method Details

    • reset

      public void reset()
    • boundForDraw

      public InfallibleAutoClosable boundForDraw()
    • alloc

      Gets a shader to the given texture. If not loaded, the texture will be loaded and a slot allocated for it.

      This method must only be called from the main thread.

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • dump

      public void dump()