Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / gl / builders / GrGLVertexShaderBuilder.h
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
11 #include "GrGLShaderBuilder.h"
12
13 class GrGLVarying;
14
15 class GrGLVertexBuilder : public GrGLShaderBuilder {
16 public:
17     GrGLVertexBuilder(GrGLProgramBuilder* program);
18
19     /**
20      * Are explicit local coordinates provided as input to the vertex shader.
21      */
22     bool hasLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
23
24     /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
25         as positionAttribute() or it may not be. It depends upon whether the rendering code
26         specified explicit local coords or not in the GrDrawState. */
27     const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
28
29     /** Returns a vertex attribute that represents the vertex position in the VS. This is the
30         pre-matrix position and is commonly used by effects to compute texture coords via a matrix.
31       */
32     const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
33
34 private:
35     /*
36      * Internal call for GrGLProgramBuilder.addVarying
37      */
38     void addVarying(const char* name, GrGLVarying*);
39
40     /*
41      * private helpers for compilation by GrGLProgramBuilder
42      */
43     void setupLocalCoords();
44     void transformGLToSkiaCoords();
45     void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr1* out);
46     void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr4* out);
47     void emitAttributes(const GrGeometryProcessor& gp);
48     void transformSkiaToGLCoords();
49     void bindVertexAttributes(GrGLuint programID);
50     bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;
51
52     // an internal call which checks for uniquness of a var before adding it to the list of inputs
53     bool addAttribute(const GrShaderVar& var);
54     struct AttributePair {
55         void set(int index, const SkString& name) {
56             fIndex = index; fName = name;
57         }
58         int      fIndex;
59         SkString fName;
60     };
61
62     GrGLShaderVar*                      fPositionVar;
63     GrGLShaderVar*                      fLocalCoordsVar;
64     int                                 fEffectAttribOffset;
65
66     friend class GrGLProgramBuilder;
67
68     typedef GrGLShaderBuilder INHERITED;
69 };
70
71 #endif