public abstract class GraphicsDevice

  1. Object
  2. GraphicsDevice

The low level command surface of the 3D API, bound to a single RenderView and its GPU context. A concrete subclass is provided by each platform backend (OpenGL ES on Android, WebGL on the browser, Metal on iOS, desktop GL on the simulator). Applications obtain the device from the Renderer callbacks and never construct it directly.

The device owns shader generation and caching: when draw is called it looks at the Material and the mesh VertexFormat, generates (once) the matching platform shader, uploads any dirty buffers and issues the draw call.

Constructors

public GraphicsDevice()

Methods

public abstract GpuCapabilities getCapabilities()Returns the capabilities and limits of the underlying GPU.
public VertexBuffer createVertexBuffer(VertexFormat format, int vertexCount)Allocates a vertex buffer.
public IndexBuffer createIndexBuffer(int indexCount)Allocates an index buffer.
public abstract Texture createTexture(Image image)Creates a GPU texture from a Codename One image.
public abstract Texture createTexture(int width, int height, int[] argb)Creates a GPU texture from raw ARGB pixel data.
public abstract void clear(int argbColor, boolean color, boolean depth)Clears the framebuffer.
public abstract void setViewport(int x, int y, int width, int height)Sets the viewport rectangle in pixels.
public void setCamera(Camera camera)Sets the active camera supplying the view and projection matrices used by subsequent draws.
public Camera getCamera()Returns the active camera, or null if none was set.
public void setLight(Light light)Sets the active directional light used by lit materials.
public Light getLight()Returns the active light.
public abstract void draw(Mesh mesh, Material material, float[] modelMatrix)Draws a mesh with the supplied material and model matrix.
public abstract void dispose(VertexBuffer buffer)Releases the GPU resources backing a vertex buffer.
public abstract void dispose(IndexBuffer buffer)Releases the GPU resources backing an index buffer.
public abstract void dispose(Texture texture)Releases the GPU resources backing a texture.

Inherited methods

Constructor details

GraphicsDevice

public GraphicsDevice()

Method details

getCapabilities

public abstract GpuCapabilities getCapabilities()
Returns the capabilities and limits of the underlying GPU.

createVertexBuffer

public VertexBuffer createVertexBuffer(VertexFormat format, int vertexCount)
Allocates a vertex buffer. The backing array is SIMD aligned so it can be uploaded to the GPU without an intermediate copy on ParparVM.

Parameters

format VertexFormat
the interleaved vertex layout
vertexCount int
the number of vertices

Returns

a new vertex buffer tracked by this device

createIndexBuffer

public IndexBuffer createIndexBuffer(int indexCount)
Allocates an index buffer.

Parameters

indexCount int
the number of indices

Returns

a new index buffer tracked by this device

createTexture

public abstract Texture createTexture(Image image)
Creates a GPU texture from a Codename One image.

Parameters

image Image
the source image

Returns

a new texture

createTexture

public abstract Texture createTexture(int width, int height, int[] argb)
Creates a GPU texture from raw ARGB pixel data.

Parameters

width int
the texture width in pixels
height int
the texture height in pixels
argb int[]
width * height packed ARGB pixels in row major order

Returns

a new texture

clear

public abstract void clear(int argbColor, boolean color, boolean depth)
Clears the framebuffer.

Parameters

argbColor int
the packed ARGB clear color
color boolean
true to clear the color buffer
depth boolean
true to clear the depth buffer

setViewport

public abstract void setViewport(int x, int y, int width, int height)
Sets the viewport rectangle in pixels.

setCamera

public void setCamera(Camera camera)
Sets the active camera supplying the view and projection matrices used by subsequent draws.

Parameters

camera Camera
the camera

getCamera

public Camera getCamera()
Returns the active camera, or null if none was set.

setLight

public void setLight(Light light)
Sets the active directional light used by lit materials.

Parameters

light Light
the light

getLight

public Light getLight()
Returns the active light.

draw

public abstract void draw(Mesh mesh, Material material, float[] modelMatrix)
Draws a mesh with the supplied material and model matrix. The device composes camera.getViewProjection() * modelMatrix, binds the generated shader for the material, applies the material render state and issues the draw call.

Parameters

mesh Mesh
the geometry to draw
material Material
how to shade the geometry
modelMatrix float[]
the 16 element column-major model transform, or null for the identity

dispose

public abstract void dispose(VertexBuffer buffer)
Releases the GPU resources backing a vertex buffer.

dispose

public abstract void dispose(IndexBuffer buffer)
Releases the GPU resources backing an index buffer.

dispose

public abstract void dispose(Texture texture)
Releases the GPU resources backing a texture.