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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 case kStandardDerivatives_GLSLFeature: | 180 case kStandardDerivatives_GLSLFeature: |
181 if (!fGpu->glCaps().shaderDerivativeSupport()) { | 181 if (!fGpu->glCaps().shaderDerivativeSupport()) { |
182 return false; | 182 return false; |
183 } | 183 } |
184 if (kGLES_GrGLStandard == fGpu->glStandard()) { | 184 if (kGLES_GrGLStandard == fGpu->glStandard()) { |
185 this->addFSFeature(1 << kStandardDerivatives_GLSLFeature, | 185 this->addFSFeature(1 << kStandardDerivatives_GLSLFeature, |
186 "GL_OES_standard_derivatives"); | 186 "GL_OES_standard_derivatives"); |
187 } | 187 } |
188 return true; | 188 return true; |
189 default: | 189 default: |
190 GrCrash("Unexpected GLSLFeature requested."); | 190 SkFAIL("Unexpected GLSLFeature requested."); |
191 return false; | 191 return false; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 bool GrGLShaderBuilder::enablePrivateFeature(GLSLPrivateFeature feature) { | 195 bool GrGLShaderBuilder::enablePrivateFeature(GLSLPrivateFeature feature) { |
196 switch (feature) { | 196 switch (feature) { |
197 case kFragCoordConventions_GLSLPrivateFeature: | 197 case kFragCoordConventions_GLSLPrivateFeature: |
198 if (!fGpu->glCaps().fragCoordConventionsSupport()) { | 198 if (!fGpu->glCaps().fragCoordConventionsSupport()) { |
199 return false; | 199 return false; |
200 } | 200 } |
(...skipping 10 matching lines...) Expand all Loading... |
211 "GL_EXT_shader_framebuffer_fetch"); | 211 "GL_EXT_shader_framebuffer_fetch"); |
212 return true; | 212 return true; |
213 case kNVShaderFramebufferFetch_GLSLPrivateFeature: | 213 case kNVShaderFramebufferFetch_GLSLPrivateFeature: |
214 if (GrGLCaps::kNV_FBFetchType != fGpu->glCaps().fbFetchType()) { | 214 if (GrGLCaps::kNV_FBFetchType != fGpu->glCaps().fbFetchType()) { |
215 return false; | 215 return false; |
216 } | 216 } |
217 this->addFSFeature(1 << kNVShaderFramebufferFetch_GLSLPrivateFeature
, | 217 this->addFSFeature(1 << kNVShaderFramebufferFetch_GLSLPrivateFeature
, |
218 "GL_NV_shader_framebuffer_fetch"); | 218 "GL_NV_shader_framebuffer_fetch"); |
219 return true; | 219 return true; |
220 default: | 220 default: |
221 GrCrash("Unexpected GLSLPrivateFeature requested."); | 221 SkFAIL("Unexpected GLSLPrivateFeature requested."); |
222 return false; | 222 return false; |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { | 226 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { |
227 if (!(featureBit & fFSFeaturesAddedMask)) { | 227 if (!(featureBit & fFSFeaturesAddedMask)) { |
228 fFSExtensions.appendf("#extension %s: require\n", extensionName); | 228 fFSExtensions.appendf("#extension %s: require\n", extensionName); |
229 fFSFeaturesAddedMask |= featureBit; | 229 fFSFeaturesAddedMask |= featureBit; |
230 } | 230 } |
231 } | 231 } |
(...skipping 10 matching lines...) Expand all Loading... |
242 out->append("x"); | 242 out->append("x"); |
243 } | 243 } |
244 out->appendf("_Stage%d", fCodeStage.stageIndex()); | 244 out->appendf("_Stage%d", fCodeStage.stageIndex()); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 const char* GrGLShaderBuilder::dstColor() { | 248 const char* GrGLShaderBuilder::dstColor() { |
249 if (fCodeStage.inStageCode()) { | 249 if (fCodeStage.inStageCode()) { |
250 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); | 250 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); |
251 if (!effect->willReadDstColor()) { | 251 if (!effect->willReadDstColor()) { |
252 GrDebugCrash("GrGLEffect asked for dst color but its generating GrEf
fect " | 252 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " |
253 "did not request access."); | 253 "did not request access."); |
254 return ""; | 254 return ""; |
255 } | 255 } |
256 } | 256 } |
257 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; | 257 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; |
258 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); | 258 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); |
259 if (GrGLCaps::kEXT_FBFetchType == fetchType) { | 259 if (GrGLCaps::kEXT_FBFetchType == fetchType) { |
260 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); | 260 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); |
261 return kFBFetchColorName; | 261 return kFBFetchColorName; |
262 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { | 262 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 392 } |
393 this->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;", | 393 this->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;", |
394 coords2D.c_str(), coords[index].c_str(), coords[index].c
_str()); | 394 coords2D.c_str(), coords[index].c_str(), coords[index].c
_str()); |
395 return coords2D; | 395 return coords2D; |
396 } | 396 } |
397 | 397 |
398 const char* GrGLShaderBuilder::fragmentPosition() { | 398 const char* GrGLShaderBuilder::fragmentPosition() { |
399 if (fCodeStage.inStageCode()) { | 399 if (fCodeStage.inStageCode()) { |
400 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); | 400 const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); |
401 if (!effect->willReadFragmentPosition()) { | 401 if (!effect->willReadFragmentPosition()) { |
402 GrDebugCrash("GrGLEffect asked for frag position but its generating
GrEffect " | 402 SkDEBUGFAIL("GrGLEffect asked for frag position but its generating G
rEffect " |
403 "did not request access."); | 403 "did not request access."); |
404 return ""; | 404 return ""; |
405 } | 405 } |
406 } | 406 } |
407 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers | 407 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers |
408 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the | 408 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the |
409 // declaration varies in earlier GLSL specs. So it is simpler to omit it. | 409 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
410 if (fTopLeftFragPosRead) { | 410 if (fTopLeftFragPosRead) { |
411 fSetupFragPosition = true; | 411 fSetupFragPosition = true; |
412 return "gl_FragCoord"; | 412 return "gl_FragCoord"; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 case GrGLShaderVar::kHigh_Precision: | 476 case GrGLShaderVar::kHigh_Precision: |
477 str->append("precision highp float;\n"); | 477 str->append("precision highp float;\n"); |
478 break; | 478 break; |
479 case GrGLShaderVar::kMedium_Precision: | 479 case GrGLShaderVar::kMedium_Precision: |
480 str->append("precision mediump float;\n"); | 480 str->append("precision mediump float;\n"); |
481 break; | 481 break; |
482 case GrGLShaderVar::kLow_Precision: | 482 case GrGLShaderVar::kLow_Precision: |
483 str->append("precision lowp float;\n"); | 483 str->append("precision lowp float;\n"); |
484 break; | 484 break; |
485 case GrGLShaderVar::kDefault_Precision: | 485 case GrGLShaderVar::kDefault_Precision: |
486 GrCrash("Default precision now allowed."); | 486 SkFAIL("Default precision now allowed."); |
487 default: | 487 default: |
488 GrCrash("Unknown precision value."); | 488 SkFAIL("Unknown precision value."); |
489 } | 489 } |
490 } | 490 } |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { | 494 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { |
495 for (int i = 0; i < vars.count(); ++i) { | 495 for (int i = 0; i < vars.count(); ++i) { |
496 vars[i].appendDecl(this->ctxInfo(), out); | 496 vars[i].appendDecl(this->ctxInfo(), out); |
497 out->append(";\n"); | 497 out->append(";\n"); |
498 } | 498 } |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 990 |
991 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, | 991 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, |
992 effectCnt); | 992 effectCnt); |
993 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, | 993 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, |
994 effectStages, | 994 effectStages, |
995 effectKeys, | 995 effectKeys, |
996 effectCnt, | 996 effectCnt, |
997 inOutFSColor); | 997 inOutFSColor); |
998 return pathTexGenEffectsBuilder.finish(); | 998 return pathTexGenEffectsBuilder.finish(); |
999 } | 999 } |
OLD | NEW |