Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
SkMesh Class Reference

#include <SkMesh.h>

Classes

class  IndexBuffer
 
struct  Result
 
class  VertexBuffer
 

Public Types

enum class  Mode { kTriangles , kTriangleStrip }
 
using ChildPtr = SkRuntimeEffect::ChildPtr
 

Public Member Functions

 SkMesh ()
 
 ~SkMesh ()
 
 SkMesh (const SkMesh &)
 
 SkMesh (SkMesh &&)
 
SkMeshoperator= (const SkMesh &)
 
SkMeshoperator= (SkMesh &&)
 
sk_sp< SkMeshSpecificationrefSpec () const
 
SkMeshSpecificationspec () const
 
Mode mode () const
 
sk_sp< VertexBufferrefVertexBuffer () const
 
VertexBuffervertexBuffer () const
 
size_t vertexOffset () const
 
size_t vertexCount () const
 
sk_sp< IndexBufferrefIndexBuffer () const
 
IndexBufferindexBuffer () const
 
size_t indexOffset () const
 
size_t indexCount () const
 
sk_sp< const SkDatarefUniforms () const
 
const SkDatauniforms () const
 
SkSpan< const ChildPtrchildren () const
 
SkRect bounds () const
 
bool isValid () const
 

Static Public Member Functions

static Result Make (sk_sp< SkMeshSpecification >, Mode, sk_sp< VertexBuffer >, size_t vertexCount, size_t vertexOffset, sk_sp< const SkData > uniforms, SkSpan< ChildPtr > children, const SkRect &bounds)
 
static Result MakeIndexed (sk_sp< SkMeshSpecification >, Mode, sk_sp< VertexBuffer >, size_t vertexCount, size_t vertexOffset, sk_sp< IndexBuffer >, size_t indexCount, size_t indexOffset, sk_sp< const SkData > uniforms, SkSpan< ChildPtr > children, const SkRect &bounds)
 

Detailed Description

A vertex buffer, a topology, optionally an index buffer, and a compatible SkMeshSpecification.

The data in the vertex buffer is expected to contain the attributes described by the spec for vertexCount vertices, beginning at vertexOffset. vertexOffset must be aligned to the SkMeshSpecification's vertex stride. The size of the buffer must be at least vertexOffset + spec->stride()*vertexCount (even if vertex attributes contains pad at the end of the stride). If the specified bounds do not contain all the points output by the spec's vertex program when applied to the vertices in the custom mesh, then the result is undefined.

MakeIndexed may be used to create an indexed mesh. indexCount indices are read from the index buffer at the specified offset, which must be aligned to 2. The indices are always unsigned 16-bit integers. The index count must be at least 3.

If Make() is used, the implicit index sequence is 0, 1, 2, 3, ... and vertexCount must be at least 3.

Both Make() and MakeIndexed() take a SkData with the uniform values. See SkMeshSpecification::uniformSize() and SkMeshSpecification::uniforms() for sizing and packing uniforms into the SkData.

Definition at line 263 of file SkMesh.h.

Member Typedef Documentation

◆ ChildPtr

Definition at line 312 of file SkMesh.h.

Member Enumeration Documentation

◆ Mode

enum class SkMesh::Mode
strong
Enumerator
kTriangles 
kTriangleStrip 

Definition at line 308 of file SkMesh.h.

@ kTriangles
The vertices are taken 3 at a time to form a triangle.

Constructor & Destructor Documentation

◆ SkMesh() [1/3]

SkMesh::SkMesh ( )
default

◆ ~SkMesh()

SkMesh::~SkMesh ( )
default

◆ SkMesh() [2/3]

SkMesh::SkMesh ( const SkMesh )
default

◆ SkMesh() [3/3]

SkMesh::SkMesh ( SkMesh &&  )
default

Member Function Documentation

◆ bounds()

SkRect SkMesh::bounds ( ) const
inline

Definition at line 369 of file SkMesh.h.

369{ return fBounds; }

◆ children()

SkSpan< const ChildPtr > SkMesh::children ( ) const
inline

Definition at line 367 of file SkMesh.h.

367{ return SkSpan(fChildren); }
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >

◆ indexBuffer()

IndexBuffer * SkMesh::indexBuffer ( ) const
inline

Definition at line 359 of file SkMesh.h.

359{ return fIB.get(); }

◆ indexCount()

size_t SkMesh::indexCount ( ) const
inline

Definition at line 362 of file SkMesh.h.

362{ return fICount; }

◆ indexOffset()

size_t SkMesh::indexOffset ( ) const
inline

Definition at line 361 of file SkMesh.h.

361{ return fIOffset; }

◆ isValid()

bool SkMesh::isValid ( ) const

Definition at line 753 of file SkMesh.cpp.

753 {
754 bool valid = SkToBool(fSpec);
755 SkASSERT(valid == std::get<0>(this->validate()));
756 return valid;
757}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80

◆ Make()

SkMesh::Result SkMesh::Make ( sk_sp< SkMeshSpecification spec,
Mode  mode,
sk_sp< VertexBuffer vb,
size_t  vertexCount,
size_t  vertexOffset,
sk_sp< const SkData uniforms,
SkSpan< ChildPtr children,
const SkRect bounds 
)
static

