com.jme3.util
Class NativeObject

java.lang.Object
  extended by com.jme3.util.NativeObject
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
AudioData, Filter, FrameBuffer, Image, Shader, Shader.ShaderSource, VertexBuffer

public abstract class NativeObject
extends java.lang.Object
implements java.lang.Cloneable

Describes a native object. An encapsulation of a certain object on the native side of the graphics or audio library. This class is used to track when OpenGL and OpenAL native objects are collected by the garbage collector, and then invoke the proper destructor on the OpenGL library to delete it from memory.


Field Summary
protected  java.lang.Object handleRef
          A reference to a "handle".
protected  int id
          The ID of the object, usually depends on its type.
protected  java.lang.Class<?> type
          The type of the GLObject, usually specified by a subclass.
protected  boolean updateNeeded
          True if the data represented by this GLObject has been changed and needs to be updated before used.
 
Constructor Summary
  NativeObject(java.lang.Class<?> type)
          Creates a new GLObject with the given type.
protected NativeObject(java.lang.Class<?> type, int id)
          Protected constructor that doesn't allocate handle ref.
 
Method Summary
 void clearUpdateNeeded()
          Internal use only.
protected  NativeObject clone()
          This should create a deep clone.
abstract  NativeObject createDestructableClone()
          Creates a shallow clone of this GL Object.
abstract  void deleteObject(java.lang.Object rendererObject)
          Deletes the GL object from the GPU when it is no longer used.
 int getId()
           
 boolean isUpdateNeeded()
          Internal use only.
abstract  void resetObject()
          Called when the GL context is restarted to reset all IDs.
 void setId(int id)
          Sets the ID of the GLObject.
 void setUpdateNeeded()
          Internal use only.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected int id
The ID of the object, usually depends on its type. Typically returned from calls like glGenTextures, glGenBuffers, etc.


handleRef

protected java.lang.Object handleRef
A reference to a "handle". By hard referencing a certain object, it's possible to find when a certain GLObject is no longer used, and to delete its instance from the graphics library.


updateNeeded

protected boolean updateNeeded
True if the data represented by this GLObject has been changed and needs to be updated before used.


type

protected final java.lang.Class<?> type
The type of the GLObject, usually specified by a subclass.

Constructor Detail

NativeObject

public NativeObject(java.lang.Class<?> type)
Creates a new GLObject with the given type. Should be called by the subclasses.

Parameters:
type - The type that the subclass represents.

NativeObject

protected NativeObject(java.lang.Class<?> type,
                       int id)
Protected constructor that doesn't allocate handle ref. This is used in subclasses for the createDestructableClone().

Method Detail

setId

public void setId(int id)
Sets the ID of the GLObject. This method is used in Renderer and must not be called by the user.

Parameters:
id - The ID to set

getId

public int getId()
Returns:
The ID of the object. Should not be used by user code in most cases.

setUpdateNeeded

public void setUpdateNeeded()
Internal use only. Indicates that the object has changed and its state needs to be updated.


clearUpdateNeeded

public void clearUpdateNeeded()
Internal use only. Indicates that the state changes were applied.


isUpdateNeeded

public boolean isUpdateNeeded()
Internal use only. Check if setUpdateNeeded() was called before.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

protected NativeObject clone()
This should create a deep clone. For a shallow clone, use createDestructableClone().

Overrides:
clone in class java.lang.Object

resetObject

public abstract void resetObject()
Called when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.


deleteObject

public abstract void deleteObject(java.lang.Object rendererObject)
Deletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.

Parameters:
rendererObject - The renderer to be used to delete the object

createDestructableClone

public abstract NativeObject createDestructableClone()
Creates a shallow clone of this GL Object. The deleteObject method should be functional for this object.