Skia
2D Graphics Library
SkMeshSpecification Class Reference

A specification for custom meshes. More...

#include <SkMesh.h>

Inheritance diagram for SkMeshSpecification:

Classes

struct  Attribute
 
struct  Result
 
struct  Varying
 

Public Types

using Uniform = SkRuntimeEffect::Uniform
 
using Child = SkRuntimeEffect::Child
 

Public Member Functions

 ~SkMeshSpecification ()
 
SkSpan< const Attributeattributes () const
 
size_t uniformSize () const
 Combined size of all 'uniform' variables. More...
 
SkSpan< const Uniformuniforms () const
 Provides info about individual uniforms including the offset into an SkData where each uniform value should be placed. More...
 
SkSpan< const Childchildren () const
 Provides basic info about individual children: names, indices and runtime effect type. More...
 
const ChildfindChild (std::string_view name) const
 Returns a pointer to the named child's description, or nullptr if not found. More...
 
const UniformfindUniform (std::string_view name) const
 Returns a pointer to the named uniform variable's description, or nullptr if not found. More...
 
const AttributefindAttribute (std::string_view name) const
 Returns a pointer to the named attribute, or nullptr if not found. More...
 
const VaryingfindVarying (std::string_view name) const
 Returns a pointer to the named varying, or nullptr if not found. More...
 
size_t stride () const
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Static Public Member Functions

static Result Make (SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs)
 If successful the return is a specification and an empty error string. More...
 
static Result Make (SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs, sk_sp< SkColorSpace > cs)
 
static Result Make (SkSpan< const Attribute > attributes, size_t vertexStride, SkSpan< const Varying > varyings, const SkString &vs, const SkString &fs, sk_sp< SkColorSpace > cs, SkAlphaType at)
 

Static Public Attributes

static constexpr size_t kMaxStride = 1024
 These values are enforced when creating a specification. More...
 
static constexpr size_t kMaxAttributes = 8
 
static constexpr size_t kStrideAlignment = 4
 
static constexpr size_t kOffsetAlignment = 4
 
static constexpr size_t kMaxVaryings = 6
 

Friends

struct SkMeshSpecificationPriv
 

Detailed Description

A specification for custom meshes.

Specifies the vertex buffer attributes and stride, the vertex program that produces a user-defined set of varyings, and a fragment program that ingests the interpolated varyings and produces local coordinates for shading and optionally a color.

The varyings must include a float2 named "position". If the passed varyings does not contain such a varying then one is implicitly added to the final specification and the SkSL Varyings struct described below. It is an error to have a varying named "position" that has a type other than float2.

The provided attributes and varyings are used to create Attributes and Varyings structs in SkSL that are used by the shaders. Each attribute from the Attribute span becomes a member of the SkSL Attributes struct and likewise for the varyings.

The signature of the vertex program must be: Varyings main(const Attributes).

The signature of the fragment program must be either: float2 main(const Varyings) or float2 main(const Varyings, out (half4|float4) color)

where the return value is the local coordinates that will be used to access SkShader. If the color variant is used, the returned color will be blended with SkPaint's SkShader (or SkPaint color in absence of a SkShader) using the SkBlender passed to SkCanvas drawMesh(). To use interpolated local space positions as the shader coordinates, equivalent to how SkPaths are shaded, return the position field from the Varying struct as the coordinates.

The vertex and fragment programs may both contain uniforms. Uniforms with the same name are assumed to be shared between stages. It is an error to specify uniforms in the vertex and fragment program with the same name but different types, dimensionality, or layouts.

Member Typedef Documentation

◆ Child

◆ Uniform

Constructor & Destructor Documentation

◆ ~SkMeshSpecification()

SkMeshSpecification::~SkMeshSpecification ( )

Member Function Documentation

◆ attributes()

SkSpan<const Attribute> SkMeshSpecification::attributes ( ) const
inline

◆ children()

SkSpan<const Child> SkMeshSpecification::children ( ) const
inline

Provides basic info about individual children: names, indices and runtime effect type.

◆ deref()

void SkNVRefCnt< SkMeshSpecification >::deref ( ) const
inlineinherited

◆ findAttribute()

const Attribute* SkMeshSpecification::findAttribute ( std::string_view  name) const

