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 "GrGLGeometryProcessor.h" | 8 #include "GrGLGeometryProcessor.h" |
9 | 9 |
10 #include "builders/GrGLProgramBuilder.h" | 10 #include "builders/GrGLProgramBuilder.h" |
11 #include "glsl/GrGLSLProcessorTypes.h" | 11 #include "glsl/GrGLSLProcessorTypes.h" |
12 | 12 |
13 void GrGLGeometryProcessor::emitCode(EmitArgs& args) { | 13 void GrGLGeometryProcessor::emitCode(EmitArgs& args) { |
14 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 14 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
15 GrGPArgs gpArgs; | 15 GrGPArgs gpArgs; |
16 this->onEmitCode(args, &gpArgs); | 16 this->onEmitCode(args, &gpArgs); |
17 vsBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar); | 17 vsBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar); |
18 } | 18 } |
19 | 19 |
20 void GrGLGeometryProcessor::emitTransforms(GrGLGPBuilder* pb, | 20 void GrGLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb, |
21 const GrShaderVar& posVar, | 21 const GrShaderVar& posVar, |
22 const char* localCoords, | 22 const char* localCoords, |
23 const SkMatrix& localMatrix, | 23 const SkMatrix& localMatrix, |
24 const TransformsIn& tin, | 24 const TransformsIn& tin, |
25 TransformsOut* tout) { | 25 TransformsOut* tout) { |
26 GrGLVertexBuilder* vb = pb->getVertexShaderBuilder(); | 26 GrGLVertexBuilder* vb = pb->getVertexShaderBuilder(); |
27 tout->push_back_n(tin.count()); | 27 tout->push_back_n(tin.count()); |
28 fInstalledTransforms.push_back_n(tin.count()); | 28 fInstalledTransforms.push_back_n(tin.count()); |
29 for (int i = 0; i < tin.count(); i++) { | 29 for (int i = 0; i < tin.count(); i++) { |
30 const ProcCoords& coordTransforms = tin[i]; | 30 const ProcCoords& coordTransforms = tin[i]; |
(...skipping 15 matching lines...) Expand all Loading... |
46 const char* uniName; | 46 const char* uniName; |
47 fInstalledTransforms[i][t].fHandle = | 47 fInstalledTransforms[i][t].fHandle = |
48 pb->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 48 pb->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
49 kMat33f_GrSLType, precision, | 49 kMat33f_GrSLType, precision, |
50 strUniName.c_str(), | 50 strUniName.c_str(), |
51 &uniName).toIndex(); | 51 &uniName).toIndex(); |
52 | 52 |
53 SkString strVaryingName("MatrixCoord"); | 53 SkString strVaryingName("MatrixCoord"); |
54 strVaryingName.appendf("_%i_%i", i, t); | 54 strVaryingName.appendf("_%i_%i", i, t); |
55 | 55 |
56 GrGLVertToFrag v(varyingType); | 56 GrGLSLVertToFrag v(varyingType); |
57 pb->addVarying(strVaryingName.c_str(), &v, precision); | 57 pb->addVarying(strVaryingName.c_str(), &v, precision); |
58 | 58 |
59 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); | 59 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); |
60 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, | 60 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, |
61 (SkString(v.fsIn()), varyingType)); | 61 (SkString(v.fsIn()), varyingType)); |
62 | 62 |
63 // varying = matrix * coords (logically) | 63 // varying = matrix * coords (logically) |
64 if (kDevice_GrCoordSet == coordType) { | 64 if (kDevice_GrCoordSet == coordType) { |
65 if (kVec2f_GrSLType == varyingType) { | 65 if (kVec2f_GrSLType == varyingType) { |
66 if (kVec2f_GrSLType == posVar.getType()) { | 66 if (kVec2f_GrSLType == posVar.getType()) { |
(...skipping 16 matching lines...) Expand all Loading... |
83 if (kVec2f_GrSLType == varyingType) { | 83 if (kVec2f_GrSLType == varyingType) { |
84 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
iName, localCoords); | 84 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
iName, localCoords); |
85 } else { | 85 } else { |
86 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
, localCoords); | 86 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
, localCoords); |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 void GrGLGeometryProcessor::emitTransforms(GrGLGPBuilder* pb, | 93 void GrGLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb, |
94 const char* localCoords, | 94 const char* localCoords, |
95 const TransformsIn& tin, | 95 const TransformsIn& tin, |
96 TransformsOut* tout) { | 96 TransformsOut* tout) { |
97 GrGLVertexBuilder* vb = pb->getVertexShaderBuilder(); | 97 GrGLVertexBuilder* vb = pb->getVertexShaderBuilder(); |
98 tout->push_back_n(tin.count()); | 98 tout->push_back_n(tin.count()); |
99 for (int i = 0; i < tin.count(); i++) { | 99 for (int i = 0; i < tin.count(); i++) { |
100 const ProcCoords& coordTransforms = tin[i]; | 100 const ProcCoords& coordTransforms = tin[i]; |
101 for (int t = 0; t < coordTransforms.count(); t++) { | 101 for (int t = 0; t < coordTransforms.count(); t++) { |
102 GrSLType varyingType = kVec2f_GrSLType; | 102 GrSLType varyingType = kVec2f_GrSLType; |
103 | 103 |
104 // Device coords aren't supported | 104 // Device coords aren't supported |
105 SkASSERT(kDevice_GrCoordSet != coordTransforms[t]->sourceCoords()); | 105 SkASSERT(kDevice_GrCoordSet != coordTransforms[t]->sourceCoords()); |
106 GrSLPrecision precision = coordTransforms[t]->precision(); | 106 GrSLPrecision precision = coordTransforms[t]->precision(); |
107 | 107 |
108 SkString strVaryingName("MatrixCoord"); | 108 SkString strVaryingName("MatrixCoord"); |
109 strVaryingName.appendf("_%i_%i", i, t); | 109 strVaryingName.appendf("_%i_%i", i, t); |
110 | 110 |
111 GrGLVertToFrag v(varyingType); | 111 GrGLSLVertToFrag v(varyingType); |
112 pb->addVarying(strVaryingName.c_str(), &v, precision); | 112 pb->addVarying(strVaryingName.c_str(), &v, precision); |
113 vb->codeAppendf("%s = %s;", v.vsOut(), localCoords); | 113 vb->codeAppendf("%s = %s;", v.vsOut(), localCoords); |
114 | 114 |
115 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], | 115 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], |
116 GrGLSLTransformedCoords, | 116 GrGLSLTransformedCoords, |
117 (SkString(v.fsIn()), varyingType)); | 117 (SkString(v.fsIn()), varyingType)); |
118 } | 118 } |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void GrGLGeometryProcessor::setupPosition(GrGLGPBuilder* pb, | 122 void GrGLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb, |
123 GrGPArgs* gpArgs, | 123 GrGPArgs* gpArgs, |
124 const char* posName) { | 124 const char* posName) { |
125 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 125 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
126 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 126 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
127 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posNam
e); | 127 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posNam
e); |
128 } | 128 } |
129 | 129 |
130 void GrGLGeometryProcessor::setupPosition(GrGLGPBuilder* pb, | 130 void GrGLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb, |
131 GrGPArgs* gpArgs, | 131 GrGPArgs* gpArgs, |
132 const char* posName, | 132 const char* posName, |
133 const SkMatrix& mat, | 133 const SkMatrix& mat, |
134 UniformHandle* viewMatrixUniform) { | 134 UniformHandle* viewMatrixUniform) { |
135 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 135 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
136 if (mat.isIdentity()) { | 136 if (mat.isIdentity()) { |
137 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 137 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
138 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), po
sName); | 138 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), po
sName); |
139 } else { | 139 } else { |
140 const char* viewMatrixName; | 140 const char* viewMatrixName; |
141 *viewMatrixUniform = pb->addUniform(GrGLProgramBuilder::kVertex_Visibili
ty, | 141 *viewMatrixUniform = pb->addUniform(GrGLProgramBuilder::kVertex_Visibili
ty, |
142 kMat33f_GrSLType, kHigh_GrSLPrecisio
n, | 142 kMat33f_GrSLType, kHigh_GrSLPrecisio
n, |
143 "uViewM", | 143 "uViewM", |
144 &viewMatrixName); | 144 &viewMatrixName); |
145 if (!mat.hasPerspective()) { | 145 if (!mat.hasPerspective()) { |
146 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 146 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); |
147 vsBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", | 147 vsBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", |
148 gpArgs->fPositionVar.c_str(), viewMatrixName,
posName); | 148 gpArgs->fPositionVar.c_str(), viewMatrixName,
posName); |
149 } else { | 149 } else { |
150 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); | 150 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); |
151 vsBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", | 151 vsBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", |
152 gpArgs->fPositionVar.c_str(), viewMatrixName,
posName); | 152 gpArgs->fPositionVar.c_str(), viewMatrixName,
posName); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
OLD | NEW |