Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclear(int argbColor, boolean color, boolean depth) Clears the framebuffer.createIndexBuffer(int indexCount) Allocates an index buffer.abstract TexturecreateTexture(int width, int height, int[] argb) Creates a GPU texture from raw ARGB pixel data.abstract TexturecreateTexture(Image image) Creates a GPU texture from a Codename One image.createVertexBuffer(VertexFormat format, int vertexCount) Allocates a vertex buffer.abstract voiddispose(IndexBuffer buffer) Releases the GPU resources backing an index buffer.abstract voidReleases the GPU resources backing a texture.abstract voiddispose(VertexBuffer buffer) Releases the GPU resources backing a vertex buffer.abstract voidDraws a mesh with the supplied material and model matrix.Returns the active camera, or null if none was set.abstract GpuCapabilitiesReturns the capabilities and limits of the underlying GPU.getLight()Returns the active light.voidSets the active camera supplying the view and projection matrices used by subsequent draws.voidSets the active directional light used by lit materials.abstract voidsetViewport(int x, int y, int width, int height) Sets the viewport rectangle in pixels.
-
Constructor Details
-
GraphicsDevice
public GraphicsDevice()
-
-
Method Details
-
getCapabilities
Returns the capabilities and limits of the underlying GPU. -
createVertexBuffer
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: the interleaved vertex layout -
vertexCount: the number of vertices
Returns
a new vertex buffer tracked by this device
-
-
createIndexBuffer
Allocates an index buffer.
Parameters
indexCount: the number of indices
Returns
a new index buffer tracked by this device
-
createTexture
-
createTexture
Creates a GPU texture from raw ARGB pixel data.
Parameters
-
width: the texture width in pixels -
height: the texture height in pixels -
argb:width * heightpacked 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: the packed ARGB clear color -
color: true to clear the color buffer -
depth: 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
Sets the active camera supplying the view and projection matrices used by subsequent draws.
Parameters
camera: the camera
-
getCamera
Returns the active camera, or null if none was set. -
setLight
Sets the active directional light used by lit materials.
Parameters
light: the light
-
getLight
Returns the active light. -
draw
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: the geometry to draw -
material: how to shade the geometry -
modelMatrix: the 16 element column-major model transform, or null for the identity
-
-
dispose
Releases the GPU resources backing a vertex buffer. -
dispose
Releases the GPU resources backing an index buffer. -
dispose
Releases the GPU resources backing a texture.
-