Class Core
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Ensures that the current thread is the main thread, otherwise a runtime exception will be thrown.static void
Ensures that the current thread is the render thread, otherwise a runtime exception will be thrown.static void
Ensures that the current thread is the UI thread, otherwise a runtime exception will be thrown.static void
This should be rarely used.static void
This should be rarely used.static void
Flush main thread calls if the main thread is not a looper thread.static Handler
Returns a shared main thread handler.static Thread
static Executor
static Thread
static Handler
Returns the sharedHandler
that created on UI thread, if initialized.static Handler
Returns the sharedHandler
that created on UI thread, if initialized.static Thread
static Executor
static void
glDebugMessage
(int source, int type, int id, int severity, int length, long message, long userParam) static void
static void
Show a dialog that lists unsupported extensions after initialized.static void
Initializes the GLFW and the main thread.static boolean
static boolean
initOpenGL
(ContextOptions options) Initializes OpenGL pipeline and the render thread.static Looper
Initializes UI thread and its event loop.static boolean
static boolean
initVulkan
(ContextOptions options) Initializes Vulkan pipeline and the render thread.static boolean
static boolean
static boolean
static boolean
Launches the associated application to open the URI.static boolean
Launches the associated application to open the URI.static ImmediateContext
static RecordingContext
static void
Post an async operation that will be executed on main thread.static void
Post an async operation that will be executed on main thread.static ByteBuffer
readIntoNativeBuffer
(InputStream stream) Allocates native memory and read buffered resource.static ByteBuffer
readIntoNativeBuffer
(ReadableByteChannel channel) Allocates native memory and read buffered resource.static Cleaner.Cleanable
registerCleanup
(Object target, Runnable action) Registers a target and a cleaning action to run when the target becomes phantom reachable.static ImmediateContext
static RecordingContext
static void
Terminates the GLFW.static long
Returns the current value of GLFW's highest-resolution monotonic time source, in milliseconds.static long
Returns the current value of GLFW's highest-resolution monotonic time source, in nanoseconds.
-
Method Details
-
registerCleanup
@NonNull public static Cleaner.Cleanable registerCleanup(@NonNull Object target, @NonNull Runnable action) Registers a target and a cleaning action to run when the target becomes phantom reachable. The action object should never hold any reference to the target object.- Parameters:
target
- the target to monitoraction
- aRunnable
to invoke when the target becomes phantom reachable- Returns:
- a
Cleanable
instance representing the registry entry
-
initialize
Initializes the GLFW and the main thread.If the GLFW has already been initialized, this method just specifies the current thread as the main thread. If both are done, it will cause an assertion error.
-
terminate
Terminates the GLFW. -
checkMainThread
public static void checkMainThread()Ensures that the current thread is the main thread, otherwise a runtime exception will be thrown. -
getMainThread
- Returns:
- the main thread if initialized, or null
-
isOnMainThread
public static boolean isOnMainThread()- Returns:
- whether the current thread is the main thread
-
initOpenGL
-
initOpenGL
Initializes OpenGL pipeline and the render thread.Before calling this method, it is necessary to ensure that the GL library is loaded and that the current thread has an OpenGL context for a certain platform window.
- Returns:
- true if successful
-
glSetupDebugCallback
-
glDebugMessage
public static void glDebugMessage(int source, int type, int id, int severity, int length, long message, long userParam) -
glShowCapsErrorDialog
Show a dialog that lists unsupported extensions after initialized. -
initVulkan
-
initVulkan
Initializes Vulkan pipeline and the render thread.Before calling this method, it is necessary to ensure that the VK library is loaded and that Vulkan is available for the current platform.
- Returns:
- true if successful
-
checkRenderThread
public static void checkRenderThread()Ensures that the current thread is the render thread, otherwise a runtime exception will be thrown. -
getRenderThread
- Returns:
- the render thread if initialized, or null
-
isOnRenderThread
public static boolean isOnRenderThread()- Returns:
- whether the current thread is the render thread
-
requireImmediateContext
-
peekImmediateContext
-
getMainHandlerAsync
Returns a shared main thread handler. The handler is not always available. ConsiderexecuteOnMainThread(Runnable)
instead.- Returns:
- async main handler
-
postOnMainThread
Post an async operation that will be executed on main thread.- Parameters:
r
- the runnable
-
executeOnMainThread
This should be rarely used. Only when the render thread and the main thread are the same thread, and you need to call some methods that must be called on the main thread.- Parameters:
r
- the runnable
-
getMainThreadExecutor
-
flushMainCalls
public static void flushMainCalls()Flush main thread calls if the main thread is not a looper thread. -
initUiThread
Initializes UI thread and its event loop.UI thread can be the main thread iff the main thread is a looper thread.
- Returns:
- the event loop
-
checkUiThread
public static void checkUiThread()Ensures that the current thread is the UI thread, otherwise a runtime exception will be thrown. -
getUiThread
- Returns:
- the UI thread if initialized, or null
-
isOnUiThread
public static boolean isOnUiThread()- Returns:
- whether the current thread is the UI thread
-
requireUiRecordingContext
-
peekUiRecordingContext
-
getUiHandler
Returns the sharedHandler
that created on UI thread, if initialized. It can be used for thread scheduling of callback operations.- Returns:
- the shared UI handler
- See Also:
-
getUiHandlerAsync
Returns the sharedHandler
that created on UI thread, if initialized. It can be used for thread scheduling of callback operations.Differently from
getUiHandler()
, this is an async version. Messages sent to an async handler are guaranteed to be ordered with respect to one another, but not necessarily with respect to messages from other Handlers.- Returns:
- the shared UI handler
- See Also:
-
postOnUiThread
Post an async operation that will be executed on main thread.- Parameters:
r
- the runnable
-
executeOnUiThread
This should be rarely used. Only when the render thread and the main thread are the same thread, and you need to call some methods that must be called on the main thread.- Parameters:
r
- the runnable
-
getUiThreadExecutor
-
timeNanos
public static long timeNanos()Returns the current value of GLFW's highest-resolution monotonic time source, in nanoseconds. The resolution of the timer is system dependent, but is usually on the order of a few micro- or nanoseconds. The timer measures time elapsed since GLFW was initialized.Calling this method is faster than
System.nanoTime()
. This time base is used in all input events and frame events, but not in high-level API (such as animations).- Returns:
- current time in nanoseconds
-
timeMillis
public static long timeMillis()Returns the current value of GLFW's highest-resolution monotonic time source, in milliseconds. The resolution of the timer is system dependent, but is usually on the order of a few micro- or nanoseconds. The timer measures time elapsed since GLFW was initialized.You should NOT use this time base in high-level API (such as animations).
- Returns:
- current time in milliseconds
-
readIntoNativeBuffer
@NonNull public static ByteBuffer readIntoNativeBuffer(@NonNull ReadableByteChannel channel) throws IOException Allocates native memory and read buffered resource. The memory MUST be manually freed byMemoryUtil.memFree(Buffer)
. This method can read up to 2GB. This method does NOT close the channel.- Parameters:
channel
- where to read input from- Returns:
- the native pointer to
unsigned char *data
- Throws:
IOException
- some errors occurred while reading
-
readIntoNativeBuffer
@NonNull public static ByteBuffer readIntoNativeBuffer(@NonNull InputStream stream) throws IOException Allocates native memory and read buffered resource. The memory MUST be manually freed byMemoryUtil.memFree(Buffer)
. This method can read up to 2GB. This method does NOT close the stream.- Parameters:
stream
- where to read input from- Returns:
- the native pointer to
unsigned char *data
- Throws:
IOException
- some errors occurred while reading
-
openURI
Launches the associated application to open the URI.- Returns:
- true on success, false on failure
-
openURI
Launches the associated application to open the URI.- Returns:
- true on success, false on failure
-