Java Code Examples for com.jme3.renderer.Renderer#readFrameBufferWithFormat()

The following examples show how to use com.jme3.renderer.Renderer#readFrameBufferWithFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoRecorderAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addImage(Renderer renderer, FrameBuffer out) {
    if (freeItems == null) {
        return;
    }
    try {
        final WorkItem item = freeItems.take();
        usedItems.add(item);
        item.buffer.clear();
        renderer.readFrameBufferWithFormat(out, item.buffer, Image.Format.BGRA8);
        executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Screenshots.convertScreenShot(item.buffer, item.image);
                item.data = writer.writeImageToBytes(item.image, quality);
                while (usedItems.peek() != item) {
                    Thread.sleep(1);
                }
                writer.addImage(item.data);
                usedItems.poll();
                freeItems.add(item);
                return null;
            }
        });
    } catch (InterruptedException ex) {
        Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 2
Source File: VideoRecorderAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addImage(Renderer renderer, FrameBuffer out) {
    if (freeItems == null) {
        return;
    }
    try {
        final WorkItem item = freeItems.take();
        usedItems.add(item);
        item.buffer.clear();
        renderer.readFrameBufferWithFormat(out, item.buffer, Image.Format.BGRA8);
        executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                if (fastMode) {
                    item.data = item.buffer.array();
                } else {
                    AndroidScreenshots.convertScreenShot(item.buffer, item.image);
                    item.data = writer.writeImageToBytes(item.image, quality);
                }
                while (usedItems.peek() != item) {
                    Thread.sleep(1);
                }
                writer.addImage(item.data);
                usedItems.poll();
                freeItems.add(item);
                return null;
            }
        });
    } catch (InterruptedException ex) {
        Logger.getLogger(VideoRecorderAppState.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 3
Source File: AWTComponentRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Copy the JMonkey frame buffer that has been rendered by the JMonkey engine and schedule the rendering of the component.
 * @param renderManager the JMonkey render manager.
 */
public void copyFrameBufferToImage(RenderManager renderManager) {

  while (!frameState.compareAndSet(WAITING_STATE, RUNNING_STATE)) {
    if (frameState.get() == DISPOSED_STATE) {
      return;
    }
  }

  // Convert screenshot.
  try {

    frameByteBuffer.clear();

    final Renderer renderer = renderManager.getRenderer();
    renderer.readFrameBufferWithFormat(frameBuffer, frameByteBuffer, Image.Format.RGBA8);

  } finally {
    if (!frameState.compareAndSet(RUNNING_STATE, WAITING_STATE)) {
      throw new RuntimeException("unknown problem with the frame state");
    }
  }

  synchronized (byteBuffer) {
    frameByteBuffer.get(byteBuffer);

    if (transferMode == TransferMode.ON_CHANGES) {

      final byte[] prevBuffer = getPrevImageByteBuffer();

      if (Arrays.equals(prevBuffer, byteBuffer)) {
        if (frameCount == 0) return;
      } else {
        frameCount = 2;
        System.arraycopy(byteBuffer, 0, prevBuffer, 0, byteBuffer.length);
      }

      frameByteBuffer.position(0);
      frameCount--;
    }
  }

  EventQueue.invokeLater(new Runnable() {

    @Override
    public void run() {
      writeFrame();
    }});
}