blob: c0a55a002c513bade4b2cbdd238f1a19e785924d [file] [log] [blame]
Chris Daltonc17bf322017-10-24 10:59:03 -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 GrGLSLVertexGeoBuilder_DEFINED
9#define GrGLSLVertexGeoBuilder_DEFINED
10
11#include "GrGLSLShaderBuilder.h"
12
13/**
14 * Base class for vertex and geometry shader builders. This is the stage that computes input
15 * geometry for the rasterizer.
16 */
17class GrGLSLVertexGeoBuilder : public GrGLSLShaderBuilder {
18protected:
19 GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
20
21 void emitNormalizedSkPosition(const char* devPos, const char* rtAdjustName,
22 GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
23 this->emitNormalizedSkPosition(&this->code(), devPos, rtAdjustName, devPosType);
24 }
25
26 void emitNormalizedSkPosition(SkString* out, const char* devPos, const char* rtAdjustName,
27 GrSLType devPosType = GrSLType::kFloat2_GrSLType);
28
29 friend class GrGLSLGeometryProcessor;
30
31 typedef GrGLSLShaderBuilder INHERITED;
32};
33
34
35class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
36public:
37 GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
38
39private:
40 void onFinalize() override;
41
42 friend class GrGLProgramBuilder;
43
44 typedef GrGLSLVertexGeoBuilder INHERITED;
45};
46
47
48class GrGLSLGeometryBuilder : public GrGLSLVertexGeoBuilder {
49public:
50 GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
51
52 enum class InputType {
53 kPoints,
54 kLines,
55 kLinesAdjacency,
56 kTriangles,
57 kTrianglesAdjacency
58 };
59
60 enum class OutputType {
61 kPoints,
62 kLineStrip,
63 kTriangleStrip
64 };
65
66 void configure(InputType, OutputType, int maxVertices, int numInvocations = 1);
67 bool isConfigured() const { return fNumInvocations; }
68
69 void emitVertex(const char* devPos, const char* rtAdjustName,
70 GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
71 this->emitVertex(&this->code(), devPos, rtAdjustName, devPosType);
72 }
73 void emitVertex(SkString* out, const char* devPos, const char* rtAdjustName,
74 GrSLType devPosType = GrSLType::kFloat2_GrSLType);
75
76 void endPrimitive();
77
78private:
79 void onFinalize() override;
80
81 int fNumInvocations = 0;
82
83 friend class GrGLProgramBuilder;
84
85 typedef GrGLSLVertexGeoBuilder INHERITED;
86};
87
88#endif