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