public void setImage(TextureData data) {
   setImage(
       data.getWidth(),
       data.getHeight(),
       data.getPixelFormat(),
       data.getPixelType(),
       data.getBuffer());
 }
 public void dispose(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   if (null != texture) {
     texture.disable();
     texture.destroy(gl);
   }
   if (null != textureData) {
     textureData.destroy();
   }
 }
  /**
   * @param buffer
   * @param tile
   * @param pool
   * @return
   */
  private Tile createTile(
      FloatBuffer buffer,
      Rectangle tile,
      GL gl,
      Deque<Texture> pool,
      TablePerspective tablePerspective) {
    final VirtualArray recordVA = tablePerspective.getRecordPerspective().getVirtualArray();
    final VirtualArray dimVA = tablePerspective.getDimensionPerspective().getVirtualArray();
    final ATableBasedDataDomain dataDomain = tablePerspective.getDataDomain();
    final int ilast = tile.y + tile.height;
    final int jlast = tile.x + tile.width;

    // fill buffer
    buffer.rewind();
    for (int i = tile.y; i < ilast; ++i) {
      int recordID = recordVA.get(i);
      for (int j = tile.x; j < jlast; ++j) {
        int dimensionID = dimVA.get(j);
        Color color = blockColorer.apply(recordID, dimensionID, dataDomain, false);
        buffer.put(color.getRGBA());
      }
    }

    // load to texture
    buffer.rewind();
    Texture texture;
    if (!pool.isEmpty()) texture = pool.poll();
    else texture = TextureIO.newTexture(GL.GL_TEXTURE_2D);

    TextureData texData = asTextureData(buffer, tile.width, tile.height);
    texture.updateImage(gl, texData);
    gl.glFlush();
    texData.destroy();

    return new Tile(tile, texture);
  }
  @Override
  public void dispose(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();
    if (null != texture) {
      texture.disable(gl);
      texture.destroy(gl);
    }
    if (null != textureData) {
      textureData.destroy();
    }

    pmvMatrixUniform = null;
    pmvMatrix = null;
    st.destroy(gl);
    st = null;
  }
  public void testImpl(boolean useFFP, final InputStream istream)
      throws InterruptedException, IOException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    GLProfile glp;
    if (useFFP && GLProfile.isAvailable(GLProfile.GL2)) {
      glp = GLProfile.getMaxFixedFunc(true);
    } else if (!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) {
      glp = GLProfile.getGL2ES2();
    } else {
      System.err.println(getSimpleTestName(".") + ": GLProfile n/a, useFFP: " + useFFP);
      return;
    }
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(1);

    final TextureData texData =
        TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.TGA);
    System.err.println("TextureData: " + texData);

    final GLWindow glad = GLWindow.create(caps);
    glad.setTitle("TestTGATextureGL2FromFileNEWT");
    // Size OpenGL to Video Surface
    glad.setSize(texData.getWidth(), texData.getHeight());

    // load texture from file inside current GL context to match the way
    // the bug submitter was doing it
    final GLEventListener gle =
        useFFP ? new TextureDraw01GL2Listener(texData) : new TextureDraw01ES2Listener(texData, 0);
    glad.addGLEventListener(gle);
    glad.addGLEventListener(
        new GLEventListener() {
          boolean shot = false;

          @Override
          public void init(GLAutoDrawable drawable) {}

          public void display(GLAutoDrawable drawable) {
            // 1 snapshot
            if (null != ((TextureDraw01Accessor) gle).getTexture() && !shot) {
              shot = true;
              snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
            }
          }

          @Override
          public void dispose(GLAutoDrawable drawable) {}

          @Override
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
        });

    Animator animator = new Animator(glad);
    animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
    QuitAdapter quitAdapter = new QuitAdapter();
    glad.addKeyListener(quitAdapter);
    glad.addWindowListener(quitAdapter);
    glad.setVisible(true);
    animator.start();

    while (!quitAdapter.shouldQuit()
        && animator.isAnimating()
        && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    animator.stop();
    glad.destroy();
  }