| 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 "GrGLSLGeometryProcessor.h" | 8 #include "GrGLSLGeometryProcessor.h" |
| 9 | 9 |
| 10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 args.fVaryingHandler->setNoPerspective(); | 22 args.fVaryingHandler->setNoPerspective(); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, | 26 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, |
| 27 GrGLSLVaryingHandler* varyingHandle
r, | 27 GrGLSLVaryingHandler* varyingHandle
r, |
| 28 GrGLSLUniformHandler* uniformHandle
r, | 28 GrGLSLUniformHandler* uniformHandle
r, |
| 29 const GrShaderVar& posVar, | 29 const GrShaderVar& posVar, |
| 30 const char* localCoords, | 30 const char* localCoords, |
| 31 const SkMatrix& localMatrix, | 31 const SkMatrix& localMatrix, |
| 32 const TransformsIn& tin, | 32 FPCoordTransformHandler* handler) { |
| 33 TransformsOut* tout) { | 33 int i = 0; |
| 34 tout->push_back_n(tin.count()); | 34 while (const GrCoordTransform* coordTransform = handler->nextCoordTransform(
)) { |
| 35 fInstalledTransforms.push_back_n(tin.count()); | 35 SkString strUniName; |
| 36 for (int i = 0; i < tin.count(); i++) { | 36 strUniName.printf("CoordTransformMatrix_%d", i); |
| 37 const ProcCoords& coordTransforms = tin[i]; | 37 GrSLType varyingType; |
| 38 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | |
| 39 for (int t = 0; t < coordTransforms.count(); t++) { | |
| 40 SkString strUniName("StageMatrix"); | |
| 41 strUniName.appendf("_%i_%i", i, t); | |
| 42 GrSLType varyingType; | |
| 43 | 38 |
| 44 GrCoordSet coordType = coordTransforms[t]->sourceCoords(); | 39 GrCoordSet coordType = coordTransform->sourceCoords(); |
| 45 uint32_t type = coordTransforms[t]->getMatrix().getType(); | 40 uint32_t type = coordTransform->getMatrix().getType(); |
| 46 if (kLocal_GrCoordSet == coordType) { | 41 if (kLocal_GrCoordSet == coordType) { |
| 47 type |= localMatrix.getType(); | 42 type |= localMatrix.getType(); |
| 48 } | 43 } |
| 49 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_
GrSLType : | 44 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSL
Type : |
| 50 kVec2f_
GrSLType; | 45 kVec2f_GrSL
Type; |
| 51 GrSLPrecision precision = coordTransforms[t]->precision(); | 46 GrSLPrecision precision = coordTransform->precision(); |
| 52 | 47 |
| 53 const char* uniName; | 48 const char* uniName; |
| 54 fInstalledTransforms[i][t].fHandle = | |
| 55 uniformHandler->addUniform(kVertex_GrShaderFlag, | |
| 56 kMat33f_GrSLType, precision, | |
| 57 strUniName.c_str(), | |
| 58 &uniName).toIndex(); | |
| 59 | 49 |
| 60 SkString strVaryingName("MatrixCoord"); | |
| 61 strVaryingName.appendf("_%i_%i", i, t); | |
| 62 | 50 |
| 63 GrGLSLVertToFrag v(varyingType); | 51 fInstalledTransforms.push_back().fHandle = uniformHandler->addUniform(kV
ertex_GrShaderFlag, |
| 64 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); | 52 kM
at33f_GrSLType, |
| 53 pr
ecision, |
| 54 st
rUniName.c_str(), |
| 55 &u
niName).toIndex(); |
| 56 SkString strVaryingName; |
| 57 strVaryingName.printf("TransformedCoords_%d", i); |
| 65 | 58 |
| 66 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); | 59 GrGLSLVertToFrag v(varyingType); |
| 67 (*tout)[i].emplace_back(SkString(v.fsIn()), varyingType); | 60 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); |
| 68 | 61 |
| 69 // varying = matrix * coords (logically) | 62 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); |
| 70 if (kDevice_GrCoordSet == coordType) { | 63 handler->specifyCoordsForCurrCoordTransform(SkString(v.fsIn()), varyingT
ype); |
| 71 if (kVec2f_GrSLType == varyingType) { | 64 |
| 72 if (kVec2f_GrSLType == posVar.getType()) { | 65 // varying = matrix * coords (logically) |
| 73 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", | 66 if (kDevice_GrCoordSet == coordType) { |
| 74 v.vsOut(), uniName, posVar.c_str()); | 67 if (kVec2f_GrSLType == varyingType) { |
| 75 } else { | 68 if (kVec2f_GrSLType == posVar.getType()) { |
| 76 // The brackets here are just to scope the temp variable | 69 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", |
| 77 vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVa
r.c_str()); | 70 v.vsOut(), uniName, posVar.c_str()); |
| 78 vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z)
; }", v.vsOut()); | |
| 79 } | |
| 80 } else { | 71 } else { |
| 81 if (kVec2f_GrSLType == posVar.getType()) { | 72 // The brackets here are just to scope the temp variable |
| 82 vb->codeAppendf("%s = %s * vec3(%s, 1);", | 73 vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_
str()); |
| 83 v.vsOut(), uniName, posVar.c_str()); | 74 vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }"
, v.vsOut()); |
| 84 } else { | |
| 85 vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, pos
Var.c_str()); | |
| 86 } | |
| 87 } | 75 } |
| 88 } else { | 76 } else { |
| 89 if (kVec2f_GrSLType == varyingType) { | 77 if (kVec2f_GrSLType == posVar.getType()) { |
| 90 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
iName, localCoords); | 78 vb->codeAppendf("%s = %s * vec3(%s, 1);", |
| 79 v.vsOut(), uniName, posVar.c_str()); |
| 91 } else { | 80 } else { |
| 92 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
, localCoords); | 81 vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.
c_str()); |
| 93 } | 82 } |
| 94 } | 83 } |
| 84 } else { |
| 85 if (kVec2f_GrSLType == varyingType) { |
| 86 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniNam
e, localCoords); |
| 87 } else { |
| 88 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, lo
calCoords); |
| 89 } |
| 95 } | 90 } |
| 91 ++i; |
| 96 } | 92 } |
| 97 } | 93 } |
| 98 | 94 |
| 95 void GrGLSLGeometryProcessor::setTransformDataHelper(const SkMatrix& localMatrix
, |
| 96 const GrGLSLProgramDataMana
ger& pdman, |
| 97 FPCoordTransformIter* trans
formIter) { |
| 98 int i = 0; |
| 99 while (const GrCoordTransform* coordTransform = transformIter->next()) { |
| 100 const SkMatrix& m = GetTransformMatrix(localMatrix, *coordTransform); |
| 101 if (!fInstalledTransforms[i].fCurrentValue.cheapEqualTo(m)) { |
| 102 pdman.setSkMatrix(fInstalledTransforms[i].fHandle.toIndex(), m); |
| 103 fInstalledTransforms[i].fCurrentValue = m; |
| 104 } |
| 105 ++i; |
| 106 } |
| 107 SkASSERT(i == fInstalledTransforms.count()); |
| 108 } |
| 109 |
| 99 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 110 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, |
| 100 GrGPArgs* gpArgs, | 111 GrGPArgs* gpArgs, |
| 101 const char* posName) { | 112 const char* posName) { |
| 102 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 113 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
| 103 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
ame); | 114 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
ame); |
| 104 } | 115 } |
| 105 | 116 |
| 106 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 117 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, |
| 107 GrGLSLUniformHandler* uniformHandler
, | 118 GrGLSLUniformHandler* uniformHandler
, |
| 108 GrGPArgs* gpArgs, | 119 GrGPArgs* gpArgs, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 122 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 133 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
| 123 vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", | 134 vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", |
| 124 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); | 135 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); |
| 125 } else { | 136 } else { |
| 126 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); | 137 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); |
| 127 vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", | 138 vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", |
| 128 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); | 139 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); |
| 129 } | 140 } |
| 130 } | 141 } |
| 131 } | 142 } |
| OLD | NEW |