Package com.jme3.util
Class NativeObject
java.lang.Object
com.jme3.util.NativeObject
- All Implemented Interfaces:
- Cloneable
- Direct Known Subclasses:
- AudioData,- BufferObject,- Filter,- FrameBuffer,- Image,- Shader,- Shader.ShaderSource,- VertexBuffer
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 SummaryFieldsModifier and TypeFieldDescriptionprotected ObjectA reference to a "handle".protected intThe ID of the object, usually depends on its type.static final intprotected NativeObjectManagerThe object manager to which this NativeObject is registered to.protected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected booleanTrue if the data represented by this GLObject has been changed and needs to be updated before used.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionCreates a new GLObject.protectedNativeObject(int id) Protected constructor that doesn't allocate handle ref.
- 
Method SummaryModifier and TypeMethodDescriptionvoidInternal use only.protected NativeObjectclone()This should create a deep clone.abstract NativeObjectCreates a shallow clone of this GL Object.protected voidDeletes any associated nativebuffers.abstract voiddeleteObject(Object rendererObject) Deletes the GL object from the GPU when it is no longer used.voiddispose()Reclaims native resources used by this NativeObject.intgetId()abstract longReturns a unique ID for this NativeObject.<T> WeakReference<T> Acquire a weak reference to this NativeObject.booleanInternal use only.abstract voidCalled when the GL context is restarted to reset all IDs.voidsetId(int id) Sets the ID of the NativeObject.voidInternal use only.toString()
- 
Field Details- 
INVALID_IDpublic static final int INVALID_ID- See Also:
 
- 
OBJTYPE_VERTEXBUFFERprotected static final int OBJTYPE_VERTEXBUFFER- See Also:
 
- 
OBJTYPE_TEXTUREprotected static final int OBJTYPE_TEXTURE- See Also:
 
- 
OBJTYPE_FRAMEBUFFERprotected static final int OBJTYPE_FRAMEBUFFER- See Also:
 
- 
OBJTYPE_SHADERprotected static final int OBJTYPE_SHADER- See Also:
 
- 
OBJTYPE_SHADERSOURCEprotected static final int OBJTYPE_SHADERSOURCE- See Also:
 
- 
OBJTYPE_AUDIOBUFFERprotected static final int OBJTYPE_AUDIOBUFFER- See Also:
 
- 
OBJTYPE_AUDIOSTREAMprotected static final int OBJTYPE_AUDIOSTREAM- See Also:
 
- 
OBJTYPE_FILTERprotected static final int OBJTYPE_FILTER- See Also:
 
- 
OBJTYPE_BOprotected static final int OBJTYPE_BO- See Also:
 
- 
objectManagerThe object manager to which this NativeObject is registered to.
- 
idprotected int idThe ID of the object, usually depends on its type. Typically returned from calls like glGenTextures, glGenBuffers, etc.
- 
handleRefA 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.
- 
updateNeededprotected boolean updateNeededTrue if the data represented by this GLObject has been changed and needs to be updated before used.
 
- 
- 
Constructor Details- 
NativeObjectpublic NativeObject()Creates a new GLObject. Should be called by the subclasses.
- 
NativeObjectprotected NativeObject(int id) Protected constructor that doesn't allocate handle ref. This is used in subclasses for the createDestructableClone().- Parameters:
- id- the desired ID
 
 
- 
- 
Method Details- 
setIdpublic void setId(int id) Sets the ID of the NativeObject. This method is used in Renderer and must not be called by the user.- Parameters:
- id- The ID to set
 
- 
getIdpublic int getId()- Returns:
- The ID of the object. Should not be used by user code in most cases.
 
- 
setUpdateNeededpublic void setUpdateNeeded()Internal use only. Indicates that the object has changed and its state needs to be updated.
- 
clearUpdateNeededpublic void clearUpdateNeeded()Internal use only. Indicates that the state changes were applied.
- 
isUpdateNeededpublic boolean isUpdateNeeded()Internal use only. Check ifsetUpdateNeeded()was called before.- Returns:
- true if an update is needed, otherwise false
 
- 
toString
- 
cloneThis should create a deep clone. For a shallow clone, use createDestructableClone().
- 
deleteNativeBuffersprotected void deleteNativeBuffers()Deletes any associated nativebuffers. 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
- 
resetObjectpublic abstract void resetObject()Called when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.
- 
deleteObjectDeletes 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
 
- 
createDestructableCloneCreates a shallow clone of this GL Object. The deleteObject method should be functional for this object.- Returns:
- a new instance
 
- 
getUniqueIdpublic abstract long getUniqueId()Returns a unique ID for this NativeObject. No other NativeObject shall have the same ID.- Returns:
- unique ID for this NativeObject.
 
- 
disposepublic 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, unlessNativeObjectManager.UNSAFEis set to true, in that case native buffers are also reclaimed which may introduce instability.
- 
getWeakRefAcquire a weak reference to this NativeObject.- Type Parameters:
- T- the type
- Returns:
- a weak reference (possibly a pre-existing one)
 
 
-