Menu

Rendering

g-dollar

Several classes participate in the rendering process, beyond the GLSurfaceView and RenderService.

Rendering resources are obtained in the RequireResourceLoader.load() method, via the ResourceLoader interface.

Scene

This class is the top-level drawable component. It contains the list of GOs that participate in the Scene.

Scenes are activated via the Install Pipeline and managed by the RenderService.

Transitions

Transition effects like cross-fade are also Scenes that take other Scenes and perform the implemented visual effect.

DrawableGameObject

This class ties everything together:

  • acquire rendering resources in load().
  • use the acquired resources to draw in render().

Rendering consists of:

  • set current Shader via RenderContext (use program, set scene-level uniforms and non-vertex attributes).
  • set model transform via RenderContext (set MVP matrix uniform).
  • set current Material via Shader (set model-level uniforms and attributes).
  • render the Geometry (set vertex attributes and issue drawing primitives e.g. glDrawElements).

Shader

This class represents the Open GL shader program, a matching set of vertex and pixel shader linked together, and their associated variables (attribute/uniform). Both Geometry and Material interact with shaders, to set the variables needed for rendering.

Each shader "program" is identified by a string key-value. Several shaders are pre-configured by AGE:

  • basic: vertex data, uniform color.
  • cpv: vertex data, per-vertex color.
  • tex: vertex/texture data, texture-mapped.
  • textex: vertex/texture data, texture-mapped 2-texture mix.
  • pvl: vertex/normal/color data, per-vertex lighting model.
  • ppl: vertex/normal/color data, per-pixel lighting model.

Additional shader programs can be registered. Shader programs are compiled and linked on the first request for that key.

Variable Names

In order to fit everything together, AGE pre-defines the most-common shader program variable names, and these must be used in your own shaders to work with the default implementation.

If you have variables not in the default set, create matching Material implementations to configure them.

Matching Components

The shader chosen must agree with both the Gemoetry and Material implementations chosen:

  • a material without per-vertex color is not appropriate with the "cpv" shader.
  • a model without texture coordinates is not appropriate with the "tex" shader.
  • a model without vertex normals would not be appropriate with "lpv/lpp" shader.

Failure to match components results in the shader's variables not setting correctly, with incorrect rendering the result.

Texture

This class represents an Open GL texture, created from a bitmap. Be advised that the Y-axis of bitmaps in Android is inverted compared to GL texture coordinates!

The purpose of this class is to generate the Open GL primitives to enable and set up texture units, and to set the corresponding shader variables.

Geometry

This abstract class is the base for model geometry, and the render() method is the interface to the RenderService.

The purpose of this class is to set up vertex attributes, and generate the Open GL primitives for drawing, e.g glDrawElements().

Geometry must be initialized during the Install Pipeline, and DrawableGameObject delegates appropriately.

IndexedVertexGeometry

This abstract class is for geometry defined by a list of vertex/normal/texture coordinates, and a vertex index list (suitable for glDrawElements). Each vertex attribute is stored in a separate array.

InterleavedVertexGeometry

This abstract class is for geometry defined by a list of vertex/normal/color/texture coordinates (suitable for glDrawArrays). All vertex attributes are stored in one array.

Material

This abstract class interfaces between the Shader variables and the color information for a model. Each material is configured to work with a specific shader programs.

A model using InterleavedVertexGeometry may not require a Material; color information (if present) gets set up by that class instead.

SolidColorMaterial

This material interfaces with the basic shader program, and provides a single color value.

PerVertexMaterial

This material interfaces with the cpv shader program, and provides per-vertex color values.

TextureMaterial

This material interfaces with the tex shader program, and provides texture mapping.


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.