joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrCoordTransform.h" |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrPipeline.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 13 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 14 | #include "src/gpu/glsl/GrGLSLVarying.h" |
| 15 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 16 | |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 17 | #include <unordered_map> |
| 18 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 19 | void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 20 | GrGPArgs gpArgs; |
| 21 | this->onEmitCode(args, &gpArgs); |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 22 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 23 | if (args.fGP.willUseTessellationShaders()) { |
| 24 | // Tessellation shaders are temporarily responsible for integrating their own code strings |
| 25 | // while we work out full support. |
| 26 | return; |
| 27 | } |
| 28 | |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 29 | GrGLSLVertexBuilder* vBuilder = args.fVertBuilder; |
| 30 | if (!args.fGP.willUseGeoShader()) { |
| 31 | // Emit the vertex position to the hardware in the normalized window coordinates it expects. |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 32 | SkASSERT(kFloat2_GrSLType == gpArgs.fPositionVar.getType() || |
| 33 | kFloat3_GrSLType == gpArgs.fPositionVar.getType()); |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 34 | vBuilder->emitNormalizedSkPosition(gpArgs.fPositionVar.c_str(), args.fRTAdjustName, |
| 35 | gpArgs.fPositionVar.getType()); |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 36 | if (kFloat2_GrSLType == gpArgs.fPositionVar.getType()) { |
| 37 | args.fVaryingHandler->setNoPerspective(); |
| 38 | } |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 39 | } else { |
| 40 | // Since we have a geometry shader, leave the vertex position in Skia device space for now. |
| 41 | // The geometry Shader will operate in device space, and then convert the final positions to |
| 42 | // normalized hardware window coordinates under the hood, once everything else has finished. |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 43 | // The subclass must call setNoPerspective on the varying handler, if applicable. |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 44 | vBuilder->codeAppendf("sk_Position = float4(%s", gpArgs.fPositionVar.c_str()); |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 45 | switch (gpArgs.fPositionVar.getType()) { |
| 46 | case kFloat_GrSLType: |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame^] | 47 | vBuilder->codeAppend(", 0"); |
| 48 | [[fallthrough]]; |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 49 | case kFloat2_GrSLType: |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame^] | 50 | vBuilder->codeAppend(", 0"); |
| 51 | [[fallthrough]]; |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 52 | case kFloat3_GrSLType: |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame^] | 53 | vBuilder->codeAppend(", 1"); |
| 54 | [[fallthrough]]; |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 55 | case kFloat4_GrSLType: |
| 56 | vBuilder->codeAppend(");"); |
| 57 | break; |
| 58 | default: |
| 59 | SK_ABORT("Invalid position var type"); |
| 60 | break; |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 61 | } |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 62 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 63 | } |
| 64 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 65 | void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 66 | GrGLSLVaryingHandler* varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 67 | GrGLSLUniformHandler* uniformHandler, |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 68 | const GrShaderVar& localCoordsVar, |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 69 | const SkMatrix& localMatrix, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 70 | FPCoordTransformHandler* handler) { |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 71 | // We only require localCoordsVar to be valid if there is a coord transform that needs |
| 72 | // it. CTs on FPs called with explicit coords do not require a local coord. |
| 73 | auto getLocalCoords = [&localCoordsVar, |
| 74 | localCoords = SkString(), |
| 75 | localCoordLength = int()]() mutable { |
| 76 | if (localCoords.isEmpty()) { |
| 77 | localCoordLength = GrSLTypeVecLength(localCoordsVar.getType()); |
| 78 | SkASSERT(GrSLTypeIsFloatType(localCoordsVar.getType())); |
| 79 | SkASSERT(localCoordLength == 2 || localCoordLength == 3); |
| 80 | if (localCoordLength == 3) { |
| 81 | localCoords = localCoordsVar.getName(); |
| 82 | } else { |
| 83 | localCoords.printf("float3(%s, 1)", localCoordsVar.c_str()); |
| 84 | } |
| 85 | } |
| 86 | return std::make_tuple(localCoords, localCoordLength); |
| 87 | }; |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 88 | |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 89 | GrShaderVar transformVar; |
Brian Salomon | 7d8b397 | 2019-11-26 22:34:44 -0500 | [diff] [blame] | 90 | for (int i = 0; *handler; ++*handler, ++i) { |
| 91 | auto [coordTransform, fp] = handler->get(); |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 92 | // Add uniform for coord transform matrix. |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 93 | SkString matrix; |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 94 | if (!fp.isSampledWithExplicitCoords() || !coordTransform.isNoOp()) { |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 95 | SkString strUniName; |
| 96 | strUniName.printf("CoordTransformMatrix_%d", i); |
Brian Salomon | 2fade72 | 2020-03-20 12:35:32 -0400 | [diff] [blame] | 97 | auto flag = fp.isSampledWithExplicitCoords() ? kFragment_GrShaderFlag |
| 98 | : kVertex_GrShaderFlag; |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 99 | auto& uni = fInstalledTransforms.push_back(); |
Brian Salomon | 14ed885 | 2020-03-24 10:43:38 -0400 | [diff] [blame] | 100 | if (fp.isSampledWithExplicitCoords() && coordTransform.matrix().isScaleTranslate()) { |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 101 | uni.fType = kFloat4_GrSLType; |
| 102 | } else { |
| 103 | uni.fType = kFloat3x3_GrSLType; |
| 104 | } |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 105 | const char* matrixName; |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 106 | uni.fHandle = |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 107 | uniformHandler->addUniform(&fp, flag, uni.fType, strUniName.c_str(), |
| 108 | &matrixName); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 109 | matrix = matrixName; |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 110 | transformVar = uniformHandler->getUniformVariable(uni.fHandle); |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 111 | } else { |
| 112 | // Install a coord transform that will be skipped. |
| 113 | fInstalledTransforms.push_back(); |
| 114 | handler->omitCoordsForCurrCoordTransform(); |
| 115 | continue; |
| 116 | } |
| 117 | |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 118 | GrShaderVar fsVar; |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 119 | // Add varying if required and register varying and matrix uniform. |
| 120 | if (!fp.isSampledWithExplicitCoords()) { |
| 121 | auto [localCoordsStr, localCoordLength] = getLocalCoords(); |
| 122 | GrGLSLVarying v(kFloat2_GrSLType); |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 123 | if (localMatrix.hasPerspective() || coordTransform.matrix().hasPerspective() || |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 124 | localCoordLength == 3) { |
| 125 | v = GrGLSLVarying(kFloat3_GrSLType); |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame] | 126 | } |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 127 | SkString strVaryingName; |
| 128 | strVaryingName.printf("TransformedCoords_%d", i); |
Brian Salomon | 706851d | 2020-02-20 14:18:00 -0500 | [diff] [blame] | 129 | varyingHandler->addVarying(strVaryingName.c_str(), &v); |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 130 | |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 131 | SkASSERT(fInstalledTransforms.back().fType == kFloat3x3_GrSLType); |
Ethan Nicholas | bffad83 | 2020-05-05 14:31:55 -0400 | [diff] [blame] | 132 | if (fp.sampleMatrix().fKind != SkSL::SampleMatrix::Kind::kConstantOrUniform) { |
| 133 | if (v.type() == kFloat2_GrSLType) { |
| 134 | vb->codeAppendf("%s = (%s * %s).xy;", v.vsOut(), matrix.c_str(), |
| 135 | localCoordsStr.c_str()); |
| 136 | } else { |
| 137 | vb->codeAppendf("%s = %s * %s;", v.vsOut(), matrix.c_str(), |
| 138 | localCoordsStr.c_str()); |
| 139 | } |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 140 | } |
Ben Wagner | dabd98c | 2020-03-25 15:17:18 -0400 | [diff] [blame] | 141 | fsVar = GrShaderVar(SkString(v.fsIn()), v.type(), GrShaderVar::TypeModifier::In); |
Ethan Nicholas | afe2c90 | 2020-04-28 13:55:02 -0400 | [diff] [blame] | 142 | fTransformInfos.push_back({ v.vsOut(), v.type(), matrix, localCoordsStr, &fp }); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 143 | } |
Ethan Nicholas | afe2c90 | 2020-04-28 13:55:02 -0400 | [diff] [blame] | 144 | handler->specifyCoordsForCurrCoordTransform(transformVar, fsVar); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | void GrGLSLGeometryProcessor::emitTransformCode(GrGLSLVertexBuilder* vb, |
| 149 | GrGLSLUniformHandler* uniformHandler) { |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 150 | std::unordered_map<const GrFragmentProcessor*, const char*> localCoordsMap; |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 151 | for (const auto& tr : fTransformInfos) { |
| 152 | switch (tr.fFP->sampleMatrix().fKind) { |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 153 | case SkSL::SampleMatrix::Kind::kConstantOrUniform: { |
| 154 | SkString localCoords; |
| 155 | localCoordsMap.insert({ tr.fFP, tr.fName }); |
| 156 | if (tr.fFP->sampleMatrix().fBase) { |
| 157 | SkASSERT(localCoordsMap[tr.fFP->sampleMatrix().fBase]); |
| 158 | localCoords = SkStringPrintf("float3(%s, 1)", |
| 159 | localCoordsMap[tr.fFP->sampleMatrix().fBase]); |
| 160 | } else { |
| 161 | localCoords = tr.fLocalCoords.c_str(); |
| 162 | } |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 163 | vb->codeAppend("{\n"); |
| 164 | uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb); |
| 165 | if (tr.fType == kFloat2_GrSLType) { |
| 166 | vb->codeAppendf("%s = (%s * %s * %s).xy", tr.fName, |
Ethan Nicholas | afe2c90 | 2020-04-28 13:55:02 -0400 | [diff] [blame] | 167 | tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(), |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 168 | localCoords.c_str()); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 169 | } else { |
| 170 | SkASSERT(tr.fType == kFloat3_GrSLType); |
| 171 | vb->codeAppendf("%s = %s * %s * %s", tr.fName, |
Ethan Nicholas | afe2c90 | 2020-04-28 13:55:02 -0400 | [diff] [blame] | 172 | tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(), |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 173 | localCoords.c_str()); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 174 | } |
| 175 | vb->codeAppend(";\n"); |
| 176 | vb->codeAppend("}\n"); |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame^] | 177 | break; |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 178 | } |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 179 | default: |
| 180 | break; |
| 181 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 185 | void GrGLSLGeometryProcessor::setTransformDataHelper(const SkMatrix& localMatrix, |
| 186 | const GrGLSLProgramDataManager& pdman, |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 187 | const CoordTransformRange& transformRange) { |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 188 | int i = 0; |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 189 | for (auto [transform, fp] : transformRange) { |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 190 | if (fInstalledTransforms[i].fHandle.isValid()) { |
| 191 | SkMatrix m; |
Brian Salomon | b10a662 | 2020-02-20 13:36:01 -0500 | [diff] [blame] | 192 | if (fp.isSampledWithExplicitCoords()) { |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 193 | m = GetTransformMatrix(transform, SkMatrix::I()); |
Brian Salomon | b10a662 | 2020-02-20 13:36:01 -0500 | [diff] [blame] | 194 | } else { |
| 195 | m = GetTransformMatrix(transform, localMatrix); |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 196 | } |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 197 | if (!SkMatrixPriv::CheapEqual(fInstalledTransforms[i].fCurrentValue, m)) { |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 198 | if (fInstalledTransforms[i].fType == kFloat4_GrSLType) { |
| 199 | float values[4] = {m.getScaleX(), m.getTranslateX(), |
| 200 | m.getScaleY(), m.getTranslateY()}; |
Brian Salomon | 14ed885 | 2020-03-24 10:43:38 -0400 | [diff] [blame] | 201 | SkASSERT(m.isScaleTranslate()); |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 202 | pdman.set4fv(fInstalledTransforms[i].fHandle.toIndex(), 1, values); |
| 203 | } else { |
Brian Salomon | 14ed885 | 2020-03-24 10:43:38 -0400 | [diff] [blame] | 204 | SkASSERT(!m.isScaleTranslate() || !fp.isSampledWithExplicitCoords()); |
Brian Salomon | 8d1dcd7 | 2020-03-20 21:06:41 -0400 | [diff] [blame] | 205 | SkASSERT(fInstalledTransforms[i].fType == kFloat3x3_GrSLType); |
| 206 | pdman.setSkMatrix(fInstalledTransforms[i].fHandle.toIndex(), m); |
| 207 | } |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 208 | fInstalledTransforms[i].fCurrentValue = m; |
| 209 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 210 | } |
| 211 | ++i; |
| 212 | } |
| 213 | SkASSERT(i == fInstalledTransforms.count()); |
| 214 | } |
| 215 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 216 | void GrGLSLGeometryProcessor::writeOutputPosition(GrGLSLVertexBuilder* vertBuilder, |
| 217 | GrGPArgs* gpArgs, |
| 218 | const char* posName) { |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 219 | gpArgs->fPositionVar.set(kFloat2_GrSLType, "pos2"); |
| 220 | vertBuilder->codeAppendf("float2 %s = %s;", gpArgs->fPositionVar.c_str(), posName); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 223 | void GrGLSLGeometryProcessor::writeOutputPosition(GrGLSLVertexBuilder* vertBuilder, |
| 224 | GrGLSLUniformHandler* uniformHandler, |
| 225 | GrGPArgs* gpArgs, |
| 226 | const char* posName, |
| 227 | const SkMatrix& mat, |
| 228 | UniformHandle* viewMatrixUniform) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 229 | if (mat.isIdentity()) { |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 230 | gpArgs->fPositionVar.set(kFloat2_GrSLType, "pos2"); |
| 231 | vertBuilder->codeAppendf("float2 %s = %s;", gpArgs->fPositionVar.c_str(), posName); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 232 | } else { |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 233 | const char* viewMatrixName; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 234 | *viewMatrixUniform = uniformHandler->addUniform(nullptr, |
| 235 | kVertex_GrShaderFlag, |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 236 | kFloat3x3_GrSLType, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 237 | "uViewM", |
| 238 | &viewMatrixName); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 239 | if (!mat.hasPerspective()) { |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 240 | gpArgs->fPositionVar.set(kFloat2_GrSLType, "pos2"); |
| 241 | vertBuilder->codeAppendf("float2 %s = (%s * float3(%s, 1)).xy;", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 242 | gpArgs->fPositionVar.c_str(), viewMatrixName, posName); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 243 | } else { |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 244 | gpArgs->fPositionVar.set(kFloat3_GrSLType, "pos3"); |
| 245 | vertBuilder->codeAppendf("float3 %s = %s * float3(%s, 1);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 246 | gpArgs->fPositionVar.c_str(), viewMatrixName, posName); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 247 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 248 | } |
| 249 | } |