Class ALspGLResource
- Direct Known Subclasses:
ALspTextureObject,TLspShaderProgram,TLspTextureFont
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.
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
ConstructorsModifierConstructorDescriptionprotectedALspGLResource(String aSourceString) Constructs an OpenGL resource object where the givenStringidentifies its source. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(ILcdGLDrawable aGLDrawable) Binds this GL resource for use with the givenILcdGLDrawable.voiddestroy(ILcdGLDrawable aGLDrawable) Destroys the OpenGL resource so that it becomes no longer available nor valid to use.abstract longgetBytes()Gets the estimated number of bytes this resource occupies in GPU memory.Gets a descriptive string that identifies the source of this OpenGL resource.booleanisBound()Returns true if this resource is currently bound in at least oneILcdGLDrawable.toString()voidunbind(ILcdGLDrawable aGLDrawable) Unbinds this GL resource from the givenILcdGLDrawable.
-
Constructor Details
-
ALspGLResource
Constructs an OpenGL resource object where the givenStringidentifies its source. This can be the name of a painter.- Parameters:
aSourceString- identifies the source of this resource
-
-
Method Details
-
destroy
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
removeit from the GL resource cache.Extensions of this class should preferably call
super.destroy. Doing so will add extra error checking in thebindandunbindmethods, 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
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
-
bind
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 invokesuper.bind(), as this is required for the correct behavior ofisBound().If this resource was already destroyed and the
destroyimplementation callssuper.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
Unbinds this GL resource from the given
ILcdGLDrawable. Implementations should override this method to perform whatever OpenGL calls are needed to undo the effects ofbind(com.luciad.view.opengl.binding.ILcdGLDrawable). Inheriting classes must also always invokesuper.unbind(), as this is required for the correct behavior ofisBound().If this resource was already destroyed and the
destroyimplementation callssuper.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 oneILcdGLDrawable.- Returns:
- true if this resource is currently bound in at least one
ILcdGLDrawable
-