Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public abstract class GraphicsDevice
- Object
- 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
Inherited methods
Constructor details
GraphicsDevice
public GraphicsDevice()Method details
getCapabilities
public abstract GpuCapabilities getCapabilities()createVertexBuffer
public VertexBuffer createVertexBuffer(VertexFormat format, int vertexCount)Parameters
formatVertexFormat- the interleaved vertex layout
vertexCountint- the number of vertices
Returns
createIndexBuffer
public IndexBuffer createIndexBuffer(int indexCount)Parameters
indexCountint- the number of indices
Returns
createTexture
public abstract Texture createTexture(Image image)Parameters
imageImage- the source image
Returns
createTexture
public abstract Texture createTexture(int width, int height, int[] argb)Parameters
widthint- the texture width in pixels
heightint- the texture height in pixels
argbint[]width * heightpacked ARGB pixels in row major order
Returns
clear
public abstract void clear(int argbColor, boolean color, boolean depth)Parameters
argbColorint- the packed ARGB clear color
colorboolean- true to clear the color buffer
depthboolean- true to clear the depth buffer
setViewport
public abstract void setViewport(int x, int y, int width, int height)setCamera
public void setCamera(Camera camera)Sets the active camera supplying the view and projection matrices used by subsequent draws.
Setting the camera starts a new frame as far as shadows go: a shadow map
rendered before it is not used again, so set the camera first and then
run beginShadowPass.
Parameters
cameraCamera- the camera
isShadowMapCurrent
protected final boolean isShadowMapCurrent()shadowMapRendered
protected final void shadowMapRendered()getCamera
public Camera getCamera()setLight
public void setLight(Light light)Parameters
lightLight- the light
getLight
public Light getLight()setEnvironment
public void setEnvironment(Environment environment)Parameters
environmentEnvironment- the environment; null restores the default, which changes nothing
getEnvironment
public Environment getEnvironment()beginShadowPass
public boolean beginShadowPass(Light light)Starts rendering the light’s shadow map. Until endShadowPass, draw
writes only depth as seen from the light, and skips materials that do
not cast shadows. Draws after endShadowPass that receive shadows
sample the map.
The default implementation supports no shadows and returns false; the caller then skips the pass and draws as usual.
Render the shadow pass before beginPostProcess, never inside it: both
passes return to the target that was active when they began, so a
shadow pass started offscreen would hand the post process its own
image to draw into.
Parameters
lightLight- the light whose shadows to render; it must have shadows on
Returns
endShadowPass
public void endShadowPass()beginShadowPass, and restores the
viewport and target that were active before it.beginPostProcess
public boolean beginPostProcess(PostProcess effects, int width, int height)Redirects drawing into an offscreen image so endPostProcess can apply
effects to it on its way to the screen.
The default implementation supports no post processing and returns false; the caller then draws straight to the screen.
Parameters
effectsPostProcess- the effects to apply
widthint- the width of the frame in pixels
heightint- the height of the frame in pixels
Returns
endPostProcess
public void endPostProcess(float timeSeconds)beginPostProcess and draws the result
to the screen. Drawing goes to the screen again afterwards.Parameters
timeSecondsfloat- a running clock, which animates the film grain
draw
public abstract void draw(Mesh mesh, Material material, float[] modelMatrix)camera.getViewProjection() * modelMatrix, binds the generated
shader for the material, applies the material render state and issues the
draw call.Parameters
meshMesh- the geometry to draw
materialMaterial- how to shade the geometry
modelMatrixfloat[]- the 16 element column-major model transform, or null for the identity
dispose
public abstract void dispose(VertexBuffer buffer)dispose
public abstract void dispose(IndexBuffer buffer)dispose
public abstract void dispose(Texture texture)