Class AndroidGraphics

java.lang.Object
arc.Graphics
arc.backend.android.AndroidGraphics
All Implemented Interfaces:
android.opengl.GLSurfaceView.Renderer, Disposable

public class AndroidGraphics extends Graphics implements android.opengl.GLSurfaceView.Renderer
An implementation of Graphics for Android.
  • Field Details

    • config

      protected final AndroidApplicationConfiguration config
      When AndroidApplication.onPause() call pause() they MUST enforce continuous rendering. If not, onDrawFrame(GL10) will not be called in the GLThread while pause() is sleeping in the Android UI Thread which will cause the pause() variable never be set to false. As a result, the pause() method will kill the current process to avoid ANR
    • lastFrameTime

      protected long lastFrameTime
    • deltaTime

      protected float deltaTime
    • frameStart

      protected long frameStart
    • frameId

      protected long frameId
    • frames

      protected int frames
    • fps

      protected int fps
  • Constructor Details

  • Method Details

    • createGLSurfaceView

      protected GLSurfaceView20 createGLSurfaceView(AndroidApplication application, ResolutionStrategy resolutionStrategy)
    • getEglConfigChooser

      protected android.opengl.GLSurfaceView.EGLConfigChooser getEglConfigChooser()
    • updatePpi

      protected void updatePpi()
    • checkGL20

      protected boolean checkGL20()
    • getGL20

      public GL20 getGL20()
      Specified by:
      getGL20 in class Graphics
      Returns:
      the GL20 instance
    • setGL20

      public void setGL20(GL20 gl20)
      Set the GL20 instance
      Specified by:
      setGL20 in class Graphics
    • getGL30

      public GL30 getGL30()
      Specified by:
      getGL30 in class Graphics
      Returns:
      the GL30 instance or null if not supported
    • setGL30

      public void setGL30(GL30 gl30)
      Set the GL30 instance
      Specified by:
      setGL30 in class Graphics
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in class Graphics
      Returns:
      the height of the client area in logical pixels
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in class Graphics
      Returns:
      the width of the client area in logical pixels.
    • getBackBufferWidth

      public int getBackBufferWidth()
      Specified by:
      getBackBufferWidth in class Graphics
      Returns:
      the width of the framebuffer in physical pixels
    • getBackBufferHeight

      public int getBackBufferHeight()
      Specified by:
      getBackBufferHeight in class Graphics
      Returns:
      the height of the framebuffer in physical pixels
    • setupGL

      protected void setupGL(javax.microedition.khronos.opengles.GL10 gl)
      This instantiates the GL20 and GL30 instances.
    • onSurfaceChanged

      public void onSurfaceChanged(javax.microedition.khronos.opengles.GL10 gl, int width, int height)
      Specified by:
      onSurfaceChanged in interface android.opengl.GLSurfaceView.Renderer
    • onSurfaceCreated

      public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, javax.microedition.khronos.egl.EGLConfig config)
      Specified by:
      onSurfaceCreated in interface android.opengl.GLSurfaceView.Renderer
    • logConfig

      protected void logConfig(javax.microedition.khronos.egl.EGLConfig config)
    • onDrawFrame

      public void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl)
      Specified by:
      onDrawFrame in interface android.opengl.GLSurfaceView.Renderer
    • getFrameId

      public long getFrameId()
      Description copied from class: Graphics
      Returns the id of the current frame. The general contract of this method is that the id is incremented only when the application is in the running state right before calling the ApplicationListener.update() method. Also, the id of the first frame is 0; the id of subsequent frames is guaranteed to take increasing values for 263-1 rendering cycles.
      Specified by:
      getFrameId in class Graphics
      Returns:
      the id of the current frame
    • getDeltaTime

      public float getDeltaTime()
      Specified by:
      getDeltaTime in class Graphics
      Returns:
      the time span between the current frame and the last frame in seconds. Might be smoothed over n frames.
    • getGLVersion

      public GLVersion getGLVersion()
      Specified by:
      getGLVersion in class Graphics
      Returns:
      the GLVersion of this Graphics instance
    • getFramesPerSecond

      public int getFramesPerSecond()
      Specified by:
      getFramesPerSecond in class Graphics
      Returns:
      the average number of frames per second
    • getView

      public android.view.View getView()
    • getPpiX

      public float getPpiX()
      Specified by:
      getPpiX in class Graphics
      Returns:
      the pixels per inch on the x-axis
    • getPpiY

      public float getPpiY()
      Specified by:
      getPpiY in class Graphics
      Returns:
      the pixels per inch on the y-axis
    • getPpcX

      public float getPpcX()
      Specified by:
      getPpcX in class Graphics
      Returns:
      the pixels per centimeter on the x-axis
    • getPpcY

      public float getPpcY()
      Specified by:
      getPpcY in class Graphics
      Returns:
      the pixels per centimeter on the y-axis.
    • getDensity

      public float getDensity()
      Description copied from class: Graphics
      This is a scaling factor for the Density Independent Pixel unit, following the same conventions as android.util.DisplayMetrics#density, where one DIP is one pixel on an approximately 160 dpi screen. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.
      Specified by:
      getDensity in class Graphics
      Returns:
      the logical density of the Display.
    • setWindowedMode

      public boolean setWindowedMode(int width, int height)
      Description copied from class: Graphics
      Sets the window to windowed mode.
      Specified by:
      setWindowedMode in class Graphics
      Parameters:
      width - the width in pixels
      height - the height in pixels
      Returns:
      whether the operation succeeded
    • setTitle

      public void setTitle(String title)
      Description copied from class: Graphics
      Sets the title of the window. Ignored on Android.
      Specified by:
      setTitle in class Graphics
      Parameters:
      title - the title.
    • setBorderless

      public void setBorderless(boolean undecorated)
      Description copied from class: Graphics
      Sets the window decoration as enabled or disabled. On Android, this will enable/disable the menu bar.

      Note that immediate behavior of this method may vary depending on the implementation. It may be necessary for the window to be recreated in order for the changes to take effect. Consult the documentation for the backend in use for more information.

      Supported on all desktop backends and on Android (to disable the menu bar).

      Specified by:
      setBorderless in class Graphics
      Parameters:
      undecorated - true if the window border or status bar should be hidden. false otherwise.
    • setResizable

      public void setResizable(boolean resizable)
      Description copied from class: Graphics
      Sets whether or not the window should be resizable. Ignored on Android.

      Note that immediate behavior of this method may vary depending on the implementation. It may be necessary for the window to be recreated in order for the changes to take effect. Consult the documentation for the backend in use for more information.

      Supported on all desktop backends.

      Specified by:
      setResizable in class Graphics
    • getBufferFormat

      public Graphics.BufferFormat getBufferFormat()
      Specified by:
      getBufferFormat in class Graphics
      Returns:
      the format of the color, depth and stencil buffer in a Graphics.BufferFormat instance
    • setVSync

      public void setVSync(boolean vsync)
      Description copied from class: Graphics
      Enable/Disable vsynching. This is a best-effort attempt which might not work on all platforms.
      Specified by:
      setVSync in class Graphics
      Parameters:
      vsync - vsync enabled or not.
    • supportsExtension

      public boolean supportsExtension(String extension)
      Specified by:
      supportsExtension in class Graphics
      Parameters:
      extension - the extension name
      Returns:
      whether the extension is supported
    • isContinuousRendering

      public boolean isContinuousRendering()
      Specified by:
      isContinuousRendering in class Graphics
      Returns:
      whether rendering is continuous.
    • setContinuousRendering

      public void setContinuousRendering(boolean isContinuous)
      Description copied from class: Graphics
      Sets whether to render continuously. In case rendering is performed non-continuously, the following events will trigger a redraw:
      • A call to Graphics.requestRendering()
      • Input events from the touch screen/mouse or keyboard
      • A Runnable is posted to the rendering thread via Application.post(Runnable). In the case of a multi-window app, all windows will request rendering if a runnable is posted to the application. To avoid this, post a runnable to the window instead.

      Life-cycle events will also be reported as usual, see ApplicationListener. This method can be called from any thread.

      Specified by:
      setContinuousRendering in class Graphics
      Parameters:
      isContinuous - whether the rendering should be continuous or not.
    • requestRendering

      public void requestRendering()
      Description copied from class: Graphics
      Requests a new frame to be rendered if the rendering mode is non-continuous. This method can be called from any thread.
      Specified by:
      requestRendering in class Graphics
    • isFullscreen

      public boolean isFullscreen()
      Description copied from class: Graphics
      Whether the app is fullscreen or not
      Specified by:
      isFullscreen in class Graphics
    • newCursor

      public Graphics.Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot)
      Description copied from class: Graphics
      Create a new cursor represented by the Pixmap. The Pixmap must be in RGBA8888 format, width & height must be powers-of-two greater than zero (not necessarily equal) and of a certain minimum size (32x32 is a safe bet), and alpha transparency must be single-bit (i.e., 0x00 or 0xFF only). This function returns a Cursor object that can be set as the system cursor by calling Graphics.setCursor(Cursor) .
      Specified by:
      newCursor in class Graphics
      Parameters:
      pixmap - the mouse cursor image as a Pixmap
      xHotspot - the x location of the hotspot pixel within the cursor image (origin top-left corner)
      yHotspot - the y location of the hotspot pixel within the cursor image (origin top-left corner)
      Returns:
      a cursor object that can be used by calling Graphics.setCursor(Cursor) or null if not supported
    • setCursor

      public void setCursor(Graphics.Cursor cursor)
      Description copied from class: Graphics
      Only viable on desktop and web. Browsers that support cursor:url() and support the png format (the pixmap is converted to a data-url of type image/png) should also support custom cursors. Will set the mouse cursor image to the image represented by the Graphics.Cursor. It is recommended to call this function in the main render thread, and maximum one time per frame. Internal use only!
      Specified by:
      setCursor in class Graphics
      Parameters:
      cursor - the mouse cursor as a Graphics.Cursor
    • setSystemCursor

      public void setSystemCursor(Graphics.Cursor.SystemCursor systemCursor)
      Description copied from class: Graphics
      Sets one of the predefined Graphics.Cursor.SystemCursors. Internal use only!
      Specified by:
      setSystemCursor in class Graphics