aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkVertices.h
diff options
context:
space:
mode:
authorGravatar Ruiqi Mao <ruiqimao@google.com>2018-06-29 14:32:21 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-29 19:34:28 +0000
commitf510149da8d32f60f08d0a809eb037496079af3c (patch)
tree13b3670a481f3bae652968165d04f9ca4890d9bf /include/core/SkVertices.h
parent38f118a2e7f986b06d69d0af41ec2d1af53dac39 (diff)
skeletal animation support added to API and software backend
SkCanvas::drawVertices now supports overloads that take an array of bone deformation matrices. SkVertices::MakeCopy and SkVertices::Builder now support two additional optional attributes, boneIndices and boneWeights. Bug: skia: Change-Id: I30a3b11691e7cdb13924907cc1401ff86d127aea Reviewed-on: https://skia-review.googlesource.com/137221 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Ruiqi Mao <ruiqimao@google.com>
Diffstat (limited to 'include/core/SkVertices.h')
-rw-r--r--include/core/SkVertices.h82
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;