示例#1
0
  // Copies source texture tex into this.
  protected void copyTexture(
      int texTarget,
      int texName,
      int texWidth,
      int texHeight,
      int x,
      int y,
      int w,
      int h,
      boolean scale) {
    if (tempFbo == null) {
      tempFbo = new FrameBuffer(parent, glWidth, glHeight);
    }

    // This texture is the color (destination) buffer of the FBO.
    tempFbo.setColorBuffer(this);
    tempFbo.disableDepthTest();

    // FBO copy:
    pg.pushFramebuffer();
    pg.setFramebuffer(tempFbo);
    if (scale) {
      // Rendering tex into "this", and scaling the source rectangle
      // to cover the entire destination region.
      pgl.drawTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, 0, 0, width, height);

    } else {
      // Rendering tex into "this" but without scaling so the contents
      // of the source texture fall in the corresponding texels of the
      // destination.
      pgl.drawTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, x, y, w, h);
    }
    pg.popFramebuffer();
    updateTexels(x, y, w, h);
  }
示例#2
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);
  }
 /**
  * Check to see if there are any FrameBuffers that have switched their interest type from read
  * to write or vice versa.
  */
 protected void processInterestChanges() {
   synchronized (selectInterestChanges) {
     for (FrameBuffer fb : selectInterestChanges) {
       fb.changeSelectInterests();
     }
     selectInterestChanges.clear();
   }
 }
 /** Do connection-close cleanup on a given SelectionKey. */
 protected void cleanupSelectionKey(SelectionKey key) {
   // remove the records from the two maps
   FrameBuffer buffer = (FrameBuffer) key.attachment();
   if (buffer != null) {
     // close the buffer
     buffer.close();
   }
   // cancel the selection key
   key.cancel();
 }
  protected void cleanupBuffers() {
    // Delete the capture buffers
    for (int i = 0; i < m_CaptureBuffers.size(); ++i) {
      FrameBuffer buffer = m_CaptureBuffers.get(i);
      buffer.free();
    }

    m_FreeBufferList.clear();
    m_CaptureBuffers.clear();
  }
    /**
     * Do the work required to read from a readable client. If the frame is fully read, then invoke
     * the method call.
     */
    protected void handleRead(SelectionKey key) {
      FrameBuffer buffer = (FrameBuffer) key.attachment();
      if (!buffer.read()) {
        cleanupSelectionKey(key);
        return;
      }

      // if the buffer's frame read is complete, invoke the method.
      if (buffer.isFrameFullyRead()) {
        if (!requestInvoke(buffer)) {
          cleanupSelectionKey(key);
        }
      }
    }
示例#7
0
 @Override
 void startLayer() {
   frameBuffer = graph.obtainFrameBuffer();
   frameBuffer.bind();
   gl.glClearColor(0, 0, 0, 0);
   gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT);
 }
示例#8
0
 private FrameBuffer obtainFrameBuffer() {
   if (frameBuffersCache.size > 0) {
     return frameBuffersCache.pop();
   } else {
     return FrameBuffer.obtain(width, height, Format.RGBA8888);
   }
 }
  protected boolean allocateBuffers() {
    // Allocate exactly 3 buffers to use as the capture destination while streaming.
    // These buffers are passed to the SDK.
    for (int i = 0; i < s_NumSdkBuffers; ++i) {
      FrameBuffer buffer =
          m_Stream.allocateFrameBuffer(m_VideoParams.outputWidth * m_VideoParams.outputHeight * 4);
      if (!buffer.getIsValid()) {
        reportError(String.format("Error while allocating frame buffer"));
        return false;
      }

      m_CaptureBuffers.add(buffer);
      m_FreeBufferList.add(buffer);
    }

    return true;
  }
示例#10
0
 public void preWarm(FrameBuffer framebuffer) {
   if (!framebuffer.usesRenderer(1)) return;
   for (int i = 0; i < textureCount; i++) {
     Texture texture = textures[i];
     Texture texture1;
     if (texture != null) texture1 = texture.getMipMappedTexture(1);
   }
 }
示例#11
0
 @Override
 void endLayer() {
   frameBuffer.unbind();
   Effect effect = layer.effect;
   if (effect != null) {
     effect.process(frameBuffer.texture);
   }
 }
