| 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 |
| 11 #include "GrGLShaderBuilder.h" | 11 #include "GrGLShaderBuilder.h" |
| 12 | 12 |
| 13 class GrGLVarying; | 13 class GrGLVarying; |
| 14 | 14 |
| 15 class GrGLVertexBuilder : public GrGLShaderBuilder { | 15 class GrGLVertexBuilder : public GrGLShaderBuilder { |
| 16 public: | 16 public: |
| 17 GrGLVertexBuilder(GrGLProgramBuilder* program); | 17 GrGLVertexBuilder(GrGLProgramBuilder* program); |
| 18 | 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. T
his may be the same | |
| 25 as positionAttribute() or it may not be. It depends upon whether the ren
dering 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 c
oords via a matrix. | |
| 31 */ | |
| 32 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } | |
| 33 | |
| 34 /** returns the expected position output */ | 19 /** returns the expected position output */ |
| 35 const char* glPosition() const { return "pos3"; } | 20 const char* glPosition() const { return "pos3"; } |
| 21 const char* positionCoords() const { return "position"; } |
| 22 const char* localCoords() const { return "localCoords"; } |
| 36 | 23 |
| 37 /** returns the expected uviewM matrix */ | 24 /** returns the expected uviewM matrix */ |
| 38 // TODO all of this fixed function stuff can live on the GP/PP | 25 // TODO all of this fixed function stuff can live on the GP/PP |
| 39 const char* uViewM() const { return "uViewM"; } | 26 const char* uViewM() const { return "uViewM"; } |
| 40 const char* inPosition() const { return "inPosition"; } | |
| 41 | 27 |
| 28 void addAttribute(const GrGeometryProcessor::GrAttribute* attr) { |
| 29 this->addAttribute(GrShaderVar(attr->fName, |
| 30 GrVertexAttribTypeToSLType(attr->fType), |
| 31 GrShaderVar::kAttribute_TypeModifier)); |
| 32 } |
| 42 | 33 |
| 43 private: | 34 private: |
| 44 /* | 35 /* |
| 45 * Internal call for GrGLProgramBuilder.addVarying | 36 * Internal call for GrGLProgramBuilder.addVarying |
| 46 */ | 37 */ |
| 47 void addVarying(const char* name, GrGLVarying*); | 38 void addVarying(const char* name, GrGLVarying*); |
| 48 | 39 |
| 49 /* | 40 /* |
| 50 * private helpers for compilation by GrGLProgramBuilder | 41 * private helpers for compilation by GrGLProgramBuilder |
| 51 */ | 42 */ |
| 52 void transformToNormalizedDeviceSpace(); | 43 void transformToNormalizedDeviceSpace(); |
| 53 //TODO GP itself should setup the uniform view matrix | 44 //TODO GP itself should setup the uniform view matrix |
| 54 void setupUniformViewMatrix(); | 45 void setupUniformViewMatrix(); |
| 55 void setupPositionAndLocalCoords(); | |
| 56 void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr1* out); | |
| 57 void setupBuiltinVertexAttribute(const char* inName, GrGLSLExpr4* out); | |
| 58 void emitAttributes(const GrGeometryProcessor& gp); | 46 void emitAttributes(const GrGeometryProcessor& gp); |
| 59 void bindVertexAttributes(GrGLuint programID); | 47 void bindVertexAttributes(GrGLuint programID); |
| 60 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; | 48 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids) const; |
| 61 | 49 |
| 62 // an internal call which checks for uniquness of a var before adding it to
the list of inputs | 50 // an internal call which checks for uniquness of a var before adding it to
the list of inputs |
| 63 bool addAttribute(const GrShaderVar& var); | 51 bool addAttribute(const GrShaderVar& var); |
| 64 struct AttributePair { | |
| 65 void set(int index, const SkString& name) { | |
| 66 fIndex = index; fName = name; | |
| 67 } | |
| 68 int fIndex; | |
| 69 SkString fName; | |
| 70 }; | |
| 71 | 52 |
| 72 GrGLShaderVar* fPositionVar; | 53 const char* fRtAdjustName; |
| 73 GrGLShaderVar* fLocalCoordsVar; | |
| 74 const char* fRtAdjustName; | |
| 75 int fEffectAttribOffset; | |
| 76 | 54 |
| 77 friend class GrGLProgramBuilder; | 55 friend class GrGLProgramBuilder; |
| 78 | 56 |
| 79 typedef GrGLShaderBuilder INHERITED; | 57 typedef GrGLShaderBuilder INHERITED; |
| 80 }; | 58 }; |
| 81 | 59 |
| 82 #endif | 60 #endif |
| OLD | NEW |