Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 , fUniformManager(uniformManager) | 105 , fUniformManager(uniformManager) |
| 106 , fFSFeaturesAddedMask(0) | 106 , fFSFeaturesAddedMask(0) |
| 107 #if GR_GL_EXPERIMENTAL_GS | 107 #if GR_GL_EXPERIMENTAL_GS |
| 108 , fUsesGS(desc.fExperimentalGS) | 108 , fUsesGS(desc.fExperimentalGS) |
| 109 #else | 109 #else |
| 110 , fUsesGS(false) | 110 , fUsesGS(false) |
| 111 #endif | 111 #endif |
| 112 , fSetupFragPosition(false) | 112 , fSetupFragPosition(false) |
| 113 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) | 113 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) |
| 114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle) | 114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle) |
| 115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) { | 115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) |
| 116 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.fFragPos) { | |
| 116 | 117 |
| 117 fPositionVar = &fVSAttrs.push_back(); | 118 fPositionVar = &fVSAttrs.push_back(); |
| 118 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition"); | 119 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition"); |
| 119 if (-1 != desc.fLocalCoordAttributeIndex) { | 120 if (-1 != desc.fLocalCoordAttributeIndex) { |
| 120 fLocalCoordsVar = &fVSAttrs.push_back(); | 121 fLocalCoordsVar = &fVSAttrs.push_back(); |
| 121 fLocalCoordsVar->set(kVec2f_GrSLType, | 122 fLocalCoordsVar->set(kVec2f_GrSLType, |
| 122 GrGLShaderVar::kAttribute_TypeModifier, | 123 GrGLShaderVar::kAttribute_TypeModifier, |
| 123 "aLocalCoords"); | 124 "aLocalCoords"); |
| 124 } else { | 125 } else { |
| 125 fLocalCoordsVar = fPositionVar; | 126 fLocalCoordsVar = fPositionVar; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi g())) { | 344 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi g())) { |
| 344 // The fact that the config is alpha-only must be considered when genera ting code. | 345 // The fact that the config is alpha-only must be considered when genera ting code. |
| 345 key |= kUseAlphaConfig_DstReadKeyBit; | 346 key |= kUseAlphaConfig_DstReadKeyBit; |
| 346 } | 347 } |
| 347 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { | 348 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
| 348 key |= kTopLeftOrigin_DstReadKeyBit; | 349 key |= kTopLeftOrigin_DstReadKeyBit; |
| 349 } | 350 } |
| 350 GrAssert(static_cast<DstReadKey>(key) == key); | 351 GrAssert(static_cast<DstReadKey>(key) == key); |
| 351 return static_cast<DstReadKey>(key); | 352 return static_cast<DstReadKey>(key); |
| 352 } | 353 } |
| 353 | 354 |
|
robertphillips
2013/05/10 13:53:58
// Note: this method only be called if the fragmen
bsalomon
2013/05/13 15:16:49
done (in the header)
| |
| 355 GrGLShaderBuilder::FragPosKey GrGLShaderBuilder::KeyForFragmentPosition(const Gr RenderTarget* dst, | |
| 356 const Gr GLCaps&) { | |
| 357 return kTopLeft_GrSurfaceOrigin == dst->origin() ? | |
|
robertphillips
2013/05/10 13:53:58
rm space?
bsalomon
2013/05/13 15:16:49
Changed to if/else.
| |
| 358 kTopLeftFragPosRead_FragPosKey : | |
| 359 kBottomLeftFragPosRead_FragPosKey; | |
| 360 } | |
| 361 | |
| 362 | |
| 354 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) { | 363 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) { |
| 355 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { | 364 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { |
| 356 if (caps.textureRedSupport()) { | 365 if (caps.textureRedSupport()) { |
| 357 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; | 366 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; |
| 358 return gRedSmear; | 367 return gRedSmear; |
| 359 } else { | 368 } else { |
| 360 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, | 369 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, |
| 361 GR_GL_ALPHA, GR_GL_ALPHA }; | 370 GR_GL_ALPHA, GR_GL_ALPHA }; |
| 362 return gAlphaSmear; | 371 return gAlphaSmear; |
| 363 } | 372 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 | 475 |
| 467 const char* GrGLShaderBuilder::fragmentPosition() { | 476 const char* GrGLShaderBuilder::fragmentPosition() { |
| 468 if (fCodeStage.inStageCode()) { | 477 if (fCodeStage.inStageCode()) { |
| 469 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); | 478 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); |
| 470 if (!effect->willReadFragmentPosition()) { | 479 if (!effect->willReadFragmentPosition()) { |
| 471 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect " | 480 GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect " |
| 472 "did not request access."); | 481 "did not request access."); |
| 473 return ""; | 482 return ""; |
| 474 } | 483 } |
| 475 } | 484 } |
| 476 #if 1 | 485 if (fTopLeftFragPosRead) { |
| 477 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { | 486 if (!fSetupFragPosition) { |
| 487 fFSInputs.push_back().set(kVec4f_GrSLType, | |
| 488 GrGLShaderVar::kIn_TypeModifier, | |
| 489 "gl_FragCoord", | |
| 490 GrGLShaderVar::kDefault_Precision); | |
| 491 fSetupFragPosition = true; | |
| 492 } | |
| 493 return "gl_FragCoord"; | |
| 494 } else if (fCtxInfo.caps()->fragCoordConventionsSupport()) { | |
| 478 if (!fSetupFragPosition) { | 495 if (!fSetupFragPosition) { |
| 479 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL PrivateFeature)); | 496 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL PrivateFeature)); |
| 480 fFSInputs.push_back().set(kVec4f_GrSLType, | 497 fFSInputs.push_back().set(kVec4f_GrSLType, |
| 481 GrGLShaderVar::kIn_TypeModifier, | 498 GrGLShaderVar::kIn_TypeModifier, |
| 482 "gl_FragCoord", | 499 "gl_FragCoord", |
| 483 GrGLShaderVar::kDefault_Precision, | 500 GrGLShaderVar::kDefault_Precision, |
| 484 GrGLShaderVar::kUpperLeft_Origin); | 501 GrGLShaderVar::kUpperLeft_Origin); |
| 485 fSetupFragPosition = true; | 502 fSetupFragPosition = true; |
| 486 } | 503 } |
| 487 return "gl_FragCoord"; | 504 return "gl_FragCoord"; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 499 "RTHeight", | 516 "RTHeight", |
| 500 &rtHeightName); | 517 &rtHeightName); |
| 501 | 518 |
| 502 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n", | 519 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n", |
| 503 kCoordName, rtHeightName); | 520 kCoordName, rtHeightName); |
| 504 fSetupFragPosition = true; | 521 fSetupFragPosition = true; |
| 505 } | 522 } |
| 506 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform); | 523 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform); |
| 507 return kCoordName; | 524 return kCoordName; |
| 508 } | 525 } |
| 509 #else | |
| 510 // This is the path we'll need to use once we have support for TopLeft | |
| 511 // render targets. | |
| 512 if (!fSetupFragPosition) { | |
| 513 fFSInputs.push_back().set(kVec4f_GrSLType, | |
| 514 GrGLShaderVar::kIn_TypeModifier, | |
| 515 "gl_FragCoord", | |
| 516 GrGLShaderVar::kDefault_Precision); | |
| 517 fSetupFragPosition = true; | |
| 518 } | |
| 519 return "gl_FragCoord"; | |
| 520 #endif | |
| 521 } | 526 } |
| 522 | 527 |
| 523 | 528 |
| 524 void GrGLShaderBuilder::emitFunction(ShaderType shader, | 529 void GrGLShaderBuilder::emitFunction(ShaderType shader, |
| 525 GrSLType returnType, | 530 GrSLType returnType, |
| 526 const char* name, | 531 const char* name, |
| 527 int argCnt, | 532 int argCnt, |
| 528 const GrGLShaderVar* args, | 533 const GrGLShaderVar* args, |
| 529 const char* body, | 534 const char* body, |
| 530 SkString* outName) { | 535 SkString* outName) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 727 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
| 723 attrib != attribEnd; | 728 attrib != attribEnd; |
| 724 ++attrib) { | 729 ++attrib) { |
| 725 if (attrib->fIndex == attributeIndex) { | 730 if (attrib->fIndex == attributeIndex) { |
| 726 return &attrib->fName; | 731 return &attrib->fName; |
| 727 } | 732 } |
| 728 } | 733 } |
| 729 | 734 |
| 730 return NULL; | 735 return NULL; |
| 731 } | 736 } |
| OLD | NEW |