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