1/*
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 "src/gpu/glsl/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 kTriangles,
56 };
57
58 enum class OutputType {
59 kPoints,
60 kLineStrip,
61 kTriangleStrip
62 };
63
64 void configure(InputType, OutputType, int maxVertices, int numInvocations = 1);
65 bool isConfigured() const { return fNumInvocations; }
66
67 void emitVertex(const char* devPos, const char* rtAdjustName,
68 GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
69 this->emitVertex(&this->code(), devPos, rtAdjustName, devPosType);
70 }
71 void emitVertex(SkString* out, const char* devPos, const char* rtAdjustName,
72 GrSLType devPosType = GrSLType::kFloat2_GrSLType);
73
74 void endPrimitive();
75
76private:
77 void onFinalize() override;
78
79 int fNumInvocations = 0;
80
81 friend class GrGLProgramBuilder;
82
83 typedef GrGLSLVertexGeoBuilder INHERITED;
84};
85
86#endif
87