MeshSpecification
open class MeshSpecification
kotlin.Any | |
↳ | 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; }
float2 main(const Varyings varyings, out float4 color) { color = vec4(1.0, 0.0, 0.0, 1.0); return varyings.position; }
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 | |
---|---|
open |
Data class to represent a single attribute in a shader. |
open |
Data class to represent a single varying variable. |
Constants | |
---|---|
static Int |
Pixel is opaque. |
static Int |
Pixel components are premultiplied by alpha. |
static Int |
uninitialized. |
static Int |
Pixel components are independent of alpha. |
static Int |
Represents one float. |
static Int |
Represents two floats. |
static Int |
Represents three floats. |
static Int |
Represents four floats. |
static Int |
Represents four bytes. |
Public methods | |
---|---|
open static MeshSpecification |
make(attributes: Array<MeshSpecification.Attribute!>, vertexStride: Int, varyings: Array<MeshSpecification.Varying!>, vertexShader: String, fragmentShader: String) Creates a |
open static MeshSpecification |
make(attributes: Array<MeshSpecification.Attribute!>, vertexStride: Int, varyings: Array<MeshSpecification.Varying!>, vertexShader: String, fragmentShader: String, colorSpace: ColorSpace) Creates a |
open static MeshSpecification |
make(attributes: Array<MeshSpecification.Attribute!>, vertexStride: Int, varyings: Array<MeshSpecification.Varying!>, vertexShader: String, fragmentShader: String, colorSpace: ColorSpace, alphaType: Int) Creates a |
Constants
ALPHA_TYPE_PREMULTIPLIED
static val ALPHA_TYPE_PREMULTIPLIED: Int
Pixel components are premultiplied by alpha.
Value: 2
ALPHA_TYPE_UNPREMULTIPLIED
static val ALPHA_TYPE_UNPREMULTIPLIED: Int
Pixel components are independent of alpha.
Value: 3
TYPE_FLOAT
static val TYPE_FLOAT: Int
Represents one float. Its equivalent shader type is float.
Value: 0
TYPE_FLOAT2
static val TYPE_FLOAT2: Int
Represents two floats. Its equivalent shader type is float2.
Value: 1
TYPE_FLOAT3
static val TYPE_FLOAT3: Int
Represents three floats. Its equivalent shader type is float3.
Value: 2
TYPE_FLOAT4
static val TYPE_FLOAT4: Int
Represents four floats. Its equivalent shader type is float4.
Value: 3
TYPE_UBYTE4
static val TYPE_UBYTE4: Int
Represents four bytes. Its equivalent shader type is half4.
Value: 4
Public methods
make
open static fun make(
attributes: Array<MeshSpecification.Attribute!>,
vertexStride: Int,
varyings: Array<MeshSpecification.Varying!>,
vertexShader: String,
fragmentShader: String
): MeshSpecification
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 |
Array<MeshSpecification.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 |
Array<MeshSpecification.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 . |
Return | |
---|---|
MeshSpecification |
MeshSpecification object for use when creating Mesh This value cannot be null . |
make
open static fun make(
attributes: Array<MeshSpecification.Attribute!>,
vertexStride: Int,
varyings: Array<MeshSpecification.Varying!>,
vertexShader: String,
fragmentShader: String,
colorSpace: ColorSpace
): MeshSpecification
Creates a MeshSpecification
object. This uses a default alphaType of ALPHA_TYPE_PREMULTIPLIED
.
Parameters | |
---|---|
attributes |
Array<MeshSpecification.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 |
Array<MeshSpecification.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 . |
Return | |
---|---|
MeshSpecification |
MeshSpecification object for use when creating Mesh This value cannot be null . |
make
open static fun make(
attributes: Array<MeshSpecification.Attribute!>,
vertexStride: Int,
varyings: Array<MeshSpecification.Varying!>,
vertexShader: String,
fragmentShader: String,
colorSpace: ColorSpace,
alphaType: Int
): MeshSpecification
Creates a MeshSpecification
object.
Parameters | |
---|---|
attributes |
Array<MeshSpecification.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 |
Array<MeshSpecification.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 android.graphics.MeshSpecification#ALPHA_TYPE_UNKNOWN , android.graphics.MeshSpecification#ALPHA_TYPE_OPAQUE , android.graphics.MeshSpecification#ALPHA_TYPE_PREMULTIPLIED , or android.graphics.MeshSpecification#ALPHA_TYPE_UNPREMULTIPLIED |
Return | |
---|---|
MeshSpecification |
MeshSpecification object for use when creating Mesh This value cannot be null . |