Class Context


  • public final class Context
    extends Object
    This class provides a Sound3D Context associated with a specified device.
    Author:
    Athomas Goldberg, Sven Gothel, et al.
    • Field Detail

      • hasALC_thread_local_context

        public final boolean hasALC_thread_local_context
    • Constructor Detail

      • Context

        public Context​(ALCcontext realContext,
                       Device device)
        Creates a new Context for a given ALCcontext for the specified device.
        Parameters:
        realContext - ALCcontext instance, maybe null
        device - The device the Context belongs to, must be valid
      • Context

        public Context​(Device device,
                       int[] attributes)
        Creates a new Context for a specified device including native ALCcontext creation.
        Parameters:
        device - The device the Context is being created for, must be valid.
        attributes - list of ALCcontext attributes for context creation, maybe empty or null
    • Method Detail

      • create

        public boolean create​(int[] attributes)
        Creates the internal ALCcontext instance if getALContext() is null
        Parameters:
        attributes - lost of ALCcontext attributes for context creation
        Returns:
        true if the internal context has been successfully created, otherwise false
      • recreate

        public boolean recreate​(int[] attributes)
        Recreates the internal ALCcontext instance, i.e. destroys it first if getALContext() not null.

        Context is made current again if it was current before.

        Parameters:
        attributes - lost of ALCcontext attributes for context creation
        Returns:
        true if the internal context has been successfully recreated and made current again if was current before, otherwise false
      • isValid

        public boolean isValid()
        Returns whether getALContext() is valid, i.e. not null, e.g. not destroy()'ed.
      • destroy

        public void destroy()
        destroys this context freeing its resources.
      • getCurrentContext

        public static Context getCurrentContext()
        Returns this thread current context. If no context is current, returns null.
        Returns:
        the context current on this thread, or null if no context is current.
        See Also:
        #makeCurrent(), #release()
      • getLockCount

        public int getLockCount()
        Return the lock count of this context, i.e. 0 if not locked, 1 if locked once, >1 for recursive locks.
      • makeCurrent

        public boolean makeCurrent​(boolean throwException)
                            throws ALException
        Makes the audio context current on the calling thread.

        Recursive call to #makeCurrent() and hence #release() are supported.

        At any point in time one context can only be current on one thread, and one thread can only have one context current.

        Parameters:
        throwException - if true, throws ALException if getALContext() is null, current thread holds another context or failed to natively make current
        Returns:
        true if getALContext() is valid, current thread holds no other context and context successfully made current, otherwise false
        Throws:
        ALException
        See Also:
        #release()
      • release

        public boolean release​(boolean throwException)
                        throws ALException
        Releases control of this audio context from the current thread, if implementation utilizes context locking.

        Recursive call to #makeCurrent() and hence #release() are supported.

        If native release fails, internal lock is not released.

        Parameters:
        throwException - if true, throws ALException if context has not been previously made current on current thread or native release failed.
        Returns:
        true if context has previously been made current on the current thread and successfully released, otherwise false
        Throws:
        ALException
        See Also:
        #makeCurrent()
      • suspend

        public void suspend()
        Suspend this context
      • getDevice

        public Device getDevice()
        Gets the device associated with this context.
        Returns:
        the device associated with this context.