Package com.jme3.util

Class NativeObject

All Implemented Interfaces:
Direct Known Subclasses:
AudioData, BufferObject, Filter, FrameBuffer, Image, Shader, Shader.ShaderSource, VertexBuffer

public abstract class NativeObject extends Object implements 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 Details


      public static final int INVALID_ID
      See Also:

      protected static final int OBJTYPE_VERTEXBUFFER
      See Also:

      protected static final int OBJTYPE_TEXTURE
      See Also:

      protected static final int OBJTYPE_FRAMEBUFFER
      See Also:

      protected static final int OBJTYPE_SHADER
      See Also:

      protected static final int OBJTYPE_SHADERSOURCE
      See Also:

      protected static final int OBJTYPE_AUDIOBUFFER
      See Also:

      protected static final int OBJTYPE_AUDIOSTREAM
      See Also:

      protected static final int OBJTYPE_FILTER
      See Also:

      protected static final int OBJTYPE_BO
      See Also:
    • objectManager

      protected NativeObjectManager objectManager
      The object manager to which this NativeObject is registered to.
    • id

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

      protected 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.
  • Constructor Details

    • NativeObject

      public NativeObject()
      Creates a new GLObject. Should be called by the subclasses.
    • NativeObject

      protected NativeObject(int id)
      Protected constructor that doesn't allocate handle ref. This is used in subclasses for the createDestructableClone().
      id - the desired ID
  • Method Details

    • setId

      public void setId(int id)
      Sets the ID of the NativeObject. This method is used in Renderer and must not be called by the user.
      id - The ID to set
    • getId

      public int getId()
      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.
      true if an update is needed, otherwise false
    • toString

      public String toString()
      toString in class Object
    • clone

      protected NativeObject clone()
      This should create a deep clone. For a shallow clone, use createDestructableClone().
      clone in class Object
    • deleteNativeBuffers

      protected void deleteNativeBuffers()
      Deletes any associated native buffers. This is necessary because it is unlikely that native buffers will be garbage collected naturally (due to how GC works), therefore the collection must be handled manually. Only implementations that manage native buffers need to override this method. Note that the behavior that occurs when a deleted native buffer is used is not defined, therefore this method is protected
    • 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(Object rendererObject)
      Deletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.
      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.
      a new instance
    • getUniqueId

      public abstract long getUniqueId()
      Returns a unique ID for this NativeObject. No other NativeObject shall have the same ID.
      unique ID for this NativeObject.
    • dispose

      public void dispose()
      Reclaims native resources used by this NativeObject. It should be safe to call this method or even use the object after it has been reclaimed, unless NativeObjectManager.UNSAFE is set to true, in that case native buffers are also reclaimed which may introduce instability.
    • getWeakRef

      public <T> WeakReference<T> getWeakRef()
      Acquire a weak reference to this NativeObject.
      Type Parameters:
      T - the type
      a weak reference (possibly a pre-existing one)