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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 , fFSOutputs(kMaxFSOutputs) | 103 , fFSOutputs(kMaxFSOutputs) |
104 , fCtxInfo(ctxInfo) | 104 , fCtxInfo(ctxInfo) |
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(SkToBool(desc.getHeader().fExperimentalGS)) | 108 , fUsesGS(SkToBool(desc.getHeader().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) | |
114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle) | |
115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) | |
116 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) { | 113 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) { |
117 | 114 |
118 const GrGLProgramDesc::KeyHeader& header = desc.getHeader(); | 115 const GrGLProgramDesc::KeyHeader& header = desc.getHeader(); |
119 | 116 |
120 fPositionVar = &fVSAttrs.push_back(); | 117 fPositionVar = &fVSAttrs.push_back(); |
121 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); | 118 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); |
122 if (-1 != header.fLocalCoordAttributeIndex) { | 119 if (-1 != header.fLocalCoordAttributeIndex) { |
123 fLocalCoordsVar = &fVSAttrs.push_back(); | 120 fLocalCoordsVar = &fVSAttrs.push_back(); |
124 fLocalCoordsVar->set(kVec2f_GrSLType, | 121 fLocalCoordsVar->set(kVec2f_GrSLType, |
125 GrGLShaderVar::kAttribute_TypeModifier, | 122 GrGLShaderVar::kAttribute_TypeModifier, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 GrSLType ty
pe, | 381 GrSLType ty
pe, |
385 const char*
name, | 382 const char*
name, |
386 int count, | 383 int count, |
387 const char*
* outName) { | 384 const char*
* outName) { |
388 GrAssert(name && strlen(name)); | 385 GrAssert(name && strlen(name)); |
389 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFr
agment_ShaderType); | 386 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFr
agment_ShaderType); |
390 GrAssert(0 == (~kVisibilityMask & visibility)); | 387 GrAssert(0 == (~kVisibilityMask & visibility)); |
391 GrAssert(0 != visibility); | 388 GrAssert(0 != visibility); |
392 | 389 |
393 BuilderUniform& uni = fUniforms.push_back(); | 390 BuilderUniform& uni = fUniforms.push_back(); |
394 UniformHandle h = index_to_handle(fUniforms.count() - 1); | 391 UniformHandle h = GrGLUniformManager::UniformHandle::CreateFromUniformIndex(
fUniforms.count() - 1); |
395 GR_DEBUGCODE(UniformHandle h2 =) | 392 GR_DEBUGCODE(UniformHandle h2 =) |
396 fUniformManager.appendUniform(type, count); | 393 fUniformManager.appendUniform(type, count); |
397 // We expect the uniform manager to initially have no uniforms and that all
uniforms are added | 394 // We expect the uniform manager to initially have no uniforms and that all
uniforms are added |
398 // by this function. Therefore, the handles should match. | 395 // by this function. Therefore, the handles should match. |
399 GrAssert(h2 == h); | 396 GrAssert(h2 == h); |
400 uni.fVariable.setType(type); | 397 uni.fVariable.setType(type); |
401 uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); | 398 uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); |
402 this->nameVariable(uni.fVariable.accessName(), 'u', name); | 399 this->nameVariable(uni.fVariable.accessName(), 'u', name); |
403 uni.fVariable.setArrayCount(count); | 400 uni.fVariable.setArrayCount(count); |
404 uni.fVisibility = visibility; | 401 uni.fVisibility = visibility; |
405 | 402 |
406 // If it is visible in both the VS and FS, the precision must match. | 403 // If it is visible in both the VS and FS, the precision must match. |
407 // We declare a default FS precision, but not a default VS. So set the var | 404 // We declare a default FS precision, but not a default VS. So set the var |
408 // to use the default FS precision. | 405 // to use the default FS precision. |
409 if ((kVertex_ShaderType | kFragment_ShaderType) == visibility) { | 406 if ((kVertex_ShaderType | kFragment_ShaderType) == visibility) { |
410 // the fragment and vertex precisions must match | 407 // the fragment and vertex precisions must match |
411 uni.fVariable.setPrecision(kDefaultFragmentPrecision); | 408 uni.fVariable.setPrecision(kDefaultFragmentPrecision); |
412 } | 409 } |
413 | 410 |
414 if (NULL != outName) { | 411 if (NULL != outName) { |
415 *outName = uni.fVariable.c_str(); | 412 *outName = uni.fVariable.c_str(); |
416 } | 413 } |
417 | 414 |
418 return h; | 415 return h; |
419 } | 416 } |
420 | 417 |
421 const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) cons
t { | |
422 return fUniforms[handle_to_index(u)].fVariable; | |
423 } | |
424 | |
425 bool GrGLShaderBuilder::addAttribute(GrSLType type, | 418 bool GrGLShaderBuilder::addAttribute(GrSLType type, |
426 const char* name) { | 419 const char* name) { |
427 for (int i = 0; i < fVSAttrs.count(); ++i) { | 420 for (int i = 0; i < fVSAttrs.count(); ++i) { |
428 const GrGLShaderVar& attr = fVSAttrs[i]; | 421 const GrGLShaderVar& attr = fVSAttrs[i]; |
429 // if attribute already added, don't add it again | 422 // if attribute already added, don't add it again |
430 if (attr.getName().equals(name)) { | 423 if (attr.getName().equals(name)) { |
431 GrAssert(attr.getType() == type); | 424 GrAssert(attr.getType() == type); |
432 return false; | 425 return false; |
433 } | 426 } |
434 } | 427 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 GrGLShaderVar::kUpperLeft_Origin); | 498 GrGLShaderVar::kUpperLeft_Origin); |
506 fSetupFragPosition = true; | 499 fSetupFragPosition = true; |
507 } | 500 } |
508 return "gl_FragCoord"; | 501 return "gl_FragCoord"; |
509 } else { | 502 } else { |
510 static const char* kCoordName = "fragCoordYDown"; | 503 static const char* kCoordName = "fragCoordYDown"; |
511 if (!fSetupFragPosition) { | 504 if (!fSetupFragPosition) { |
512 // temporarily change the stage index because we're inserting non-st
age code. | 505 // temporarily change the stage index because we're inserting non-st
age code. |
513 CodeStage::AutoStageRestore csar(&fCodeStage, NULL); | 506 CodeStage::AutoStageRestore csar(&fCodeStage, NULL); |
514 | 507 |
515 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fRTHeightUnifo
rm); | 508 GrAssert(!fRTHeightUniform.isValid()); |
516 const char* rtHeightName; | 509 const char* rtHeightName; |
517 | 510 |
518 fRTHeightUniform = this->addUniform(kFragment_ShaderType, | 511 fRTHeightUniform = this->addUniform(kFragment_ShaderType, |
519 kFloat_GrSLType, | 512 kFloat_GrSLType, |
520 "RTHeight", | 513 "RTHeight", |
521 &rtHeightName); | 514 &rtHeightName); |
522 | 515 |
523 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra
gCoord.y, gl_FragCoord.zw);\n", | 516 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra
gCoord.y, gl_FragCoord.zw);\n", |
524 kCoordName, rtHeightName); | 517 kCoordName, rtHeightName); |
525 fSetupFragPosition = true; | 518 fSetupFragPosition = true; |
526 } | 519 } |
527 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform); | 520 GrAssert(fRTHeightUniform.isValid()); |
528 return kCoordName; | 521 return kCoordName; |
529 } | 522 } |
530 } | 523 } |
531 | 524 |
532 | 525 |
533 void GrGLShaderBuilder::emitFunction(ShaderType shader, | 526 void GrGLShaderBuilder::emitFunction(ShaderType shader, |
534 GrSLType returnType, | 527 GrSLType returnType, |
535 const char* name, | 528 const char* name, |
536 int argCnt, | 529 int argCnt, |
537 const GrGLShaderVar* args, | 530 const GrGLShaderVar* args, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 720 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
728 attrib != attribEnd; | 721 attrib != attribEnd; |
729 ++attrib) { | 722 ++attrib) { |
730 if (attrib->fIndex == attributeIndex) { | 723 if (attrib->fIndex == attributeIndex) { |
731 return &attrib->fName; | 724 return &attrib->fName; |
732 } | 725 } |
733 } | 726 } |
734 | 727 |
735 return NULL; | 728 return NULL; |
736 } | 729 } |
OLD | NEW |