diff options
author | Kenneth Russel <[email protected]> | 2005-02-26 01:41:28 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-02-26 01:41:28 +0000 |
commit | b41b720c4366d4e2cdc1ba146123b87da966d724 (patch) | |
tree | 6c6c8196e9ac0ef57f068f394c1720ec034639c2 /src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java | |
parent | 2bb02ad536c5404f008ff71c6d4ca013abaff683 (diff) |
Merged with current JOGL trunk (tag JOGL_1_1_PRE_B10)
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@245 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java')
-rw-r--r-- | src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java index d3795905f..f0ce74d9d 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java @@ -43,7 +43,7 @@ import net.java.games.jogl.*; import net.java.games.jogl.impl.*; public class WindowsPbufferGLContext extends WindowsGLContext { - private static final boolean DEBUG = false; + private static final boolean DEBUG = Debug.debug("WindowsPbufferGLContext"); private int initWidth; private int initHeight; @@ -75,6 +75,13 @@ public class WindowsPbufferGLContext extends WindowsGLContext { throw new GLException("Initial width and height of pbuffer must be positive (were (" + initWidth + ", " + initHeight + "))"); } + + if (DEBUG) { + System.out.println("Pbuffer caps on init: " + capabilities + + (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + + (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + + (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); + } } public boolean canCreatePbufferContext() { @@ -128,6 +135,13 @@ public class WindowsPbufferGLContext extends WindowsGLContext { int nfattribs = 0; int niattribs = 0; + if (DEBUG) { + System.out.println("Pbuffer caps: " + capabilities + + (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + + (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + + (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); + } + rtt = capabilities.getOffscreenRenderToTexture(); rect = capabilities.getOffscreenRenderToTextureRectangle(); boolean useFloat = capabilities.getOffscreenFloatingPointBuffers(); @@ -228,9 +242,10 @@ public class WindowsPbufferGLContext extends WindowsGLContext { iattributes[5] = GL.WGL_FLOAT_COMPONENTS_NV; iattributes[6] = GL.WGL_SAMPLE_BUFFERS_EXT; iattributes[7] = GL.WGL_SAMPLES_EXT; - int[] ivalues = new int[8]; + iattributes[8] = GL.WGL_DRAW_TO_PBUFFER_ARB; + int[] ivalues = new int[9]; for (int i = 0; i < nformats; i++) { - if (!gl.wglGetPixelFormatAttribivARB(parentHdc, pformats[i], 0, 8, iattributes, ivalues)) { + if (!gl.wglGetPixelFormatAttribivARB(parentHdc, pformats[i], 0, 9, iattributes, ivalues)) { throw new GLException("Error while querying pixel format " + pformats[i] + "'s (index " + i + "'s) capabilities for debugging"); } @@ -245,38 +260,49 @@ public class WindowsPbufferGLContext extends WindowsGLContext { if (ivalues[5] != 0) { System.err.print(" [float]"); } + if (ivalues[8] != 0) { + System.err.print(" [pbuffer]"); + } System.err.println(); } } - int format = pformats[0]; + long tmpBuffer = 0; + int whichFormat = 0; + // Loop is a workaround for bugs in NVidia's recent drivers + do { + int format = pformats[whichFormat]; - // Create the p-buffer. - niattribs = 0; + // Create the p-buffer. + niattribs = 0; - if (rtt) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FORMAT_ARB; - if (useFloat) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FLOAT_RGB_NV; - } else { - iattributes[niattribs++] = GL.WGL_TEXTURE_RGBA_ARB; - } + if (rtt) { + iattributes[niattribs++] = GL.WGL_TEXTURE_FORMAT_ARB; + if (useFloat) { + iattributes[niattribs++] = GL.WGL_TEXTURE_FLOAT_RGB_NV; + } else { + iattributes[niattribs++] = GL.WGL_TEXTURE_RGBA_ARB; + } - iattributes[niattribs++] = GL.WGL_TEXTURE_TARGET_ARB; - iattributes[niattribs++] = rect ? GL.WGL_TEXTURE_RECTANGLE_NV : GL.WGL_TEXTURE_2D_ARB; + iattributes[niattribs++] = GL.WGL_TEXTURE_TARGET_ARB; + iattributes[niattribs++] = rect ? GL.WGL_TEXTURE_RECTANGLE_NV : GL.WGL_TEXTURE_2D_ARB; - iattributes[niattribs++] = GL.WGL_MIPMAP_TEXTURE_ARB; - iattributes[niattribs++] = GL.GL_FALSE; + iattributes[niattribs++] = GL.WGL_MIPMAP_TEXTURE_ARB; + iattributes[niattribs++] = GL.GL_FALSE; - iattributes[niattribs++] = GL.WGL_PBUFFER_LARGEST_ARB; - iattributes[niattribs++] = GL.GL_FALSE; - } + iattributes[niattribs++] = GL.WGL_PBUFFER_LARGEST_ARB; + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = 0; - iattributes[niattribs++] = 0; + tmpBuffer = gl.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes); + ++whichFormat; + } while ((tmpBuffer == 0) && (whichFormat < nformats)); - long tmpBuffer = gl.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes); if (tmpBuffer == 0) { - throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: " + wglGetLastError()); + throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: tried " + nformats + + " pixel formats, last error was: " + wglGetLastError()); } // Get the device context. @@ -308,10 +334,16 @@ public class WindowsPbufferGLContext extends WindowsGLContext { if (buffer == 0) { // pbuffer not instantiated yet + if (DEBUG) { + System.err.println("pbuffer not instantiated yet"); + } return false; } boolean res = super.makeCurrent(initAction); + if (DEBUG) { + System.err.println("super.makeCurrent() = " + res + ", created = " + created); + } if (created) { // Initialize render-to-texture support if requested rtt = capabilities.getOffscreenRenderToTexture(); @@ -396,6 +428,22 @@ public class WindowsPbufferGLContext extends WindowsGLContext { } } + protected void destroyImpl() throws GLException { + if (hglrc != 0) { + super.destroyImpl(); + // Must release DC and pbuffer + GL gl = getGL(); + if (gl.wglReleasePbufferDCARB(buffer, hdc) == 0) { + throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); + } + hdc = 0; + if (!gl.wglDestroyPbufferARB(buffer)) { + throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); + } + buffer = 0; + } + } + public void swapBuffers() throws GLException { // FIXME: do we need to do anything if the pbuffer is double-buffered? // For now, just grab the pixels for the render-to-texture support. |