From a167589233db343ac22b761d30d9dcd73016fe54 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sat, 5 Mar 2011 03:28:37 +0100
Subject: Fix GLStateTracker PixelStore popAttrib(): Only write new state if
 corresponding push was of ClientPixelStore type

---
 src/jogl/classes/jogamp/opengl/GLStateTracker.java | 28 +++++++++++++++-------
 1 file changed, 19 insertions(+), 9 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/GLStateTracker.java')

diff --git a/src/jogl/classes/jogamp/opengl/GLStateTracker.java b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
index 22874c0c3..e31187bf6 100644
--- a/src/jogl/classes/jogamp/opengl/GLStateTracker.java
+++ b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
@@ -59,14 +59,25 @@ public class GLStateTracker {
   private IntIntHashMap pixelStateMap;
 
   static class SavedState {
+    /**
+     * Empty pixel-store state
+     */ 
     SavedState() {
         this.pixelStateMap = null;
     }
+    
+    /**
+     * set (client) pixel-store state
+     */ 
     void putPixelStateMap(IntIntHashMap pixelStateMap) {
         this.pixelStateMap = new IntIntHashMap();
         this.pixelStateMap.setKeyNotFoundValue(-1);
         this.pixelStateMap.putAll(pixelStateMap);
     }
+    
+    /**
+     * get (client) pixel-store state
+     */ 
     IntIntHashMap getPixelStateMap() { return pixelStateMap; }
 
     private IntIntHashMap pixelStateMap;
@@ -127,11 +138,12 @@ public class GLStateTracker {
 
   public void pushAttrib(int flags) {
     if(enabled) {
-        SavedState state = new SavedState();
+        SavedState state = new SavedState(); // empty-slot
         if( 0 != (flags&GL2.GL_CLIENT_PIXEL_STORE_BIT) ) {
+            // save client pixel-store state
             state.putPixelStateMap(pixelStateMap);
         }
-        stack.add(0, state);
+        stack.add(0, state); // push
     }
   }
 
@@ -140,21 +152,19 @@ public class GLStateTracker {
         if(stack.size()==0) {
             throw new GLException("stack contains no elements");
         }
-        SavedState state = (SavedState) stack.remove(0);
+        SavedState state = (SavedState) stack.remove(0); // pop
         if(null==state) {
             throw new GLException("null stack element (remaining stack size "+stack.size()+")");
         }
 
-        IntIntHashMap pixelStateMapNew = new IntIntHashMap();
-        pixelStateMapNew.setKeyNotFoundValue(-1);
         if ( null != state.getPixelStateMap() ) {
-            pixelStateMapNew.putAll(state.getPixelStateMap());
-        }
-        pixelStateMap = pixelStateMapNew;
+            // use pulled client pixel-store state from stack
+            pixelStateMap = state.getPixelStateMap();
+        } // else: empty-slot, not pushed by GL_CLIENT_PIXEL_STORE_BIT        
     }
   }
 
-  public void resetStates() {
+  private void resetStates() {
     pixelStateMap.clear();
 
     pixelStateMap.put(GL.GL_PACK_ALIGNMENT,          4);
-- 
cgit v1.2.3