diff --git a/src/java/org/lwjgl/opengl/Window.java b/src/java/org/lwjgl/opengl/Window.java index 50caec9f..b96aad07 100644 --- a/src/java/org/lwjgl/opengl/Window.java +++ b/src/java/org/lwjgl/opengl/Window.java @@ -79,21 +79,9 @@ public final class Window { /** Title of the window */ private static String title; - /** Color bits */ - private static int color; - - /** Alpha bits */ - private static int alpha; - - /** Depth bits */ - private static int depth; - - /** Stencil bits */ - private static int stencil; - /** Fullscreen */ private static boolean fullscreen; - + /** Vsync */ private static boolean vsync; @@ -244,23 +232,21 @@ public final class Window { * @param alpha Minimum bits per pixel in alpha buffer * @param depth Minimum bits per pixel in depth buffer * @param stencil Minimum bits per pixel in stencil buffer + * @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec). + Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported. * @throws Exception if the window could not be created for any reason; typically because * the minimum requirements could not be met satisfactorily */ - public static void create(String title, int bpp, int alpha, int depth, int stencil) throws Exception { + public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws Exception { if (isCreated()) throw new Exception("Only one LWJGL window may be instantiated at any one time."); + Window.fullscreen = true; Window.x = 0; Window.y = 0; - Window.color = bpp; - Window.alpha = alpha; - Window.depth = depth; - Window.stencil = stencil; - Window.fullscreen = true; - Window.title = title; Window.width = Display.getWidth(); Window.height = Display.getHeight(); - createWindow(); + Window.title = title; + createWindow(bpp, alpha, depth, stencil, samples); } /** @@ -278,24 +264,22 @@ public final class Window { * @param alpha Minimum bits per pixel in alpha buffer * @param depth Minimum bits per pixel in depth buffer * @param stencil Minimum bits per pixel in stencil buffer + * @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec). + Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported. * @throws Exception if the window could not be created for any reason; typically because * the minimum requirements could not be met satisfactorily */ - public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) + public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples) throws Exception { if (isCreated()) throw new Exception("Only one LWJGL window may be instantiated at any one time."); + Window.fullscreen = false; Window.x = x; Window.y = y; Window.width = width; Window.height = height; - Window.color = bpp; - Window.alpha = alpha; - Window.depth = depth; - Window.stencil = stencil; - Window.fullscreen = false; Window.title = title; - createWindow(); + createWindow(bpp, alpha, depth, stencil, samples); } /** @@ -313,12 +297,13 @@ public final class Window { int alpha, int depth, int stencil, + int samples, HashSet extensions) throws Exception; - private static void createWindow() 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, color, alpha, depth, stencil, extensions); + nCreate(title, x, y, width, height, fullscreen, bpp, alpha, depth, stencil, samples, extensions); GLCaps.determineAvailableExtensions(extensions); context = new Window(); created = true; diff --git a/src/native/common/extgl.cpp b/src/native/common/extgl.cpp index cace120b..818ebae8 100755 --- a/src/native/common/extgl.cpp +++ b/src/native/common/extgl.cpp @@ -1075,6 +1075,7 @@ static void extgl_InitGLXSupportedExtensions(JNIEnv *env, jobject ext_set, Displ extgl_Extensions.GLX_EXT_visual_info = GLXQueryExtension(env, ext_set, disp, screen, "GLX_EXT_visual_info"); extgl_Extensions.GLX_EXT_visual_rating = GLXQueryExtension(env, ext_set, disp, screen, "GLX_EXT_visual_rating"); extgl_Extensions.GLX_SGI_swap_control = GLXQueryExtension(env, ext_set, disp, screen, "GLX_SGI_swap_control"); + extgl_Extensions.GLX_ARB_multisample = GLXQueryExtension(env, ext_set, disp, screen, "GLX_ARB_multisample"); } static void extgl_InitGLXSGISwapControl(JNIEnv *env, jobject ext_set) diff --git a/src/native/common/extgl.h b/src/native/common/extgl.h index 5b4fe0b6..59a011d5 100644 --- a/src/native/common/extgl.h +++ b/src/native/common/extgl.h @@ -3161,6 +3161,7 @@ struct ExtensionTypes bool GLX_EXT_visual_info; bool GLX_EXT_visual_rating; bool GLX_SGI_swap_control; + bool GLX_ARB_multisample; #endif /* X11 */ bool OpenGL12; diff --git a/src/native/common/org_lwjgl_opengl_GL15.cpp b/src/native/common/org_lwjgl_opengl_GL15.cpp index 7258d77c..2254e29c 100644 --- a/src/native/common/org_lwjgl_opengl_GL15.cpp +++ b/src/native/common/org_lwjgl_opengl_GL15.cpp @@ -359,4 +359,5 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL15_nglGetQueryObjectuiv GLuint *params_ptr = (GLuint *)env->GetDirectBufferAddress(params) + paramsOffset; glGetQueryObjectuiv(id, pname, params_ptr); CHECK_GL_ERROR -} \ No newline at end of file +} + diff --git a/src/native/common/org_lwjgl_opengl_Window.h b/src/native/common/org_lwjgl_opengl_Window.h index 1da9f961..b4b08ca2 100644 --- a/src/native/common/org_lwjgl_opengl_Window.h +++ b/src/native/common/org_lwjgl_opengl_Window.h @@ -14,10 +14,6 @@ extern "C" { /* Inaccessible static: width */ /* Inaccessible static: height */ /* Inaccessible static: title */ -/* Inaccessible static: color */ -/* Inaccessible static: alpha */ -/* Inaccessible static: depth */ -/* Inaccessible static: stencil */ /* Inaccessible static: fullscreen */ /* Inaccessible static: vsync */ /* Inaccessible static: vbo_tracker */ @@ -90,10 +86,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers /* * Class: org_lwjgl_opengl_Window * Method: nCreate - * Signature: (Ljava/lang/String;IIIIZIIIILjava/util/HashSet;)V + * Signature: (Ljava/lang/String;IIIIZIIIIILjava/util/HashSet;)V */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate - (JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jobject); + (JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jobject); /* * Class: org_lwjgl_opengl_Window diff --git a/src/native/linux/org_lwjgl_opengl_Window.cpp b/src/native/linux/org_lwjgl_opengl_Window.cpp index c8f71397..cd521b2d 100644 --- a/src/native/linux/org_lwjgl_opengl_Window.cpp +++ b/src/native/linux/org_lwjgl_opengl_Window.cpp @@ -297,7 +297,7 @@ GLXContext getCurrentContext(void) { return context; } -static GLXFBConfig *chooseVisualGLX13(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { +static GLXFBConfig *chooseVisualGLX13(Display *disp, int screen, int bpp, int depth, int alpha, int stencil, int samples) { int bpe = convertToBPE(bpp); int attriblist[] = {GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, True, @@ -308,8 +308,16 @@ static GLXFBConfig *chooseVisualGLX13(Display *disp, int screen, int bpp, int de GLX_BLUE_SIZE, bpe, GLX_ALPHA_SIZE, alpha, GLX_STENCIL_SIZE, stencil, + None, None, /* For ARB_multisample */ + None, None, /* */ None}; int num_formats = 0; + if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) { + attriblist[18] = GLX_SAMPLE_BUFFERS_ARB; + attriblist[19] = 1; + attriblist[20] = GLX_SAMPLES_ARB; + attriblist[21] = samples; + } GLXFBConfig* configs = glXChooseFBConfig(disp, screen, attriblist, &num_formats); if (num_formats > 0) return configs; @@ -320,7 +328,7 @@ static GLXFBConfig *chooseVisualGLX13(Display *disp, int screen, int bpp, int de } } -static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { +static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil, int samples) { int bpe = convertToBPE(bpp); int attriblist[] = {GLX_RGBA, GLX_DOUBLEBUFFER, @@ -330,19 +338,33 @@ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, GLX_BLUE_SIZE, bpe, GLX_ALPHA_SIZE, alpha, GLX_STENCIL_SIZE, stencil, + None, None, /* For ARB_multisample */ + None, None, /* */ None}; + if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) { + attriblist[14] = GLX_SAMPLE_BUFFERS_ARB; + attriblist[15] = 1; + attriblist[16] = GLX_SAMPLES_ARB; + attriblist[17] = samples; + } return glXChooseVisual(disp, screen, attriblist); } static void dumpVisualInfo(Display *disp, XVisualInfo *vis_info) { int alpha, depth, stencil, r, g, b; + int sample_buffers = 0; + int samples = 0; glXGetConfig(disp, vis_info, GLX_RED_SIZE, &r); glXGetConfig(disp, vis_info, GLX_GREEN_SIZE, &g); glXGetConfig(disp, vis_info, GLX_BLUE_SIZE, &b); glXGetConfig(disp, vis_info, GLX_ALPHA_SIZE, &alpha); glXGetConfig(disp, vis_info, GLX_DEPTH_SIZE, &depth); glXGetConfig(disp, vis_info, GLX_STENCIL_SIZE, &stencil); - printf("Pixel format chosen sizes: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d\n", r, g, b, alpha, depth, stencil); + if (extgl_Extensions.GLX_ARB_multisample) { + glXGetConfig(disp, vis_info, GLX_SAMPLE_BUFFERS_ARB, &sample_buffers); + glXGetConfig(disp, vis_info, GLX_SAMPLES_ARB, &samples); + } + printf("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples); } static void destroy(void) { @@ -357,8 +379,8 @@ static void destroy(void) { extgl_Close(); } -static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, bool fscreen) { - GLXFBConfig *configs = chooseVisualGLX13(disp, screen, bpp, depth, alpha, stencil); +static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen) { + GLXFBConfig *configs = chooseVisualGLX13(disp, screen, bpp, depth, alpha, stencil, samples); if (configs == NULL) { throwException(env, "Could not find a matching pixel format"); return false; @@ -372,7 +394,7 @@ static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring titl if (glXIsDirect(disp, context) == False) { glXDestroyContext(disp, context); XFree(configs); - throwException(env, "Could not create a GLX context"); + throwException(env, "Could not create a direct GLX context"); return false; } XVisualInfo * vis_info = glXGetVisualFromFBConfig(disp, configs[0]); @@ -382,18 +404,18 @@ static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring titl throwException(env, "Could not create visual info from FB config"); return false; } - if (ISDEBUGENABLED()) - dumpVisualInfo(disp, vis_info); createWindow(env, disp, screen, vis_info, title, x, y, width, height, fscreen); glx_window = glXCreateWindow(disp, configs[0], getCurrentWindow(), NULL); makeCurrent(); + if (ISDEBUGENABLED()) + dumpVisualInfo(disp, vis_info); XFree(configs); XFree(vis_info); return true; } -static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, bool fscreen) { - XVisualInfo *vis_info = chooseVisual(disp, screen, bpp, depth, alpha, stencil); +static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen) { + XVisualInfo *vis_info = chooseVisual(disp, screen, bpp, depth, alpha, stencil, samples); if (vis_info == NULL) { throwException(env, "Could not find a matching pixel format"); return false; @@ -424,7 +446,7 @@ static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title, * Signature: (IIII)Z */ 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, 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, jobject ext_set) { int screen; Display *disp; @@ -450,13 +472,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate } bool create_success; if (USEGLX13) { - create_success = initWindowGLX13(env, disp, screen, title, x, y, width, height, bpp, depth, alpha, stencil, fscreen); + create_success = initWindowGLX13(env, disp, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen); } else { - create_success = initWindowGLX(env, disp, screen, title, x, y, width, height, bpp, depth, alpha, stencil, fscreen); + create_success = initWindowGLX(env, disp, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen); } if (!create_success) { XCloseDisplay(disp); extgl_Close(); + throwException(env, "Could not create window"); return; } if (!extgl_Initialize(env, ext_set)) { diff --git a/src/native/macosx/org_lwjgl_opengl_Window.cpp b/src/native/macosx/org_lwjgl_opengl_Window.cpp index 5ed4be6d..29a68321 100644 --- a/src/native/macosx/org_lwjgl_opengl_Window.cpp +++ b/src/native/macosx/org_lwjgl_opengl_Window.cpp @@ -101,7 +101,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv return JNI_FALSE; } -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, jobject ext_set) { +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) { vsync_enabled = false; current_fullscreen = fullscreen == JNI_TRUE; if (!extgl_Open()) { diff --git a/src/native/win32/org_lwjgl_opengl_Window.cpp b/src/native/win32/org_lwjgl_opengl_Window.cpp index d25d0fbe..00e03d50 100755 --- a/src/native/win32/org_lwjgl_opengl_Window.cpp +++ b/src/native/win32/org_lwjgl_opengl_Window.cpp @@ -501,7 +501,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, 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, jobject ext_set) { closerequested = false; minimized = false;