Class AWTComponentRenderer

java.lang.Object
com.jme3.system.AWTComponentRenderer

public class AWTComponentRenderer extends Object

This class enables to update graphics of an AWT component with the result of JMonkey 3D rendering.

This class is based on the JavaFX original code provided by Alexander Brui (see JME3-FX)

  • Field Details

    • RUNNING_STATE

      protected static final int RUNNING_STATE
      The constant RUNNING_STATE.
      See Also:
    • WAITING_STATE

      protected static final int WAITING_STATE
      The constant WAITING_STATE.
      See Also:
    • DISPOSING_STATE

      protected static final int DISPOSING_STATE
      The constant DISPOSING_STATE.
      See Also:
    • DISPOSED_STATE

      protected static final int DISPOSED_STATE
      The constant DISPOSED_STATE.
      See Also:
    • frameState

      protected final AtomicInteger frameState
      The Frame state.
    • imageState

      protected final AtomicInteger imageState
      The Image state.
    • frameBuffer

      protected final FrameBuffer frameBuffer
      The Frame buffer.
    • pixelWriter

      protected final Graphics pixelWriter
      The Pixel writer.
    • frameByteBuffer

      protected final ByteBuffer frameByteBuffer
      The Frame byte buffer.
    • transferMode

      protected final AWTFrameProcessor.TransferMode transferMode
      The transfer mode.
    • byteBuffer

      protected final byte[] byteBuffer
      The byte buffer.
    • imageByteBuffer

      protected final int[] imageByteBuffer
      The image byte buffer.
    • prevImageByteBuffer

      protected final byte[] prevImageByteBuffer
      The prev image byte buffer.
    • frameCount

      protected int frameCount
      How many frames need to write else.
  • Constructor Details

    • AWTComponentRenderer

      public AWTComponentRenderer(Component destination, int width, int height, AWTFrameProcessor.TransferMode transferMode)
      Create a new component renderer attached to the given destination. The graphics of the destination are updated with the JMonkeyEngine rendering result.
      Parameters:
      destination - the AWT component to use as target of the JMonkeyEngine rendering.
      width - the width of the component in pixels.
      height - the height of the component in pixels.
      transferMode - the rendering mode that can be AWTFrameProcessor.TransferMode.ALWAYS if the component has to be rendered at each update or AWTFrameProcessor.TransferMode.ON_CHANGES if the component has to be rendered only when changes are occurring.
    • AWTComponentRenderer

      public AWTComponentRenderer(Component destination, AWTFrameProcessor.TransferMode transferMode, FrameBuffer frameBuffer, int width, int height)
      Create a new component renderer attached to the given destination. The graphics of the destination are updated with the JMonkeyEngine rendering result.
      Parameters:
      destination - the AWT component to use as target of the JMonkeyEngine rendering.
      transferMode - the rendering mode that can be AWTFrameProcessor.TransferMode.ALWAYS if the component has to be rendered at each update or AWTFrameProcessor.TransferMode.ON_CHANGES if the component has to be rendered only when changes are occurring.
      frameBuffer - the JMonkey frame buffer to use (if null is passed, a new default frame buffer is created)
      width - the width of the component in pixels.
      height - the height of the component in pixels.
  • Method Details

    • init

      public void init(Renderer renderer, boolean main)
      Initialize the component renderer.
      Parameters:
      renderer - the JMonkey renderer to use.
      main - true if the attached frame buffer is the main one or false otherwise.
    • getGraphics

      protected Graphics getGraphics(Component destination)
      Get the graphics context of the given component.
      Parameters:
      destination - the AWT component used for rendering (not null)
      Returns:
      the graphics context of the given component.
    • getWidth

      public int getWidth()
      Get the width of the area to render.
      Returns:
      the width of the area to render.
      See Also:
    • getHeight

      public int getHeight()
      Get the height of the area to render.
      Returns:
      the height of the area to render.
      See Also:
    • copyFrameBufferToImage

      public void copyFrameBufferToImage(RenderManager renderManager)
      Copy the JMonkey frame buffer that has been rendered by the JMonkey engine and schedule the rendering of the component.
      Parameters:
      renderManager - the JMonkey render manager.
    • writeFrame

      protected void writeFrame()
      Write the current rendered frame to the component graphics context.
    • getImageByteBuffer

      protected int[] getImageByteBuffer()
      Get the image byte buffer.
      Returns:
      the image byte buffer.
    • getPrevImageByteBuffer

      protected byte[] getPrevImageByteBuffer()
      Get the previous image byte buffer.
      Returns:
      the previous image byte buffer.
    • dispose

      public void dispose()
      Dispose this renderer. The underlying frame buffer is also disposed.