Chris Dalton | 6a3dbee | 2017-10-16 10:44: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 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 8 | #ifndef GrCCCubicShader_DEFINED |
| 9 | #define GrCCCubicShader_DEFINED |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 10 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 11 | #include "ccpr/GrCCCoverageProcessor.h" |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * This class renders the coverage of convex closed cubic segments using the techniques outlined in |
| 15 | * "Resolution Independent Curve Rendering using Programmable Graphics Hardware" by Charles Loop and |
| 16 | * Jim Blinn: |
| 17 | * |
| 18 | * https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf |
| 19 | * |
| 20 | * The provided curve segments must be convex, monotonic with respect to the vector of their closing |
| 21 | * edge [P3 - P0], and must not contain or be near any inflection points or loop intersections. |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 22 | * (Use GrCCGeometry.) |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 23 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 24 | class GrCCCubicShader : public GrCCCoverageProcessor::Shader { |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 25 | protected: |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 26 | void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 27 | const char* wind, GeometryVars*) const final; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 28 | |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 29 | virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
| 30 | GeometryVars*) const {} |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 31 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 32 | WindHandling onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, |
| 33 | const char* position, const char* coverage, const char* wind) final; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 34 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 35 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) = 0; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 36 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame] | 37 | GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType}; |
| 38 | GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType}; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 39 | GrGLSLVarying fKLMD; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 42 | class GrCCCubicHullShader : public GrCCCubicShader { |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 43 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 44 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 45 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 46 | GrGLSLVarying fGradMatrix; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 47 | }; |
| 48 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 49 | class GrCCCubicCornerShader : public GrCCCubicShader { |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 50 | void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 51 | GeometryVars*) const override; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 52 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 53 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 54 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 55 | GrGLSLVarying fdKLMDdx; |
| 56 | GrGLSLVarying fdKLMDdy; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #endif |