OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLVertexShader_DEFINED | 8 #ifndef GrGLVertexShader_DEFINED |
9 #define GrGLVertexShader_DEFINED | 9 #define GrGLVertexShader_DEFINED |
| 10 |
10 #include "GrGLShaderBuilder.h" | 11 #include "GrGLShaderBuilder.h" |
11 | 12 |
12 class GrGLProgramBuilder; | 13 class GrGLProgramBuilder; |
13 | 14 |
14 class GrGLVertexShaderBuilder : public GrGLFullShaderBuilder { | 15 // TODO we only actually ever need to return a GrGLShaderBuilder for this guy, n
one of the below |
| 16 // functions need to be part of VertexShaderBuilder's public interface |
| 17 class GrGLVertexBuilder : public GrGLShaderBuilder { |
15 public: | 18 public: |
16 GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program); | 19 GrGLVertexBuilder(GrGLProgramBuilder* program); |
17 | |
18 /* | |
19 * this call is only for GrGLProgramEffects' internal use | |
20 */ | |
21 void emitAttributes(const GrGeometryProcessor& gp); | |
22 | 20 |
23 /** | 21 /** |
24 * Are explicit local coordinates provided as input to the vertex shader. | 22 * Are explicit local coordinates provided as input to the vertex shader. |
25 */ | 23 */ |
26 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } | 24 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } |
27 | 25 |
28 const SkString* getEffectAttributeName(int attributeIndex) const; | |
29 | |
30 /** Returns a vertex attribute that represents the local coords in the VS. T
his may be the same | 26 /** Returns a vertex attribute that represents the local coords in the VS. T
his may be the same |
31 as positionAttribute() or it may not be. It depends upon whether the ren
dering code | 27 as positionAttribute() or it may not be. It depends upon whether the ren
dering code |
32 specified explicit local coords or not in the GrDrawState. */ | 28 specified explicit local coords or not in the GrDrawState. */ |
33 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar;
} | 29 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar;
} |
34 | 30 |
35 /** Returns a vertex attribute that represents the vertex position in the VS
. This is the | 31 /** 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 c
oords via a matrix. | 32 pre-matrix position and is commonly used by effects to compute texture c
oords via a matrix. |
37 */ | 33 */ |
38 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } | 34 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } |
39 | 35 |
40 private: | |
41 /* | 36 /* |
42 * Add attribute will push a new attribute onto the end. It will also asser
t if there is | 37 * Internal call for GrGLProgramBuilder.addVarying |
43 * a duplicate attribute | |
44 */ | 38 */ |
45 bool addAttribute(const GrShaderVar& var); | 39 SkString* addVarying(GrSLType type, const char* name, const char** vsOutName
); |
46 | |
47 /* | |
48 * Internal call for GrGLFullProgramBuilder.addVarying | |
49 */ | |
50 void addVarying(GrSLType type, | |
51 const char* name, | |
52 const char** vsOutName); | |
53 | 40 |
54 /* | 41 /* |
55 * private helpers for compilation by GrGLProgramBuilder | 42 * private helpers for compilation by GrGLProgramBuilder |
56 */ | 43 */ |
57 void bindProgramLocations(GrGLuint programId); | 44 void setupLocalCoords(); |
| 45 void transformGLToSkiaCoords(); |
| 46 void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr4* out); |
| 47 void emitAttributes(const GrGeometryProcessor& gp); |
| 48 void transformSkiaToGLCoords(); |
| 49 void bindVertexAttributes(GrGLuint programID); |
58 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; | 50 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; |
59 void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage); | |
60 void emitCodeAfterEffects(); | |
61 | 51 |
| 52 private: |
| 53 // an internal call which checks for uniquness of a var before adding it to
the list of inputs |
| 54 bool addAttribute(const GrShaderVar& var); |
62 struct AttributePair { | 55 struct AttributePair { |
63 void set(int index, const SkString& name) { | 56 void set(int index, const SkString& name) { |
64 fIndex = index; fName = name; | 57 fIndex = index; fName = name; |
65 } | 58 } |
66 int fIndex; | 59 int fIndex; |
67 SkString fName; | 60 SkString fName; |
68 }; | 61 }; |
69 | 62 |
70 GrGLShaderVar* fPositionVar; | 63 GrGLShaderVar* fPositionVar; |
71 GrGLShaderVar* fLocalCoordsVar; | 64 GrGLShaderVar* fLocalCoordsVar; |
72 int fEffectAttribOffset; | 65 int fEffectAttribOffset; |
73 | 66 |
74 friend class GrGLFullProgramBuilder; | 67 typedef GrGLShaderBuilder INHERITED; |
75 | |
76 typedef GrGLFullShaderBuilder INHERITED; | |
77 }; | 68 }; |
78 | 69 |
79 #endif | 70 #endif |
OLD | NEW |