Class ResourceRegistry<R,N>

java.lang.Object
dev.engine.graphics.resource.ResourceRegistry<R,N>
Type Parameters:
R - the phantom resource type (e.g., BufferResource)
N - the native resource data (e.g., Integer for GL names, or a record for VK allocations)

public class ResourceRegistry<R,N> extends Object
Generic resource registry combining a HandlePool with native resource tracking. Used by backends to manage GPU resources (buffers, textures, pipelines, etc.).
  • Constructor Details

    • ResourceRegistry

      public ResourceRegistry(String resourceType)
  • Method Details

    • register

      public Handle<R> register(N nativeResource)
      Allocates a handle and associates native resource data.
    • allocate

      public Handle<R> allocate()
      Allocates a handle without native data (for lazy init).
    • put

      public void put(Handle<R> handle, N nativeResource)
      Associates native data with an existing handle.
    • get

      public N get(Handle<R> handle)
      Gets the native resource for a handle.
    • get

      public N get(int index)
      Gets the native resource by raw index.
    • remove

      public N remove(Handle<R> handle)
      Removes and returns the native resource, releases the handle.
    • isValid

      public boolean isValid(Handle<R> handle)
      Checks if a handle is valid (allocated and not released).
    • size

      public int size()
      Number of currently allocated handles.
    • forEach

      public void forEach(BiConsumer<Integer,N> action)
      Iterates all live resources.
    • destroyAll

      public void destroyAll(Consumer<N> cleanup)
      Destroys all resources using the given cleanup function, then clears.
    • reportLeaks

      public int reportLeaks()
      Reports leaked handles.
    • clear

      public void clear()
      Clears all resources without cleanup.