| 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 "glsl/GrGLSLFragmentShaderBuilder.h" | 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 11 #include "glsl/GrGLSLProcessorTypes.h" | 12 #include "glsl/GrGLSLProcessorTypes.h" |
| 12 #include "glsl/GrGLSLProgramBuilder.h" | 13 #include "glsl/GrGLSLUniformHandler.h" |
| 13 #include "glsl/GrGLSLVarying.h" | 14 #include "glsl/GrGLSLVarying.h" |
| 14 #include "glsl/GrGLSLVertexShaderBuilder.h" | 15 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 15 | 16 |
| 16 void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) { | 17 void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) { |
| 17 GrGLSLVertexBuilder* vBuilder = args.fVertBuilder; | 18 GrGLSLVertexBuilder* vBuilder = args.fVertBuilder; |
| 18 GrGPArgs gpArgs; | 19 GrGPArgs gpArgs; |
| 19 this->onEmitCode(args, &gpArgs); | 20 this->onEmitCode(args, &gpArgs); |
| 20 vBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar); | 21 vBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb, | 24 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, |
| 24 GrGLSLVertexBuilder* vb, | |
| 25 GrGLSLVaryingHandler* varyingHandle
r, | 25 GrGLSLVaryingHandler* varyingHandle
r, |
| 26 GrGLSLUniformHandler* uniformHandle
r, |
| 26 const GrShaderVar& posVar, | 27 const GrShaderVar& posVar, |
| 27 const char* localCoords, | 28 const char* localCoords, |
| 28 const SkMatrix& localMatrix, | 29 const SkMatrix& localMatrix, |
| 29 const TransformsIn& tin, | 30 const TransformsIn& tin, |
| 30 TransformsOut* tout) { | 31 TransformsOut* tout) { |
| 31 tout->push_back_n(tin.count()); | 32 tout->push_back_n(tin.count()); |
| 32 fInstalledTransforms.push_back_n(tin.count()); | 33 fInstalledTransforms.push_back_n(tin.count()); |
| 33 for (int i = 0; i < tin.count(); i++) { | 34 for (int i = 0; i < tin.count(); i++) { |
| 34 const ProcCoords& coordTransforms = tin[i]; | 35 const ProcCoords& coordTransforms = tin[i]; |
| 35 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 36 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
| 36 for (int t = 0; t < coordTransforms.count(); t++) { | 37 for (int t = 0; t < coordTransforms.count(); t++) { |
| 37 SkString strUniName("StageMatrix"); | 38 SkString strUniName("StageMatrix"); |
| 38 strUniName.appendf("_%i_%i", i, t); | 39 strUniName.appendf("_%i_%i", i, t); |
| 39 GrSLType varyingType; | 40 GrSLType varyingType; |
| 40 | 41 |
| 41 GrCoordSet coordType = coordTransforms[t]->sourceCoords(); | 42 GrCoordSet coordType = coordTransforms[t]->sourceCoords(); |
| 42 uint32_t type = coordTransforms[t]->getMatrix().getType(); | 43 uint32_t type = coordTransforms[t]->getMatrix().getType(); |
| 43 if (kLocal_GrCoordSet == coordType) { | 44 if (kLocal_GrCoordSet == coordType) { |
| 44 type |= localMatrix.getType(); | 45 type |= localMatrix.getType(); |
| 45 } | 46 } |
| 46 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_
GrSLType : | 47 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_
GrSLType : |
| 47 kVec2f_
GrSLType; | 48 kVec2f_
GrSLType; |
| 48 GrSLPrecision precision = coordTransforms[t]->precision(); | 49 GrSLPrecision precision = coordTransforms[t]->precision(); |
| 49 | 50 |
| 50 const char* uniName; | 51 const char* uniName; |
| 51 fInstalledTransforms[i][t].fHandle = | 52 fInstalledTransforms[i][t].fHandle = |
| 52 pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility, | 53 uniformHandler->addUniform(GrGLSLUniformHandler::kVertex_Vis
ibility, |
| 53 kMat33f_GrSLType, precision, | 54 kMat33f_GrSLType, precision, |
| 54 strUniName.c_str(), | 55 strUniName.c_str(), |
| 55 &uniName).toIndex(); | 56 &uniName).toIndex(); |
| 56 | 57 |
| 57 SkString strVaryingName("MatrixCoord"); | 58 SkString strVaryingName("MatrixCoord"); |
| 58 strVaryingName.appendf("_%i_%i", i, t); | 59 strVaryingName.appendf("_%i_%i", i, t); |
| 59 | 60 |
| 60 GrGLSLVertToFrag v(varyingType); | 61 GrGLSLVertToFrag v(varyingType); |
| 61 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); | 62 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); |
| 62 | 63 |
| 63 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); | 64 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); |
| 64 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, | 65 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, |
| 65 (SkString(v.fsIn()), varyingType)); | 66 (SkString(v.fsIn()), varyingType)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 87 if (kVec2f_GrSLType == varyingType) { | 88 if (kVec2f_GrSLType == varyingType) { |
| 88 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
iName, localCoords); | 89 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
iName, localCoords); |
| 89 } else { | 90 } else { |
| 90 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
, localCoords); | 91 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
, localCoords); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb, | 98 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, |
| 98 GrGLSLVertexBuilder* vb, | |
| 99 GrGLSLVaryingHandler* varyingHandle
r, | 99 GrGLSLVaryingHandler* varyingHandle
r, |
| 100 const char* localCoords, | 100 const char* localCoords, |
| 101 const TransformsIn& tin, | 101 const TransformsIn& tin, |
| 102 TransformsOut* tout) { | 102 TransformsOut* tout) { |
| 103 tout->push_back_n(tin.count()); | 103 tout->push_back_n(tin.count()); |
| 104 for (int i = 0; i < tin.count(); i++) { | 104 for (int i = 0; i < tin.count(); i++) { |
| 105 const ProcCoords& coordTransforms = tin[i]; | 105 const ProcCoords& coordTransforms = tin[i]; |
| 106 for (int t = 0; t < coordTransforms.count(); t++) { | 106 for (int t = 0; t < coordTransforms.count(); t++) { |
| 107 GrSLType varyingType = kVec2f_GrSLType; | 107 GrSLType varyingType = kVec2f_GrSLType; |
| 108 | 108 |
| 109 // Device coords aren't supported | 109 // Device coords aren't supported |
| 110 SkASSERT(kDevice_GrCoordSet != coordTransforms[t]->sourceCoords()); | 110 SkASSERT(kDevice_GrCoordSet != coordTransforms[t]->sourceCoords()); |
| 111 GrSLPrecision precision = coordTransforms[t]->precision(); | 111 GrSLPrecision precision = coordTransforms[t]->precision(); |
| 112 | 112 |
| 113 SkString strVaryingName("MatrixCoord"); | 113 SkString strVaryingName("MatrixCoord"); |
| 114 strVaryingName.appendf("_%i_%i", i, t); | 114 strVaryingName.appendf("_%i_%i", i, t); |
| 115 | 115 |
| 116 GrGLSLVertToFrag v(varyingType); | 116 GrGLSLVertToFrag v(varyingType); |
| 117 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); | 117 varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); |
| 118 vb->codeAppendf("%s = %s;", v.vsOut(), localCoords); | 118 vb->codeAppendf("%s = %s;", v.vsOut(), localCoords); |
| 119 | 119 |
| 120 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], | 120 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], |
| 121 GrGLSLTransformedCoords, | 121 GrGLSLTransformedCoords, |
| 122 (SkString(v.fsIn()), varyingType)); | 122 (SkString(v.fsIn()), varyingType)); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void GrGLSLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb, | 127 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, |
| 128 GrGLSLVertexBuilder* vertBuilder, | |
| 129 GrGPArgs* gpArgs, | 128 GrGPArgs* gpArgs, |
| 130 const char* posName) { | 129 const char* posName) { |
| 131 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 130 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
| 132 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
ame); | 131 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
ame); |
| 133 } | 132 } |
| 134 | 133 |
| 135 void GrGLSLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb, | 134 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, |
| 136 GrGLSLVertexBuilder* vertBuilder, | 135 GrGLSLUniformHandler* uniformHandler
, |
| 137 GrGPArgs* gpArgs, | 136 GrGPArgs* gpArgs, |
| 138 const char* posName, | 137 const char* posName, |
| 139 const SkMatrix& mat, | 138 const SkMatrix& mat, |
| 140 UniformHandle* viewMatrixUniform) { | 139 UniformHandle* viewMatrixUniform) { |
| 141 if (mat.isIdentity()) { | 140 if (mat.isIdentity()) { |
| 142 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 141 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
| 143 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(),
posName); | 142 vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(),
posName); |
| 144 } else { | 143 } else { |
| 145 const char* viewMatrixName; | 144 const char* viewMatrixName; |
| 146 *viewMatrixUniform = pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibi
lity, | 145 *viewMatrixUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kV
ertex_Visibility, |
| 147 kMat33f_GrSLType, kHigh_GrSLPrecisio
n, | 146 kMat33f_GrSLType, kHigh_
GrSLPrecision, |
| 148 "uViewM", | 147 "uViewM", |
| 149 &viewMatrixName); | 148 &viewMatrixName); |
| 150 if (!mat.hasPerspective()) { | 149 if (!mat.hasPerspective()) { |
| 151 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 150 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
| 152 vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", | 151 vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", |
| 153 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); | 152 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); |
| 154 } else { | 153 } else { |
| 155 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); | 154 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); |
| 156 vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", | 155 vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", |
| 157 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); | 156 gpArgs->fPositionVar.c_str(), viewMatrixNam
e, posName); |
| 158 } | 157 } |
| 159 } | 158 } |
| 160 } | 159 } |
| OLD | NEW |