Home | History | Annotate | Download | only in builders
      1 /*
      2  * Copyright 2014 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 GrGLVertexShader_DEFINED
      9 #define GrGLVertexShader_DEFINED
     10 #include "GrGLShaderBuilder.h"
     11 
     12 class GrGLProgramBuilder;
     13 
     14 class GrGLVertexShaderBuilder : public GrGLFullShaderBuilder {
     15 public:
     16     GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program);
     17 
     18     /*
     19      * this call is only for GrGLProgramEffects' internal use
     20      */
     21     void emitAttributes(const GrGeometryProcessor& gp);
     22 
     23     /**
     24      * Are explicit local coordinates provided as input to the vertex shader.
     25      */
     26     bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
     27 
     28     const SkString* getEffectAttributeName(int attributeIndex) const;
     29 
     30     /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
     31         as positionAttribute() or it may not be. It depends upon whether the rendering code
     32         specified explicit local coords or not in the GrDrawState. */
     33     const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
     34 
     35     /** Returns a vertex attribute that represents the vertex position in the VS. This is the
     36         pre-matrix position and is commonly used by effects to compute texture coords via a matrix.
     37       */
     38     const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
     39 
     40 private:
     41     /*
     42      * Add attribute will push a new attribute onto the end.  It will also assert if there is
     43      * a duplicate attribute
     44      */
     45     bool addAttribute(const GrShaderVar& var);
     46 
     47     /*
     48      * Internal call for GrGLFullProgramBuilder.addVarying
     49      */
     50     void addVarying(GrSLType type,
     51                    const char* name,
     52                    const char** vsOutName);
     53 
     54     /*
     55      * private helpers for compilation by GrGLProgramBuilder
     56      */
     57     void bindProgramLocations(GrGLuint programId);
     58     bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;
     59     void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage);
     60     void emitCodeAfterEffects();
     61 
     62     struct AttributePair {
     63         void set(int index, const SkString& name) {
     64             fIndex = index; fName = name;
     65         }
     66         int      fIndex;
     67         SkString fName;
     68     };
     69 
     70     GrGLShaderVar*                      fPositionVar;
     71     GrGLShaderVar*                      fLocalCoordsVar;
     72     int                                 fEffectAttribOffset;
     73 
     74     friend class GrGLFullProgramBuilder;
     75 
     76     typedef GrGLFullShaderBuilder INHERITED;
     77 };
     78 
     79 #endif
     80