Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: src/gpu/gl/GrGLShaderBuilder.cpp

Issue 12668019: Make GrGLShaderBuilder responsible for enabling GLSL extensions (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: sync to TOT Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 : fUniforms(kVarsPerBlock) 97 : fUniforms(kVarsPerBlock)
98 , fVSAttrs(kVarsPerBlock) 98 , fVSAttrs(kVarsPerBlock)
99 , fVSOutputs(kVarsPerBlock) 99 , fVSOutputs(kVarsPerBlock)
100 , fGSInputs(kVarsPerBlock) 100 , fGSInputs(kVarsPerBlock)
101 , fGSOutputs(kVarsPerBlock) 101 , fGSOutputs(kVarsPerBlock)
102 , fFSInputs(kVarsPerBlock) 102 , fFSInputs(kVarsPerBlock)
103 , fFSOutputs(kMaxFSOutputs) 103 , fFSOutputs(kMaxFSOutputs)
104 , fCtxInfo(ctxInfo) 104 , fCtxInfo(ctxInfo)
105 , fUniformManager(uniformManager) 105 , fUniformManager(uniformManager)
106 , fCurrentStageIdx(kNonStageIdx) 106 , fCurrentStageIdx(kNonStageIdx)
107 , fFSFeaturesAddedMask(0)
107 #if GR_GL_EXPERIMENTAL_GS 108 #if GR_GL_EXPERIMENTAL_GS
108 , fUsesGS(desc.fExperimentalGS) 109 , fUsesGS(desc.fExperimentalGS)
109 #else 110 #else
110 , fUsesGS(false) 111 , fUsesGS(false)
111 #endif 112 #endif
112 , fSetupFragPosition(false) 113 , fSetupFragPosition(false)
113 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) 114 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
114 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle) 115 , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle)
115 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) { 116 , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle) {
116 117
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName); 151 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName);
151 if (!topDown) { 152 if (!topDown) {
152 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n"); 153 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n");
153 } 154 }
154 this->fsCodeAppendf("\tvec4 %s = ", kDstColorName); 155 this->fsCodeAppendf("\tvec4 %s = ", kDstColorName);
155 this->appendTextureLookup(kFragment_ShaderType, fDstCopySampler, "_dstTe xCoord"); 156 this->appendTextureLookup(kFragment_ShaderType, fDstCopySampler, "_dstTe xCoord");
156 this->fsCodeAppend(";\n\n"); 157 this->fsCodeAppend(";\n\n");
157 } 158 }
158 } 159 }
159 160
161 bool GrGLShaderBuilder::enableFeature(GLSLFeature feature) {
162 switch (feature) {
163 case kStandardDerivatives_GLSLFeature:
164 if (!fCtxInfo.caps()->shaderDerivativeSupport()) {
165 return false;
166 }
167 if (kES2_GrGLBinding == fCtxInfo.binding()) {
168 this->addFSFeature(1 << kStandardDerivatives_GLSLFeature,
169 "GL_OES_standard_derivatives");
170 }
171 return true;
172 default:
173 GrCrash("Unexpected GLSLFeature requested.");
174 return false;
175 }
176 }
177
178 bool GrGLShaderBuilder::enablePrivateFeature(GLSLPrivateFeature feature) {
179 switch (feature) {
180 case kFragCoordConventions_GLSLPrivateFeature:
181 if (!fCtxInfo.caps()->fragCoordConventionsSupport()) {
182 return false;
183 }
184 if (fCtxInfo.glslGeneration() < k150_GrGLSLGeneration) {
185 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature ,
186 "GL_ARB_fragment_coord_conventions");
187 }
188 return true;
189 default:
190 GrCrash("Unexpected GLSLPrivateFeature requested.");
191 return false;
192 }
193 }
194
195 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN ame) {
196 if (!(featureBit & fFSFeaturesAddedMask)) {
197 fFSHeader.appendf("#extension %s: require\n", extensionName);
198 fFSFeaturesAddedMask |= featureBit;
199 }
200 }
201
160 const char* GrGLShaderBuilder::dstColor() const { 202 const char* GrGLShaderBuilder::dstColor() const {
161 if (fDstCopySampler.isInitialized()) { 203 if (fDstCopySampler.isInitialized()) {
162 return kDstColorName; 204 return kDstColorName;
163 } else { 205 } else {
164 return NULL; 206 return NULL;
165 } 207 }
166 } 208 }
167 209
168 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis t args) { 210 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis t args) {
169 SkString* string = NULL; 211 SkString* string = NULL;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 fFSInputs.back().setName(*fsName); 423 fFSInputs.back().setName(*fsName);
382 if (fsInName) { 424 if (fsInName) {
383 *fsInName = fsName->c_str(); 425 *fsInName = fsName->c_str();
384 } 426 }
385 } 427 }
386 428
387 const char* GrGLShaderBuilder::fragmentPosition() { 429 const char* GrGLShaderBuilder::fragmentPosition() {
388 #if 1 430 #if 1
389 if (fCtxInfo.caps()->fragCoordConventionsSupport()) { 431 if (fCtxInfo.caps()->fragCoordConventionsSupport()) {
390 if (!fSetupFragPosition) { 432 if (!fSetupFragPosition) {
391 if (fCtxInfo.glslGeneration() < k150_GrGLSLGeneration) { 433 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL PrivateFeature));
392 fFSHeader.append("#extension GL_ARB_fragment_coord_conventions: require\n");
393 }
394 fFSInputs.push_back().set(kVec4f_GrSLType, 434 fFSInputs.push_back().set(kVec4f_GrSLType,
395 GrGLShaderVar::kIn_TypeModifier, 435 GrGLShaderVar::kIn_TypeModifier,
396 "gl_FragCoord", 436 "gl_FragCoord",
397 GrGLShaderVar::kDefault_Precision, 437 GrGLShaderVar::kDefault_Precision,
398 GrGLShaderVar::kUpperLeft_Origin); 438 GrGLShaderVar::kUpperLeft_Origin);
399 fSetupFragPosition = true; 439 fSetupFragPosition = true;
400 } 440 }
401 return "gl_FragCoord"; 441 return "gl_FragCoord";
402 } else { 442 } else {
403 static const char* kCoordName = "fragCoordYDown"; 443 static const char* kCoordName = "fragCoordYDown";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) cons t { 540 void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) cons t {
501 for (int i = 0; i < fUniforms.count(); ++i) { 541 for (int i = 0; i < fUniforms.count(); ++i) {
502 if (fUniforms[i].fVisibility & stype) { 542 if (fUniforms[i].fVisibility & stype) {
503 fUniforms[i].fVariable.appendDecl(fCtxInfo, out); 543 fUniforms[i].fVariable.appendDecl(fCtxInfo, out);
504 out->append(";\n"); 544 out->append(";\n");
505 } 545 }
506 } 546 }
507 } 547 }
508 548
509 void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const { 549 void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const {
550 const char* version = GrGetGLSLVersionDecl(fCtxInfo.binding(), fCtxInfo.glsl Generation());
551
510 switch (type) { 552 switch (type) {
511 case kVertex_ShaderType: 553 case kVertex_ShaderType:
512 *shaderStr = fHeader; 554 *shaderStr = version;
513 this->appendUniformDecls(kVertex_ShaderType, shaderStr); 555 this->appendUniformDecls(kVertex_ShaderType, shaderStr);
514 this->appendDecls(fVSAttrs, shaderStr); 556 this->appendDecls(fVSAttrs, shaderStr);
515 this->appendDecls(fVSOutputs, shaderStr); 557 this->appendDecls(fVSOutputs, shaderStr);
516 shaderStr->append("void main() {\n"); 558 shaderStr->append("void main() {\n");
517 shaderStr->append(fVSCode); 559 shaderStr->append(fVSCode);
518 shaderStr->append("}\n"); 560 shaderStr->append("}\n");
519 break; 561 break;
520 case kGeometry_ShaderType: 562 case kGeometry_ShaderType:
521 if (fUsesGS) { 563 if (fUsesGS) {
522 *shaderStr = fHeader; 564 *shaderStr = version;
523 shaderStr->append(fGSHeader); 565 shaderStr->append(fGSHeader);
524 this->appendDecls(fGSInputs, shaderStr); 566 this->appendDecls(fGSInputs, shaderStr);
525 this->appendDecls(fGSOutputs, shaderStr); 567 this->appendDecls(fGSOutputs, shaderStr);
526 shaderStr->append("void main() {\n"); 568 shaderStr->append("void main() {\n");
527 shaderStr->append(fGSCode); 569 shaderStr->append(fGSCode);
528 shaderStr->append("}\n"); 570 shaderStr->append("}\n");
529 } else { 571 } else {
530 shaderStr->reset(); 572 shaderStr->reset();
531 } 573 }
532 break; 574 break;
533 case kFragment_ShaderType: 575 case kFragment_ShaderType:
534 *shaderStr = fHeader; 576 *shaderStr = version;
535 append_default_precision_qualifier(kDefaultFragmentPrecision, 577 append_default_precision_qualifier(kDefaultFragmentPrecision,
536 fCtxInfo.binding(), 578 fCtxInfo.binding(),
537 shaderStr); 579 shaderStr);
538 shaderStr->append(fFSHeader); 580 shaderStr->append(fFSHeader);
539 this->appendUniformDecls(kFragment_ShaderType, shaderStr); 581 this->appendUniformDecls(kFragment_ShaderType, shaderStr);
540 this->appendDecls(fFSInputs, shaderStr); 582 this->appendDecls(fFSInputs, shaderStr);
541 // We shouldn't have declared outputs on 1.10 583 // We shouldn't have declared outputs on 1.10
542 GrAssert(k110_GrGLSLGeneration != fCtxInfo.glslGeneration() || fFSOu tputs.empty()); 584 GrAssert(k110_GrGLSLGeneration != fCtxInfo.glslGeneration() || fFSOu tputs.empty());
543 this->appendDecls(fFSOutputs, shaderStr); 585 this->appendDecls(fFSOutputs, shaderStr);
544 shaderStr->append(fFSFunctions); 586 shaderStr->append(fFSFunctions);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 for (const AttributePair* attrib = this->getEffectAttributes().begin(); 648 for (const AttributePair* attrib = this->getEffectAttributes().begin();
607 attrib != attribEnd; 649 attrib != attribEnd;
608 ++attrib) { 650 ++attrib) {
609 if (attrib->fIndex == attributeIndex) { 651 if (attrib->fIndex == attributeIndex) {
610 return &attrib->fName; 652 return &attrib->fName;
611 } 653 }
612 } 654 }
613 655
614 return NULL; 656 return NULL;
615 } 657 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698