| 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 | |
| 11 #include "GrGLShaderBuilder.h" | 10 #include "GrGLShaderBuilder.h" |
| 12 | 11 |
| 13 class GrGLProgramBuilder; | 12 class GrGLProgramBuilder; |
| 14 | 13 |
| 15 // TODO we only actually ever need to return a GrGLShaderBuilder for this guy, n
one of the below | 14 class GrGLVertexShaderBuilder : public GrGLFullShaderBuilder { |
| 16 // functions need to be part of VertexShaderBuilder's public interface | |
| 17 class GrGLVertexBuilder : public GrGLShaderBuilder { | |
| 18 public: | 15 public: |
| 19 GrGLVertexBuilder(GrGLProgramBuilder* program); | 16 GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program); |
| 17 |
| 18 /* |
| 19 * this call is only for GrGLProgramEffects' internal use |
| 20 */ |
| 21 void emitAttributes(const GrGeometryProcessor& gp); |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * Are explicit local coordinates provided as input to the vertex shader. | 24 * Are explicit local coordinates provided as input to the vertex shader. |
| 23 */ | 25 */ |
| 24 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } | 26 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } |
| 25 | 27 |
| 28 const SkString* getEffectAttributeName(int attributeIndex) const; |
| 29 |
| 26 /** 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 |
| 27 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 |
| 28 specified explicit local coords or not in the GrDrawState. */ | 32 specified explicit local coords or not in the GrDrawState. */ |
| 29 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar;
} | 33 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar;
} |
| 30 | 34 |
| 31 /** 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 |
| 32 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. |
| 33 */ | 37 */ |
| 34 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } | 38 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } |
| 35 | 39 |
| 40 private: |
| 36 /* | 41 /* |
| 37 * Internal call for GrGLProgramBuilder.addVarying | 42 * Add attribute will push a new attribute onto the end. It will also asser
t if there is |
| 43 * a duplicate attribute |
| 38 */ | 44 */ |
| 39 SkString* addVarying(GrSLType type, const char* name, const char** vsOutName
); | 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); |
| 40 | 53 |
| 41 /* | 54 /* |
| 42 * private helpers for compilation by GrGLProgramBuilder | 55 * private helpers for compilation by GrGLProgramBuilder |
| 43 */ | 56 */ |
| 44 void setupLocalCoords(); | 57 void bindProgramLocations(GrGLuint programId); |
| 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); | |
| 50 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; | 58 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; |
| 59 void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage); |
| 60 void emitCodeAfterEffects(); |
| 51 | 61 |
| 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); | |
| 55 struct AttributePair { | 62 struct AttributePair { |
| 56 void set(int index, const SkString& name) { | 63 void set(int index, const SkString& name) { |
| 57 fIndex = index; fName = name; | 64 fIndex = index; fName = name; |
| 58 } | 65 } |
| 59 int fIndex; | 66 int fIndex; |
| 60 SkString fName; | 67 SkString fName; |
| 61 }; | 68 }; |
| 62 | 69 |
| 63 GrGLShaderVar* fPositionVar; | 70 GrGLShaderVar* fPositionVar; |
| 64 GrGLShaderVar* fLocalCoordsVar; | 71 GrGLShaderVar* fLocalCoordsVar; |
| 65 int fEffectAttribOffset; | 72 int fEffectAttribOffset; |
| 66 | 73 |
| 67 typedef GrGLShaderBuilder INHERITED; | 74 friend class GrGLFullProgramBuilder; |
| 75 |
| 76 typedef GrGLFullShaderBuilder INHERITED; |
| 68 }; | 77 }; |
| 69 | 78 |
| 70 #endif | 79 #endif |
| OLD | NEW |