blob: a9875b6a4c4237289566ada2695c5c81743fff1a [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 Dalton6a3dbee2017-10-16 10:44:41 -060028
Chris Dalton1fbdb612017-12-12 12:48:47 -070029 virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
30 GeometryVars*) const {}
Chris Dalton6a3dbee2017-10-16 10:44:41 -060031
Chris Dalton90e8fb12017-12-22 02:24:53 -070032 WindHandling onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
33 const char* position, const char* coverage, const char* wind) final;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060034
Chris Dalton90e8fb12017-12-22 02:24:53 -070035 virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) = 0;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060036
Chris Dalton27372882017-12-08 13:34:21 -070037 GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
38 GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
Chris Dalton90e8fb12017-12-22 02:24:53 -070039 GrGLSLVarying fKLMD;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060040};
41
Chris Dalton383a2ef2018-01-08 17:21:41 -050042class GrCCCubicHullShader : public GrCCCubicShader {
Chris Dalton90e8fb12017-12-22 02:24:53 -070043 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Robert Phillips7f861922018-01-30 13:13:42 +000044 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060045
Chris Dalton90e8fb12017-12-22 02:24:53 -070046 GrGLSLVarying fGradMatrix;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060047};
48
Chris Dalton383a2ef2018-01-08 17:21:41 -050049class GrCCCubicCornerShader : public GrCCCubicShader {
Chris Dalton1fbdb612017-12-12 12:48:47 -070050 void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060051 GeometryVars*) const override;
Chris Dalton90e8fb12017-12-22 02:24:53 -070052 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Robert Phillips7f861922018-01-30 13:13:42 +000053 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060054
Chris Dalton90e8fb12017-12-22 02:24:53 -070055 GrGLSLVarying fdKLMDdx;
56 GrGLSLVarying fdKLMDdy;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060057};
58
59#endif