/*
 * Copyright © 2015 <code@io7m.com> http://io7m.com
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.jcanephora.jogl;

import com.io7m.jareas.core.AreaInclusiveUnsignedLType;
import com.io7m.jcanephora.core.JCGLException;
import com.io7m.jcanephora.core.api.JCGLScissorType;
import com.io7m.jnull.NullCheck;
import com.io7m.junsigned.ranges.UnsignedRangeInclusiveL;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL3;

final class JOGLScissor implements JCGLScissorType
{
  private final GL3     gl;
  private       boolean enabled;

  JOGLScissor(final JOGLContext c)
  {
    final JOGLContext context = NullCheck.notNull(c);
    this.gl = context.getGL3();
    this.gl.glDisable(GL.GL_SCISSOR_TEST);
    this.enabled = false;
  }

  @Override public void scissorDisable()
    throws JCGLException
  {
    if (this.enabled) {
      this.gl.glDisable(GL.GL_SCISSOR_TEST);
      this.enabled = false;
    }
  }

  @Override public void scissorEnable(
    final AreaInclusiveUnsignedLType area)
    throws JCGLException
  {
    NullCheck.notNull(area);

    final UnsignedRangeInclusiveL range_x = area.getRangeX();
    final UnsignedRangeInclusiveL range_y = area.getRangeY();

    this.gl.glEnable(GL.GL_SCISSOR_TEST);
    this.enabled = true;
    this.gl.glScissor(
      (int) range_x.getLower(),
      (int) range_y.getLower(),
      (int) range_x.getInterval(),
      (int) range_y.getInterval());
  }

  @Override public boolean scissorIsEnabled()
    throws JCGLException
  {
    return this.enabled;
  }
}

@@ -1130,61 +1130,224 @@
 L3;%0A
-%0Afinal class JOGLScissor implements JCGLScissorType%0A%7B
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Afinal class JOGLScissor implements JCGLScissorType%0A%7B%0A  private static final Logger LOG;%0A%0A  static %7B%0A    LOG = LoggerFactory.getLogger(JOGLScissor.class);%0A  %7D%0A
 %0A  p
@@ -1771,16 +1771,95 @@
  false;%0A
+    %7D else %7B%0A      JOGLScissor.LOG.trace(%22redundant scissor disable ignored%22);%0A
     %7D%0A  
@@ -2123,24 +2123,51 @@
 tRangeY();%0A%0A
+    if (!this.enabled) %7B%0A  
     this.gl.
@@ -2192,32 +2192,34 @@
 SSOR_TEST);%0A    
+  
 this.enabled = t
@@ -2223,16 +2223,18 @@
 = true;%0A
+  
     this
@@ -2250,24 +2250,26 @@
 ssor(%0A      
+  
 (int) range_
@@ -2274,32 +2274,34 @@
 e_x.getLower(),%0A
+  
       (int) rang
@@ -2314,32 +2314,34 @@
 tLower(),%0A      
+  
 (int) range_x.ge
@@ -2349,24 +2349,26 @@
 Interval(),%0A
+  
       (int) 
@@ -2391,16 +2391,100 @@
 val());%0A
+    %7D else %7B%0A      JOGLScissor.LOG.trace(%22redundant scissor enable ignored%22);%0A    %7D%0A
   %7D%0A%0A  @

Add trace logs for redundant scissor state changes