mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBlendMode.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkColorFilter.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkMatrix.h" |
| 14 | #include "include/core/SkPaint.h" |
| 15 | #include "include/core/SkPoint.h" |
| 16 | #include "include/core/SkRefCnt.h" |
| 17 | #include "include/core/SkScalar.h" |
| 18 | #include "include/core/SkShader.h" |
| 19 | #include "include/core/SkSize.h" |
| 20 | #include "include/core/SkString.h" |
| 21 | #include "include/core/SkTileMode.h" |
| 22 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "include/core/SkVertices.h" |
| 24 | #include "include/effects/SkGradientShader.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 25 | #include "include/effects/SkRuntimeEffect.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 26 | #include "include/private/SkTDArray.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "include/utils/SkRandom.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 28 | #include "src/core/SkVerticesPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/shaders/SkLocalMatrixShader.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 30 | #include "src/utils/SkPatchUtils.h" |
| 31 | #include "tools/Resources.h" |
Brian Osman | e41fa2d | 2020-03-20 15:45:49 -0400 | [diff] [blame] | 32 | #include "tools/ToolUtils.h" |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 33 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 34 | #include <initializer_list> |
| 35 | #include <utility> |
| 36 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 37 | static constexpr SkScalar kShaderSize = 40; |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 38 | static sk_sp<SkShader> make_shader1(SkScalar shaderScale) { |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 39 | const SkColor colors[] = { |
| 40 | SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, |
| 41 | SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, |
| 42 | }; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 43 | const SkPoint pts[] = {{kShaderSize / 4, 0}, {3 * kShaderSize / 4, kShaderSize}}; |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 44 | const SkMatrix localMatrix = SkMatrix::Scale(shaderScale, shaderScale); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 45 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 46 | sk_sp<SkShader> grad = SkGradientShader::MakeLinear(pts, colors, nullptr, |
| 47 | SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 48 | SkTileMode::kMirror, 0, |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 49 | &localMatrix); |
| 50 | // Throw in a couple of local matrix wrappers for good measure. |
| 51 | return shaderScale == 1 |
| 52 | ? grad |
| 53 | : sk_make_sp<SkLocalMatrixShader>( |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 54 | sk_make_sp<SkLocalMatrixShader>(std::move(grad), SkMatrix::Translate(-10, 0)), |
| 55 | SkMatrix::Translate(10, 0)); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 56 | } |
| 57 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 58 | static sk_sp<SkShader> make_shader2() { |
Mike Reed | c8bea7d | 2019-04-09 13:55:36 -0400 | [diff] [blame] | 59 | return SkShaders::Color(SK_ColorBLUE); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 60 | } |
| 61 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 62 | static sk_sp<SkColorFilter> make_color_filter() { |
Mike Reed | b286bc2 | 2019-04-08 16:23:20 -0400 | [diff] [blame] | 63 | return SkColorFilters::Blend(0xFFAABBCC, SkBlendMode::kDarken); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 66 | static constexpr SkScalar kMeshSize = 30; |
| 67 | |
| 68 | // start with the center of a 3x3 grid of vertices. |
| 69 | static constexpr uint16_t kMeshFan[] = { |
| 70 | 4, |
| 71 | 0, 1, 2, 5, 8, 7, 6, 3, 0 |
| 72 | }; |
| 73 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 74 | static const int kMeshIndexCnt = (int)SK_ARRAY_COUNT(kMeshFan); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 75 | static const int kMeshVertexCnt = 9; |
| 76 | |
| 77 | static void fill_mesh(SkPoint pts[kMeshVertexCnt], SkPoint texs[kMeshVertexCnt], |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 78 | SkColor colors[kMeshVertexCnt], SkScalar shaderScale) { |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 79 | pts[0].set(0, 0); |
| 80 | pts[1].set(kMeshSize / 2, 3); |
| 81 | pts[2].set(kMeshSize, 0); |
| 82 | pts[3].set(3, kMeshSize / 2); |
| 83 | pts[4].set(kMeshSize / 2, kMeshSize / 2); |
| 84 | pts[5].set(kMeshSize - 3, kMeshSize / 2); |
| 85 | pts[6].set(0, kMeshSize); |
| 86 | pts[7].set(kMeshSize / 2, kMeshSize - 3); |
| 87 | pts[8].set(kMeshSize, kMeshSize); |
| 88 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 89 | const auto shaderSize = kShaderSize * shaderScale; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 90 | texs[0].set(0, 0); |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 91 | texs[1].set(shaderSize / 2, 0); |
| 92 | texs[2].set(shaderSize, 0); |
| 93 | texs[3].set(0, shaderSize / 2); |
| 94 | texs[4].set(shaderSize / 2, shaderSize / 2); |
| 95 | texs[5].set(shaderSize, shaderSize / 2); |
| 96 | texs[6].set(0, shaderSize); |
| 97 | texs[7].set(shaderSize / 2, shaderSize); |
| 98 | texs[8].set(shaderSize, shaderSize); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 99 | |
| 100 | SkRandom rand; |
| 101 | for (size_t i = 0; i < kMeshVertexCnt; ++i) { |
| 102 | colors[i] = rand.nextU() | 0xFF000000; |
| 103 | } |
| 104 | } |
| 105 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 106 | class VerticesGM : public skiagm::GM { |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 107 | SkPoint fPts[kMeshVertexCnt]; |
| 108 | SkPoint fTexs[kMeshVertexCnt]; |
| 109 | SkColor fColors[kMeshVertexCnt]; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 110 | sk_sp<SkShader> fShader1; |
| 111 | sk_sp<SkShader> fShader2; |
| 112 | sk_sp<SkColorFilter> fColorFilter; |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 113 | SkScalar fShaderScale; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 114 | |
| 115 | public: |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 116 | VerticesGM(SkScalar shaderScale) : fShaderScale(shaderScale) {} |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 117 | |
| 118 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 119 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 120 | void onOnceBeforeDraw() override { |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 121 | fill_mesh(fPts, fTexs, fColors, fShaderScale); |
| 122 | fShader1 = make_shader1(fShaderScale); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 123 | fShader2 = make_shader2(); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 124 | fColorFilter = make_color_filter(); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 125 | } |
| 126 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 127 | SkString onShortName() override { |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 128 | SkString name("vertices"); |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 129 | if (fShaderScale != 1) { |
| 130 | name.append("_scaled_shader"); |
| 131 | } |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 132 | return name; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 133 | } |
| 134 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 135 | SkISize onISize() override { |
Brian Salomon | 3216180 | 2017-02-10 10:48:15 -0500 | [diff] [blame] | 136 | return SkISize::Make(975, 1175); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 137 | } |
| 138 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 139 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 140 | const SkBlendMode modes[] = { |
| 141 | SkBlendMode::kClear, |
| 142 | SkBlendMode::kSrc, |
| 143 | SkBlendMode::kDst, |
| 144 | SkBlendMode::kSrcOver, |
| 145 | SkBlendMode::kDstOver, |
| 146 | SkBlendMode::kSrcIn, |
| 147 | SkBlendMode::kDstIn, |
| 148 | SkBlendMode::kSrcOut, |
| 149 | SkBlendMode::kDstOut, |
| 150 | SkBlendMode::kSrcATop, |
| 151 | SkBlendMode::kDstATop, |
| 152 | SkBlendMode::kXor, |
| 153 | SkBlendMode::kPlus, |
| 154 | SkBlendMode::kModulate, |
| 155 | SkBlendMode::kScreen, |
| 156 | SkBlendMode::kOverlay, |
| 157 | SkBlendMode::kDarken, |
| 158 | SkBlendMode::kLighten, |
| 159 | SkBlendMode::kColorDodge, |
| 160 | SkBlendMode::kColorBurn, |
| 161 | SkBlendMode::kHardLight, |
| 162 | SkBlendMode::kSoftLight, |
| 163 | SkBlendMode::kDifference, |
| 164 | SkBlendMode::kExclusion, |
| 165 | SkBlendMode::kMultiply, |
| 166 | SkBlendMode::kHue, |
| 167 | SkBlendMode::kSaturation, |
| 168 | SkBlendMode::kColor, |
| 169 | SkBlendMode::kLuminosity, |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 170 | }; |
skia.committer@gmail.com | 4c91286 | 2013-12-30 07:01:37 +0000 | [diff] [blame] | 171 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 172 | SkPaint paint; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 173 | |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 174 | canvas->translate(4, 4); |
| 175 | int x = 0; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 176 | for (auto mode : modes) { |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 177 | canvas->save(); |
Mike Reed | 9407e24 | 2019-02-15 16:13:57 -0500 | [diff] [blame] | 178 | for (float alpha : {1.0f, 0.5f}) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 179 | for (const auto& cf : {sk_sp<SkColorFilter>(nullptr), fColorFilter}) { |
| 180 | for (const auto& shader : {fShader1, fShader2}) { |
| 181 | static constexpr struct { |
| 182 | bool fHasColors; |
| 183 | bool fHasTexs; |
| 184 | } kAttrs[] = {{true, false}, {false, true}, {true, true}}; |
| 185 | for (auto attrs : kAttrs) { |
| 186 | paint.setShader(shader); |
| 187 | paint.setColorFilter(cf); |
Mike Reed | 9407e24 | 2019-02-15 16:13:57 -0500 | [diff] [blame] | 188 | paint.setAlphaf(alpha); |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 189 | |
| 190 | const SkColor* colors = attrs.fHasColors ? fColors : nullptr; |
| 191 | const SkPoint* texs = attrs.fHasTexs ? fTexs : nullptr; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 192 | auto v = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 193 | kMeshVertexCnt, fPts, texs, colors, |
| 194 | kMeshIndexCnt, kMeshFan); |
| 195 | canvas->drawVertices(v, mode, paint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 196 | canvas->translate(40, 0); |
| 197 | ++x; |
| 198 | } |
| 199 | } |
| 200 | } |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 201 | } |
| 202 | canvas->restore(); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 203 | canvas->translate(0, 40); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 207 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame^] | 208 | using INHERITED = skiagm::GM; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 211 | ///////////////////////////////////////////////////////////////////////////////////// |
| 212 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 213 | DEF_GM(return new VerticesGM(1);) |
| 214 | DEF_GM(return new VerticesGM(1 / kShaderSize);) |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 215 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 216 | static void draw_batching(SkCanvas* canvas) { |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 217 | // Triangle fans can't batch so we convert to regular triangles, |
| 218 | static constexpr int kNumTris = kMeshIndexCnt - 2; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 219 | SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, kMeshVertexCnt, 3 * kNumTris, |
Mike Reed | aa9e332 | 2017-03-16 14:38:48 -0400 | [diff] [blame] | 220 | SkVertices::kHasColors_BuilderFlag | |
| 221 | SkVertices::kHasTexCoords_BuilderFlag); |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 222 | |
| 223 | SkPoint* pts = builder.positions(); |
| 224 | SkPoint* texs = builder.texCoords(); |
| 225 | SkColor* colors = builder.colors(); |
| 226 | fill_mesh(pts, texs, colors, 1); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 227 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 228 | SkTDArray<SkMatrix> matrices; |
| 229 | matrices.push()->reset(); |
| 230 | matrices.push()->setTranslate(0, 40); |
| 231 | SkMatrix* m = matrices.push(); |
| 232 | m->setRotate(45, kMeshSize / 2, kMeshSize / 2); |
| 233 | m->postScale(1.2f, .8f, kMeshSize / 2, kMeshSize / 2); |
| 234 | m->postTranslate(0, 80); |
| 235 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 236 | auto shader = make_shader1(1); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 237 | |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 238 | uint16_t* indices = builder.indices(); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 239 | for (size_t i = 0; i < kNumTris; ++i) { |
| 240 | indices[3 * i] = kMeshFan[0]; |
| 241 | indices[3 * i + 1] = kMeshFan[i + 1]; |
| 242 | indices[3 * i + 2] = kMeshFan[i + 2]; |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 243 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 244 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 245 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 246 | canvas->save(); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 247 | canvas->translate(10, 10); |
| 248 | for (bool useShader : {false, true}) { |
| 249 | for (bool useTex : {false, true}) { |
| 250 | for (const auto& m : matrices) { |
| 251 | canvas->save(); |
| 252 | canvas->concat(m); |
| 253 | SkPaint paint; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 254 | paint.setShader(useShader ? shader : nullptr); |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 255 | |
| 256 | const SkPoint* t = useTex ? texs : nullptr; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 257 | auto v = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, kMeshVertexCnt, |
| 258 | pts, t, colors, kNumTris * 3, indices); |
| 259 | canvas->drawVertices(v, SkBlendMode::kModulate, paint); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 260 | canvas->restore(); |
| 261 | } |
| 262 | canvas->translate(0, 120); |
| 263 | } |
| 264 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 265 | canvas->restore(); |
| 266 | } |
| 267 | |
| 268 | // This test exists to exercise batching in the gpu backend. |
| 269 | DEF_SIMPLE_GM(vertices_batching, canvas, 100, 500) { |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 270 | draw_batching(canvas); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 271 | canvas->translate(50, 0); |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 272 | draw_batching(canvas); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 273 | } |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 274 | |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 275 | using AttrType = SkVertices::Attribute::Type; |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 276 | |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 277 | DEF_SIMPLE_GM(vertices_data, canvas, 512, 256) { |
| 278 | for (auto attrType : {AttrType::kFloat4, AttrType::kByte4_unorm}) { |
| 279 | SkRect r = SkRect::MakeWH(256, 256); |
| 280 | int vcount = 4; // just a quad |
| 281 | int icount = 0; |
| 282 | SkVertices::Attribute attrs[] = { attrType }; |
| 283 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, vcount, icount, attrs, 1); |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 284 | |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 285 | r.toQuad(builder.positions()); |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 286 | |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 287 | if (attrType == AttrType::kFloat4) { |
| 288 | SkV4* col = (SkV4*)builder.customData(); |
| 289 | col[0] = {1, 0, 0, 1}; // red |
| 290 | col[1] = {0, 1, 0, 1}; // green |
| 291 | col[2] = {0, 0, 1, 1}; // blue |
| 292 | col[3] = {0.5, 0.5, 0.5, 1}; // gray |
| 293 | } else { |
| 294 | uint32_t* col = (uint32_t*)builder.customData(); |
| 295 | col[0] = 0xFF0000FF; |
| 296 | col[1] = 0xFF00FF00; |
| 297 | col[2] = 0xFFFF0000; |
| 298 | col[3] = 0xFF7F7F7F; |
Brian Osman | f11e331 | 2020-03-24 14:57:38 -0400 | [diff] [blame] | 299 | } |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 300 | |
| 301 | SkPaint paint; |
| 302 | const char* gProg = R"( |
| 303 | varying float4 vtx_color; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 304 | half4 main(float2 p) { |
| 305 | return half4(vtx_color); |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 306 | } |
| 307 | )"; |
| 308 | auto[effect, errorText] = SkRuntimeEffect::Make(SkString(gProg)); |
Ethan Nicholas | 63d7ee3 | 2020-08-17 10:57:12 -0400 | [diff] [blame] | 309 | if (!effect) { |
| 310 | SK_ABORT("RuntimeEffect error: %s\n", errorText.c_str()); |
| 311 | } |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 312 | paint.setShader(effect->makeShader(nullptr, nullptr, 0, nullptr, true)); |
| 313 | canvas->drawVertices(builder.detach(), paint); |
| 314 | canvas->translate(r.width(), 0); |
| 315 | } |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 316 | } |
Brian Osman | e41fa2d | 2020-03-20 15:45:49 -0400 | [diff] [blame] | 317 | |
| 318 | // Test case for skbug.com/10069. We need to draw the vertices twice (with different matrices) to |
| 319 | // trigger the bug. |
| 320 | DEF_SIMPLE_GM(vertices_perspective, canvas, 256, 256) { |
| 321 | SkPaint paint; |
| 322 | paint.setShader(ToolUtils::create_checkerboard_shader(SK_ColorBLACK, SK_ColorWHITE, 32)); |
| 323 | |
| 324 | SkRect r = SkRect::MakeWH(128, 128); |
| 325 | |
| 326 | SkPoint pos[4]; |
| 327 | r.toQuad(pos); |
| 328 | auto verts = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, pos, pos, nullptr); |
| 329 | |
| 330 | SkMatrix persp; |
| 331 | persp.setPerspY(SK_Scalar1 / 100); |
| 332 | |
| 333 | canvas->save(); |
| 334 | canvas->concat(persp); |
| 335 | canvas->drawRect(r, paint); |
| 336 | canvas->restore(); |
| 337 | |
| 338 | canvas->save(); |
| 339 | canvas->translate(r.width(), 0); |
| 340 | canvas->concat(persp); |
| 341 | canvas->drawRect(r, paint); |
| 342 | canvas->restore(); |
| 343 | |
| 344 | canvas->save(); |
| 345 | canvas->translate(0, r.height()); |
| 346 | canvas->concat(persp); |
| 347 | canvas->drawVertices(verts, paint); |
| 348 | canvas->restore(); |
| 349 | |
| 350 | canvas->save(); |
| 351 | canvas->translate(r.width(), r.height()); |
| 352 | canvas->concat(persp); |
| 353 | canvas->drawVertices(verts, paint); |
| 354 | canvas->restore(); |
| 355 | } |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 356 | |
| 357 | DEF_SIMPLE_GM(vertices_data_lerp, canvas, 256, 256) { |
| 358 | SkPoint pts[12] = {{0, 0}, {85, 0}, {171, 0}, {256, 0}, {256, 85}, {256, 171}, |
| 359 | {256, 256}, {171, 256}, {85, 256}, {0, 256}, {0, 171}, {0, 85}}; |
| 360 | |
| 361 | auto patchVerts = SkPatchUtils::MakeVertices(pts, nullptr, nullptr, 12, 12); |
Brian Osman | 8cbedf9 | 2020-03-31 10:38:31 -0400 | [diff] [blame] | 362 | SkVerticesPriv pv(patchVerts->priv()); |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 363 | |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 364 | SkVertices::Attribute attrs[1] = { AttrType::kFloat }; |
| 365 | SkVertices::Builder builder(pv.mode(), pv.vertexCount(), pv.indexCount(), attrs, 1); |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 366 | |
Brian Osman | 8cbedf9 | 2020-03-31 10:38:31 -0400 | [diff] [blame] | 367 | memcpy(builder.positions(), pv.positions(), pv.vertexCount() * sizeof(SkPoint)); |
| 368 | memcpy(builder.indices(), pv.indices(), pv.indexCount() * sizeof(uint16_t)); |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 369 | |
| 370 | SkRandom rnd; |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 371 | float* lerpData = (float*)builder.customData(); |
Brian Osman | 8cbedf9 | 2020-03-31 10:38:31 -0400 | [diff] [blame] | 372 | for (int i = 0; i < pv.vertexCount(); ++i) { |
Brian Osman | ffd11f4a | 2020-03-30 09:57:53 -0400 | [diff] [blame] | 373 | lerpData[i] = rnd.nextBool() ? 1.0f : 0.0f; |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | auto verts = builder.detach(); |
| 377 | |
| 378 | SkPaint paint; |
| 379 | const char* gProg = R"( |
Brian Osman | 28590d5 | 2020-03-23 16:59:08 -0400 | [diff] [blame] | 380 | in shader c0; |
| 381 | in shader c1; |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 382 | varying float vtx_lerp; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 383 | half4 main(float2 p) { |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 384 | half4 col0 = sample(c0, p); |
| 385 | half4 col1 = sample(c1, p); |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 386 | return mix(col0, col1, half(vtx_lerp)); |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 387 | } |
| 388 | )"; |
| 389 | auto [effect, errorText] = SkRuntimeEffect::Make(SkString(gProg)); |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 390 | SkMatrix scale = SkMatrix::Scale(2, 2); |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 391 | sk_sp<SkShader> children[] = { |
| 392 | GetResourceAsImage("images/mandrill_256.png")->makeShader(), |
| 393 | GetResourceAsImage("images/color_wheel.png")->makeShader(scale), |
| 394 | }; |
| 395 | paint.setShader(effect->makeShader(nullptr, children, 2, nullptr, false)); |
| 396 | |
| 397 | canvas->drawVertices(verts, paint); |
| 398 | } |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 399 | |
| 400 | static constexpr SkScalar kSin60 = 0.8660254f; // sqrt(3) / 2 |
| 401 | static constexpr SkPoint kHexVerts[] = { |
| 402 | { 0, 0 }, |
| 403 | { 0, -1 }, |
| 404 | { kSin60, -0.5f }, |
| 405 | { kSin60, 0.5f }, |
| 406 | { 0, 1 }, |
| 407 | { -kSin60, 0.5f }, |
| 408 | { -kSin60, -0.5f }, |
| 409 | { 0, -1 }, |
| 410 | }; |
| 411 | |
| 412 | static constexpr SkColor4f kColors[] = { |
| 413 | SkColors::kWhite, |
| 414 | SkColors::kRed, |
| 415 | SkColors::kYellow, |
| 416 | SkColors::kGreen, |
| 417 | SkColors::kCyan, |
| 418 | SkColors::kBlue, |
| 419 | SkColors::kMagenta, |
| 420 | SkColors::kRed, |
| 421 | }; |
| 422 | |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 423 | using Attr = SkVertices::Attribute; |
| 424 | |
| 425 | DEF_SIMPLE_GM(vertices_custom_colors, canvas, 400, 200) { |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 426 | ToolUtils::draw_checkerboard(canvas); |
| 427 | |
| 428 | auto draw = [=](SkScalar cx, SkScalar cy, SkVertices::Builder& builder, const SkPaint& paint) { |
| 429 | memcpy(builder.positions(), kHexVerts, sizeof(kHexVerts)); |
| 430 | |
| 431 | canvas->save(); |
| 432 | canvas->translate(cx, cy); |
| 433 | canvas->scale(45, 45); |
| 434 | canvas->drawVertices(builder.detach(), paint); |
| 435 | canvas->restore(); |
| 436 | }; |
| 437 | |
| 438 | auto transColor = [](int i) { |
| 439 | return SkColor4f { kColors[i].fR, kColors[i].fG, kColors[i].fB, i % 2 ? 0.5f : 1.0f }; |
| 440 | }; |
| 441 | |
| 442 | // Fixed function SkVertices, opaque |
| 443 | { |
| 444 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, |
| 445 | SkVertices::kHasColors_BuilderFlag); |
| 446 | for (int i = 0; i < 8; ++i) { |
| 447 | builder.colors()[i] = kColors[i].toSkColor(); |
| 448 | } |
| 449 | draw(50, 50, builder, SkPaint()); |
| 450 | } |
| 451 | |
| 452 | // Fixed function SkVertices, w/transparency |
| 453 | { |
| 454 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, |
| 455 | SkVertices::kHasColors_BuilderFlag); |
| 456 | for (int i = 0; i < 8; ++i) { |
| 457 | builder.colors()[i] = transColor(i).toSkColor(); |
| 458 | } |
| 459 | draw(50, 150, builder, SkPaint()); |
| 460 | } |
| 461 | |
| 462 | const char* gProg = R"( |
| 463 | varying half4 vtx_color; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 464 | half4 main(float2 p) { |
| 465 | return vtx_color; |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 466 | } |
| 467 | )"; |
| 468 | SkPaint skslPaint; |
| 469 | auto [effect, errorText] = SkRuntimeEffect::Make(SkString(gProg)); |
| 470 | skslPaint.setShader(effect->makeShader(nullptr, nullptr, 0, nullptr, false)); |
| 471 | |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 472 | Attr byteColorAttr(Attr::Type::kByte4_unorm, Attr::Usage::kColor); |
| 473 | Attr float4ColorAttr(Attr::Type::kFloat4, Attr::Usage::kColor); |
| 474 | Attr float3ColorAttr(Attr::Type::kFloat3, Attr::Usage::kColor); |
| 475 | |
| 476 | // Custom vertices, byte colors, opaque |
| 477 | { |
| 478 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, &byteColorAttr, 1); |
| 479 | for (int i = 0; i < 8; ++i) { |
| 480 | ((uint32_t*)builder.customData())[i] = kColors[i].toBytes_RGBA(); |
| 481 | } |
| 482 | draw(150, 50, builder, skslPaint); |
| 483 | } |
| 484 | |
| 485 | // Custom vertices, byte colors, w/transparency |
| 486 | { |
| 487 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, &byteColorAttr, 1); |
| 488 | for (int i = 0; i < 8; ++i) { |
| 489 | ((uint32_t*)builder.customData())[i] = transColor(i).toBytes_RGBA(); |
| 490 | } |
| 491 | draw(150, 150, builder, skslPaint); |
| 492 | } |
| 493 | |
| 494 | // Custom vertices, float4 colors, opaque |
| 495 | { |
| 496 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, &float4ColorAttr, 1); |
| 497 | for (int i = 0; i < 8; ++i) { |
| 498 | ((SkColor4f*)builder.customData())[i] = kColors[i]; |
| 499 | } |
| 500 | draw(250, 50, builder, skslPaint); |
| 501 | } |
| 502 | |
| 503 | // Custom vertices, float4 colors, w/transparency |
| 504 | { |
| 505 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, &float4ColorAttr, 1); |
| 506 | SkColor4f* clr = (SkColor4f*)builder.customData(); |
| 507 | for (int i = 0; i < 8; ++i) { |
| 508 | clr[i] = transColor(i); |
| 509 | } |
| 510 | draw(250, 150, builder, skslPaint); |
| 511 | } |
| 512 | |
| 513 | // Custom vertices, float3 colors, opaque |
| 514 | { |
| 515 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 8, 0, &float3ColorAttr, 1); |
| 516 | for (int i = 0; i < 8; ++i) { |
| 517 | ((SkV3*)builder.customData())[i] = { kColors[i].fR, kColors[i].fG, kColors[i].fB }; |
| 518 | } |
| 519 | draw(350, 50, builder, skslPaint); |
| 520 | } |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 521 | } |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 522 | |
Brian Osman | 548de74 | 2020-04-24 12:02:25 -0400 | [diff] [blame] | 523 | static sk_sp<SkVertices> make_cone(Attr::Usage u, const char* markerName) { |
| 524 | Attr attr(Attr::Type::kFloat3, u, markerName); |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 525 | |
| 526 | constexpr int kPerimeterVerts = 64; |
| 527 | // +1 for the center, +1 to repeat the first perimeter point (so we draw a complete circle) |
| 528 | constexpr int kNumVerts = kPerimeterVerts + 2; |
| 529 | |
John Stiles | 8cc118d | 2020-07-30 11:22:35 -0400 | [diff] [blame] | 530 | SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, kNumVerts, /*indexCount=*/0, |
| 531 | &attr, /*attrCount=*/1); |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 532 | |
| 533 | SkPoint* pos = builder.positions(); |
| 534 | SkPoint3* vec = static_cast<SkPoint3*>(builder.customData()); |
| 535 | |
| 536 | pos[0] = { 0, 0 }; |
| 537 | vec[0] = { 0, 0, 1 }; |
| 538 | |
| 539 | for (int i = 0; i < kPerimeterVerts + 1; ++i) { |
| 540 | SkScalar t = (i / SkIntToScalar(kPerimeterVerts)) * 2 * SK_ScalarPI; |
| 541 | SkScalar s = SkScalarSin(t), |
| 542 | c = SkScalarCos(t); |
| 543 | pos[i + 1] = { c, s }; |
| 544 | vec[i + 1] = { c, s, 0 }; |
| 545 | } |
| 546 | |
| 547 | return builder.detach(); |
| 548 | } |
| 549 | |
Brian Osman | 2ad3dfb | 2020-05-15 15:47:25 -0400 | [diff] [blame] | 550 | DEF_SIMPLE_GM(vertices_custom_matrices, canvas, 400, 400) { |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 551 | ToolUtils::draw_checkerboard(canvas); |
| 552 | |
Brian Osman | 548de74 | 2020-04-24 12:02:25 -0400 | [diff] [blame] | 553 | const char* kViewSpace = "local_to_view"; |
| 554 | const char* kWorldSpace = "local_to_world"; |
| 555 | const char* kLocalSpace = "local_to_local"; |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 556 | |
| 557 | auto draw = [=](SkScalar cx, SkScalar cy, sk_sp<SkVertices> vertices, const char* prog, |
| 558 | SkScalar squish = 1.0f) { |
| 559 | SkPaint paint; |
| 560 | auto [effect, errorText] = SkRuntimeEffect::Make(SkString(prog)); |
| 561 | paint.setShader(effect->makeShader(nullptr, nullptr, 0, nullptr, false)); |
| 562 | |
| 563 | canvas->save(); |
| 564 | |
| 565 | // Device space: mesh is upright, translated to its "cell" |
| 566 | canvas->translate(cx, cy); |
| 567 | |
| 568 | // View (camera) space: Mesh is upright, centered on origin, device scale |
| 569 | canvas->markCTM(kViewSpace); |
| 570 | canvas->rotate(90); |
| 571 | |
| 572 | // World space: Mesh is sideways, centered on origin, device scale (possibly squished) |
| 573 | canvas->markCTM(kWorldSpace); |
| 574 | canvas->rotate(-90); |
| 575 | canvas->scale(45, 45 * squish); |
| 576 | |
| 577 | // Local space: Mesh is upright, centered on origin, unit scale |
| 578 | canvas->markCTM(kLocalSpace); |
| 579 | canvas->drawVertices(vertices, paint); |
| 580 | |
| 581 | canvas->restore(); |
| 582 | }; |
| 583 | |
| 584 | const char* vectorProg = R"( |
| 585 | varying float3 vtx_vec; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 586 | half4 main(float2 p) { |
| 587 | return (half3(vtx_vec) * 0.5 + 0.5).rgb1; |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 588 | })"; |
| 589 | |
| 590 | // raw, local vectors, normals, and positions should all look the same (no real transform) |
Brian Osman | 548de74 | 2020-04-24 12:02:25 -0400 | [diff] [blame] | 591 | draw(50, 50, make_cone(Attr::Usage::kRaw, nullptr), vectorProg); |
Brian Osman | d1afef6 | 2020-04-09 16:24:23 -0400 | [diff] [blame] | 592 | draw(150, 50, make_cone(Attr::Usage::kVector, kLocalSpace), vectorProg); |
| 593 | draw(250, 50, make_cone(Attr::Usage::kNormalVector, kLocalSpace), vectorProg); |
| 594 | draw(350, 50, make_cone(Attr::Usage::kPosition, kLocalSpace), vectorProg); |
| 595 | |
| 596 | // world-space vectors and normals are rotated 90 degrees, positions are centered but scaled up |
| 597 | draw(150, 150, make_cone(Attr::Usage::kVector, kWorldSpace), vectorProg); |
| 598 | draw(250, 150, make_cone(Attr::Usage::kNormalVector, kWorldSpace), vectorProg); |
| 599 | draw(350, 150, make_cone(Attr::Usage::kPosition, kWorldSpace), vectorProg); |
| 600 | |
| 601 | // Squished vectors are "wrong", but normals are correct (because we use the inverse transpose) |
| 602 | // Positions remain scaled up (saturated), but otherwise correct |
| 603 | draw(150, 250, make_cone(Attr::Usage::kVector, kWorldSpace), vectorProg, 0.5f); |
| 604 | draw(250, 250, make_cone(Attr::Usage::kNormalVector, kWorldSpace), vectorProg, 0.5f); |
| 605 | draw(350, 250, make_cone(Attr::Usage::kPosition, kWorldSpace), vectorProg, 0.5f); |
Brian Osman | 2ad3dfb | 2020-05-15 15:47:25 -0400 | [diff] [blame] | 606 | |
| 607 | draw( 50, 350, make_cone(Attr::Usage::kVector, nullptr), vectorProg, 0.5f); |
| 608 | draw(150, 350, make_cone(Attr::Usage::kNormalVector, nullptr), vectorProg, 0.5f); |
| 609 | |
| 610 | // For canvas-space positions, color them according to their position relative to the center. |
| 611 | // We do this test twice, with and without saveLayer. That ensures that we get the canvas CTM, |
| 612 | // not just a local-to-device matrix, which exposes effect authors to an implementation detail. |
| 613 | |
| 614 | const char* ctmPositionProg250 = R"( |
| 615 | varying float3 vtx_pos; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 616 | half4 main(float2 p) { |
| 617 | return ((half3(vtx_pos) - half3(250, 350, 0)) / 50 + 0.5).rgb1; |
Brian Osman | 2ad3dfb | 2020-05-15 15:47:25 -0400 | [diff] [blame] | 618 | } |
| 619 | )"; |
| 620 | draw(250, 350, make_cone(Attr::Usage::kPosition, nullptr), ctmPositionProg250, 0.5f); |
| 621 | |
| 622 | const char* ctmPositionProg350 = R"( |
| 623 | varying float3 vtx_pos; |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 624 | half4 main(float2 p) { |
| 625 | return ((half3(vtx_pos) - half3(350, 350, 0)) / 50 + 0.5).rgb1; |
Brian Osman | 2ad3dfb | 2020-05-15 15:47:25 -0400 | [diff] [blame] | 626 | } |
| 627 | )"; |
| 628 | canvas->saveLayer({ 300, 300, 400, 400 }, nullptr); |
| 629 | draw(350, 350, make_cone(Attr::Usage::kPosition, nullptr), ctmPositionProg350, 0.5f); |
| 630 | canvas->restore(); |
Brian Osman | 68219bf | 2020-04-07 16:04:24 -0400 | [diff] [blame] | 631 | } |