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 #include "GrGLVertexShaderBuilder.h" | 8 #include "GrGLVertexShaderBuilder.h" |
9 #include "GrGLProgramBuilder.h" | 9 #include "GrGLProgramBuilder.h" |
10 #include "GrGLShaderStringBuilder.h" | 10 #include "GrGLShaderStringBuilder.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // setup RT Uniform | 46 // setup RT Uniform |
47 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = | 47 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = |
48 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 48 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
49 kVec4f_GrSLType, kDefault_GrSLPrecision, | 49 kVec4f_GrSLType, kDefault_GrSLPrecision, |
50 fProgramBuilder->rtAdjustment(), | 50 fProgramBuilder->rtAdjustment(), |
51 &fRtAdjustName); | 51 &fRtAdjustName); |
52 // Wire transforms | 52 // Wire transforms |
53 SkTArray<GrGLProgramBuilder::TransformVarying, true>& transVs = fProgramBuil
der->fCoordVaryings; | 53 SkTArray<GrGLProgramBuilder::TransformVarying, true>& transVs = fProgramBuil
der->fCoordVaryings; |
54 int transformCount = transVs.count(); | 54 int transformCount = transVs.count(); |
55 for (int i = 0; i < transformCount; i++) { | 55 for (int i = 0; i < transformCount; i++) { |
56 const char* coords = transVs[i].fSourceCoords.c_str(); | 56 GrCoordSet coordSet = transVs[i].fCoordSet; |
| 57 const char* coords; |
| 58 switch (coordSet) { |
| 59 default: |
| 60 SkFAIL("Case missing"); |
| 61 case kPosition_GrCoordSet: |
| 62 coords = this->positionCoords(); |
| 63 break; |
| 64 case kLocal_GrCoordSet: |
| 65 coords = this->localCoords(); |
| 66 break; |
| 67 case kDevice_GrCoordSet: |
| 68 coords = this->glPosition(); |
| 69 break; |
| 70 } |
57 | 71 |
58 // varying = matrix * coords (logically) | 72 // varying = matrix * coords (logically) |
59 const GrGLVarying& v = transVs[i].fV; | 73 const GrGLVarying& v = transVs[i].fV; |
60 if (kVec2f_GrSLType == v.fType) { | 74 if (kDevice_GrCoordSet == coordSet) { |
61 this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, transVs[i
].fUniName.c_str(), | 75 if (kVec2f_GrSLType == v.fType) { |
62 coords); | 76 this->codeAppendf("%s = (%s * %s).xy;", v.fVsOut, transVs[i].fUn
iName.c_str(), |
| 77 coords); |
| 78 } else { |
| 79 this->codeAppendf("%s = %s * %s;", v.fVsOut, transVs[i].fUniName
.c_str(), coords); |
| 80 } |
63 } else { | 81 } else { |
64 this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i].fUn
iName.c_str(), | 82 if (kVec2f_GrSLType == v.fType) { |
65 coords); | 83 this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, trans
Vs[i].fUniName.c_str(), |
| 84 coords); |
| 85 } else { |
| 86 this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i]
.fUniName.c_str(), |
| 87 coords); |
| 88 } |
66 } | 89 } |
67 } | 90 } |
68 | 91 |
69 // Transform from Skia's device coords to GL's normalized device coords. | 92 // Transform from Skia's device coords to GL's normalized device coords. |
70 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw),
0, %s.z);", | 93 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw),
0, %s.z);", |
71 this->glPosition(), fRtAdjustName, this->glPosition(), fRt
AdjustName, | 94 this->glPosition(), fRtAdjustName, this->glPosition(), fRt
AdjustName, |
72 this->glPosition()); | 95 this->glPosition()); |
73 } | 96 } |
74 | 97 |
75 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { | 98 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 for (int i = 0; i < fInputs.count(); ++i) { | 133 for (int i = 0; i < fInputs.count(); ++i) { |
111 const GrGLShaderVar& attr = fInputs[i]; | 134 const GrGLShaderVar& attr = fInputs[i]; |
112 // if attribute already added, don't add it again | 135 // if attribute already added, don't add it again |
113 if (attr.getName().equals(var.getName())) { | 136 if (attr.getName().equals(var.getName())) { |
114 return false; | 137 return false; |
115 } | 138 } |
116 } | 139 } |
117 fInputs.push_back(var); | 140 fInputs.push_back(var); |
118 return true; | 141 return true; |
119 } | 142 } |
OLD | NEW |