diff options
Diffstat (limited to 'include/core/SkVertices.h')
-rw-r--r-- | include/core/SkVertices.h | 82 |
1 files changed, 72 insertions, 10 deletions
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h index d5e97e12d5..6c4fb390d0 100644 --- a/include/core/SkVertices.h +++ b/include/core/SkVertices.h @@ -19,6 +19,20 @@ */ class SK_API SkVertices : public SkNVRefCnt<SkVertices> { public: + // BoneIndices indicates which (of a maximum of 4 bones) a given vertex will interpolate + // between. To indicate that a slot is not used, the convention is to assign the bone index + // to 0. + struct BoneIndices { + uint32_t indices[4]; + }; + + // BoneWeights stores the interpolation weight for each of the (maximum of 4) bones a given + // vertex interpolates between. To indicate that a slot is not used, the weight for that + // slot should be 0. + struct BoneWeights { + float weights[4]; + }; + enum VertexMode { kTriangles_VertexMode, kTriangleStrip_VertexMode, @@ -28,21 +42,60 @@ public: }; /** - * Create a vertices by copying the specified arrays. texs and colors may be nullptr, - * and indices is ignored if indexCount == 0. + * Create a vertices by copying the specified arrays. texs, colors, boneIndices, and + * boneWeights may be nullptr, and indices is ignored if indexCount == 0. + * + * boneIndices and boneWeights must either both be nullptr or both point to valid data. + * If specified, they must both contain 'vertexCount' entries. */ static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], + const BoneIndices boneIndices[], + const BoneWeights boneWeights[], int indexCount, const uint16_t indices[]); static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], + const SkColor colors[], + const BoneIndices boneIndices[], + const BoneWeights boneWeights[]) { + return MakeCopy(mode, + vertexCount, + positions, + texs, + colors, + boneIndices, + boneWeights, + 0, + nullptr); + } + + static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, + const SkPoint positions[], + const SkPoint texs[], + const SkColor colors[], + int indexCount, + const uint16_t indices[]) { + return MakeCopy(mode, + vertexCount, + positions, + texs, + colors, + nullptr, + nullptr, + indexCount, + indices); + } + + static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, + const SkPoint positions[], + const SkPoint texs[], const SkColor colors[]) { - return MakeCopy(mode, vertexCount, positions, texs, colors, 0, nullptr); + return MakeCopy(mode, vertexCount, positions, texs, colors, nullptr, nullptr); } struct Sizes; @@ -50,6 +103,7 @@ public: enum BuilderFlags { kHasTexCoords_BuilderFlag = 1 << 0, kHasColors_BuilderFlag = 1 << 1, + kHasBones_BuilderFlag = 1 << 2, }; class Builder { public: @@ -61,9 +115,11 @@ public: int vertexCount() const; int indexCount() const; SkPoint* positions(); - SkPoint* texCoords(); // returns null if there are no texCoords - SkColor* colors(); // returns null if there are no colors - uint16_t* indices(); // returns null if there are no indices + SkPoint* texCoords(); // returns null if there are no texCoords + SkColor* colors(); // returns null if there are no colors + BoneIndices* boneIndices(); // returns null if there are no bone indices + BoneWeights* boneWeights(); // returns null if there are no bone weights + uint16_t* indices(); // returns null if there are no indices // Detach the built vertices object. After the first call, this will always return null. sk_sp<SkVertices> detach(); @@ -88,6 +144,7 @@ public: bool hasColors() const { return SkToBool(this->colors()); } bool hasTexCoords() const { return SkToBool(this->texCoords()); } + bool hasBones() const { return SkToBool(this->boneIndices()); } bool hasIndices() const { return SkToBool(this->indices()); } int vertexCount() const { return fVertexCnt; } @@ -95,6 +152,9 @@ public: const SkPoint* texCoords() const { return fTexs; } const SkColor* colors() const { return fColors; } + const BoneIndices* boneIndices() const { return fBoneIndices; } + const BoneWeights* boneWeights() const { return fBoneWeights; } + int indexCount() const { return fIndexCnt; } const uint16_t* indices() const { return fIndices; } @@ -128,10 +188,12 @@ private: uint32_t fUniqueID; // these point inside our allocation, so none of these can be "freed" - SkPoint* fPositions; - SkPoint* fTexs; - SkColor* fColors; - uint16_t* fIndices; + SkPoint* fPositions; + SkPoint* fTexs; + SkColor* fColors; + BoneIndices* fBoneIndices; + BoneWeights* fBoneWeights; + uint16_t* fIndices; SkRect fBounds; // computed to be the union of the fPositions[] int fVertexCnt; |