Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #ifndef GrCCPRCubicProcessor_DEFINED |
| 9 | #define GrCCPRCubicProcessor_DEFINED |
| 10 | |
| 11 | #include "ccpr/GrCCPRCoverageProcessor.h" |
| 12 | |
| 13 | class GrGLSLGeometryBuilder; |
| 14 | |
| 15 | /** |
| 16 | * This class renders the coverage of convex closed cubic segments using the techniques outlined in |
| 17 | * "Resolution Independent Curve Rendering using Programmable Graphics Hardware" by Charles Loop and |
| 18 | * Jim Blinn: |
| 19 | * |
| 20 | * https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf |
| 21 | * |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 22 | * The provided curves must be convex, monotonic with respect to the vector of their closing edge |
| 23 | * [P3 - P0], and must not contain or be near any inflection points or loop intersections. |
| 24 | * (Use GrCCPRGeometry.) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 25 | */ |
| 26 | class GrCCPRCubicProcessor : public GrCCPRCoverageProcessor::PrimitiveProcessor { |
| 27 | public: |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 28 | enum class CubicType { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 29 | kSerpentine, |
| 30 | kLoop |
| 31 | }; |
| 32 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 33 | GrCCPRCubicProcessor(CubicType cubicType) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 34 | : INHERITED(CoverageType::kShader) |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 35 | , fCubicType(cubicType) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 36 | , fKLMMatrix("klm_matrix", kHighFloat3x3_GrSLType, GrShaderVar::kNonArray, |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 37 | kHigh_GrSLPrecision) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 38 | , fKLMDerivatives("klm_derivatives", kHighFloat2_GrSLType, 3, kHigh_GrSLPrecision) |
| 39 | , fEdgeDistanceEquation("edge_distance_equation", kHighFloat3_GrSLType, |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 40 | GrShaderVar::kNonArray, kHigh_GrSLPrecision) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 41 | , fKLMD(kHighFloat4_GrSLType) {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 42 | |
| 43 | void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 44 | varyingHandler->addVarying("klmd", &fKLMD, kHigh_GrSLPrecision); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void onEmitVertexShader(const GrCCPRCoverageProcessor&, GrGLSLVertexBuilder*, |
| 48 | const TexelBufferHandle& pointsBuffer, const char* atlasOffset, |
| 49 | const char* rtAdjust, GrGPArgs*) const override; |
| 50 | void emitWind(GrGLSLGeometryBuilder*, const char* rtAdjust, const char* outputWind) const final; |
| 51 | void onEmitGeometryShader(GrGLSLGeometryBuilder*, const char* emitVertexFn, const char* wind, |
| 52 | const char* rtAdjust) const final; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 53 | void emitPerVertexGeometryCode(SkString* fnBody, const char* position, const char* coverage, |
| 54 | const char* wind) const final; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | virtual void emitCubicGeometry(GrGLSLGeometryBuilder*, const char* emitVertexFn, |
| 58 | const char* wind, const char* rtAdjust) const = 0; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 59 | virtual void onEmitPerVertexGeometryCode(SkString* fnBody) const = 0; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 60 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 61 | const CubicType fCubicType; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 62 | GrShaderVar fKLMMatrix; |
| 63 | GrShaderVar fKLMDerivatives; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 64 | GrShaderVar fEdgeDistanceEquation; |
| 65 | GrGLSLGeoToFrag fKLMD; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 66 | |
| 67 | typedef GrCCPRCoverageProcessor::PrimitiveProcessor INHERITED; |
| 68 | }; |
| 69 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 70 | class GrCCPRCubicHullProcessor : public GrCCPRCubicProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 71 | public: |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 72 | GrCCPRCubicHullProcessor(CubicType cubicType) |
| 73 | : INHERITED(cubicType) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 74 | , fGradMatrix(kHighFloat2x2_GrSLType) {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 75 | |
| 76 | void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { |
| 77 | this->INHERITED::resetVaryings(varyingHandler); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 78 | varyingHandler->addVarying("grad_matrix", &fGradMatrix, kHigh_GrSLPrecision); |
| 79 | } |
| 80 | |
| 81 | void emitCubicGeometry(GrGLSLGeometryBuilder*, const char* emitVertexFn, |
| 82 | const char* wind, const char* rtAdjust) const override; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 83 | void onEmitPerVertexGeometryCode(SkString* fnBody) const override; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 84 | void emitShaderCoverage(GrGLSLFragmentBuilder*, const char* outputCoverage) const override; |
| 85 | |
| 86 | protected: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 87 | GrGLSLGeoToFrag fGradMatrix; |
| 88 | |
| 89 | typedef GrCCPRCubicProcessor INHERITED; |
| 90 | }; |
| 91 | |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 92 | class GrCCPRCubicCornerProcessor : public GrCCPRCubicProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 93 | public: |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 94 | GrCCPRCubicCornerProcessor(CubicType cubicType) |
| 95 | : INHERITED(cubicType) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 96 | , fEdgeDistanceDerivatives("edge_distance_derivatives", kHighFloat2_GrSLType, |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 97 | GrShaderVar::kNonArray, kHigh_GrSLPrecision) |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame^] | 98 | , fdKLMDdx(kHighFloat4_GrSLType) |
| 99 | , fdKLMDdy(kHighFloat4_GrSLType) {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 100 | |
| 101 | void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { |
| 102 | this->INHERITED::resetVaryings(varyingHandler); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 103 | varyingHandler->addFlatVarying("dklmddx", &fdKLMDdx, kHigh_GrSLPrecision); |
| 104 | varyingHandler->addFlatVarying("dklmddy", &fdKLMDdy, kHigh_GrSLPrecision); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void emitCubicGeometry(GrGLSLGeometryBuilder*, const char* emitVertexFn, |
| 108 | const char* wind, const char* rtAdjust) const override; |
Chris Dalton | 7f578bf | 2017-09-05 16:46:48 -0600 | [diff] [blame] | 109 | void onEmitPerVertexGeometryCode(SkString* fnBody) const override; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 110 | void emitShaderCoverage(GrGLSLFragmentBuilder*, const char* outputCoverage) const override; |
| 111 | |
| 112 | protected: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 113 | GrShaderVar fEdgeDistanceDerivatives; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 114 | GrGLSLGeoToFrag fdKLMDdx; |
| 115 | GrGLSLGeoToFrag fdKLMDdy; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 116 | |
| 117 | typedef GrCCPRCubicProcessor INHERITED; |
| 118 | }; |
| 119 | |
| 120 | #endif |