RuntimeShader
public
class
RuntimeShader
extends Shader
| java.lang.Object | ||
| ↳ | android.graphics.Shader | |
| ↳ | android.graphics.RuntimeShader | |
A RuntimeShader calculates a per-pixel color based on the output of a user defined
Android Graphics Shading Language (AGSL) function.
Android Graphics Shading Language
The AGSL syntax is very similar to OpenGL ES Shading Language, but there are some important
differences that are highlighted here. Most of these differences are summed up in one basic fact:
With GPU shading languages, you are programming a stage of the GPU pipeline. With AGSL, you
are programming a stage of the Canvas or RenderNode drawing pipeline.
In particular, a GLSL fragment shader controls the entire behavior of the GPU between the rasterizer and the blending hardware. That shader does all of the work to compute a color, and the color it generates is exactly what is fed to the blending stage of the pipeline.
In contrast, AGSL functions exist as part of a larger pipeline. When you issue a
Canvas drawing operation, Android (generally) assembles a single GPU fragment shader to
do all of the required work. This shader typically includes several pieces. For example, it might
include:
- Evaluating whether a pixel falls inside or outside of the shape being drawn (or on the border, where it might apply antialiasing).
- Evaluating whether a pixel falls inside or outside of the clipping region (again, with possible antialiasing logic for border pixels).
- Logic for the
Shader,ColorFilter, andBlendModeon thePaint. - Color space conversion code, as part of Android's color management.
A RuntimeShader, like other Shader types, effectively contributes a function
to the GPU's fragment shader.
AGSL Shader Execution
Just like a GLSL shader, an AGSL shader begins execution in a main function. Unlike GLSL, the function receives as an input par