Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Side by Side Diff: src/gpu/gl/GrGLGeometryProcessor.cpp

Issue 1441683008: Move GrGLPrimitive/GeometryProc to GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@xferProcs
Patch Set: nits Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLGeometryProcessor.h ('k') | src/gpu/gl/GrGLPrimitiveProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
8 #include "GrGLGeometryProcessor.h"
9
10 #include "glsl/GrGLSLFragmentShaderBuilder.h"
11 #include "glsl/GrGLSLProcessorTypes.h"
12 #include "glsl/GrGLSLProgramBuilder.h"
13 #include "glsl/GrGLSLVertexShaderBuilder.h"
14
15 void GrGLGeometryProcessor::emitCode(EmitArgs& args) {
16 GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
17 GrGPArgs gpArgs;
18 this->onEmitCode(args, &gpArgs);
19 vsBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar);
20 }
21
22 void GrGLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
23 const GrShaderVar& posVar,
24 const char* localCoords,
25 const SkMatrix& localMatrix,
26 const TransformsIn& tin,
27 TransformsOut* tout) {
28 GrGLSLVertexBuilder* vb = pb->getVertexShaderBuilder();
29 tout->push_back_n(tin.count());
30 fInstalledTransforms.push_back_n(tin.count());
31 for (int i = 0; i < tin.count(); i++) {
32 const ProcCoords& coordTransforms = tin[i];
33 fInstalledTransforms[i].push_back_n(coordTransforms.count());
34 for (int t = 0; t < coordTransforms.count(); t++) {
35 SkString strUniName("StageMatrix");
36 strUniName.appendf("_%i_%i", i, t);
37 GrSLType varyingType;
38
39 GrCoordSet coordType = coordTransforms[t]->sourceCoords();
40 uint32_t type = coordTransforms[t]->getMatrix().getType();
41 if (kLocal_GrCoordSet == coordType) {
42 type |= localMatrix.getType();
43 }
44 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_ GrSLType :
45 kVec2f_ GrSLType;
46 GrSLPrecision precision = coordTransforms[t]->precision();
47
48 const char* uniName;
49 fInstalledTransforms[i][t].fHandle =
50 pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
51 kMat33f_GrSLType, precision,
52 strUniName.c_str(),
53 &uniName).toIndex();
54
55 SkString strVaryingName("MatrixCoord");
56 strVaryingName.appendf("_%i_%i", i, t);
57
58 GrGLSLVertToFrag v(varyingType);
59 pb->addVarying(strVaryingName.c_str(), &v, precision);
60
61 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin gType);
62 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords,
63 (SkString(v.fsIn()), varyingType));
64
65 // varying = matrix * coords (logically)
66 if (kDevice_GrCoordSet == coordType) {
67 if (kVec2f_GrSLType == varyingType) {
68 if (kVec2f_GrSLType == posVar.getType()) {
69 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
70 v.vsOut(), uniName, posVar.c_str());
71 } else {
72 // The brackets here are just to scope the temp variable
73 vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVa r.c_str());
74 vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z) ; }", v.vsOut());
75 }
76 } else {
77 if (kVec2f_GrSLType == posVar.getType()) {
78 vb->codeAppendf("%s = %s * vec3(%s, 1);",
79 v.vsOut(), uniName, posVar.c_str());
80 } else {
81 vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, pos Var.c_str());
82 }
83 }
84 } else {
85 if (kVec2f_GrSLType == varyingType) {
86 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un iName, localCoords);
87 } else {
88 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName , localCoords);
89 }
90 }
91 }
92 }
93 }
94
95 void GrGLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
96 const char* localCoords,
97 const TransformsIn& tin,
98 TransformsOut* tout) {
99 GrGLSLVertexBuilder* vb = pb->getVertexShaderBuilder();
100 tout->push_back_n(tin.count());
101 for (int i = 0; i < tin.count(); i++) {
102 const ProcCoords& coordTransforms = tin[i];
103 for (int t = 0; t < coordTransforms.count(); t++) {
104 GrSLType varyingType = kVec2f_GrSLType;
105
106 // Device coords aren't supported
107 SkASSERT(kDevice_GrCoordSet != coordTransforms[t]->sourceCoords());
108 GrSLPrecision precision = coordTransforms[t]->precision();
109
110 SkString strVaryingName("MatrixCoord");
111 strVaryingName.appendf("_%i_%i", i, t);
112
113 GrGLSLVertToFrag v(varyingType);
114 pb->addVarying(strVaryingName.c_str(), &v, precision);
115 vb->codeAppendf("%s = %s;", v.vsOut(), localCoords);
116
117 SkNEW_APPEND_TO_TARRAY(&(*tout)[i],
118 GrGLSLTransformedCoords,
119 (SkString(v.fsIn()), varyingType));
120 }
121 }
122 }
123
124 void GrGLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
125 GrGPArgs* gpArgs,
126 const char* posName) {
127 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
128 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
129 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posNam e);
130 }
131
132 void GrGLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
133 GrGPArgs* gpArgs,
134 const char* posName,
135 const SkMatrix& mat,
136 UniformHandle* viewMatrixUniform) {
137 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
138 if (mat.isIdentity()) {
139 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
140 vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), po sName);
141 } else {
142 const char* viewMatrixName;
143 *viewMatrixUniform = pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibi lity,
144 kMat33f_GrSLType, kHigh_GrSLPrecisio n,
145 "uViewM",
146 &viewMatrixName);
147 if (!mat.hasPerspective()) {
148 gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
149 vsBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));",
150 gpArgs->fPositionVar.c_str(), viewMatrixName, posName);
151 } else {
152 gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3");
153 vsBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);",
154 gpArgs->fPositionVar.c_str(), viewMatrixName, posName);
155 }
156 }
157 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGeometryProcessor.h ('k') | src/gpu/gl/GrGLPrimitiveProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698