blob: ffb91039698ba6a3f43f6034aa5d0204a78dcb0e [file] [log] [blame]
Chris Dalton6a3dbee2017-10-16 10:44:41 -06001/*
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 Dalton383a2ef2018-01-08 17:21:41 -05008#ifndef GrCCCubicShader_DEFINED
9#define GrCCCubicShader_DEFINED
Chris Dalton6a3dbee2017-10-16 10:44:41 -060010
Chris Dalton383a2ef2018-01-08 17:21:41 -050011#include "ccpr/GrCCCoverageProcessor.h"
Chris Dalton6a3dbee2017-10-16 10:44:41 -060012
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 Dalton383a2ef2018-01-08 17:21:41 -050022 * (Use GrCCGeometry.)
Chris Dalton6a3dbee2017-10-16 10:44:41 -060023 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050024class GrCCCubicShader : public GrCCCoverageProcessor::Shader {
Chris Dalton6a3dbee2017-10-16 10:44:41 -060025protected:
Chris Dalton1fbdb612017-12-12 12:48:47 -070026 void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060027 const char* wind, GeometryVars*) const final;
Chris Dalton1fbdb612017-12-12 12:48:47 -070028 virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
29 GeometryVars*) const {}
Chris Dalton6a3dbee2017-10-16 10:44:41 -060030
Chris Daltonf510e262018-01-30 16:42:37 -070031 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
32 const char* position, const char* inputCoverage, const char* wind) final;
Chris Dalton90e8fb12017-12-22 02:24:53 -070033 virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) = 0;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060034
Chris Daltonf510e262018-01-30 16:42:37 -070035 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const final;
36 virtual void emitCoverage(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const = 0;
37
Chris Dalton27372882017-12-08 13:34:21 -070038 GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
39 GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
Chris Dalton90e8fb12017-12-22 02:24:53 -070040 GrGLSLVarying fKLMD;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060041};
42
Chris Dalton383a2ef2018-01-08 17:21:41 -050043class GrCCCubicHullShader : public GrCCCubicShader {
Chris Dalton90e8fb12017-12-22 02:24:53 -070044 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Chris Daltonf510e262018-01-30 16:42:37 -070045 void emitCoverage(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060046
Chris Dalton90e8fb12017-12-22 02:24:53 -070047 GrGLSLVarying fGradMatrix;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060048};
49
Chris Dalton383a2ef2018-01-08 17:21:41 -050050class GrCCCubicCornerShader : public GrCCCubicShader {
Chris Dalton1fbdb612017-12-12 12:48:47 -070051 void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060052 GeometryVars*) const override;
Chris Dalton90e8fb12017-12-22 02:24:53 -070053 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Chris Daltonf510e262018-01-30 16:42:37 -070054 void emitCoverage(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060055
Chris Dalton90e8fb12017-12-22 02:24:53 -070056 GrGLSLVarying fdKLMDdx;
57 GrGLSLVarying fdKLMDdy;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060058};
59
60#endif