aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkVertState.h
blob: ab794521b08d6bb5658a9aad2881e4b9eb26aedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkVertState_DEFINED
#define SkVertState_DEFINED

#include "SkCanvas.h"

/** \struct VertState
    This is a helper for drawVertices(). It is used to iterate over the triangles
    that are to be rendered based on an SkCanvas::VertexMode and (optionally) an
    index array. It does not copy the index array and the client must ensure it
    remains valid for the lifetime of the VertState object.
*/

struct VertState {
    int f0, f1, f2;

    /**
     *  Construct a VertState from a vertex count, index array, and index count.
     *  If the vertices are unindexed pass nullptr for indices.
     */
    VertState(int vCount, const uint16_t indices[], int indexCount)
            : fIndices(indices) {
        fCurrIndex = 0;
        if (indices) {
            fCount = indexCount;
        } else {
            fCount = vCount;
        }
    }

    typedef bool (*Proc)(VertState*);

    /**
     *  Choose an appropriate function to traverse the vertices.
     *  @param mode    Specifies the SkCanvas::VertexMode.
     */
    Proc chooseProc(SkCanvas::VertexMode mode);

private:
    int             fCount;
    int             fCurrIndex;
    const uint16_t* fIndices;

    static bool Triangles(VertState*);
    static bool TrianglesX(VertState*);
    static bool TriangleStrip(VertState*);
    static bool TriangleStripX(VertState*);
    static bool TriangleFan(VertState*);
    static bool TriangleFanX(VertState*);
};

#endif