Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 GrCCConicShader_DEFINED |
| 9 | #define GrCCConicShader_DEFINED |
| 10 | |
| 11 | #include "ccpr/GrCCCoverageProcessor.h" |
| 12 | |
| 13 | /** |
| 14 | * This class renders the coverage of closed conic curves 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 curves must be monotonic with respect to the vector of their closing edge [P2 - P0]. |
| 21 | * (Use GrCCGeometry::conicTo().) |
| 22 | */ |
| 23 | class GrCCConicShader : public GrCCCoverageProcessor::Shader { |
| 24 | public: |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 25 | bool calculatesOwnEdgeCoverage() const override { return true; } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 26 | |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 27 | void emitSetupCode( |
| 28 | GrGLSLVertexGeoBuilder*, const char* pts, const char** outHull4) const override; |
| 29 | |
| 30 | void onEmitVaryings( |
| 31 | GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, const char* position, |
| 32 | const char* coverage, const char* cornerCoverage, const char* wind) override; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 33 | |
| 34 | void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override; |
| 35 | |
| 36 | private: |
| 37 | void calcHullCoverage(SkString* code, const char* klm, const char* grad, |
| 38 | const char* outputCoverage) const; |
| 39 | |
| 40 | const GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType}; |
| 41 | const GrShaderVar fControlPoint{"control_point", kFloat2_GrSLType}; |
| 42 | GrGLSLVarying fKLM_fWind; |
| 43 | GrGLSLVarying fGrad_fCorner; |
| 44 | }; |
| 45 | |
| 46 | #endif |