blob: 10f4dffd768268d83411893bdeb69b97a6b9b47a [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
8#ifndef GrCCPRCubicShader_DEFINED
9#define GrCCPRCubicShader_DEFINED
10
11#include "ccpr/GrCCPRCoverageProcessor.h"
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.
22 * (Use GrCCPRGeometry.)
23 */
24class GrCCPRCubicShader : public GrCCPRCoverageProcessor::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
32 WindHandling onEmitVaryings(GrGLSLVaryingHandler*, SkString* code, const char* position,
33 const char* coverage, const char* wind) final;
34
35 virtual void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) = 0;
36
Chris Dalton27372882017-12-08 13:34:21 -070037 GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
38 GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
39 GrGLSLVarying fKLMD{kFloat4_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
Chris Dalton6a3dbee2017-10-16 10:44:41 -060040};
41
42class GrCCPRCubicHullShader : public GrCCPRCubicShader {
Chris Dalton6a3dbee2017-10-16 10:44:41 -060043 void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override;
44 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
45
Chris Dalton27372882017-12-08 13:34:21 -070046 GrGLSLVarying fGradMatrix{kFloat2x2_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
Chris Dalton6a3dbee2017-10-16 10:44:41 -060047};
48
49class GrCCPRCubicCornerShader : public GrCCPRCubicShader {
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 Dalton6a3dbee2017-10-16 10:44:41 -060052 void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override;
53 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
54
Chris Dalton27372882017-12-08 13:34:21 -070055 GrGLSLVarying fdKLMDdx{kFloat4_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
56 GrGLSLVarying fdKLMDdy{kFloat4_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
Chris Dalton6a3dbee2017-10-16 10:44:41 -060057};
58
59#endif