示例#12
0
 public void run() {
   if (frameBuffer.trans_ instanceof TNonblockingSocket) {
     TNonblockingSocket tsock = (TNonblockingSocket) frameBuffer.trans_;
     Socket sock = tsock.getSocketChannel().socket();
     clientAddress.set(sock.getInetAddress().getHostAddress() + ":" + sock.getPort());
   }
   frameBuffer.invoke();
 }
示例#13
0
 @Override
 public void reset() {
   clear();
   externalRootFrameBuffer = 0;
   if (rootFrameBuffer != null) {
     rootFrameBuffer.free();
     rootFrameBuffer = null;
   }
   CanvasUtils.resetArray(frameBuffersCache);
   frameBuffersStack.clear();
   width = 0;
   height = 0;
   glContext = null;
 }
  public OverlappingFrameBuffer(FrameBuffer inner, double overlap) {
    if (overlap <= 0 || overlap >= 1) {
      throw new IllegalArgumentException("overlap should be > 0, < 1.");
    }

    this.overlap = overlap;
    this.inner = inner;
    this.overlapSize = (int) (overlap * inner.getFrameSize());

    numFrames =
        (int)
            Math.floor(
                (inner.getNumFrames() * inner.getFrameSize())
                    / (inner.getFrameSize() - overlapSize));

    double oldFps = inner.getFramesPerSecond();
    double growth = (numFrames / (double) inner.getNumFrames());

    fps = (oldFps * growth);
  }
示例#15
0
  public void bufferUnlockCallback(long address) {
    FrameBuffer buffer = FrameBuffer.lookupBuffer(address);

    // Put back on the free list
    m_FreeBufferList.add(buffer);
  }
 @Override
 public double getSampleRate() {
   return inner.getSampleRate();
 }
 @Override
 public int getFrameSize() {
   return inner.getFrameSize();
 }
 /** Let a writable client get written, if there's data to be written. */
 protected void handleWrite(SelectionKey key) {
   FrameBuffer buffer = (FrameBuffer) key.attachment();
   if (!buffer.write()) {
     cleanupSelectionKey(key);
   }
 }
 @Override
 public int getHeight() {
   return frameBuffer.getHeight();
 }
 @Override
 public int getWidth() {
   return frameBuffer.getWidth();
 }
示例#21
0
 public boolean isSupported() {
   return FrameBuffer.isSupported();
 }
示例#22
0
 void init(GlContext glContext, Texture texture) {
   this.glContext = glContext;
   this.width = glContext.getWidth();
   this.height = glContext.getHeight();
   this.rootFrameBuffer = FrameBuffer.obtain(texture);
 }
示例#23
0
  // Copies source texture tex into this.
  protected void copyTexture(Texture tex, int x, int y, int w, int h, boolean scale) {
    if (tex == null) {
      throw new RuntimeException("Source texture is null");
    }

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

    // This texture is the color (destination) buffer of the FBO.
    tempFbo.setColorBuffer(this);
    tempFbo.disableDepthTest();

    // FBO copy:
    PGraphicsOpenGL.pushFramebuffer();
    PGraphicsOpenGL.setFramebuffer(tempFbo);
    // Clear the color buffer to make sure that the alpha channel is set to
    // full transparency
    pgl.clearColor(0, 0, 0, 0);
    pgl.clear(PGL.COLOR_BUFFER_BIT);
    if (scale) {
      // Rendering tex into "this", and scaling the source rectangle
      // to cover the entire destination region.
      pgl.drawTexture(
          tex.glTarget,
          tex.glName,
          tex.glWidth,
          tex.glHeight,
          tempFbo.width,
          tempFbo.height,
          x,
          y,
          w,
          h,
          0,
          0,
          width,
          height);

    } else {
      // Rendering tex into "this" but without scaling so the contents
      // of the source texture fall in the corresponding texels of the
      // destination.
      pgl.drawTexture(
          tex.glTarget,
          tex.glName,
          tex.glWidth,
          tex.glHeight,
          tempFbo.width,
          tempFbo.height,
          x,
          y,
          w,
          h,
          x,
          y,
          w,
          h);
    }
    PGraphicsOpenGL.popFramebuffer();

    updateTexels(x, y, w, h);
  }
示例#24
0
 /**
  * Preview frame from the camera
  *
  * @param data Frame
  * @param camera Camera
  */
 public void onPreviewFrame(byte[] data, Camera camera) {
   if (!started) {
     return;
   }
   frameBuffer.setData(data);
 };