Class SwapChain


  • public class SwapChain
    extends java.lang.Object
    A SwapChain represents an Operating System's native renderable surface.

    Typically it's a native window or a view. Because a SwapChain is initialized from a native object, it is given to filament as an Object, which must be of the proper type for each platform filament is running on.

    SwapChain swapChain = engine.createSwapChain(nativeWindow);

    The nativeWindow parameter above must be of type:

    Platform nativeWindow type
    Android Surface

    Examples

    Android

    A Surface can be retrieved from a SurfaceView or SurfaceHolder easily using SurfaceHolder.getSurface() and/or SurfaceView.getHolder().

    To use a Textureview as a SwapChain, it is necessary to first get its SurfaceTexture, for instance using SurfaceTextureListener and then create a Surface:

      // using a TextureView.SurfaceTextureListener:
      public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
          mSurface = new Surface(surfaceTexture);
          // mSurface can now be used with Engine.createSwapChain()
      }
     
    See Also:
    Engine
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long CONFIG_DEFAULT  
      static long CONFIG_ENABLE_XCB
      Indicates that the native X11 window is an XCB window rather than an XLIB window.
      static long CONFIG_READABLE
      This flag indicates that the SwapChain may be used as a source surface for reading back render results.
      static long CONFIG_TRANSPARENT
      This flag indicates that the SwapChain must be allocated with an alpha-channel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getNativeObject()  
      java.lang.Object getNativeWindow()  
      void setFrameCompletedCallback​(java.lang.Object handler, java.lang.Runnable callback)
      FrameCompletedCallback is a callback function that notifies an application when a frame's contents have completed rendering on the GPU.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getNativeWindow

        public java.lang.Object getNativeWindow()
        Returns:
        the native Object this SwapChain was created from or null for a headless SwapChain.
      • setFrameCompletedCallback

        public void setFrameCompletedCallback​(@NonNull
                                              java.lang.Object handler,
                                              @NonNull
                                              java.lang.Runnable callback)
        FrameCompletedCallback is a callback function that notifies an application when a frame's contents have completed rendering on the GPU.

        Use setFrameCompletedCallback to set a callback on an individual SwapChain. Each time a frame completes GPU rendering, the callback will be called.

        The FrameCompletedCallback is guaranteed to be called on the main Filament thread.

        Warning: Only Filament's Metal backend supports frame callbacks. Other backends ignore the callback (which will never be called) and proceed normally.

        Parameters:
        handler - A Executor.
        callback - The Runnable callback to invoke.
      • getNativeObject

        public long getNativeObject()