title: Nested scissor boxes with OpenGL
body: <p>I am working on an OpenGL-based UI written in C. I have a hierarchy of controls -- small square 2D boxes inside a scrollable region of a bigger control. Inside the small boxes 3D scenes are drawn. The 3D scene must be scissored within the small 2D boxes and the small 2D boxes must be scissored within the larger region.</p>
  
  <p><code>glScissor()</code> is an obvious candidate for making sure drawing takes places within the desired region. The problem is that I cannot simultaneously call <code>glScissor()</code> for the large region and then call <code>glScissor()</code> again for subregions inside the larger scissored region.</p>
  
  <p>Example code to demonstrate what I want:</p>
  
  <pre><code>void drawBigBox() {
      glScissor( ... ); //set the bounds of the larger region
      for each little box {
          //these might be anywhere, but they should only be visible if inside the glScissor bounds
          drawLittleBoxes(); 
      }
  }
  
  void drawLittleBoxes() {
      //draw only inside little box -- Whoops! This replaces the big box bounds!
      //How can I meet this constraint while retaining the outer scissor region?
      glScissor( ... );
      draw3dScene();
  }
  </code></pre>
  
  <p>Is there a simple way of doing what I want? Obviously I can also calculate the intersection of the small and large scissor boxes, or I could more carefully clip/project my 3D scene, but that is more complicated than an OpenGL call. Perhaps there is another approach to doing this that I am unaware of.</p>
  
  <p>Thanks!</p>