Line data Source code
1 : /*
2 : * Copyright 2014 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #include "SkVertState.h"
9 :
10 0 : bool VertState::Triangles(VertState* state) {
11 0 : int index = state->fCurrIndex;
12 0 : if (index + 3 > state->fCount) {
13 0 : return false;
14 : }
15 0 : state->f0 = index + 0;
16 0 : state->f1 = index + 1;
17 0 : state->f2 = index + 2;
18 0 : state->fCurrIndex = index + 3;
19 0 : return true;
20 : }
21 :
22 0 : bool VertState::TrianglesX(VertState* state) {
23 0 : const uint16_t* indices = state->fIndices;
24 0 : int index = state->fCurrIndex;
25 0 : if (index + 3 > state->fCount) {
26 0 : return false;
27 : }
28 0 : state->f0 = indices[index + 0];
29 0 : state->f1 = indices[index + 1];
30 0 : state->f2 = indices[index + 2];
31 0 : state->fCurrIndex = index + 3;
32 0 : return true;
33 : }
34 :
35 0 : bool VertState::TriangleStrip(VertState* state) {
36 0 : int index = state->fCurrIndex;
37 0 : if (index + 3 > state->fCount) {
38 0 : return false;
39 : }
40 0 : state->f2 = index + 2;
41 0 : if (index & 1) {
42 0 : state->f0 = index + 1;
43 0 : state->f1 = index + 0;
44 : } else {
45 0 : state->f0 = index + 0;
46 0 : state->f1 = index + 1;
47 : }
48 0 : state->fCurrIndex = index + 1;
49 0 : return true;
50 : }
51 :
52 0 : bool VertState::TriangleStripX(VertState* state) {
53 0 : const uint16_t* indices = state->fIndices;
54 0 : int index = state->fCurrIndex;
55 0 : if (index + 3 > state->fCount) {
56 0 : return false;
57 : }
58 0 : state->f2 = indices[index + 2];
59 0 : if (index & 1) {
60 0 : state->f0 = indices[index + 1];
61 0 : state->f1 = indices[index + 0];
62 : } else {
63 0 : state->f0 = indices[index + 0];
64 0 : state->f1 = indices[index + 1];
65 : }
66 0 : state->fCurrIndex = index + 1;
67 0 : return true;
68 : }
69 :
70 0 : bool VertState::TriangleFan(VertState* state) {
71 0 : int index = state->fCurrIndex;
72 0 : if (index + 3 > state->fCount) {
73 0 : return false;
74 : }
75 0 : state->f0 = 0;
76 0 : state->f1 = index + 1;
77 0 : state->f2 = index + 2;
78 0 : state->fCurrIndex = index + 1;
79 0 : return true;
80 : }
81 :
82 0 : bool VertState::TriangleFanX(VertState* state) {
83 0 : const uint16_t* indices = state->fIndices;
84 0 : int index = state->fCurrIndex;
85 0 : if (index + 3 > state->fCount) {
86 0 : return false;
87 : }
88 0 : state->f0 = indices[0];
89 0 : state->f1 = indices[index + 1];
90 0 : state->f2 = indices[index + 2];
91 0 : state->fCurrIndex = index + 1;
92 0 : return true;
93 : }
94 :
95 0 : VertState::Proc VertState::chooseProc(SkVertices::VertexMode mode) {
96 0 : switch (mode) {
97 : case SkVertices::kTriangles_VertexMode:
98 0 : return fIndices ? TrianglesX : Triangles;
99 : case SkVertices::kTriangleStrip_VertexMode:
100 0 : return fIndices ? TriangleStripX : TriangleStrip;
101 : case SkVertices::kTriangleFan_VertexMode:
102 0 : return fIndices ? TriangleFanX : TriangleFan;
103 : default:
104 0 : return nullptr;
105 : }
106 : }
|