• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
17 class GrGLSLVertexGeoBuilder : public GrGLSLShaderBuilder {
18 public:
19     // Copies the given text verbatim to the function definitions section. Does not mangle the name.
20     // 'functionDefinition' should be a fully valid SkSL function, complete with return type, name,
21     // arguments, braces, and a body.
insertFunction(const char * functionDefinition)22     void insertFunction(const char* functionDefinition) {
23         this->functions().append(functionDefinition);
24     }
25     using GrGLSLShaderBuilder::functions;
26 
27 protected:
GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder * program)28     GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
29 
30     void emitNormalizedSkPosition(const char* devPos,
31                                   GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
32         this->emitNormalizedSkPosition(&this->code(), devPos, devPosType);
33     }
34 
35     void emitNormalizedSkPosition(SkString* out, const char* devPos,
36                                   GrSLType devPosType = GrSLType::kFloat2_GrSLType);
37 
38     friend class GrGLSLGeometryProcessor;
39 
40     using INHERITED = GrGLSLShaderBuilder;
41 };
42 
43 
44 class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
45 public:
GrGLSLVertexBuilder(GrGLSLProgramBuilder * program)46     GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
47 
48 private:
49     void onFinalize() override;
50 
51     friend class GrGLProgramBuilder;
52 
53     using INHERITED = GrGLSLVertexGeoBuilder;
54 };
55 
56 
57 class GrGLSLGeometryBuilder : public GrGLSLVertexGeoBuilder {
58 public:
GrGLSLGeometryBuilder(GrGLSLProgramBuilder * program)59     GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
60 
61     enum class InputType {
62         kPoints,
63         kLines,
64         kTriangles,
65     };
66 
67     enum class OutputType {
68         kPoints,
69         kLineStrip,
70         kTriangleStrip
71     };
72 
73     void configure(InputType, OutputType, int maxVertices, int numInvocations = 1);
isConfigured()74     bool isConfigured() const { return fNumInvocations; }
75 
76     void emitVertex(const char* devPos, GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
77         this->emitVertex(&this->code(), devPos, devPosType);
78     }
79     void emitVertex(SkString* out, const char* devPos,
80                     GrSLType devPosType = GrSLType::kFloat2_GrSLType);
81 
82     void endPrimitive();
83 
84 private:
85     void onFinalize() override;
86 
87     int fNumInvocations = 0;
88 
89     friend class GrGLProgramBuilder;
90 
91     using INHERITED = GrGLSLVertexGeoBuilder;
92 };
93 
94 #endif
95