Creates a non-indexed SkMesh. The returned SkMesh can be tested for validity using SkMesh::isValid(). An invalid mesh simply fails to draws if passed to SkCanvas::drawMesh(). If the mesh is invalid the returned string give contain the reason for the failure (e.g. the vertex buffer was null or uniform data too small).

Definition at line 694 of file SkMesh.cpp.

701 {
702 SkMesh mesh;
703 mesh.fSpec = std::move(spec);
704 mesh.fMode = mode;
705 mesh.fVB = std::move(vb);
706 mesh.fUniforms = std::move(uniforms);
707 mesh.fChildren.push_back_n(children.size(), children.data());
708 mesh.fVCount = vertexCount;
709 mesh.fVOffset = vertexOffset;
710 mesh.fBounds = bounds;
711 auto [valid, msg] = mesh.validate();
712 if (!valid) {
713 mesh = {};
714 }
715 return {std::move(mesh), std::move(msg)};
716}
Definition: SkMesh.h:263
SkSpan< const ChildPtr > children() const
Definition: SkMesh.h:367
size_t vertexCount() const
Definition: SkMesh.h:356
size_t vertexOffset() const
Definition: SkMesh.h:355
Mode mode() const
Definition: SkMesh.h:350
SkRect bounds() const
Definition: SkMesh.h:369
const SkData * uniforms() const
Definition: SkMesh.h:365
SkMeshSpecification * spec() const
Definition: SkMesh.h:348
SkMesh mesh
Definition: SkRecords.h:345

◆ MakeIndexed()

SkMesh::Result SkMesh::MakeIndexed ( sk_sp< SkMeshSpecification spec,
Mode  mode,
sk_sp< VertexBuffer vb,
size_t  vertexCount,
size_t  vertexOffset,
sk_sp< IndexBuffer ib,
size_t  indexCount,
size_t  indexOffset,
sk_sp< const SkData uniforms,
SkSpan< ChildPtr children,
const SkRect bounds 
)
static

Creates an indexed SkMesh. The returned SkMesh can be tested for validity using SkMesh::isValid(). A invalid mesh simply fails to draw if passed to SkCanvas::drawMesh(). If the mesh is invalid the returned string give contain the reason for the failure (e.g. the index buffer was null or uniform data too small).

Definition at line 718 of file SkMesh.cpp.

728 {
729 if (!ib) {
730 // We check this before calling validate to disambiguate from a non-indexed mesh where
731 // IB is expected to be null.
732 return {{}, SkString{"An index buffer is required."}};
733 }
734 SkMesh mesh;
735 mesh.fSpec = std::move(spec);
736 mesh.fMode = mode;
737 mesh.fVB = std::move(vb);
738 mesh.fVCount = vertexCount;
739 mesh.fVOffset = vertexOffset;
740 mesh.fIB = std::move(ib);
741 mesh.fUniforms = std::move(uniforms);
742 mesh.fChildren.push_back_n(children.size(), children.data());
743 mesh.fICount = indexCount;
744 mesh.fIOffset = indexOffset;
745 mesh.fBounds = bounds;
746 auto [valid, msg] = mesh.validate();
747 if (!valid) {
748 mesh = {};
749 }
750 return {std::move(mesh), std::move(msg)};
751}
size_t indexCount() const
Definition: SkMesh.h:362
size_t indexOffset() const
Definition: SkMesh.h:361

◆ mode()

Mode SkMesh::mode ( ) const
inline

Definition at line 350 of file SkMesh.h.

350{ return fMode; }

◆ operator=() [1/2]

SkMesh & SkMesh::operator= ( const SkMesh )
default

◆ operator=() [2/2]

SkMesh & SkMesh::operator= ( SkMesh &&  )
default

◆ refIndexBuffer()

sk_sp< IndexBuffer > SkMesh::refIndexBuffer ( ) const
inline

Definition at line 358 of file SkMesh.h.

358{ return fIB; }

◆ refSpec()

sk_sp< SkMeshSpecification > SkMesh::refSpec ( ) const
inline

Definition at line 347 of file SkMesh.h.

347{ return fSpec; }

◆ refUniforms()

sk_sp< const SkData > SkMesh::refUniforms ( ) const
inline

Definition at line 364 of file SkMesh.h.

364{ return fUniforms; }

◆ refVertexBuffer()

sk_sp< VertexBuffer > SkMesh::refVertexBuffer ( ) const
inline

Definition at line 352 of file SkMesh.h.

352{ return fVB; }

◆ spec()

SkMeshSpecification * SkMesh::spec ( ) const
inline

Definition at line 348 of file SkMesh.h.

348{ return fSpec.get(); }
T * get() const
Definition: SkRefCnt.h:303

◆ uniforms()

const SkData * SkMesh::uniforms ( ) const
inline

Definition at line 365 of file SkMesh.h.

365{ return fUniforms.get(); }

◆ vertexBuffer()

VertexBuffer * SkMesh::vertexBuffer ( ) const
inline

Definition at line 353 of file SkMesh.h.

353{ return fVB.get(); }

◆ vertexCount()

size_t SkMesh::vertexCount ( ) const
inline

Definition at line 356 of file SkMesh.h.

356{ return fVCount; }

◆ vertexOffset()

size_t SkMesh::vertexOffset ( ) const
inline

Definition at line 355 of file SkMesh.h.

355{ return fVOffset; }

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