From 6a58bc26e6014adb4cbe8666b0c8a6178b98e06f Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Mon, 23 Feb 2004 23:42:58 +0000 Subject: [PATCH] New context management code (incomplete) --- src/java/org/lwjgl/AWTAdapter.java | 64 ++++++++ src/java/org/lwjgl/Adapter.java | 52 +++++++ src/java/org/lwjgl/Sys.java | 42 ++++-- src/java/org/lwjgl/opengl/GLContext.java | 48 ++---- src/java/org/lwjgl/opengl/Window.java | 7 +- src/java/org/lwjgl/test/SysTest.java | 4 +- src/native/common/extgl.cpp | 70 ++++----- src/native/common/extgl.h | 10 +- .../common/org_lwjgl_opengl_GLContext.cpp | 61 ++++++++ .../common/org_lwjgl_opengl_GLContext.h | 138 ++++++++++++++++++ src/native/common/org_lwjgl_opengl_Window.h | 23 ++- src/native/win32/org_lwjgl_Sys.cpp | 14 +- src/native/win32/org_lwjgl_Sys.h | 79 ++++++++++ src/native/win32/org_lwjgl_opengl_Window.cpp | 9 +- 14 files changed, 501 insertions(+), 120 deletions(-) create mode 100644 src/java/org/lwjgl/AWTAdapter.java create mode 100644 src/java/org/lwjgl/Adapter.java create mode 100644 src/native/common/org_lwjgl_opengl_GLContext.cpp create mode 100644 src/native/common/org_lwjgl_opengl_GLContext.h create mode 100644 src/native/win32/org_lwjgl_Sys.h diff --git a/src/java/org/lwjgl/AWTAdapter.java b/src/java/org/lwjgl/AWTAdapter.java new file mode 100644 index 00000000..3ad30970 --- /dev/null +++ b/src/java/org/lwjgl/AWTAdapter.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2002 Lightweight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl; + +import javax.swing.JOptionPane; + +/** + * $Id$ + * + * An AWT adapter for using AWT to take care of things on platforms where we + * know AWT is present. + *

Note To compile LWJGL applications with Excelsior JET that use JetPerfect + * and that have no dependencies on AWT, do not include this class in your + * JET project. + * + * @author cix_foo + * @version $Revision$ + */ +final class AWTAdapter implements Adapter { + /** + * C'tor + */ + AWTAdapter() { + } + + /** + * Spawn a "modal" dialog in the centre of the screen with a message in it + * and an OK button. This method blocks until the dialog is dismissed. + * @param title + * @param message + */ + public void alert(String title, String message) { + JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE); + } +} diff --git a/src/java/org/lwjgl/Adapter.java b/src/java/org/lwjgl/Adapter.java new file mode 100644 index 00000000..67d07ecb --- /dev/null +++ b/src/java/org/lwjgl/Adapter.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002 Lightweight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl; + + +/** + * $Id$ + * + * Interface for adapting to window environments. + * + * @author cix_foo + * @version $Revision$ + */ +public interface Adapter { + + /** + * Spawn a "modal" dialog in the centre of the screen with a message in it + * and an OK button. This method blocks until the dialog is dismissed. + * @param title + * @param message + */ + public void alert(String title, String message); +} diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 326171cf..ab2aa5b5 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -188,12 +188,13 @@ public final class Sys { * Attempt to display a modal alert to the user. This method should be used * when a game fails to initialize properly or crashes out losing its display * in the process. It is provided because AWT may not be available on the target - * platform. - * + * platform, although on Mac and Linux and other platforms supporting AWT we + * delegate the task to AWT instead of doing it ourselves. + *

* The alert should display the title and the message and then the current * thread should block until the user dismisses the alert - typically with an * OK button click. - * + *

* It may be that the user's system has no windowing system installed for some * reason, in which case this method may do nothing at all, or attempt to provide * some console output. @@ -201,31 +202,41 @@ public final class Sys { * @param title The title of the alert. We suggest using the title of your game. * @param message The message text for the alert. */ - public static native void alert(String title, String message); - - /* - * Cas: this is just a debugging aid. The native code is also commented out. - * - public static native int getDirectBufferAddress(Buffer buf); - */ + public static void alert(String title, String message) { + String osName = System.getProperty("os.name"); + if (osName.startsWith("Windoxws")) { + nAlert(title, message); + } else { + try { + Adapter adapter = (Adapter) Class.forName("org.lwjgl.AWTAdapter").newInstance(); // This avoids a Jet error message + adapter.alert(title, message); + } catch (Exception e) { + e.printStackTrace(System.err); + } + } + } + + private static native void nAlert(String title, String message); /** * Open the system web browser and point it at the specified URL. It is recommended * that this not be called whilst your game is running, but on application exit in * a shutdown hook, as the screen resolution will not be reset when the browser is * brought into view. - * + *

* There is no guarantee that this will work, nor that we can detect if it has * failed - hence we don't return success code or throw an Exception. This is just a * best attempt at opening the URL given - don't rely on it to work! + *

* @param url The URL + * @return false if we are CERTAIN the call has failed */ - public static void openURL(String url) { + public static boolean openURL(String url) { String osName = System.getProperty("os.name"); if (osName.startsWith("Mac OS") || osName.startsWith("Windows")) { // Mac and Windows both do this nicely from native code. nOpenURL(url); - return; + return true; } // Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it // right anyway. @@ -235,12 +246,15 @@ public final class Sys { for (int i = 0; i < browsers.length; i ++) { try { Runtime.getRuntime().exec(new String[] { browsers[i], url }); - break; + return true; } catch (IOException e) { // Ignore e.printStackTrace(System.err); } } + + // Seems to have failed + return false; } diff --git a/src/java/org/lwjgl/opengl/GLContext.java b/src/java/org/lwjgl/opengl/GLContext.java index 5d60cb44..ef70daf4 100644 --- a/src/java/org/lwjgl/opengl/GLContext.java +++ b/src/java/org/lwjgl/opengl/GLContext.java @@ -36,7 +36,7 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.HashMap; -import java.util.Iterator; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -60,6 +60,9 @@ public final class GLContext { /** A map of WeakReferences to contexts to LWJGL pointers-to-extension-structs */ private static final Map contextMap = new HashMap(); + /** A map of WeakReferences to contents to Sets of extension names */ + private static final Map extensionsMap = new HashMap(); + /* * Available extensions */ @@ -132,9 +135,6 @@ public final class GLContext { public static boolean GL_ATI_vertex_streams; public static boolean GL_ATI_separate_stencil; - public static boolean GL_ATIX_point_sprites; - public static boolean GL_ATIX_texture_env_route; - public static boolean GL_NV_blend_square; public static boolean GL_NV_copy_depth_to_color; public static boolean GL_NV_depth_clamp; @@ -177,25 +177,6 @@ public final class GLContext { System.loadLibrary(Sys.getLibraryName()); } - private static void setExtensionFields(Set exts, HashMap field_map) { - Sys.log("Available extensions:"); - Iterator it = exts.iterator(); - while ( it.hasNext() ) { - String ext = (String)it.next(); - Sys.log(ext); - - Field f = (Field)field_map.get(ext); - if ( f != null ) { - try { - f.setBoolean(GLContext.class, true); - } catch (IllegalAccessException e) { - e.printStackTrace(System.err); - } - } - - } - } - /** * Determine which extensions are available. Use this to initialize capability fields. Can only be * called _after_ a GLWindow or Pbuffer has been created (or a context from some other GL library). @@ -204,23 +185,19 @@ public final class GLContext { * * @param exts A Set of OpenGL extension string names */ - public static void determineAvailableExtensions(Set exts) { + private static void determineAvailableExtensions(Set exts) { // Grab all the public static booleans out of this class Field[] fields = GLContext.class.getDeclaredFields(); - HashMap map = new HashMap(fields.length); for ( int i = 0; i < fields.length; i++ ) { if ( Modifier.isStatic(fields[i].getModifiers()) && fields[i].getType() == boolean.class ) { - map.put(fields[i].getName(), fields[i]); // reset fields try { - fields[i].setBoolean(GLContext.class, false); + fields[i].setBoolean(GLContext.class, exts.contains(fields[i].getName())); } catch (IllegalAccessException e) { e.printStackTrace(System.err); } } } - - setExtensionFields(exts, map); } /** @@ -248,27 +225,30 @@ public final class GLContext { // Look in the context map to see if we've encountered this context before Integer encountered = (Integer) contextMap.get(currentContext); + Set exts; if (encountered != null) { + exts = (Set) extensionsMap.get(currentContext); reinit(encountered.intValue()); } else { - contextMap.put(currentContext, new Integer(init())); + exts = new HashSet(); + contextMap.put(currentContext, new Integer(init(exts))); } - // Now determine the available extensions - + determineAvailableExtensions(exts); } /** * Native method to initialize a context from scratch or load its function pointers from a * cache. + * @param exts An empty Set of Strings that will be filled with the names of enabled extensions * @return a LWJGL context-index-pointer */ - private static native int init(); + private static native int init(Set exts); /** * Native method to re-initialize a context. * @param context Hash code of the context object */ - private static native int reinit(int context); + private static native void reinit(int context); } diff --git a/src/java/org/lwjgl/opengl/Window.java b/src/java/org/lwjgl/opengl/Window.java index a81a6c26..21886231 100644 --- a/src/java/org/lwjgl/opengl/Window.java +++ b/src/java/org/lwjgl/opengl/Window.java @@ -308,16 +308,13 @@ public final class Window { int alpha, int depth, int stencil, - int samples, - HashSet extensions) + int samples) throws Exception; private static void createWindow(int bpp, int alpha, int depth, int stencil, int samples) throws Exception { - HashSet extensions = new HashSet(); - nCreate(title, x, y, width, height, fullscreen, bpp, alpha, depth, stencil, samples, extensions); + nCreate(title, x, y, width, height, fullscreen, bpp, alpha, depth, stencil, samples); context = new Window(); makeCurrent(); - GLContext.determineAvailableExtensions(extensions); } /** diff --git a/src/java/org/lwjgl/test/SysTest.java b/src/java/org/lwjgl/test/SysTest.java index 516833f1..538078e7 100644 --- a/src/java/org/lwjgl/test/SysTest.java +++ b/src/java/org/lwjgl/test/SysTest.java @@ -54,10 +54,10 @@ public class SysTest { * Runs the tests */ public void executeTest() { - testDebug(); + testAlert(); + testDebug(); testTimer(); testPriority(); - testAlert(); testUrl(); } diff --git a/src/native/common/extgl.cpp b/src/native/common/extgl.cpp index 4ade672b..582117d4 100755 --- a/src/native/common/extgl.cpp +++ b/src/native/common/extgl.cpp @@ -719,7 +719,7 @@ void *extgl_GetProcAddress(const char *name) #endif #ifdef _AGL - CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNull); + CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNULL); void *func_pointer = CFBundleGetFunctionPointerForName(opengl_bundle_ref, str); if (func_pointer == NULL) { func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str); @@ -785,7 +785,9 @@ static bool QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extension if (*terminator == ' ' || *terminator == '\0') { - insertExtension(env, ext_set, name); + if (ext_set != NULL) { + insertExtension(env, ext_set, name); + } return true; @@ -806,7 +808,7 @@ static bool QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extension #ifdef _WIN32 /** returns true if the extention is available */ -static bool WGLQueryExtension(JNIEnv *env, jobject ext_set, const char *name) +static bool WGLQueryExtension(JNIEnv *env, const char *name) { const GLubyte *extensions; @@ -817,10 +819,10 @@ static bool WGLQueryExtension(JNIEnv *env, jobject ext_set, const char *name) extensions = (GLubyte*)wglGetExtensionsStringEXT(); else extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); - return QueryExtension(env, ext_set, extensions, name); + return QueryExtension(env, NULL, extensions, name); } -static void extgl_InitWGLARBBufferRegion(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLARBBufferRegion(JNIEnv *env) { if (!extgl_Extensions.WGL_ARB_buffer_region) return; @@ -829,10 +831,10 @@ static void extgl_InitWGLARBBufferRegion(JNIEnv *env, jobject ext_set) wglSaveBufferRegionARB = (wglSaveBufferRegionARBPROC) extgl_GetProcAddress("wglSaveBufferRegionARB"); wglRestoreBufferRegionARB = (wglRestoreBufferRegionARBPROC) extgl_GetProcAddress("wglRestoreBufferRegionARB"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_ARB_buffer_region); + EXTGL_SANITY_CHECK(env, NULL, WGL_ARB_buffer_region); } -static void extgl_InitWGLARBPbuffer(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLARBPbuffer(JNIEnv *env) { if (!extgl_Extensions.WGL_ARB_pbuffer) return; @@ -841,66 +843,66 @@ static void extgl_InitWGLARBPbuffer(JNIEnv *env, jobject ext_set) wglReleasePbufferDCARB = (wglReleasePbufferDCARBPROC) extgl_GetProcAddress("wglReleasePbufferDCARB"); wglDestroyPbufferARB = (wglDestroyPbufferARBPROC) extgl_GetProcAddress("wglDestroyPbufferARB"); wglQueryPbufferARB = (wglQueryPbufferARBPROC) extgl_GetProcAddress("wglQueryPbufferARB"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_ARB_pbuffer); + EXTGL_SANITY_CHECK(env, NULL, WGL_ARB_pbuffer); } -static void extgl_InitWGLARBPixelFormat(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLARBPixelFormat(JNIEnv *env) { if (!extgl_Extensions.WGL_ARB_pixel_format) return; wglGetPixelFormatAttribivARB = (wglGetPixelFormatAttribivARBPROC) extgl_GetProcAddress("wglGetPixelFormatAttribivARB"); wglGetPixelFormatAttribfvARB = (wglGetPixelFormatAttribfvARBPROC) extgl_GetProcAddress("wglGetPixelFormatAttribfvARB"); wglChoosePixelFormatARB = (wglChoosePixelFormatARBPROC) extgl_GetProcAddress("wglChoosePixelFormatARB"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_ARB_pixel_format); + EXTGL_SANITY_CHECK(env, NULL, WGL_ARB_pixel_format); } -static void extgl_InitWGLARBRenderTexture(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLARBRenderTexture(JNIEnv *env) { if (!extgl_Extensions.WGL_ARB_render_texture) return; wglBindTexImageARB = (wglBindTexImageARBPROC) extgl_GetProcAddress("wglBindTexImageARB"); wglReleaseTexImageARB = (wglReleaseTexImageARBPROC) extgl_GetProcAddress("wglReleaseTexImageARB"); wglSetPbufferAttribARB = (wglSetPbufferAttribARBPROC) extgl_GetProcAddress("wglSetPbufferAttribARB"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_ARB_render_texture); + EXTGL_SANITY_CHECK(env, NULL, WGL_ARB_render_texture); } -static void extgl_InitWGLEXTSwapControl(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLEXTSwapControl(JNIEnv *env) { if (!extgl_Extensions.WGL_EXT_swap_control) return; wglSwapIntervalEXT = (wglSwapIntervalEXTPROC) extgl_GetProcAddress("wglSwapIntervalEXT"); wglGetSwapIntervalEXT = (wglGetSwapIntervalEXTPROC) extgl_GetProcAddress("wglGetSwapIntervalEXT"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_EXT_swap_control); + EXTGL_SANITY_CHECK(env, NULL, WGL_EXT_swap_control); } -static void extgl_InitWGLARBMakeCurrentRead(JNIEnv *env, jobject ext_set) +static void extgl_InitWGLARBMakeCurrentRead(JNIEnv *env) { if (!extgl_Extensions.WGL_ARB_make_current_read) return; wglMakeContextCurrentARB = (wglMakeContextCurrentARBPROC) extgl_GetProcAddress("wglMakeContextCurrentARB"); wglGetCurrentReadDCARB = (wglGetCurrentReadDCARBPROC) extgl_GetProcAddress("wglGetCurrentReadDCARB"); - EXTGL_SANITY_CHECK(env, ext_set, WGL_ARB_make_current_read); + EXTGL_SANITY_CHECK(env, NULL, WGL_ARB_make_current_read); } -static void extgl_InitSupportedWGLExtensions(JNIEnv *env, jobject ext_set) +static void extgl_InitSupportedWGLExtensions(JNIEnv *env) { - extgl_Extensions.WGL_ARB_buffer_region = WGLQueryExtension(env, ext_set, "WGL_ARB_buffer_region"); - extgl_Extensions.WGL_ARB_make_current_read = WGLQueryExtension(env, ext_set, "WGL_ARB_make_current_read"); - extgl_Extensions.WGL_ARB_multisample = WGLQueryExtension(env, ext_set, "WGL_ARB_multisample"); - extgl_Extensions.WGL_ARB_pbuffer = WGLQueryExtension(env, ext_set, "WGL_ARB_pbuffer"); - extgl_Extensions.WGL_ARB_pixel_format = WGLQueryExtension(env, ext_set, "WGL_ARB_pixel_format"); - extgl_Extensions.WGL_ARB_render_texture = WGLQueryExtension(env, ext_set, "WGL_ARB_render_texture"); - extgl_Extensions.WGL_EXT_swap_control = WGLQueryExtension(env, ext_set, "WGL_EXT_swap_control"); - extgl_Extensions.WGL_NV_render_depth_texture = WGLQueryExtension(env, ext_set, "WGL_NV_render_depth_texture"); - extgl_Extensions.WGL_NV_render_texture_rectangle = WGLQueryExtension(env, ext_set, "WGL_NV_render_texture_rectangle"); + extgl_Extensions.WGL_ARB_buffer_region = WGLQueryExtension(env, "WGL_ARB_buffer_region"); + extgl_Extensions.WGL_ARB_make_current_read = WGLQueryExtension(env, "WGL_ARB_make_current_read"); + extgl_Extensions.WGL_ARB_multisample = WGLQueryExtension(env, "WGL_ARB_multisample"); + extgl_Extensions.WGL_ARB_pbuffer = WGLQueryExtension(env, "WGL_ARB_pbuffer"); + extgl_Extensions.WGL_ARB_pixel_format = WGLQueryExtension(env, "WGL_ARB_pixel_format"); + extgl_Extensions.WGL_ARB_render_texture = WGLQueryExtension(env, "WGL_ARB_render_texture"); + extgl_Extensions.WGL_EXT_swap_control = WGLQueryExtension(env, "WGL_EXT_swap_control"); + extgl_Extensions.WGL_NV_render_depth_texture = WGLQueryExtension(env, "WGL_NV_render_depth_texture"); + extgl_Extensions.WGL_NV_render_texture_rectangle = WGLQueryExtension(env, "WGL_NV_render_texture_rectangle"); } -void extgl_InitWGL(JNIEnv *env, jobject ext_set) +void extgl_InitWGL(JNIEnv *env) { wglGetExtensionsStringARB = (wglGetExtensionsStringARBPROC) extgl_GetProcAddress("wglGetExtensionsStringARB"); wglGetExtensionsStringEXT = (wglGetExtensionsStringEXTPROC) extgl_GetProcAddress("wglGetExtensionsStringEXT"); @@ -908,14 +910,14 @@ void extgl_InitWGL(JNIEnv *env, jobject ext_set) extgl_Extensions.WGL_EXT_extensions_string = wglGetExtensionsStringEXT != NULL; extgl_error = false; - extgl_InitSupportedWGLExtensions(env, ext_set); + extgl_InitSupportedWGLExtensions(env); - extgl_InitWGLARBMakeCurrentRead(env, ext_set); - extgl_InitWGLEXTSwapControl(env, ext_set); - extgl_InitWGLARBRenderTexture(env, ext_set); - extgl_InitWGLARBPixelFormat(env, ext_set); - extgl_InitWGLARBPbuffer(env, ext_set); - extgl_InitWGLARBBufferRegion(env, ext_set); + extgl_InitWGLARBMakeCurrentRead(env); + extgl_InitWGLEXTSwapControl(env); + extgl_InitWGLARBRenderTexture(env); + extgl_InitWGLARBPixelFormat(env); + extgl_InitWGLARBPbuffer(env); + extgl_InitWGLARBBufferRegion(env); } #endif /* WIN32 */ diff --git a/src/native/common/extgl.h b/src/native/common/extgl.h index 1bec3b74..b00e5d8b 100644 --- a/src/native/common/extgl.h +++ b/src/native/common/extgl.h @@ -3278,13 +3278,13 @@ extern glGetStringPROC glGetString; bool extgl_Initialize(JNIEnv *env, jobject gl_extensions); bool extgl_Open(void); #ifdef _WIN32 -void extgl_InitWGL(JNIEnv *env, jobject ext_set); +void extgl_InitWGL(JNIEnv *env); #endif #ifdef _X11 -bool extgl_InitGLX(JNIEnv *env, jobject ext_set, Display *disp, int screen); +bool extgl_InitGLX(JNIEnv *env, Display *disp, int screen); #endif #ifdef _AGL -bool extgl_InitAGL(JNIEnv *env, jobject ext_set); +bool extgl_InitAGL(JNIEnv *env); #endif void *extgl_GetProcAddress(const char *name); void extgl_Close(void); @@ -3294,7 +3294,9 @@ void extgl_removeExtension(JNIEnv *env, jobject ext_set, const char *ext); extgl_Extensions.x = 0; \ printf("NOTICE: %s disabled because of missing driver symbols\n", #x); \ extgl_error = false; \ - extgl_removeExtension(e, h, #x); \ + if (h != NULL) { \ + extgl_removeExtension(e, h, #x); \ + } \ } #ifdef __cplusplus } diff --git a/src/native/common/org_lwjgl_opengl_GLContext.cpp b/src/native/common/org_lwjgl_opengl_GLContext.cpp new file mode 100644 index 00000000..e671b074 --- /dev/null +++ b/src/native/common/org_lwjgl_opengl_GLContext.cpp @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2002 Lightweight Java Game Library Project +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* * Neither the name of 'Light Weight Java Game Library' nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "org_lwjgl_opengl_GLContext.h" +#include "extgl.h" +#include "checkGLerror.h" + +/* + * Class: org_lwjgl_opengl_GLContext + * Method: init + * Signature: (Ljava/util/Set;)I + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLContext_init + (JNIEnv * env, jclass clazz, jobject exts) +{ + if (!extgl_Initialize(env, exts)) { + throwException(env, "Failed to initialize GL extensions"); + return -1; + } + + return 0; +} + +/* + * Class: org_lwjgl_opengl_GLContext + * Method: reinit + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_reinit + (JNIEnv * env, jclass clazz, jint context) +{ +} \ No newline at end of file diff --git a/src/native/common/org_lwjgl_opengl_GLContext.h b/src/native/common/org_lwjgl_opengl_GLContext.h new file mode 100644 index 00000000..e643ade9 --- /dev/null +++ b/src/native/common/org_lwjgl_opengl_GLContext.h @@ -0,0 +1,138 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_lwjgl_opengl_GLContext */ + +#ifndef _Included_org_lwjgl_opengl_GLContext +#define _Included_org_lwjgl_opengl_GLContext +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: currentContext */ +/* Inaccessible static: contextMap */ +/* Inaccessible static: extensionsMap */ +/* Inaccessible static: GL_ARB_imaging */ +/* Inaccessible static: GL_ARB_depth_texture */ +/* Inaccessible static: GL_ARB_fragment_program */ +/* Inaccessible static: GL_ARB_fragment_shader */ +/* Inaccessible static: GL_ARB_matrix_palette */ +/* Inaccessible static: GL_ARB_multisample */ +/* Inaccessible static: GL_ARB_multitexture */ +/* Inaccessible static: GL_ARB_occlusion_query */ +/* Inaccessible static: GL_ARB_point_parameters */ +/* Inaccessible static: GL_ARB_point_sprite */ +/* Inaccessible static: GL_ARB_shading_language */ +/* Inaccessible static: GL_ARB_shader_objects */ +/* Inaccessible static: GL_ARB_shadow */ +/* Inaccessible static: GL_ARB_shadow_ambient */ +/* Inaccessible static: GL_ARB_texture_compression */ +/* Inaccessible static: GL_ARB_texture_env_add */ +/* Inaccessible static: GL_ARB_texture_env_dot3 */ +/* Inaccessible static: GL_ARB_texture_env_combine */ +/* Inaccessible static: GL_ARB_texture_env_crossbar */ +/* Inaccessible static: GL_ARB_texture_border_clamp */ +/* Inaccessible static: GL_ARB_texture_cube_map */ +/* Inaccessible static: GL_ARB_texture_mirrored_repeat */ +/* Inaccessible static: GL_ARB_texture_non_power_of_two */ +/* Inaccessible static: GL_ARB_transpose_matrix */ +/* Inaccessible static: GL_ARB_vertex_blend */ +/* Inaccessible static: GL_ARB_vertex_program */ +/* Inaccessible static: GL_ARB_vertex_buffer_object */ +/* Inaccessible static: GL_ARB_vertex_shader */ +/* Inaccessible static: GL_ARB_window_pos */ +/* Inaccessible static: GL_EXT_abgr */ +/* Inaccessible static: GL_EXT_bgra */ +/* Inaccessible static: GL_EXT_blend_function_separate */ +/* Inaccessible static: GL_EXT_blend_subtract */ +/* Inaccessible static: GL_EXT_compiled_vertex_array */ +/* Inaccessible static: GL_EXT_draw_range_elements */ +/* Inaccessible static: GL_EXT_multi_draw_arrays */ +/* Inaccessible static: GL_EXT_fog_coord */ +/* Inaccessible static: GL_EXT_packed_pixels */ +/* Inaccessible static: GL_EXT_point_parameters */ +/* Inaccessible static: GL_EXT_rescale_normal */ +/* Inaccessible static: GL_EXT_secondary_color */ +/* Inaccessible static: GL_EXT_separate_specular_color */ +/* Inaccessible static: GL_EXT_shadow_funcs */ +/* Inaccessible static: GL_EXT_shared_texture_palette */ +/* Inaccessible static: GL_EXT_stencil_two_side */ +/* Inaccessible static: GL_EXT_stencil_wrap */ +/* Inaccessible static: GL_EXT_texture_compression_s3tc */ +/* Inaccessible static: GL_EXT_texture_env_combine */ +/* Inaccessible static: GL_EXT_texture_env_dot3 */ +/* Inaccessible static: GL_EXT_texture_filter_anisotropic */ +/* Inaccessible static: GL_EXT_texture_lod_bias */ +/* Inaccessible static: GL_EXT_texture_rectangle */ +/* Inaccessible static: GL_EXT_vertex_shader */ +/* Inaccessible static: GL_EXT_vertex_weighting */ +/* Inaccessible static: GL_ATI_draw_buffers */ +/* Inaccessible static: GL_ATI_element_array */ +/* Inaccessible static: GL_ATI_envmap_bumpmap */ +/* Inaccessible static: GL_ATI_fragment_shader */ +/* Inaccessible static: GL_ATI_map_object_buffer */ +/* Inaccessible static: GL_ATI_pn_triangles */ +/* Inaccessible static: GL_ATI_texture_float */ +/* Inaccessible static: GL_ATI_texture_mirror_once */ +/* Inaccessible static: GL_ATI_vertex_array_object */ +/* Inaccessible static: GL_ATI_vertex_attrib_array_object */ +/* Inaccessible static: GL_ATI_vertex_streams */ +/* Inaccessible static: GL_ATI_separate_stencil */ +/* Inaccessible static: GL_ATIX_point_sprites */ +/* Inaccessible static: GL_ATIX_texture_env_route */ +/* Inaccessible static: GL_NV_blend_square */ +/* Inaccessible static: GL_NV_copy_depth_to_color */ +/* Inaccessible static: GL_NV_depth_clamp */ +/* Inaccessible static: GL_NV_evaluators */ +/* Inaccessible static: GL_NV_fence */ +/* Inaccessible static: GL_NV_fragment_program */ +/* Inaccessible static: GL_NV_float_buffer */ +/* Inaccessible static: GL_NV_fog_distance */ +/* Inaccessible static: GL_NV_half_float */ +/* Inaccessible static: GL_NV_light_max_exponent */ +/* Inaccessible static: GL_NV_multisample_filter_hint */ +/* Inaccessible static: GL_NV_occlusion_query */ +/* Inaccessible static: GL_NV_packed_depth_stencil */ +/* Inaccessible static: GL_NV_pixel_data_range */ +/* Inaccessible static: GL_NV_point_sprite */ +/* Inaccessible static: GL_NV_primitive_restart */ +/* Inaccessible static: GL_NV_register_combiners */ +/* Inaccessible static: GL_NV_register_combiners2 */ +/* Inaccessible static: GL_NV_texgen_reflection */ +/* Inaccessible static: GL_NV_texture_compression_vtc */ +/* Inaccessible static: GL_NV_texture_env_combine4 */ +/* Inaccessible static: GL_NV_texture_expand_normal */ +/* Inaccessible static: GL_NV_texture_rectangle */ +/* Inaccessible static: GL_NV_texture_shader */ +/* Inaccessible static: GL_NV_texture_shader2 */ +/* Inaccessible static: GL_NV_texture_shader3 */ +/* Inaccessible static: GL_NV_vertex_array_range */ +/* Inaccessible static: GL_NV_vertex_array_range2 */ +/* Inaccessible static: GL_NV_vertex_program */ +/* Inaccessible static: GL_NV_vertex_program1_1 */ +/* Inaccessible static: GL_NV_vertex_program2 */ +/* Inaccessible static: OpenGL11 */ +/* Inaccessible static: OpenGL12 */ +/* Inaccessible static: OpenGL13 */ +/* Inaccessible static: OpenGL14 */ +/* Inaccessible static: OpenGL15 */ +/* Inaccessible static: class_000240 */ +/* Inaccessible static: class_000241 */ +/* + * Class: org_lwjgl_opengl_GLContext + * Method: init + * Signature: (Ljava/util/Set;)I + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLContext_init + (JNIEnv *, jclass, jobject); + +/* + * Class: org_lwjgl_opengl_GLContext + * Method: reinit + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_reinit + (JNIEnv *, jclass, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/common/org_lwjgl_opengl_Window.h b/src/native/common/org_lwjgl_opengl_Window.h index 260470f4..ca8b3973 100644 --- a/src/native/common/org_lwjgl_opengl_Window.h +++ b/src/native/common/org_lwjgl_opengl_Window.h @@ -8,7 +8,6 @@ extern "C" { #endif /* Inaccessible static: _00024assertionsDisabled */ -/* Inaccessible static: created */ /* Inaccessible static: x */ /* Inaccessible static: y */ /* Inaccessible static: width */ @@ -18,7 +17,7 @@ extern "C" { /* Inaccessible static: vsync */ /* Inaccessible static: vbo_tracker */ /* Inaccessible static: context */ -/* Inaccessible static: class_00024org_00024lwjgl_00024opengl_00024Window */ +/* Inaccessible static: class_000240 */ /* * Class: org_lwjgl_opengl_Window * Method: nSetTitle @@ -83,13 +82,21 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers (JNIEnv *, jclass); +/* + * Class: org_lwjgl_opengl_Window + * Method: nMakeCurrent + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent + (JNIEnv *, jclass); + /* * Class: org_lwjgl_opengl_Window * Method: nCreate - * Signature: (Ljava/lang/String;IIIIZIIIIILjava/util/HashSet;)V + * Signature: (Ljava/lang/String;IIIIZIIIII)V */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate - (JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jobject); + (JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint); /* * Class: org_lwjgl_opengl_Window @@ -123,14 +130,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVSyncEnabled JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled (JNIEnv *, jclass, jboolean); -/* - * Class: org_lwjgl_opengl_Window - * Method: nMakeCurrent - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent - (JNIEnv *, jclass); - #ifdef __cplusplus } #endif diff --git a/src/native/win32/org_lwjgl_Sys.cpp b/src/native/win32/org_lwjgl_Sys.cpp index 0ea4e83c..c46eaa56 100644 --- a/src/native/win32/org_lwjgl_Sys.cpp +++ b/src/native/win32/org_lwjgl_Sys.cpp @@ -129,7 +129,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority * Method: alert * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ -JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert (JNIEnv * env, jclass clazz, jstring title, jstring message) { jboolean copy = JNI_FALSE; @@ -143,18 +143,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert env->ReleaseStringUTFChars(title, cTitleBarText); } -// Cas: I've left this here as sometimes it's handy to just pop it back in to debug stuff -/* - * Class: org_lwjgl_Sys - * Method: getDirectBufferAddress - * Signature: (Ljava/nio/Buffer;)I -JNIEXPORT jint JNICALL Java_org_lwjgl_Sys_getDirectBufferAddress - (JNIEnv * env, jclass clazz, jobject buf) -{ - return (jint) env->GetDirectBufferAddress(buf); -} - */ - /* * Class: org_lwjgl_Sys * Method: openURL diff --git a/src/native/win32/org_lwjgl_Sys.h b/src/native/win32/org_lwjgl_Sys.h new file mode 100644 index 00000000..2f518e81 --- /dev/null +++ b/src/native/win32/org_lwjgl_Sys.h @@ -0,0 +1,79 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_lwjgl_Sys */ + +#ifndef _Included_org_lwjgl_Sys +#define _Included_org_lwjgl_Sys +#ifdef __cplusplus +extern "C" { +#endif +#undef org_lwjgl_Sys_LOW_PRIORITY +#define org_lwjgl_Sys_LOW_PRIORITY -1L +#undef org_lwjgl_Sys_NORMAL_PRIORITY +#define org_lwjgl_Sys_NORMAL_PRIORITY 0L +#undef org_lwjgl_Sys_HIGH_PRIORITY +#define org_lwjgl_Sys_HIGH_PRIORITY 1L +#undef org_lwjgl_Sys_REALTIME_PRIORITY +#define org_lwjgl_Sys_REALTIME_PRIORITY 2L +/* Inaccessible static: LIBRARY_NAME */ +/* Inaccessible static: DEBUG */ +/* + * Class: org_lwjgl_Sys + * Method: setDebug + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug + (JNIEnv *, jclass, jboolean); + +/* + * Class: org_lwjgl_Sys + * Method: getTimerResolution + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution + (JNIEnv *, jclass); + +/* + * Class: org_lwjgl_Sys + * Method: getTime + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime + (JNIEnv *, jclass); + +/* + * Class: org_lwjgl_Sys + * Method: setTime + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime + (JNIEnv *, jclass, jlong); + +/* + * Class: org_lwjgl_Sys + * Method: setProcessPriority + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority + (JNIEnv *, jclass, jint); + +/* + * Class: org_lwjgl_Sys + * Method: nAlert + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert + (JNIEnv *, jclass, jstring, jstring); + +/* + * Class: org_lwjgl_Sys + * Method: nOpenURL + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL + (JNIEnv *, jclass, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/win32/org_lwjgl_opengl_Window.cpp b/src/native/win32/org_lwjgl_opengl_Window.cpp index 39e83074..de568e57 100755 --- a/src/native/win32/org_lwjgl_opengl_Window.cpp +++ b/src/native/win32/org_lwjgl_opengl_Window.cpp @@ -519,7 +519,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers * Signature: (Ljava/lang/String;IIIIZIIII)V */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate - (JNIEnv * env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jint samples, jobject ext_set) + (JNIEnv * env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jint samples) { closerequested = false; isMinimized = false; @@ -549,7 +549,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate return; } - extgl_InitWGL(env, ext_set); + // Some crazy strangeness here so we can use ARB_pixel_format to specify the number + // of multisamples we want. If the extension is present we'll delete the existing + // rendering context and start over, using the ARB extension instead to pick the context. + extgl_InitWGL(env); if (extgl_Extensions.WGL_ARB_pixel_format) { wglMakeCurrent(NULL, NULL); wglDeleteContext(hglrc); @@ -564,12 +567,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate return; } } + /* if (!extgl_Initialize(env, ext_set)) { closeWindow(); extgl_Close(); throwException(env, "Failed to initialize GL extensions"); return; } + */ if (!createDirectInput()) { // Close the window closeWindow();