diff options
author | Chien Yang <[email protected]> | 2004-10-28 21:22:10 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2004-10-28 21:22:10 +0000 |
commit | 2ce93668c57e29a6d2ea992f8675afdd0719c820 (patch) | |
tree | b2a42e5956025c0da23bd716dd407c9f15b3baaa | |
parent | cc979689cf50222764a085f775dc39c583add82d (diff) |
1) Fixed issue 77 : Scene antialiasing is disabled on Windows / OpenGL
2) For Win32-OGL : Apply similar technique, used in fix to 77, to Stereo, DoubleBuffer and Accum.
3) For Unix and Win32-OGL : Automat multisample density request in chooseFBConfig/ChoosePixelFormat if ARB_multisample is supported. It starts with sample density = 8 and move down if it can't find one.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@63 ba19aa83-45c5-6ac9-afd3-db810772062c
-rw-r--r-- | src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java | 20 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/Renderer.java | 16 | ||||
-rw-r--r-- | src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java | 20 | ||||
-rw-r--r-- | src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java | 60 | ||||
-rw-r--r-- | src/native/d3d/NativeConfigTemplate3D.cpp | 30 | ||||
-rw-r--r-- | src/native/ogl/Canvas3D.c | 56 | ||||
-rw-r--r-- | src/native/ogl/NativeConfigTemplate3D.c | 397 | ||||
-rw-r--r-- | src/native/ogl/gldefs.h | 23 |
8 files changed, 321 insertions, 301 deletions
diff --git a/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java index 7e36e71..30cab7c 100644 --- a/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java +++ b/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java @@ -60,7 +60,7 @@ class NativeConfigTemplate3D { native boolean isStereoAvailable(long display, int screen, int vid); native boolean isDoubleBufferAvailable(long display, int screen, int vid); native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingMultiSamplesAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); /* @@ -201,7 +201,9 @@ class NativeConfigTemplate3D { // Return whether stereo is available. - boolean hasStereo(GraphicsConfiguration gc) { + boolean hasStereo(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -214,7 +216,9 @@ class NativeConfigTemplate3D { } // Return whether a double buffer is available. - boolean hasDoubleBuffer(GraphicsConfiguration gc) { + boolean hasDoubleBuffer(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -227,7 +231,9 @@ class NativeConfigTemplate3D { } // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(GraphicsConfiguration gc) { + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -241,7 +247,9 @@ class NativeConfigTemplate3D { // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultiSamples(GraphicsConfiguration gc) { + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -250,7 +258,7 @@ class NativeConfigTemplate3D { int screen = nativeScreenInfo.getScreen(); int vid = ((X11GraphicsConfig)gc).getVisual(); - return isSceneAntialiasingMultiSamplesAvailable(display, screen, vid); + return isSceneAntialiasingMultisampleAvailable(display, screen, vid); } // Ensure that the native libraries are loaded diff --git a/src/classes/share/javax/media/j3d/Renderer.java b/src/classes/share/javax/media/j3d/Renderer.java index cd47249..fd560cd 100644 --- a/src/classes/share/javax/media/j3d/Renderer.java +++ b/src/classes/share/javax/media/j3d/Renderer.java @@ -380,7 +380,6 @@ class Renderer extends J3dThread { Integer reqType = (Integer) m[nmesg].args[2]; Canvas3D c = (Canvas3D) secondArg; if (reqType == MasterControl.SET_GRAPHICSCONFIG_FEATURES) { - GraphicsConfiguration gc = c.graphicsConfiguration; NativeConfigTemplate3D nct = GraphicsConfigTemplate3D.nativeTemplate; if (c.offScreen) { @@ -389,16 +388,17 @@ class Renderer extends J3dThread { c.doubleBufferAvailable = false; c.stereoAvailable = false; } else { - c.doubleBufferAvailable = nct.hasDoubleBuffer(gc); - c.stereoAvailable = nct.hasStereo(gc); + c.doubleBufferAvailable = nct.hasDoubleBuffer(c); + c.stereoAvailable = nct.hasStereo(c); } c.sceneAntialiasingMultiSamplesAvailable = - nct.hasSceneAntialiasingMultiSamples(gc); + nct.hasSceneAntialiasingMultisample(c); + if (c.sceneAntialiasingMultiSamplesAvailable) { c.sceneAntialiasingAvailable = true; } else { c.sceneAntialiasingAvailable = - nct.hasSceneAntialiasingAccum(gc); + nct.hasSceneAntialiasingAccum(c); } GraphicsConfigTemplate3D.runMonitor(J3dThread.NOTIFY); } else if (reqType == MasterControl.SET_QUERYPROPERTIES){ @@ -935,6 +935,7 @@ class Renderer extends J3dThread { // full screen anti-aliasing setup if (canvas.view.getSceneAntialiasingEnable() && canvas.sceneAntialiasingAvailable) { + if (!VirtualUniverse.mc.isD3D() && ((canvas.extensionsSupported & Canvas3D.ARB_MULTISAMPLE) == 0) || !canvas.sceneAntialiasingMultiSamplesAvailable) { @@ -981,13 +982,18 @@ class Renderer extends J3dThread { } } } else { + if (!canvas.antialiasingSet) { + // System.out.println("Renderer : Enable FullSceneAntialiasing"); + canvas.setFullSceneAntialiasing(canvas.ctx, true); canvas.antialiasingSet = true; } } } else { + if (canvas.antialiasingSet) { + // System.out.println("Renderer : Disable SceneAntialiasing"); canvas.setFullSceneAntialiasing(canvas.ctx, false); canvas.antialiasingSet = false; } diff --git a/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java index d892a53..158c87f 100644 --- a/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java +++ b/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java @@ -52,7 +52,7 @@ class NativeConfigTemplate3D { native boolean isStereoAvailable(long display, int screen, int vid); native boolean isDoubleBufferAvailable(long display, int screen, int vid); native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingMultiSamplesAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); /* @@ -192,7 +192,9 @@ class NativeConfigTemplate3D { // Return whether stereo is available. - boolean hasStereo(GraphicsConfiguration gc) { + boolean hasStereo(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -205,7 +207,9 @@ class NativeConfigTemplate3D { } // Return whether a double buffer is available. - boolean hasDoubleBuffer(GraphicsConfiguration gc) { + boolean hasDoubleBuffer(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -218,7 +222,9 @@ class NativeConfigTemplate3D { } // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(GraphicsConfiguration gc) { + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -232,7 +238,9 @@ class NativeConfigTemplate3D { // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultiSamples(GraphicsConfiguration gc) { + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + X11GraphicsDevice gd = (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); @@ -241,7 +249,7 @@ class NativeConfigTemplate3D { int screen = nativeScreenInfo.getScreen(); int vid = ((X11GraphicsConfig)gc).getVisual(); - return isSceneAntialiasingMultiSamplesAvailable(display, screen, vid); + return isSceneAntialiasingMultisampleAvailable(display, screen, vid); } // Ensure that the native libraries are loaded diff --git a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java index 2759ea5..eca5def 100644 --- a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java +++ b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java @@ -49,10 +49,10 @@ class NativeConfigTemplate3D { static native void freePixelFormatInfo(long pFormatInfo); // Native methods to return whether a particular attribute is available - native boolean isStereoAvailable(long ctx, long display, int screen, int pixelFormat); - native boolean isDoubleBufferAvailable(long ctx, long display, int screen, int pixelFormat); - native boolean isSceneAntialiasingAccumAvailable(long ctx, long display, int screen, int pixelFormat); - native boolean isSceneAntialiasingMultiSamplesAvailable(long ctx, long display, int screen, int pixelFormat); + native boolean isStereoAvailable(long pFormatInfo, boolean offScreen); + native boolean isDoubleBufferAvailable(long pFormatInfo, boolean offScreen); + native boolean isSceneAntialiasingAccumAvailable(long pFormatInfo, boolean offScreen); + native boolean isSceneAntialiasingMultisampleAvailable(long pFormatInfo, boolean offScreen, int screen); /** * Chooses the best PixelFormat for Java 3D apps. @@ -179,56 +179,30 @@ class NativeConfigTemplate3D { // Return whether stereo is available. - boolean hasStereo(GraphicsConfiguration gc) { - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - int display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - // Temporary until Win32 GraphicsConfig stuff complete - int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); - - return isStereoAvailable(0, display, screen, pixelFormat); + boolean hasStereo(Canvas3D c3d) { + return isStereoAvailable(c3d.fbConfig, c3d.offScreen); } // Return whether a double buffer is available. - boolean hasDoubleBuffer(GraphicsConfiguration gc) { - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - // Temporary until Win32 GraphicsConfig stuff complete - int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); - - return isDoubleBufferAvailable(0, display, screen, pixelFormat); + boolean hasDoubleBuffer(Canvas3D c3d) { + return isDoubleBufferAvailable(c3d.fbConfig, c3d.offScreen); } // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(GraphicsConfiguration gc) { - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - // Temporary until Win32 GraphicsConfig stuff complete - int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); - - return isSceneAntialiasingAccumAvailable(0, display, screen, pixelFormat); + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + return isSceneAntialiasingAccumAvailable(c3d.fbConfig, c3d.offScreen); } // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultiSamples(GraphicsConfiguration gc) { + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int display = nativeScreenInfo.getDisplay(); + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); int screen = nativeScreenInfo.getScreen(); - // Temporary until Win32 GraphicsConfig stuff complete - int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); - - return isSceneAntialiasingMultiSamplesAvailable(0, display, screen, pixelFormat); + /* Fix to issue 77 */ + return isSceneAntialiasingMultisampleAvailable(c3d.fbConfig, c3d.offScreen, screen); } // Ensure that the native libraries are loaded diff --git a/src/native/d3d/NativeConfigTemplate3D.cpp b/src/native/d3d/NativeConfigTemplate3D.cpp index 5238ad6..347d866 100644 --- a/src/native/d3d/NativeConfigTemplate3D.cpp +++ b/src/native/d3d/NativeConfigTemplate3D.cpp @@ -17,10 +17,8 @@ extern "C" JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( JNIEnv *env, jobject obj, - jlong ctx, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { // DirectX 8.0 don't support stereo return false; @@ -31,23 +29,20 @@ extern "C" JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvailable( JNIEnv *env, jobject obj, - jlong ctx, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { // D3D always support double buffer return true; } extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultiSamplesAvailable( +jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, - jlong ctx, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen, + jint screen) { BOOL antialiasingSupport = false; @@ -73,10 +68,8 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing extern "C" JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable(JNIEnv *env, jobject obj, - jlong ctx, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { return JNI_FALSE; } @@ -127,8 +120,7 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( } if (mx_ptr[ANTIALIASING] == REQUIRED) { - if (Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultiSamplesAvailable( - env, obj, ctx, 0, screen, 0) == JNI_TRUE) + if (Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable(env, obj, 0, JNI_TRUE, screen) == JNI_TRUE) { retValue |= (1 << 31); } else { diff --git a/src/native/ogl/Canvas3D.c b/src/native/ogl/Canvas3D.c index d5b31c2..24654ff 100644 --- a/src/native/ogl/Canvas3D.c +++ b/src/native/ogl/Canvas3D.c @@ -432,7 +432,9 @@ BOOL getPropertiesFromCurrentContext( GraphicsContextPropertiesInfo *ctxInfo, jlong hdc, int pixelFormat, - int stencilSize) + int stencilSize, + jlong fbConfigListPtr, + jboolean offScreen) { JNIEnv table = *env; @@ -446,10 +448,8 @@ BOOL getPropertiesFromCurrentContext( #ifdef WIN32 - PFNWGLGETPIXELFORMATATTRIBIVEXTPROC wglGetPixelFormatAttribivEXT = NULL; PIXELFORMATDESCRIPTOR pfd; - int attr[3]; - int piValues[2]; + PixelFormatInfo *PixelFormatInfoPtr = (PixelFormatInfo *)fbConfigListPtr; #endif /* get OpenGL version */ @@ -472,6 +472,11 @@ BOOL getPropertiesFromCurrentContext( return FALSE; } tmpExtensionStr = strdup(extensionStr); + + /* + fprintf(stderr, " pixelFormat : %d\n", pixelFormat); + fprintf(stderr, " extensionStr : %s\n", tmpExtensionStr); + */ ctxInfo->versionStr = strdup(glversion); ctxInfo->extensionStr = strdup(extensionStr); @@ -683,27 +688,23 @@ BOOL getPropertiesFromCurrentContext( } #endif -#ifdef WIN32 /* This is fine, but might need cleanup. -- Chien */ - wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) - wglGetProcAddress("wglGetPixelFormatAttribivARB"); - - if (wglGetPixelFormatAttribivEXT == NULL) { - wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) - wglGetProcAddress("wglGetPixelFormatAttribivEXT"); - } - - ctxInfo->arb_multisample = JNI_FALSE; - if (wglGetPixelFormatAttribivEXT != NULL) { - attr[0] = WGL_SAMPLE_BUFFERS_ARB; - attr[1] = WGL_SAMPLES_ARB; - attr[2] = 0; - - if (wglGetPixelFormatAttribivEXT((HDC) hdc, pixelFormat, 0, 2, attr, piValues)) { - if ((piValues[0] == TRUE) && (piValues[1] > 1)) { - ctxInfo->arb_multisample = JNI_TRUE; - } - } +#ifdef WIN32 + if(offScreen) { + ctxInfo->arb_multisample = PixelFormatInfoPtr->offScreenHasMultisample; } + else { + ctxInfo->arb_multisample = PixelFormatInfoPtr->onScreenHasMultisample; + } + + /* + fprintf(stderr, "Canvas3D - onScreenHasMultisample = %d, offScreenHasMultisample = %d\n", + PixelFormatInfoPtr->onScreenHasMultisample, + PixelFormatInfoPtr->offScreenHasMultisample); + + fprintf(stderr, "Canvas3D - ctxInfo->arb_multisample = %d, offScreen = %d\n", + ctxInfo->arb_multisample, offScreen); + */ + #endif /* @@ -719,9 +720,6 @@ BOOL getPropertiesFromCurrentContext( */ checkTextureExtensions(env, obj, tmpExtensionStr, versionNumbers[1], ctxInfo); - - - /* ... */ @@ -1302,7 +1300,7 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( ctxInfo->context = gctx; if (!getPropertiesFromCurrentContext(env, obj, ctxInfo, (jlong) hdc, PixelFormatID, - stencilSize)) { + stencilSize, fbConfigListPtr, offScreen)) { return 0; } @@ -3452,7 +3450,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( /* get current context properties */ if (getPropertiesFromCurrentContext(env, obj, ctxInfo, (jlong) hdc, PixelFormatID, - stencilSize)) { + stencilSize, fbConfigListPtr, offScreen)) { /* put the properties to the Java side */ setupCanvasProperties(env, obj, ctxInfo); } diff --git a/src/native/ogl/NativeConfigTemplate3D.c b/src/native/ogl/NativeConfigTemplate3D.c index ae1ab22..8d147ff 100644 --- a/src/native/ogl/NativeConfigTemplate3D.c +++ b/src/native/ogl/NativeConfigTemplate3D.c @@ -136,19 +136,26 @@ GLXFBConfig *find_AA_S_FBConfigs(jlong display, glxExtensions = (const char *) glXGetClientString((Display*)display, GLX_EXTENSIONS); if(isExtensionSupported(glxExtensions, "GLX_ARB_multisample")){ + static const int SAMPLE_LENGTH = 5; + static const int samples[] = {8,6,4,3,2}; + int i, samplesIndex; index = antialiasIndex; glxAttrs[index++] = GLX_SAMPLE_BUFFERS_ARB; glxAttrs[index++] = 1; glxAttrs[index++] = GLX_SAMPLES_ARB; - glxAttrs[index++] = 2; + samplesIndex = index++; /* Will assign samples in the sample selection loop */ glxAttrs[index] = None; - fbConfigList = find_S_FBConfigs(display, screen, - glxAttrs, sVal, index); + for(i=0; i < SAMPLE_LENGTH; i++) { + /* fprintf(stderr, "find_AA_S_FBConfigs samples = %d\n", samples[i]); */ + glxAttrs[samplesIndex] = samples[i]; + fbConfigList = find_S_FBConfigs(display, screen, + glxAttrs, sVal, index); - if(fbConfigList != NULL) { - return fbConfigList; + if(fbConfigList != NULL) { + return fbConfigList; + } } } } @@ -473,7 +480,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultiSamplesAvailable( +jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, jlong display, @@ -841,24 +848,32 @@ int find_AA_S_PixelFormat( HDC hdc, PixelFormatInfo * pFormatInfo, } if(supportMS) { - + static const int SAMPLE_LENGTH = 5; + static const int samples[] = {8,6,4,3,2}; + int i, samplesIndex; + index = antialiasIndex; wglAttrs[index++] = WGL_SAMPLE_BUFFERS_ARB; wglAttrs[index++] = 1; wglAttrs[index++] = WGL_SAMPLES_ARB; - wglAttrs[index++] = 2; + samplesIndex = index++; /* Will assign samples in the sample selection loop */ /* * Terminate by 2 zeros to avoid driver bugs * that assume attributes always come in pairs. */ wglAttrs[index] = 0; wglAttrs[index+1] = 0; - - pFormat = find_S_PixelFormat(hdc, pFormatInfo, - wglAttrs, sVal, index); - - if(pFormat >= 0) { - return pFormat; + + + for(i=0; i < SAMPLE_LENGTH; i++) { + /* fprintf(stderr, "find_AA_S_PixelFormat samples = %d\n", samples[i]); */ + + wglAttrs[samplesIndex] = samples[i]; + pFormat = find_S_PixelFormat(hdc, pFormatInfo, + wglAttrs, sVal, index); + if(pFormat >= 0) { + return pFormat; + } } } } @@ -984,6 +999,96 @@ int find_DB_AA_S_PixelFormat( HDC hdc, PixelFormatInfo * pFormatInfo, return -1; } +/* Fix to issue 77 */ +/* Check PixelFormat capabilities and cache the info. into pFormatInfo structure */ +void checkPixelFormat(HDC hdc, + PixelFormatInfo *pFormatInfo, + GLboolean offScreen ) +{ + int wglAttrs[3]; + int piValues[2]; + int pf = -1; + GLboolean hasMultisample = GL_FALSE; + GLboolean hasStereo = GL_FALSE; + GLboolean hasDoubleBuffer = GL_FALSE; + GLboolean hasAccum = GL_FALSE; + PIXELFORMATDESCRIPTOR pfd; + + /* fprintf(stderr, "*** checkPixelFormat : offScreen = %d\n", offScreen); */ + + if(!offScreen) { + pf = pFormatInfo->onScreenPFormat; + } + else { + pf = pFormatInfo->offScreenPFormat; + } + + /* Assert that pf is valid */ + J3D_ASSERT(pf >= 0); + piValues[0] = GL_FALSE; + piValues[1] = -1; + + if( pFormatInfo->supportARB && + isSupportedWGL( pFormatInfo->supportedExtensions, "WGL_ARB_multisample")){ + wglAttrs[0] = WGL_SAMPLE_BUFFERS_ARB; + wglAttrs[1] = WGL_SAMPLES_ARB; + wglAttrs[2] = 0; + if (pFormatInfo->wglGetPixelFormatAttribivARB(hdc, pf, 0, 2, + wglAttrs, piValues)) { + if ((piValues[0]) && (piValues[1] > 1)) { + hasMultisample = GL_TRUE; + } + } + /* + fprintf(stderr, "*** checkPixelFormat : hasMultisample = %d numSamples %d\n", + hasMultisample, piValues[1]); + */ + } + + DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd); + + if (pfd.dwFlags & PFD_STEREO) { + hasStereo = GL_TRUE; + } + if (pfd.dwFlags & PFD_DOUBLEBUFFER) { + hasDoubleBuffer = GL_TRUE; + } + if (pfd.cAccumRedBits > 0) { + hasAccum = GL_TRUE; + } + + /* + fprintf(stderr, "hasStereo = %d, hasDoubleBuffer %d, hasAccum %d\n", + hasStereo, hasDoubleBuffer, hasAccum); + */ + + if(pFormatInfo->onScreenPFormat == pFormatInfo->offScreenPFormat) { + pFormatInfo->onScreenHasMultisample = hasMultisample; + pFormatInfo->onScreenHasStereo = hasStereo; + pFormatInfo->onScreenHasDoubleBuffer = hasDoubleBuffer; + pFormatInfo->onScreenHasAccum = hasAccum; + + pFormatInfo->offScreenHasMultisample = hasMultisample; + pFormatInfo->offScreenHasStereo = hasStereo; + pFormatInfo->offScreenHasDoubleBuffer = hasDoubleBuffer; + pFormatInfo->offScreenHasAccum = hasAccum; + } + else if(!offScreen) { + pFormatInfo->onScreenHasMultisample = hasMultisample; + pFormatInfo->onScreenHasStereo = hasStereo; + pFormatInfo->onScreenHasDoubleBuffer = hasDoubleBuffer; + pFormatInfo->onScreenHasAccum = hasAccum; + } + else { + pFormatInfo->offScreenHasMultisample = hasMultisample; + pFormatInfo->offScreenHasStereo = hasStereo; + pFormatInfo->offScreenHasDoubleBuffer = hasDoubleBuffer; + pFormatInfo->offScreenHasAccum = hasAccum; + } + +} + + int chooseSTDPixelFormat( JNIEnv *env, jint screen, @@ -1071,12 +1176,21 @@ int chooseSTDPixelFormat( PixelFormatInfo * newPixelFormatInfo(HDC hdc) { PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL; - + PixelFormatInfo *pFormatInfo = (PixelFormatInfo *) malloc(sizeof(PixelFormatInfo)); /* Initialize pFormatInfo */ pFormatInfo->onScreenPFormat = -1; + pFormatInfo->onScreenHasMultisample = GL_FALSE; + pFormatInfo->onScreenHasStereo = GL_FALSE; + pFormatInfo->onScreenHasDoubleBuffer = GL_FALSE; + pFormatInfo->onScreenHasAccum = GL_FALSE; + pFormatInfo->offScreenPFormat = -1; + pFormatInfo->offScreenHasMultisample = GL_FALSE; + pFormatInfo->offScreenHasStereo = GL_FALSE; + pFormatInfo->offScreenHasDoubleBuffer = GL_FALSE; + pFormatInfo->offScreenHasAccum = GL_FALSE; pFormatInfo->drawToPbuffer = GL_FALSE; pFormatInfo->supportARB = GL_FALSE; @@ -1144,13 +1258,13 @@ PixelFormatInfo * newPixelFormatInfo(HDC hdc) else { printErrorMessage("Problem in getting WGL_ARB_pbuffer functions !\n"); } - } + } } else { printErrorMessage("Problem in getting WGL_ARB_pixel_format functions !\n"); } } - + return pFormatInfo; } @@ -1181,7 +1295,10 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( PixelFormatInfo *pFormatInfo = NULL; jlong * offScreenPFListPtr; PIXELFORMATDESCRIPTOR dummy_pfd = getDummyPFD(); - + + + /* fprintf(stderr, "In NativeConfigTemplate.\n"); */ + /* * Select any pixel format and bound current context to * it so that we can get the wglChoosePixelFormatARB entry point. @@ -1275,12 +1392,15 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( wglAttrs, sVal, dbVal, antialiasVal, index); - if(pFormatInfo->onScreenPFormat >= 0) { - + if(pFormatInfo->onScreenPFormat >= 0) { /* Since the return pixel format support pbuffer, - copy OnScreenPFormat to offScreenPFormat */ + we can use it for onScreen and offScreen. */ pFormatInfo->drawToPbuffer = GL_TRUE; pFormatInfo->offScreenPFormat = pFormatInfo->onScreenPFormat; + + /* Fix to issue 77 */ + checkPixelFormat(hdc, pFormatInfo, GL_FALSE ); + offScreenPFListPtr[0] = (jlong) pFormatInfo; (*env)->ReleaseLongArrayElements(env, offScreenPFArray, offScreenPFListPtr, 0); @@ -1333,10 +1453,18 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( return -1; } + /* Fix to issue 77 */ + checkPixelFormat(hdc, pFormatInfo, GL_FALSE ); + /* Create offScreen with standard ChoosePixelFormat */ pFormatInfo->offScreenPFormat = chooseSTDPixelFormat( env, screen, attrList, hdc, GL_TRUE); /* fprintf(stderr, "********* offScreenPFormat = %d\n", pFormatInfo->offScreenPFormat ); */ + + /* Fix to issue 77 */ + if(pFormatInfo->offScreenPFormat >= 0) { + checkPixelFormat(hdc, pFormatInfo, GL_TRUE ); + } offScreenPFListPtr[0] = (jlong) pFormatInfo; (*env)->ReleaseLongArrayElements(env, offScreenPFArray, offScreenPFListPtr, 0); @@ -1377,17 +1505,13 @@ JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( JNIEnv *env, jobject obj, - jlong ctxInfo, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { - HDC hdc; /* HW Device Context */ - - PIXELFORMATDESCRIPTOR pfd; - + static GLboolean first_time = GL_TRUE; static GLboolean force_no_stereo = GL_FALSE; + PixelFormatInfo *pfInfo = (PixelFormatInfo *) pFormatInfo; if (first_time) { if (getenv("J3D_NO_STEREO") != NULL) { @@ -1400,18 +1524,19 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( if (force_no_stereo) return JNI_FALSE; - hdc = getMonitorDC(screen); - - /* Check the chosen PixelFormat to see if it is stereo capable */ - DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd); - - DeleteDC(hdc); - if (pfd.dwFlags & PFD_STEREO) - return JNI_TRUE; - else - return JNI_FALSE; + if(offScreen) { + /* fprintf(stderr, "offScreen isStereoAvailable %d\n", + pfInfo->offScreenHasStereo); */ + + return pfInfo->offScreenHasStereo; + } + else { + /* fprintf(stderr, "onScreen isStereoAvailable %d\n", + pfInfo->onScreenHasStereo); */ + + return pfInfo->onScreenHasStereo; + } - return JNI_TRUE; } @@ -1419,169 +1544,69 @@ JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvailable( JNIEnv *env, jobject obj, - jlong ctxInfo, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { - HDC hdc; /* HW Device Context */ - - PIXELFORMATDESCRIPTOR pfd; - hdc = getMonitorDC(screen); - - /* Check the chosen PixelFormat to see if it is doubleBuffer capable */ - DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd); + PixelFormatInfo *pfInfo = (PixelFormatInfo *) pFormatInfo; + if(offScreen) { + /* fprintf(stderr, "offScreen isDoubleBufferAvailable %d\n", + pfInfo->offScreenHasDoubleBuffer); */ + + return pfInfo->offScreenHasDoubleBuffer; + } + else { + /* fprintf(stderr, "onScreen isDoubleBufferAvailable %d\n", + pfInfo->onScreenHasDoubleBuffer); */ + + return pfInfo->onScreenHasDoubleBuffer; + } - DeleteDC(hdc); - if (pfd.dwFlags & PFD_DOUBLEBUFFER) - return JNI_TRUE; - else - return JNI_FALSE; } - - JNIEXPORT jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable( JNIEnv *env, jobject obj, - jlong ctxInfo, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen) { - HDC hdc; /* HW Device Context */ - PIXELFORMATDESCRIPTOR pfd; - - hdc = getMonitorDC(screen); - /* Check the chosen PixelFormat to see if it is sceneAntialiasing capable */ - DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd); - - DeleteDC(hdc); - if (pfd.cAccumRedBits > 0) - return JNI_TRUE; - else - return JNI_FALSE; + PixelFormatInfo *pfInfo = (PixelFormatInfo *) pFormatInfo; + if(offScreen) { + /* fprintf(stderr, "offScreen isSceneAntialiasingAccumAvailable %d\n", + pfInfo->offScreenHasAccum); */ + + return pfInfo->offScreenHasAccum; + } + else { + /* fprintf(stderr, "onScreen isSceneAntialiasingAccumAvailable %d\n", + pfInfo->onScreenHasAccum); */ + + return pfInfo->onScreenHasAccum; + } } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultiSamplesAvailable( +jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, - jlong ctxInfo, - jlong display, - jint screen, - jint pixelFormat) + jlong pFormatInfo, + jboolean offScreen, + jint screen) { - /* - * Issue 16: this routine is commented out (and JNI_FALSE is - * returned) until a solution can be found that doesn't affect the - * current WGL context for the calling thread, or we need to - * define and implement a mechanism to revalidate the current - * context. - */ - return JNI_FALSE; - -#if 0 - static char szAppName[] = "Choose Pixel Format"; - HWND hwnd; - HGLRC hrc; - HDC hdc; - int attr[3]; - int piValues[2]; - int pf; - BOOL support; - - static PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), - 1, /* Version number */ - PFD_DRAW_TO_WINDOW | - PFD_SUPPORT_OPENGL, - PFD_TYPE_RGBA, - 16, /* 16 bit color depth */ - 0, 0, 0, /* RGB bits and pixel sizes */ - 0, 0, 0, /* Do not care about them */ - 0, 0, /* no alpha buffer info */ - 0, 0, 0, 0, 0, /* no accumulation buffer */ - 8, /* 8 bit depth buffer */ - 0, /* no stencil buffer */ - 0, /* no auxiliary buffers */ - PFD_MAIN_PLANE, /* layer type */ - 0, /* reserved, must be 0 */ - 0, /* no layer mask */ - 0, /* no visible mask */ - 0 /* no damage mask */ - }; - - PFNWGLGETPIXELFORMATATTRIBIVEXTPROC wglGetPixelFormatAttribivEXT = NULL; - - hwnd = createDummyWindow((const char *)szAppName); - - if (!hwnd) { - return -1; - } - hdc = GetDC(hwnd); - - pf = ChoosePixelFormat(hdc, &pfd); - if (!pf) { - printErrorMessage("Failed in ChoosePixelFormat"); - DestroyWindow(hwnd); - UnregisterClass(szAppName, (HINSTANCE)NULL); - return -1; - } - - SetPixelFormat(hdc, pf, &pfd); - - hrc = wglCreateContext(hdc); - if (!hrc) { - printErrorMessage("Failed in wglCreateContext"); - DestroyWindow(hwnd); - UnregisterClass(szAppName, (HINSTANCE)NULL); - return -1; - } - - if (!wglMakeCurrent(hdc, hrc)) { - printErrorMessage("Failed in wglMakeCurrent"); - ReleaseDC(hwnd, hdc); - wglDeleteContext(hrc); - DestroyWindow(hwnd); - UnregisterClass(szAppName, (HINSTANCE)NULL); - return -1; + /* Fix to issue 77 */ + PixelFormatInfo *pfInfo = (PixelFormatInfo *) pFormatInfo; + if(offScreen) { + /* fprintf(stderr, "offScreen isSceneAntialiasingMultisampleAvailable %d\n", + pfInfo->offScreenHasMultisample); */ + + return pfInfo->offScreenHasMultisample; } - - wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) - wglGetProcAddress("wglGetPixelFormatAttribivARB"); - - if (wglGetPixelFormatAttribivEXT == NULL) { - wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) - wglGetProcAddress("wglGetPixelFormatAttribivEXT"); - - if (wglGetPixelFormatAttribivEXT == NULL) { - ReleaseDC(hwnd, hdc); - wglDeleteContext(hrc); - DestroyWindow(hwnd); - UnregisterClass(szAppName, (HINSTANCE)NULL); - return FALSE; - } + else { + /* fprintf(stderr, "onScreen isSceneAntialiasingMultisampleAvailable %d\n", + pfInfo->onScreenHasMultisample); */ + + return pfInfo->onScreenHasMultisample; } - - attr[0] = WGL_SAMPLE_BUFFERS_ARB; - attr[1] = WGL_SAMPLES_ARB; - attr[2] = 0; - support = FALSE; - - if (wglGetPixelFormatAttribivEXT(hdc, pixelFormat, 0, 2, attr, piValues)) { - if ((piValues[0] == TRUE) && (piValues[1] > 1)) { - support = TRUE; - } - } - - ReleaseDC(hwnd, hdc); - wglDeleteContext(hrc); - DestroyWindow(hwnd); - UnregisterClass(szAppName, (HINSTANCE)NULL); - return support; -#endif /* 0 */ } #endif /* WIN32 */ diff --git a/src/native/ogl/gldefs.h b/src/native/ogl/gldefs.h index f5ce5f6..b1fbe7d 100644 --- a/src/native/ogl/gldefs.h +++ b/src/native/ogl/gldefs.h @@ -602,16 +602,28 @@ typedef struct { typedef struct PixelFormatInfoRec PixelFormatInfo; struct PixelFormatInfoRec { - /* Information about pixel format(s) */ + /* Information about onScreen pixel format */ int onScreenPFormat; /* PixelFormat for onScreen */ + GLboolean onScreenHasMultisample; /* TRUE if WGL_SAMPLE_BUFFERS_ARB is TRUE and + WGL_SAMPLES_ARB > 1 */ + GLboolean onScreenHasStereo; + GLboolean onScreenHasDoubleBuffer; + GLboolean onScreenHasAccum; + /* Information about onScreen pixel format */ int offScreenPFormat; /* PixelFormat for offScreen */ + GLboolean offScreenHasMultisample; /* TRUE if WGL_SAMPLE_BUFFERS_ARB is TRUE and + WGL_SAMPLES_ARB > 1 */ + GLboolean offScreenHasStereo; + GLboolean offScreenHasDoubleBuffer; + GLboolean offScreenHasAccum; GLboolean drawToPbuffer; /* value of DRAW_TO_PBUFFER attr for offScreenPFormat */ - + /* Information about extension support */ + char* supportedExtensions; /* list of supported ARB extensions */ GLboolean supportARB; /* TRUE if wgl*PixelFormat*ARB functions supported */ GLboolean supportPbuffer; /* TRUE if wgl*Pbuffer functions supported */ - char* supportedExtensions; /* list of supported ARB extensions */ - + + /* handle to ARB functions */ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB; @@ -620,9 +632,6 @@ struct PixelFormatInfoRec { PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB; PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB; PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB; - - /* TODO include multi-samples buffer */ - }; #endif /* WIN32 */ |