MeshSpecification


public class MeshSpecification
extends Object

java.lang.Object
   ↳ android.graphics.MeshSpecification


Class responsible for holding specifications for Mesh creations. This class generates a MeshSpecification via the MeshSpecification#make(Attribute[], int, Varying[], String, String) method, where multiple parameters to set up the mesh are supplied, including attributes, vertex stride, Varying, and vertex/fragment shaders. There are also additional methods to provide an optional ColorSpace as well as an alpha type. For example a vertex shader that leverages a Varying may look like the following:

        Varyings main(const Attributes attributes) {
             Varyings varyings;
             varyings.position = attributes.position;
             return varyings;
        }
 
The corresponding fragment shader that may consume the varying look like the following:
      float2 main(const Varyings varyings, out float4 color) {
             color = vec4(1.0, 0.0, 0.0, 1.0);
             return varyings.position;
      }
 
The color returned from this fragment shader is blended with the other parameters that are configured on the Paint object (ex. Paint#setBlendMode(BlendMode) used to draw the mesh. The position returned in the fragment shader can be consumed by any following fragment shaders in the shader chain. See https://developer.android.com/develop/ui/views/graphics/agsl for more information regarding Android Graphics Shader Language. Note that there are several limitations on various mesh specifications: 1. The max amount of attributes allowed is 8. 2. The offset alignment length is 4 bytes. 2. The max stride length is 1024. 3. The max amount of varyings is 6. These should be kept in mind when generating a mesh specification, as exceeding them will lead to errors.

Summary

Nested classes

class MeshSpecification.Attribute

Data class to represent a single attribute in a shader. 

class MeshSpecification.Varying

Data class to represent a single varying variable. 

Constants

int ALPHA_TYPE_OPAQUE

Pixel is opaque.

int ALPHA_TYPE_PREMULTIPLIED

Pixel components are premultiplied by alpha.

int ALPHA_TYPE_UNKNOWN

uninitialized.

int ALPHA_TYPE_UNPREMULTIPLIED

Pixel components are independent of alpha.

int TYPE_FLOAT

Represents one float.

int TYPE_FLOAT2

Represents two floats.

int TYPE_FLOAT3

Represents three floats.

int TYPE_FLOAT4

Represents four floats.

int TYPE_UBYTE4

Represents four bytes.

Public methods

static MeshSpecification make(Attribute[] attributes, int vertexStride, Varying[] varyings, String vertexShader, String fragmentShader, ColorSpace colorSpace, int alphaType)

Creates a MeshSpecification object.

static MeshSpecification make(Attribute[] attributes, int vertexStride, Varying[] varyings, String vertexShader, String fragmentShader, ColorSpace colorSpace)

Creates a MeshSpecification object.

static MeshSpecification make(Attribute[] attributes, int vertexStride, Varying[] varyings, String vertexShader, String fragmentShader)

Creates a MeshSpecification object for use within Mesh.

Inherited methods

Constants

ALPHA_TYPE_OPAQUE

Added in API level 34
public static final int ALPHA_TYPE_OPAQUE

Pixel is opaque.

Constant Value: 1 (0x00000001)

ALPHA_TYPE_PREMULTIPLIED

Added in API level 34
public static final int ALPHA_TYPE_PREMULTIPLIED

Pixel components are premultiplied by alpha.

Constant Value: 2 (0x00000002)

ALPHA_TYPE_UNKNOWN

Added in API level 34
public static final int ALPHA_TYPE_UNKNOWN

uninitialized.

Constant Value: 0 (0x00000000)

ALPHA_TYPE_UNPREMULTIPLIED

Added in API level 34
public static final int ALPHA_TYPE_UNPREMULTIPLIED

Pixel components are independent of alpha.

Constant Value: 3 (0x00000003)

TYPE_FLOAT

Added in API level 34
public static final int TYPE_FLOAT

Represents one float. Its equivalent shader type is float.

Constant Value: 0 (0x00000000)

TYPE_FLOAT2

Added in API level 34
public static final int TYPE_FLOAT2

Represents two floats. Its equivalent shader type is float2.

Constant Value: 1 (0x00000001)

TYPE_FLOAT3

Added in API level 34
public static final int TYPE_FLOAT3

Represents three floats. Its equivalent shader type is float3.

Constant Value: 2 (0x00000002)

TYPE_FLOAT4

Added in API level 34
public static final int TYPE_FLOAT4

Represents four floats. Its equivalent shader type is float4.

Constant Value: 3 (0x00000003)

TYPE_UBYTE4

Added in API level 34
public static final int TYPE_UBYTE4

Represents four bytes. Its equivalent shader type is half4.

Constant Value: 4 (0x00000004)

Public methods

make

Added in API level 34
public static MeshSpecification make (Attribute[] attributes, 
                int vertexStride, 
                Varying[] varyings, 
                String vertexShader, 
                String fragmentShader, 
                ColorSpace colorSpace, 
                int alphaType)

Creates a MeshSpecification object.

Parameters
attributes Attribute: list of attributes represented by Attribute. Can hold a max of 8. This value cannot be null.

vertexStride int: length of vertex stride in bytes. This should be the size of a single vertex' attributes. Max of 1024 is accepted. Value is between 1 and 1024 inclusive

varyings Varying: List of varyings represented by Varying. Can hold a max of 6. Note that `position` is provided by default, does not need to be provided in the list, and does not count towards the 6 varyings allowed. This value cannot be null.

vertexShader String: vertex shader to be supplied to the mesh. Ensure that the position varying is set within the shader to get proper results. See MeshSpecification for an example vertex shader implementation This value cannot be null.

fragmentShader String: fragment shader to be supplied to the mesh. See MeshSpecification for an example fragment shader implementation This value cannot be null.

colorSpace ColorSpace: ColorSpace to tell what color space to work in. This value cannot be null.

alphaType int: Describes how to interpret the alpha component for a pixel. Must be one of MeshSpecification#ALPHA_TYPE_UNKNOWN, MeshSpecification#ALPHA_TYPE_OPAQUE, MeshSpecification#ALPHA_TYPE_PREMULTIPLIED, or MeshSpecification#ALPHA_TYPE_UNPREMULTIPLIED Value is ALPHA_TYPE_UNKNOWN, ALPHA_TYPE_OPAQUE, ALPHA_TYPE_PREMULTIPLIED, or ALPHA_TYPE_UNPREMULTIPLIED

Returns
MeshSpecification MeshSpecification object for use when creating Mesh This value cannot be null.

make

Added in API level 34
public static MeshSpecification make (Attribute[] attributes, 
                int vertexStride, 
                Varying[] varyings, 
                String vertexShader, 
                String fragmentShader, 
                ColorSpace colorSpace)

Creates a MeshSpecification object. This uses a default alphaType of ALPHA_TYPE_PREMULTIPLIED.

Parameters
attributes Attribute: list of attributes represented by Attribute. Can hold a max of 8. This value cannot be null.

vertexStride int: length of vertex stride in bytes. This should be the size of a single vertex' attributes. Max of 1024 is accepted. Value is between 1 and 1024 inclusive

varyings Varying: List of varyings represented by Varying. Can hold a max of 6. Note that `position` is provided by default, does not need to be provided in the list, and does not count towards the 6 varyings allowed. This value cannot be null.

vertexShader String: vertex shader to be supplied to the mesh. Ensure that the position varying is set within the shader to get proper results. See MeshSpecification for an example vertex shader implementation This value cannot be null.

fragmentShader String: fragment shader to be supplied to the mesh. See MeshSpecification for an example fragment shader implementation This value cannot be null.

colorSpace ColorSpace: ColorSpace to tell what color space to work in. This value cannot be null.

Returns
MeshSpecification MeshSpecification object for use when creating Mesh This value cannot be null.

make

Added in API level 34
public static MeshSpecification make (Attribute[] attributes, 
                int vertexStride, 
                Varying[] varyings, 
                String vertexShader, 
                String fragmentShader)

Creates a MeshSpecification object for use within Mesh. This uses a default color space of ColorSpace.Named#SRGB and alphaType of ALPHA_TYPE_PREMULTIPLIED.

Parameters
attributes Attribute: list of attributes represented by Attribute. Can hold a max of 8. This value cannot be null.

vertexStride int: length of vertex stride in bytes. This should be the size of a single vertex' attributes. Max of 1024 is accepted. Value is between 1 and 1024 inclusive

varyings Varying: List of varyings represented by Varying. Can hold a max of 6. Note that `position` is provided by default, does not need to be provided in the list, and does not count towards the 6 varyings allowed. This value cannot be null.

vertexShader String: vertex shader to be supplied to the mesh. Ensure that the position varying is set within the shader to get proper results. See MeshSpecification for an example vertex shader implementation This value cannot be null.

fragmentShader String: fragment shader to be supplied to the mesh. See MeshSpecification for an example fragment shader implementation This value cannot be null.

Returns
MeshSpecification MeshSpecification object for use when creating Mesh This value cannot be null.