Home | History | Annotate | Download | only in glsl
      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 "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 protected:
     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 
     35 class GrGLSLVertexBuilder : public GrGLSLVertexGeoBuilder {
     36 public:
     37     GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
     38 
     39 private:
     40     void onFinalize() override;
     41 
     42     friend class GrGLProgramBuilder;
     43 
     44     typedef GrGLSLVertexGeoBuilder INHERITED;
     45 };
     46 
     47 
     48 class GrGLSLGeometryBuilder : public GrGLSLVertexGeoBuilder {
     49 public:
     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 
     78 private:
     79     void onFinalize() override;
     80 
     81     int fNumInvocations = 0;
     82 
     83     friend class GrGLProgramBuilder;
     84 
     85     typedef GrGLSLVertexGeoBuilder INHERITED;
     86 };
     87 
     88 #endif
     89