Class ALspGLResource

java.lang.Object
com.luciad.view.lightspeed.services.glcache.ALspGLResource
Direct Known Subclasses:
ALspTextureObject, TLspShaderProgram, TLspTextureFont

public abstract class ALspGLResource extends Object

Any kind of OpenGL resource such as a texture object or frame buffer object, that is destroyable. GL resource objects can be bound and unbound from a given ILcdGLDrawable, and are only valid for use while bound.

The lifecycle of a GL resource should be managed by the view's ILspGLResourceCache:

  • Add the resource to the resource cache using put.
  • Remove it from the view's GL resource cache using remove.
The cache can be obtained from the view's view services. It is important to realize that the cache itself is allowed to remove and destroy resources at any time, e.g., using a least-recently-used principle to free GPU memory. Hence, applications that use the GL resource cache should therefore be prepared to recreate a disposed GL resource if they still need to use it after it was evicted from the cache.

Since:
2012.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ALspGLResource(String aSourceString)
    Constructs an OpenGL resource object where the given String identifies its source.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(ILcdGLDrawable aGLDrawable)
    Binds this GL resource for use with the given ILcdGLDrawable.
    void
    destroy(ILcdGLDrawable aGLDrawable)
    Destroys the OpenGL resource so that it becomes no longer available nor valid to use.
    abstract long
    Gets the estimated number of bytes this resource occupies in GPU memory.
    Gets a descriptive string that identifies the source of this OpenGL resource.
    boolean
    Returns true if this resource is currently bound in at least one ILcdGLDrawable.
     
    void
    unbind(ILcdGLDrawable aGLDrawable)
    Unbinds this GL resource from the given ILcdGLDrawable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ALspGLResource

      protected ALspGLResource(String aSourceString)
      Constructs an OpenGL resource object where the given String identifies its source. This can be the name of a painter.
      Parameters:
      aSourceString - identifies the source of this resource
  • Method Details

    • destroy

      public void destroy(ILcdGLDrawable aGLDrawable)

      Destroys the OpenGL resource so that it becomes no longer available nor valid to use.

      You should never call this yourself. The GL resource cache will automatically remove old resources. Alternatively, if you don't need the resource anymore, manually remove it from the GL resource cache.

      Extensions of this class should preferably call super.destroy. Doing so will add extra error checking in the bind and unbind methods, to make sure that no destroyed resources are used during painting (this may lead to native crashes).

      Parameters:
      aGLDrawable - the drawable this resource is used for
    • getBytes

      public abstract long getBytes()
      Gets the estimated number of bytes this resource occupies in GPU memory.
      Returns:
      the estimated number of bytes
    • getSourceString

      public String getSourceString()
      Gets a descriptive string that identifies the source of this OpenGL resource. It can for example be the name of a painter. Such info is mainly useful for debugging.
      Returns:
      a descriptive string identifying the source of the resource
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • bind

      public void bind(ILcdGLDrawable aGLDrawable)

      Binds this GL resource for use with the given ILcdGLDrawable. Implementations should override this method to perform the appropriate OpenGL call, e.g. glBindTexture(). Inheriting classes must also always invoke super.bind(), as this is required for the correct behavior of isBound().

      If this resource was already destroyed and the destroy implementation calls super.destroy, a runtime exception will be thrown when calling this method.

      Parameters:
      aGLDrawable - the GL drawable in which this resource is to be bound
    • unbind

      public void unbind(ILcdGLDrawable aGLDrawable)

      Unbinds this GL resource from the given ILcdGLDrawable. Implementations should override this method to perform whatever OpenGL calls are needed to undo the effects of bind(com.luciad.view.opengl.binding.ILcdGLDrawable). Inheriting classes must also always invoke super.unbind(), as this is required for the correct behavior of isBound().

      If this resource was already destroyed and the destroy implementation calls super.destroy, a runtime exception will be thrown when calling this method.

      Parameters:
      aGLDrawable - the drawable from which the GL resource should be unbound
    • isBound

      public boolean isBound()
      Returns true if this resource is currently bound in at least one ILcdGLDrawable.
      Returns:
      true if this resource is currently bound in at least one ILcdGLDrawable