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
:
put
.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.
Modifier | Constructor and Description |
---|---|
protected |
ALspGLResource(String aSourceString)
Constructs an OpenGL resource object where the
given
String identifies its source. |
Modifier and Type | Method and 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 |
getBytes()
Gets the estimated number of bytes this resource occupies
in GPU memory.
|
String |
getSourceString()
Gets a descriptive string that identifies the
source of this OpenGL resource.
|
boolean |
isBound()
Returns true if this resource is currently bound in at least one
ILcdGLDrawable . |
String |
toString() |
void |
unbind(ILcdGLDrawable aGLDrawable)
Unbinds this GL resource from the given
ILcdGLDrawable . |
protected ALspGLResource(String aSourceString)
String
identifies its source. This
can be the name of a painter.aSourceString
- identifies the source of this resourcepublic 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).
aGLDrawable
- the drawable this resource is used forpublic abstract long getBytes()
public String getSourceString()
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.
aGLDrawable
- the GL drawable in which this resource is to be boundpublic 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.
aGLDrawable
- the drawable from which the GL resource should be unboundpublic boolean isBound()
ILcdGLDrawable
.ILcdGLDrawable