Beispiel #1
0
  /** Copy texture to pixels. Involves video memory to main memory transfer (slow). */
  public void get(int[] pixels) {
    if (pixels == null) {
      throw new RuntimeException("Trying to copy texture to null pixels array");
    }
    if (pixels.length != width * height) {
      throw new RuntimeException("Trying to copy texture to pixels array of " + "wrong size");
    }

    if (tempFbo == null) {
      tempFbo = new FrameBuffer(parent, glWidth, glHeight);
    }

    // Attaching the texture to the color buffer of a FBO, binding the FBO and
    // reading the pixels from the current draw buffer (which is the color
    // buffer of the FBO).
    tempFbo.setColorBuffer(this);
    pg.pushFramebuffer();
    pg.setFramebuffer(tempFbo);
    tempFbo.readPixels();
    pg.popFramebuffer();

    tempFbo.getPixels(pixels);
    convertToARGB(pixels);

    if (invertedX) flipArrayOnX(pixels, 1);
    if (invertedY) flipArrayOnY(pixels, 1);
  }
Beispiel #2
0
 public void getBufferPixels(int[] pixels) {
   BufferData data = null;
   if (usedBuffers != null && 0 < usedBuffers.size()) {
     // the last used buffer is the one currently stored in the opengl the
     // texture
     data = usedBuffers.getLast();
   } else if (bufferCache != null && 0 < bufferCache.size()) {
     // The first buffer in the cache will be uploaded to the opengl texture
     // the next time it is rendered
     data = bufferCache.getFirst();
   }
   if (data != null) {
     data.rgbBuf.rewind();
     data.rgbBuf.get(pixels);
     convertToARGB(pixels);
   }
 }
Beispiel #3
0
  protected boolean bufferUpdate(int[] pixels) {
    BufferData data = null;
    try {
      data = bufferCache.remove(0);
    } catch (NoSuchElementException ex) {
      PGraphics.showWarning("Don't have pixel data to copy to texture");
    }

    if (data != null) {
      if ((data.w != width) || (data.h != height)) {
        init(data.w, data.h);
      }
      setNative(data.rgbBuf, 0, 0, width, height);

      data.rgbBuf.get(pixels);
      convertToARGB(pixels);

      data.dispose();

      return true;
    } else {
      return false;
    }
  }