Class RenderView

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class RenderView extends Container

A Codename One component that hosts a hardware accelerated 3D rendering surface and drives an application supplied Renderer. It behaves like any other component: add it to a Form or Container, give it a layout constraint, and it participates in scrolling, transitions and z-ordering. Internally it wraps a platform specific GPU peer (a GLSurfaceView on Android, a WebGL canvas on the browser, an MTKView on iOS, a desktop GL canvas in the simulator) using the same peer integration as BrowserComponent.

When the running platform has no GPU backend, isSupported() returns false and the view shows a placeholder instead of crashing. Always create the view the same way; only the result of isSupported() differs per platform.

Example
RenderView view = new RenderView(new Renderer() {
    Camera camera = new Camera();
    Mesh cube;
    Material material;

    public void onInit(GraphicsDevice device) {
        cube = Primitives.cube(device, 1f);
        material = new Material(Material.Type.PHONG).setColor(0xff3366ff);
    }

    public void onResize(GraphicsDevice device, int w, int h) {
        camera.setAspect((float) w / h);
        device.setViewport(0, 0, w, h);
    }

    public void onFrame(GraphicsDevice device) {
        device.clear(0xff101018, true, true);
        device.setCamera(camera);
        device.draw(cube, material, null);
    }

    public void onDispose(GraphicsDevice device) { }
});
view.setContinuous(true);
form.add(BorderLayout.CENTER, view);
  • Constructor Details

    • RenderView

      public RenderView(Renderer renderer)

      Creates a render view driven by the supplied renderer.

      Parameters
      • renderer: the callback that initializes and draws the scene
  • Method Details

    • getRenderer

      public Renderer getRenderer()
      Returns the renderer driving this view.
    • isSupported

      public boolean isSupported()
      Returns true if the current platform provides a 3D backend. Equivalent to Display.getInstance().isGpuSupported().
    • isContinuous

      public boolean isContinuous()
      Returns true if the view continuously renders frames.
    • setContinuous

      public RenderView setContinuous(boolean continuous)

      Controls whether the view renders continuously (an animation loop) or only when requestRender() is called (on demand). On demand is the default and conserves battery for static scenes.

      Parameters
      • continuous: true to render every frame
      Returns

      this view for chaining

    • requestRender

      public void requestRender()
      Requests that a single frame be rendered. Has no effect when the view is in continuous mode or when 3D is unsupported.
    • getPeer

      public PeerComponent getPeer()
      Returns the underlying native peer once created, or null before the view has been added to the UI or on unsupported platforms.
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component