From 139e7b4cfbd435953b67612a8b8460761ed708a8 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 25 Nov 2002 17:04:56 +0000 Subject: [PATCH] Added releaseContext to BaseGL.java (and native for linux) --- src/java/org/lwjgl/opengl/BaseGL.java | 15 +++++++++++++++ src/native/common/org_lwjgl_opengl_BaseGL.h | 10 +++++++++- src/native/linux/org_lwjgl_opengl_BaseGL.cpp | 17 +++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/java/org/lwjgl/opengl/BaseGL.java b/src/java/org/lwjgl/opengl/BaseGL.java index 0f3374d6..9bd94550 100644 --- a/src/java/org/lwjgl/opengl/BaseGL.java +++ b/src/java/org/lwjgl/opengl/BaseGL.java @@ -165,6 +165,16 @@ abstract class BaseGL { destroy(); } + /** + * Free the context from the current thread. + */ + public final void releaseContext() { + assert created : "GL has not been created yet."; + renderThread = null; + currentContext = null; + nReleaseContext(); + } + /** * Make this the current context for the current thread. */ @@ -180,6 +190,11 @@ abstract class BaseGL { */ public native void swapBuffers(); + /** + * Native method to free the context + */ + private native void nReleaseContext(); + /** * Native method to make this the current thread */ diff --git a/src/native/common/org_lwjgl_opengl_BaseGL.h b/src/native/common/org_lwjgl_opengl_BaseGL.h index a8603502..696055ba 100644 --- a/src/native/common/org_lwjgl_opengl_BaseGL.h +++ b/src/native/common/org_lwjgl_opengl_BaseGL.h @@ -9,7 +9,7 @@ extern "C" { #endif /* Inaccessible static: _00024assertionsDisabled */ /* Inaccessible static: currentContext */ -/* Inaccessible static: class_000240 */ +/* Inaccessible static: class_00024org_00024lwjgl_00024opengl_00024BaseGL */ /* * Class: org_lwjgl_opengl_BaseGL * Method: nCreate @@ -34,6 +34,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers (JNIEnv *, jobject); +/* + * Class: org_lwjgl_opengl_BaseGL + * Method: nReleaseContext + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext + (JNIEnv *, jobject); + /* * Class: org_lwjgl_opengl_BaseGL * Method: nMakeCurrent diff --git a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp index 32ff5696..8e57fe32 100644 --- a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp +++ b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp @@ -51,6 +51,10 @@ void makeCurrent(void) { glXMakeCurrent(disp, win, context); } +void releaseContext(void) { + glXMakeCurrent(disp, None, NULL); +} + /* * Class: org_lwjgl_opengl_BaseGL * Method: nCreate @@ -92,8 +96,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy (JNIEnv * env, jobject obj) { - glXMakeCurrent(disp, None, NULL); - + releaseContext(); // Delete the rendering context if (context != NULL) glXDestroyContext(disp, context); @@ -120,3 +123,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent makeCurrent(); } +/* + * * Class: org_lwjgl_opengl_BaseGL + * * Method: nFreeContext + * * Signature: ()V + * */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext + (JNIEnv *, jobject) +{ + releaseContext(); +}