| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
| 9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
| 10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 name); | 379 name); |
| 380 return true; | 380 return true; |
| 381 } | 381 } |
| 382 | 382 |
| 383 void GrGLShaderBuilder::addVarying(GrSLType type, | 383 void GrGLShaderBuilder::addVarying(GrSLType type, |
| 384 const char* name, | 384 const char* name, |
| 385 const char** vsOutName, | 385 const char** vsOutName, |
| 386 const char** fsInName) { | 386 const char** fsInName) { |
| 387 fVSOutputs.push_back(); | 387 fVSOutputs.push_back(); |
| 388 fVSOutputs.back().setType(type); | 388 fVSOutputs.back().setType(type); |
| 389 fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); | 389 fVSOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); |
| 390 if (kNonStageIdx == fCurrentStageIdx) { | 390 if (kNonStageIdx == fCurrentStageIdx) { |
| 391 fVSOutputs.back().accessName()->printf("v%s", name); | 391 fVSOutputs.back().accessName()->printf("v%s", name); |
| 392 } else { | 392 } else { |
| 393 fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStageIdx); | 393 fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStageIdx); |
| 394 } | 394 } |
| 395 if (vsOutName) { | 395 if (vsOutName) { |
| 396 *vsOutName = fVSOutputs.back().getName().c_str(); | 396 *vsOutName = fVSOutputs.back().getName().c_str(); |
| 397 } | 397 } |
| 398 // input to FS comes either from VS or GS | 398 // input to FS comes either from VS or GS |
| 399 const SkString* fsName; | 399 const SkString* fsName; |
| 400 if (fUsesGS) { | 400 if (fUsesGS) { |
| 401 // if we have a GS take each varying in as an array | 401 // if we have a GS take each varying in as an array |
| 402 // and output as non-array. | 402 // and output as non-array. |
| 403 fGSInputs.push_back(); | 403 fGSInputs.push_back(); |
| 404 fGSInputs.back().setType(type); | 404 fGSInputs.back().setType(type); |
| 405 fGSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier); | 405 fGSInputs.back().setTypeModifier(GrGLShaderVar::kVaryingIn_TypeModifier)
; |
| 406 fGSInputs.back().setUnsizedArray(); | 406 fGSInputs.back().setUnsizedArray(); |
| 407 *fGSInputs.back().accessName() = fVSOutputs.back().getName(); | 407 *fGSInputs.back().accessName() = fVSOutputs.back().getName(); |
| 408 fGSOutputs.push_back(); | 408 fGSOutputs.push_back(); |
| 409 fGSOutputs.back().setType(type); | 409 fGSOutputs.back().setType(type); |
| 410 fGSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); | 410 fGSOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifie
r); |
| 411 if (kNonStageIdx == fCurrentStageIdx) { | 411 if (kNonStageIdx == fCurrentStageIdx) { |
| 412 fGSOutputs.back().accessName()->printf("g%s", name); | 412 fGSOutputs.back().accessName()->printf("g%s", name); |
| 413 } else { | 413 } else { |
| 414 fGSOutputs.back().accessName()->printf("g%s%d", name, fCurrentStageI
dx); | 414 fGSOutputs.back().accessName()->printf("g%s%d", name, fCurrentStageI
dx); |
| 415 } | 415 } |
| 416 fsName = fGSOutputs.back().accessName(); | 416 fsName = fGSOutputs.back().accessName(); |
| 417 } else { | 417 } else { |
| 418 fsName = fVSOutputs.back().accessName(); | 418 fsName = fVSOutputs.back().accessName(); |
| 419 } | 419 } |
| 420 fFSInputs.push_back(); | 420 fFSInputs.push_back(); |
| 421 fFSInputs.back().setType(type); | 421 fFSInputs.back().setType(type); |
| 422 fFSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier); | 422 fFSInputs.back().setTypeModifier(GrGLShaderVar::kVaryingIn_TypeModifier); |
| 423 fFSInputs.back().setName(*fsName); | 423 fFSInputs.back().setName(*fsName); |
| 424 if (fsInName) { | 424 if (fsInName) { |
| 425 *fsInName = fsName->c_str(); | 425 *fsInName = fsName->c_str(); |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 const char* GrGLShaderBuilder::fragmentPosition() { | 429 const char* GrGLShaderBuilder::fragmentPosition() { |
| 430 #if 1 | 430 #if 1 |
| 431 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { | 431 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { |
| 432 if (!fSetupFragPosition) { | 432 if (!fSetupFragPosition) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 void GrGLShaderBuilder::emitFunction(ShaderType shader, | 480 void GrGLShaderBuilder::emitFunction(ShaderType shader, |
| 481 GrSLType returnType, | 481 GrSLType returnType, |
| 482 const char* name, | 482 const char* name, |
| 483 int argCnt, | 483 int argCnt, |
| 484 const GrGLShaderVar* args, | 484 const GrGLShaderVar* args, |
| 485 const char* body, | 485 const char* body, |
| 486 SkString* outName) { | 486 SkString* outName) { |
| 487 GrAssert(kFragment_ShaderType == shader); | 487 GrAssert(kFragment_ShaderType == shader); |
| 488 fFSFunctions.append(GrGLSLTypeString(returnType)); | 488 fFSFunctions.append(GrGLSLTypeString(returnType)); |
| 489 if (kNonStageIdx != fCurrentStageIdx) { | 489 if (kNonStageIdx != fCurrentStageIdx) { |
| 490 outName->printf(" %s_%d", name, fCurrentStageIdx); | 490 outName->printf("%s_%d", name, fCurrentStageIdx); |
| 491 } else { | 491 } else { |
| 492 *outName = name; | 492 *outName = name; |
| 493 } | 493 } |
| 494 fFSFunctions.append(*outName); | 494 fFSFunctions.appendf(" %s", outName->c_str()); |
| 495 fFSFunctions.append("("); | 495 fFSFunctions.append("("); |
| 496 for (int i = 0; i < argCnt; ++i) { | 496 for (int i = 0; i < argCnt; ++i) { |
| 497 args[i].appendDecl(fCtxInfo, &fFSFunctions); | 497 args[i].appendDecl(fCtxInfo, &fFSFunctions); |
| 498 if (i < argCnt - 1) { | 498 if (i < argCnt - 1) { |
| 499 fFSFunctions.append(", "); | 499 fFSFunctions.append(", "); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 fFSFunctions.append(") {\n"); | 502 fFSFunctions.append(") {\n"); |
| 503 fFSFunctions.append(body); | 503 fFSFunctions.append(body); |
| 504 fFSFunctions.append("}\n\n"); | 504 fFSFunctions.append("}\n\n"); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 648 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
| 649 attrib != attribEnd; | 649 attrib != attribEnd; |
| 650 ++attrib) { | 650 ++attrib) { |
| 651 if (attrib->fIndex == attributeIndex) { | 651 if (attrib->fIndex == attributeIndex) { |
| 652 return &attrib->fName; | 652 return &attrib->fName; |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 | 655 |
| 656 return NULL; | 656 return NULL; |
| 657 } | 657 } |
| OLD | NEW |