1/*
2 * Copyright 2019 Google LLC.
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#ifndef GrStencilPathShader_DEFINED
9#define GrStencilPathShader_DEFINED
10
11#include "src/gpu/tessellate/GrPathShader.h"
12
13// This is the base class for shaders that stencil path elements, namely, triangles, standalone
14// cubics, and wedges.
15class GrStencilPathShader : public GrPathShader {
16public:
17 GrStencilPathShader(ClassID classID, const SkMatrix& viewMatrix, GrPrimitiveType primitiveType,
18 int tessellationPatchVertexCount = 0)
19 : GrPathShader(classID, viewMatrix, primitiveType, tessellationPatchVertexCount) {
20 constexpr static Attribute kPointAttrib = {
21 "point", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
22 this->setVertexAttributes(&kPointAttrib, 1);
23 }
24
25private:
26 void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
27 b->add32(this->viewMatrix().isIdentity());
28 }
29 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
30
31 class Impl;
32};
33
34// Draws simple triangles to the stencil buffer.
35class GrStencilTriangleShader : public GrStencilPathShader {
36public:
37 GrStencilTriangleShader(const SkMatrix& viewMatrix) : GrStencilPathShader(
38 kTessellate_GrStencilTriangleShader_ClassID, viewMatrix, GrPrimitiveType::kTriangles) {}
39 const char* name() const override { return "tessellate_GrStencilTriangleShader"; }
40};
41
42// Uses GPU tessellation shaders to linearize, triangulate, and render standalone cubics. Here, a
43// "cubic" is a standalone closed contour consisting of a single cubic bezier.
44// TODO: Eventually we want to use rational cubic wedges in order to support perspective and conics.
45class GrStencilCubicShader : public GrStencilPathShader {
46public:
47 GrStencilCubicShader(const SkMatrix& viewMatrix) : GrStencilPathShader(
48 kTessellate_GrStencilCubicShader_ClassID, viewMatrix, GrPrimitiveType::kPatches, 4) {}
49 const char* name() const override { return "tessellate_GrStencilCubicShader"; }
50
51private:
52 SkString getTessControlShaderGLSL(const char* versionAndExtensionDecls,
53 const GrShaderCaps&) const override;
54 SkString getTessEvaluationShaderGLSL(const char* versionAndExtensionDecls,
55 const GrShaderCaps&) const override;
56};
57
58// Uses GPU tessellation shaders to linearize, triangulate, and render cubic "wedge" patches. A
59// wedge is a 5-point patch consisting of 4 cubic control points, plus an anchor point fanning from
60// the center of the curve's resident contour.
61// TODO: Eventually we want to use rational cubic wedges in order to support perspective and conics.
62class GrStencilWedgeShader : public GrStencilPathShader {
63public:
64 GrStencilWedgeShader(const SkMatrix& viewMatrix) : GrStencilPathShader(
65 kTessellate_GrStencilWedgeShader_ClassID, viewMatrix, GrPrimitiveType::kPatches, 5) {}
66 const char* name() const override { return "tessellate_GrStencilWedgeShader"; }
67
68private:
69 SkString getTessControlShaderGLSL(const char* versionAndExtensionDecls,
70 const GrShaderCaps&) const override;
71 SkString getTessEvaluationShaderGLSL(const char* versionAndExtensionDecls,
72 const GrShaderCaps&) const override;
73};
74
75#endif
76