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 "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLSLPrettyPrint.h" | 10 #include "gl/GrGLSLPrettyPrint.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 , fFS(this, desc) | 119 , fFS(this, desc) |
120 , fOutOfStage(true) | 120 , fOutOfStage(true) |
121 , fStageIndex(-1) | 121 , fStageIndex(-1) |
122 , fGeometryProcessor(NULL) | 122 , fGeometryProcessor(NULL) |
123 , fOptState(optState) | 123 , fOptState(optState) |
124 , fDesc(desc) | 124 , fDesc(desc) |
125 , fGpu(gpu) | 125 , fGpu(gpu) |
126 , fUniforms(kVarsPerBlock) { | 126 , fUniforms(kVarsPerBlock) { |
127 } | 127 } |
128 | 128 |
129 void GrGLProgramBuilder::addVarying(GrSLType type, | 129 void GrGLProgramBuilder::addVarying(const char* name, |
130 const char* name, | 130 GrGLVarying* varying, |
131 const char** vsOutName, | |
132 const char** fsInName, | |
133 GrGLShaderVar::Precision fsPrecision) { | 131 GrGLShaderVar::Precision fsPrecision) { |
134 SkString* fsInputName = fVS.addVarying(type, name, vsOutName); | 132 SkASSERT(varying); |
135 fFS.addVarying(type, fsInputName->c_str(), fsInName, fsPrecision); | 133 if (varying->vsVarying()) { |
| 134 fVS.addVarying(name, varying); |
| 135 } |
| 136 if (fOptState.hasGeometryProcessor() && fOptState.getGeometryProcessor()->wi
llUseGeoShader()) { |
| 137 fGS.addVarying(name, varying); |
| 138 } |
| 139 if (varying->fsVarying()) { |
| 140 fFS.addVarying(varying, fsPrecision); |
| 141 } |
136 } | 142 } |
137 | 143 |
138 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na
me) { | 144 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na
me) { |
139 if ('\0' == prefix) { | 145 if ('\0' == prefix) { |
140 *out = name; | 146 *out = name; |
141 } else { | 147 } else { |
142 out->printf("%c%s", prefix, name); | 148 out->printf("%c%s", prefix, name); |
143 } | 149 } |
144 if (!fOutOfStage) { | 150 if (!fOutOfStage) { |
145 if (out->endsWith('_')) { | 151 if (out->endsWith('_')) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 uniName, | 361 uniName, |
356 &uniName).toShaderBuilder
Index(); | 362 &uniName).toShaderBuilder
Index(); |
357 | 363 |
358 const char* varyingName = "MatrixCoord"; | 364 const char* varyingName = "MatrixCoord"; |
359 SkString suffixedVaryingName; | 365 SkString suffixedVaryingName; |
360 if (0 != t) { | 366 if (0 != t) { |
361 suffixedVaryingName.append(varyingName); | 367 suffixedVaryingName.append(varyingName); |
362 suffixedVaryingName.appendf("_%i", t); | 368 suffixedVaryingName.appendf("_%i", t); |
363 varyingName = suffixedVaryingName.c_str(); | 369 varyingName = suffixedVaryingName.c_str(); |
364 } | 370 } |
365 const char* vsVaryingName; | 371 GrGLVertToFrag v(varyingType); |
366 const char* fsVaryingName; | 372 this->addVarying(varyingName, &v); |
367 this->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingNam
e); | |
368 | 373 |
369 const GrGLShaderVar& coords = | 374 const GrGLShaderVar& coords = |
370 kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords()
? | 375 kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords()
? |
371 fVS.positionAttribute() : | 376 fVS.positionAttribute() : |
372 fVS.localCoordsAttribute(); | 377 fVS.localCoordsAttribute(); |
373 | 378 |
374 // varying = matrix * coords (logically) | 379 // varying = matrix * coords (logically) |
375 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); | 380 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); |
376 if (kVec2f_GrSLType == varyingType) { | 381 if (kVec2f_GrSLType == varyingType) { |
377 fVS.codeAppendf("%s = (%s * vec3(%s, 1)).xy;", | 382 fVS.codeAppendf("%s = (%s * vec3(%s, 1)).xy;", |
378 vsVaryingName, uniName, coords.c_str()); | 383 v.vsOut(), uniName, coords.c_str()); |
379 } else { | 384 } else { |
380 fVS.codeAppendf("%s = %s * vec3(%s, 1);", | 385 fVS.codeAppendf("%s = %s * vec3(%s, 1);", |
381 vsVaryingName, uniName, coords.c_str()); | 386 v.vsOut(), uniName, coords.c_str()); |
382 } | 387 } |
383 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, | 388 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, |
384 (SkString(fsVaryingName), varyingType)); | 389 (SkString(v.fsIn()), varyingType)); |
385 } | 390 } |
386 } | 391 } |
387 | 392 |
388 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, | 393 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, |
389 GrGLProcessor::TextureSamplerArray* outSam
plers, | 394 GrGLProcessor::TextureSamplerArray* outSam
plers, |
390 GrGLInstalledProc* ip) { | 395 GrGLInstalledProc* ip) { |
391 int numTextures = processor.numTextures(); | 396 int numTextures = processor.numTextures(); |
392 ip->fSamplers.push_back_n(numTextures); | 397 ip->fSamplers.push_back_n(numTextures); |
393 SkString name; | 398 SkString name; |
394 for (int t = 0; t < numTextures; ++t) { | 399 for (int t = 0; t < numTextures; ++t) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 508 } |
504 | 509 |
505 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 510 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
506 | 511 |
507 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 512 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
508 int numProcs = fProcs.count(); | 513 int numProcs = fProcs.count(); |
509 for (int e = 0; e < numProcs; ++e) { | 514 for (int e = 0; e < numProcs; ++e) { |
510 SkDELETE(fProcs[e]); | 515 SkDELETE(fProcs[e]); |
511 } | 516 } |
512 } | 517 } |
OLD | NEW |