aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl/GrGLSLVertexGeoBuilder.h
blob: c0a55a002c513bade4b2cbdd238f1a19e785924d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrGLSLVertexGeoBuilder_DEFINED
#define GrGLSLVertexGeoBuilder_DEFINED

#include "GrGLSLShaderBuilder.h"

/**
 * Base class for vertex and geometry shader builders. This is the stage that computes input
 * geometry for the rasterizer.
 */
class GrGLSLVertexGeoBuilder : public GrGLSLShaderBuilder {
protected:
    GrGLSLVertexGeoBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}

    void emitNormalizedSkPosition(const char* devPos, const char* rtAdjustName,
                                  GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
        this->emitNormalizedSkPosition(&this->code(), devPos, rtAdjustName, devPosType);
    }

    void emitNormalizedSkPosition(SkString* out, const char* devPos, const char* rtAdjustName,
                                  GrSLType devPosType = GrSLType::kFloat2_GrSLType);

    friend class GrGLSLGeometryProcessor;

    typedef GrGLSLShaderBuilder INHERITED;
};


class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
public:
    GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}

private:
    void onFinalize() override;

    friend class GrGLProgramBuilder;

    typedef GrGLSLVertexGeoBuilder INHERITED;
};


class GrGLSLGeometryBuilder : public GrGLSLVertexGeoBuilder {
public:
    GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}

    enum class InputType {
        kPoints,
        kLines,
        kLinesAdjacency,
        kTriangles,
        kTrianglesAdjacency
    };

    enum class OutputType {
        kPoints,
        kLineStrip,
        kTriangleStrip
    };

    void configure(InputType, OutputType, int maxVertices, int numInvocations = 1);
    bool isConfigured() const { return fNumInvocations; }

    void emitVertex(const char* devPos, const char* rtAdjustName,
                    GrSLType devPosType = GrSLType::kFloat2_GrSLType) {
        this->emitVertex(&this->code(), devPos, rtAdjustName, devPosType);
    }
    void emitVertex(SkString* out, const char* devPos, const char* rtAdjustName,
                    GrSLType devPosType = GrSLType::kFloat2_GrSLType);

    void endPrimitive();

private:
    void onFinalize() override;

    int fNumInvocations = 0;

    friend class GrGLProgramBuilder;

    typedef GrGLSLVertexGeoBuilder INHERITED;
};

#endif