Returns a pointer to the named attribute, or nullptr if not found.

◆ findChild()

const Child* SkMeshSpecification::findChild ( std::string_view  name) const

Returns a pointer to the named child's description, or nullptr if not found.

◆ findUniform()

const Uniform* SkMeshSpecification::findUniform ( std::string_view  name) const

Returns a pointer to the named uniform variable's description, or nullptr if not found.

◆ findVarying()

const Varying* SkMeshSpecification::findVarying ( std::string_view  name) const

Returns a pointer to the named varying, or nullptr if not found.

◆ Make() [1/3]

static Result SkMeshSpecification::Make ( SkSpan< const Attribute attributes,
size_t  vertexStride,
SkSpan< const Varying varyings,
const SkString vs,
const SkString fs 
)
static

If successful the return is a specification and an empty error string.

Otherwise, it is a null specification a non-empty error string.

Parameters
attributesThe vertex attributes that will be consumed by 'vs'. Attributes need not be tightly packed but attribute offsets must be aligned to kOffsetAlignment and offset + size may not be greater than 'vertexStride'. At least one attribute is required.
vertexStrideThe offset between successive attribute values. This must be aligned to kStrideAlignment.
varyingsThe varyings that will be written by 'vs' and read by 'fs'. This may be empty.
vsThe vertex shader code that computes a vertex position and the varyings from the attributes.
fsThe fragment code that computes a local coordinate and optionally a color from the varyings. The local coordinate is used to sample SkShader.
csThe colorspace of the color produced by 'fs'. Ignored if 'fs's main() function does not have a color out param.
atThe alpha type of the color produced by 'fs'. Ignored if 'fs's main() function does not have a color out param. Cannot be kUnknown.

◆ Make() [2/3]

static Result SkMeshSpecification::Make ( SkSpan< const Attribute attributes,
size_t  vertexStride,
SkSpan< const Varying varyings,
const SkString vs,
const SkString fs,
sk_sp< SkColorSpace cs 
)
static

◆ Make() [3/3]

static Result SkMeshSpecification::Make ( SkSpan< const Attribute attributes,
size_t  vertexStride,
SkSpan< const Varying varyings,
const SkString vs,
const SkString fs,
sk_sp< SkColorSpace cs,
SkAlphaType  at 
)
static

◆ ref()

void SkNVRefCnt< SkMeshSpecification >::ref ( ) const
inlineinherited

◆ refCntGreaterThan()

bool SkNVRefCnt< SkMeshSpecification >::refCntGreaterThan ( int32_t  threadIsolatedTestCnt) const
inlineinherited

◆ stride()

size_t SkMeshSpecification::stride ( ) const
inline

◆ uniforms()

SkSpan<const Uniform> SkMeshSpecification::uniforms ( ) const
inline

Provides info about individual uniforms including the offset into an SkData where each uniform value should be placed.

◆ uniformSize()

size_t SkMeshSpecification::uniformSize ( ) const

Combined size of all 'uniform' variables.

When creating a SkMesh with this specification provide an SkData of this size, containing values for all of those variables. Use uniforms() to get the offset of each uniform within the SkData.

◆ unique()

bool SkNVRefCnt< SkMeshSpecification >::unique ( ) const
inlineinherited

◆ unref()

void SkNVRefCnt< SkMeshSpecification >::unref ( ) const
inlineinherited

Friends And Related Function Documentation

◆ SkMeshSpecificationPriv

friend struct SkMeshSpecificationPriv
friend

Member Data Documentation

◆ kMaxAttributes

constexpr size_t SkMeshSpecification::kMaxAttributes = 8
staticconstexpr

◆ kMaxStride

constexpr size_t SkMeshSpecification::kMaxStride = 1024
staticconstexpr

These values are enforced when creating a specification.

◆ kMaxVaryings

constexpr size_t SkMeshSpecification::kMaxVaryings = 6
staticconstexpr

◆ kOffsetAlignment

constexpr size_t SkMeshSpecification::kOffsetAlignment = 4
staticconstexpr

◆ kStrideAlignment

constexpr size_t SkMeshSpecification::kStrideAlignment = 4
staticconstexpr

The documentation for this class was generated from the following file: