| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (fCodeStage.inStageCode()) { | 223 if (fCodeStage.inStageCode()) { |
| 224 if (out->endsWith('_')) { | 224 if (out->endsWith('_')) { |
| 225 // Names containing "__" are reserved. | 225 // Names containing "__" are reserved. |
| 226 out->append("x"); | 226 out->append("x"); |
| 227 } | 227 } |
| 228 out->appendf("_Stage%d", fCodeStage.stageIndex()); | 228 out->appendf("_Stage%d", fCodeStage.stageIndex()); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 const char* GrGLShaderBuilder::dstColor() { | 232 const char* GrGLShaderBuilder::dstColor() { |
| 233 if (fCodeStage.inStageCode()) { |
| 234 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); |
| 235 if (!effect->willReadDstColor()) { |
| 236 GrDebugCrash("GrGLEffect asked for dst color but its generating GrEf
fect " |
| 237 "did not request access."); |
| 238 return ""; |
| 239 } |
| 240 } |
| 233 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; | 241 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; |
| 234 GrGLCaps::FBFetchType fetchType = fCtxInfo.caps()->fbFetchType(); | 242 GrGLCaps::FBFetchType fetchType = fCtxInfo.caps()->fbFetchType(); |
| 235 if (GrGLCaps::kEXT_FBFetchType == fetchType) { | 243 if (GrGLCaps::kEXT_FBFetchType == fetchType) { |
| 236 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); | 244 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); |
| 237 return kFBFetchColorName; | 245 return kFBFetchColorName; |
| 238 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { | 246 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { |
| 239 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL
PrivateFeature)); | 247 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL
PrivateFeature)); |
| 240 return kFBFetchColorName; | 248 return kFBFetchColorName; |
| 241 } else if (fDstCopySampler.isInitialized()) { | 249 } else if (fDstCopySampler.isInitialized()) { |
| 242 return kDstCopyColorName; | 250 return kDstCopyColorName; |
| 243 } else { | 251 } else { |
| 244 return NULL; | 252 return ""; |
| 245 } | 253 } |
| 246 } | 254 } |
| 247 | 255 |
| 248 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis
t args) { | 256 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis
t args) { |
| 249 SkString* string = NULL; | 257 SkString* string = NULL; |
| 250 switch (type) { | 258 switch (type) { |
| 251 case kVertex_ShaderType: | 259 case kVertex_ShaderType: |
| 252 string = &fVSCode; | 260 string = &fVSCode; |
| 253 break; | 261 break; |
| 254 case kGeometry_ShaderType: | 262 case kGeometry_ShaderType: |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 fFSInputs.push_back(); | 458 fFSInputs.push_back(); |
| 451 fFSInputs.back().setType(type); | 459 fFSInputs.back().setType(type); |
| 452 fFSInputs.back().setTypeModifier(GrGLShaderVar::kVaryingIn_TypeModifier); | 460 fFSInputs.back().setTypeModifier(GrGLShaderVar::kVaryingIn_TypeModifier); |
| 453 fFSInputs.back().setName(*fsName); | 461 fFSInputs.back().setName(*fsName); |
| 454 if (fsInName) { | 462 if (fsInName) { |
| 455 *fsInName = fsName->c_str(); | 463 *fsInName = fsName->c_str(); |
| 456 } | 464 } |
| 457 } | 465 } |
| 458 | 466 |
| 459 const char* GrGLShaderBuilder::fragmentPosition() { | 467 const char* GrGLShaderBuilder::fragmentPosition() { |
| 468 if (fCodeStage.inStageCode()) { |
| 469 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); |
| 470 if (!effect->willReadFragmentPosition()) { |
| 471 GrDebugCrash("GrGLEffect asked for frag position but its generating
GrEffect " |
| 472 "did not request access."); |
| 473 return ""; |
| 474 } |
| 475 } |
| 460 #if 1 | 476 #if 1 |
| 461 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { | 477 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { |
| 462 if (!fSetupFragPosition) { | 478 if (!fSetupFragPosition) { |
| 463 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL
PrivateFeature)); | 479 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL
PrivateFeature)); |
| 464 fFSInputs.push_back().set(kVec4f_GrSLType, | 480 fFSInputs.push_back().set(kVec4f_GrSLType, |
| 465 GrGLShaderVar::kIn_TypeModifier, | 481 GrGLShaderVar::kIn_TypeModifier, |
| 466 "gl_FragCoord", | 482 "gl_FragCoord", |
| 467 GrGLShaderVar::kDefault_Precision, | 483 GrGLShaderVar::kDefault_Precision, |
| 468 GrGLShaderVar::kUpperLeft_Origin); | 484 GrGLShaderVar::kUpperLeft_Origin); |
| 469 fSetupFragPosition = true; | 485 fSetupFragPosition = true; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 722 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
| 707 attrib != attribEnd; | 723 attrib != attribEnd; |
| 708 ++attrib) { | 724 ++attrib) { |
| 709 if (attrib->fIndex == attributeIndex) { | 725 if (attrib->fIndex == attributeIndex) { |
| 710 return &attrib->fName; | 726 return &attrib->fName; |
| 711 } | 727 } |
| 712 } | 728 } |
| 713 | 729 |
| 714 return NULL; | 730 return NULL; |
| 715 } | 731 } |
| OLD | NEW |