From e9b806b277428b74a51afb5e076afe7dfabb26d4 Mon Sep 17 00:00:00 2001
From: Kenneth Russel <kbrussel@alum.mit.edu>
Date: Wed, 22 Jun 2005 08:05:55 +0000
Subject: Fixed Issue 166: Memory leak with ATI Mobility Radeon 9700

Worked around memory leak in ATI's OpenGL drivers by adding system
property -Djogl.GLContext.nofree which users can specify on the
command line. There is no good general-purpose workaround for this bug
which works well on all hardware and in all kinds of applications.
Issues may remain if this workaround is used and if the GLCanvas is
removed and re-added to its parent container. Use at your own risk.

Also cleaned up Windows ChoosePixelFormat code path; made sure
PIXELFORMATDESCRIPTOR was completely filled out.


git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@306 232f8b59-042b-4e1e-8c03-345bb8c30851
---
 .../games/jogl/impl/windows/WindowsGLContext.java  | 43 ++++++++++++++++------
 1 file changed, 32 insertions(+), 11 deletions(-)

(limited to 'src/net/java/games/jogl/impl/windows/WindowsGLContext.java')

diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java
index d808634f2..f597d56b7 100644
--- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java
+++ b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java
@@ -140,12 +140,24 @@ public abstract class WindowsGLContext extends GLContext {
       created = true;
     }
 
-    if (!WGL.wglMakeCurrent(hdc, hglrc)) {
-      throw new GLException("Error making context current: " + WGL.GetLastError());
-    } else {
-      if (DEBUG && VERBOSE) {
-        System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + hdcToString(hdc) +
-                           ", hglrc " + hdcToString(hglrc) + ") succeeded");
+    boolean skipMakeCurrent = false;
+    if (NO_FREE) {
+      if (WGL.wglGetCurrentContext() == hglrc) {
+        if (DEBUG && VERBOSE) {
+          System.err.println(getThreadName() + ": skipping wglMakeCurrent because context already current");
+        }
+        skipMakeCurrent = true;
+      }
+    }
+
+    if (!skipMakeCurrent) {
+      if (!WGL.wglMakeCurrent(hdc, hglrc)) {
+        throw new GLException("Error making context current: " + WGL.GetLastError());
+      } else {
+        if (DEBUG && VERBOSE) {
+          System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + hdcToString(hdc) +
+                             ", hglrc " + hdcToString(hglrc) + ") succeeded");
+        }
       }
     }
 
@@ -174,8 +186,10 @@ public abstract class WindowsGLContext extends GLContext {
   }
 
   protected synchronized void free() throws GLException {
-    if (!WGL.wglMakeCurrent(0, 0)) {
-      throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError());
+    if (!NO_FREE) {
+      if (!WGL.wglMakeCurrent(0, 0)) {
+        throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError());
+      }
     }
   }
 
@@ -550,9 +564,6 @@ public abstract class WindowsGLContext extends GLContext {
                     WGL.PFD_GENERIC_ACCELERATED);
     if (caps.getDoubleBuffered()) {
       pfdFlags |= WGL.PFD_DOUBLEBUFFER;
-      if (onscreen) {
-        pfdFlags |= WGL.PFD_SWAP_EXCHANGE;
-      }
     }
     if (onscreen) {
       pfdFlags |= WGL.PFD_DRAW_TO_WINDOW;
@@ -565,7 +576,17 @@ public abstract class WindowsGLContext extends GLContext {
     pfd.cRedBits  ((byte) caps.getRedBits());
     pfd.cGreenBits((byte) caps.getGreenBits());
     pfd.cBlueBits ((byte) caps.getBlueBits());
+    pfd.cAlphaBits((byte) caps.getAlphaBits());
+    int accumDepth = (caps.getAccumRedBits() +
+                      caps.getAccumGreenBits() +
+                      caps.getAccumBlueBits());
+    pfd.cAccumBits     ((byte) accumDepth);
+    pfd.cAccumRedBits  ((byte) caps.getAccumRedBits());
+    pfd.cAccumGreenBits((byte) caps.getAccumGreenBits());
+    pfd.cAccumBlueBits ((byte) caps.getAccumBlueBits());
+    pfd.cAccumAlphaBits((byte) caps.getAccumAlphaBits());
     pfd.cDepthBits((byte) caps.getDepthBits());
+    pfd.cStencilBits((byte) caps.getStencilBits());
     pfd.iLayerType((byte) WGL.PFD_MAIN_PLANE);
     return pfd;
   }
-- 
cgit v1.2.3