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