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