gt:             if(anisotropicMode != ANISOTROPIC_MODE_NONE)
context: /*****************************************************************************
   *                     Yumetech, Inc Copyright (c) 2004-2005
   *                               Java Source
   *
   * This source is licensed under the GNU LGPL v2.1
   * Please read http://www.gnu.org/copyleft/lgpl.html for more information
   *
   * This software comes with the standard NO WARRANTY disclaimer for any
   * purpose. Use it at your own risk. If there's a problem you get to fix it.
   *
   ****************************************************************************/
  
  package org.j3d.aviatrix3d;
  
  // External imports
  import java.nio.ByteBuffer;
  
  import javax.media.opengl.GL;
  
  // Local imports
  import org.j3d.aviatrix3d.iutil.TextureUpdateData;
  
  /**
   * Describes the 3D (volume) texture properties of an object.
   *
   * @author Justin Couch
   * @version $Revision: 1.33 $
   */
  public class Texture3D extends Texture
  {
      /** The boundary mode R value */
      private int boundaryModeR;
  
      /** The height of the main texture. */
      private int height;
  
      /** The depth of the main texture (the first image in the component */
      private int depth;
  
      /** The boundary mode S value */
      private int boundaryModeT;
  
      /**
       * Constructs a texture with default values.
       */
      public Texture3D()
      {
          super(GL.GL_TEXTURE_3D, 1);
          height = -1;
          depth = -1;
  
          init();
      }
  
      /**
       * Constructs a texture using just a single image, thus setting it initially
       * as MODE_BASE_LEVEL.
       */
      public Texture3D(int format, TextureComponent3D singleImage)
      {
          super(GL.GL_TEXTURE_3D, 1);
  
          this.format = format;
          sources = new TextureSource[1];
          sources[0] = singleImage;
  
          width = singleImage.getWidth();
          height = singleImage.getHeight();
          depth = singleImage.getDepth();
          numSources = 1;
  
          init();
      }
  
      //---------------------------------------------------------------
      // Methods defined by Texture
      //---------------------------------------------------------------
  
      /**
       * Set a new collection of sources for this texture to use.
       *
       * @param mipMapMode Flag stating the type of texture mode to use
       * @param format Image format to use for grayscale sources
       * @param texSources The source data to use, single for base level
       * @param num The valid number of sources to use from the array
       * @throws IllegalArgumentException Source must be 3D texture data
       * @throws InvalidWriteTimingException An attempt was made to write outside
       *   of the NodeUpdateListener callback method
       */
      public void setSources(int mipMapMode,
                             int format,
                             TextureSource[] texSources,
                             int num)
          throws InvalidWriteTimingException
      {
          if((num > 0) && !(texSources[0] instanceof TextureComponent3D))
              throw new IllegalArgumentException("Must be a 3D texture source");
  
          super.setSources(mipMapMode, format, texSources, num);
  
          // Check to see if the source is a multipass source or not.
          if(num > 0)
          {
              depth = ((TextureComponent3D)sources[0]).getDepth();
              height = ((TextureComponent3D)sources[0]).getHeight();
          }
  
          stateChanged.setAll(true);
      }
  
      //---------------------------------------------------------------
      // Methods defined by Comparable
      //---------------------------------------------------------------
  
      /**
       * Compares this object with the specified object for order. Returns a
       * negative integer, zero, or a positive integer as this object is less
       * than, equal to, or greater than the specified object. Derived instances
       * should override this to add texture-specific extensions.
       *
       * @param tex The texture instance to be compared
       * @return -1, 0 or 1 depending on order
       */
      public int compareTo(Texture tex)
      {
          int res = super.compareTo(tex);
          if(res != 0)
              return res;
  
          Texture3D t3d = (Texture3D)tex;
  
          if(height != t3d.height)
              return height < t3d.height ? -1 : 1;
  
          if(depth != t3d.depth)
              return depth < t3d.depth ? -1 : 1;
  
          if(boundaryModeS != t3d.boundaryModeS)
              return boundaryModeS < t3d.boundaryModeS ? -1 : 1;
  
          if(boundaryModeT != t3d.boundaryModeT)
              return boundaryModeT < t3d.boundaryModeT ? -1 : 1;
  
          if(boundaryModeR != t3d.boundaryModeR)
              return boundaryModeR < t3d.boundaryModeR ? -1 : 1;
  
          return 0;
      }
  
      /**
       * Compares this object with the specified object to check for equivalence.
       *
       * @param tex The texture instance to be compared
       * @return true if the objects represent identical values
       */
      public boolean equals(Texture tex)
      {
          if(!super.equals(tex))
              return false;
  
          if(!(tex instanceof Texture3D))
              return false;
  
          Texture3D t3d = (Texture3D)tex;
  
          if((height != t3d.height) ||
             (depth != t3d.depth) ||
             (boundaryModeS != t3d.boundaryModeS) ||
             (boundaryModeT != t3d.boundaryModeT) ||
             (boundaryModeR != t3d.boundaryModeR))
              return false;
  
          return true;
      }
  
      //---------------------------------------------------------------
      // Methods defined by ObjectRenderable
      //---------------------------------------------------------------
  
      /**
       * Issue ogl commands needed for this component
       *
       * @param gl The gl context to draw with
       */
      public void render(GL gl)
      {
          if(numSources == 0)
              return;
  
          Integer t_id = textureIdMap.get(gl);
          if(t_id == null)
          {
              int[] tex_id_tmp = new int[1];
              gl.glGenTextures(1, tex_id_tmp, 0);
              textureIdMap.put(gl, new Integer(tex_id_tmp[0]));
  
              gl.glBindTexture(textureType, tex_id_tmp[0]);
  
              // Set the flag so that we update later in the method
              imageChanged.put(gl, true);
              stateChanged.put(gl, true);
              updateManagers[0].addContext(gl);
          }
          else
          {
              gl.glBindTexture(textureType, t_id.intValue());
          }
  
          if(stateChanged.getState(gl))
          {
              stateChanged.put(gl, false);
  
              gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
              gl.glTexParameteri(GL.GL_TEXTURE_3D,
                                 GL.GL_TEXTURE_WRAP_S,
                                 boundaryModeS);
  
              gl.glTexParameteri(GL.GL_TEXTURE_3D,
                                 GL.GL_TEXTURE_WRAP_T,
                                 boundaryModeT);
  
              gl.glTexParameteri(GL.GL_TEXTURE_3D,
                                 GL.GL_TEXTURE_WRAP_R,
                                 boundaryModeR);
  
              int mode = 0;
              switch(magFilter)
              {
                  case MAGFILTER_FASTEST:
                  case MAGFILTER_BASE_LEVEL_POINT:
                      mode = GL.GL_NEAREST;
                      break;
  
                  case MAGFILTER_NICEST:
                  case MAGFILTER_BASE_LEVEL_LINEAR:
                      mode = GL.GL_LINEAR;
                      break;
  
                  default: System.out.println("Unknown mode in MagFilter: " + magFilter);
              }
  
              gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, mode);
  
              switch(minFilter)
              {
                  case MINFILTER_FASTEST:
                  case MINFILTER_BASE_LEVEL_POINT:
                      mode = GL.GL_NEAREST;
                      break;
  
                  case MINFILTER_BASE_LEVEL_LINEAR:
                      mode = GL.GL_LINEAR;
                      break;
  
                  case MINFILTER_MULTI_LEVEL_LINEAR:
                      mode = GL.GL_LINEAR_MIPMAP_LINEAR;
                      break;
  
                  case MINFILTER_MULTI_LEVEL_POINT:
                      mode = GL.GL_NEAREST_MIPMAP_NEAREST;
                      break;
  
                  case MINFILTER_NICEST:
                      mode = (numSources > 1) ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR;
                      break;
  
                  default: System.out.println("Unknown mode in MinFilter: " + minFilter);
              }
  
              gl.glTexParameteri(GL.GL_TEXTURE_3D,
                                 GL.GL_TEXTURE_MIN_FILTER,
                                 mode);
  
  