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