| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrGLFragmentShaderBuilder.h" | 8 #include "GrGLFragmentShaderBuilder.h" |
| 9 #include "GrRenderTarget.h" | 9 #include "GrRenderTarget.h" |
| 10 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 "gl_FragCoord", | 136 "gl_FragCoord", |
| 137 kDefault_GrSLPrecision, | 137 kDefault_GrSLPrecision, |
| 138 GrGLSLShaderVar::kUpperLeft_Origin); | 138 GrGLSLShaderVar::kUpperLeft_Origin); |
| 139 fSetupFragPosition = true; | 139 fSetupFragPosition = true; |
| 140 } | 140 } |
| 141 return "gl_FragCoord"; | 141 return "gl_FragCoord"; |
| 142 } else { | 142 } else { |
| 143 static const char* kTempName = "tmpXYFragCoord"; | 143 static const char* kTempName = "tmpXYFragCoord"; |
| 144 static const char* kCoordName = "fragCoordYDown"; | 144 static const char* kCoordName = "fragCoordYDown"; |
| 145 if (!fSetupFragPosition) { | 145 if (!fSetupFragPosition) { |
| 146 // temporarily change the stage index because we're inserting non-st
age code. | |
| 147 GrGLProgramBuilder::AutoStageRestore asr(fProgramBuilder); | |
| 148 SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 146 SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| 149 const char* rtHeightName; | 147 const char* rtHeightName; |
| 150 | 148 |
| 151 fProgramBuilder->fUniformHandles.fRTHeightUni = | 149 fProgramBuilder->fUniformHandles.fRTHeightUni = |
| 152 fProgramBuilder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 150 fProgramBuilder->addFragPosUniform(GrGLProgramBuilder::kFrag
ment_Visibility, |
| 153 kFloat_GrSLType, | 151 kFloat_GrSLType, |
| 154 kDefault_GrSLPrecision, | 152 kDefault_GrSLPrecision, |
| 155 "RTHeight", | 153 "RTHeight", |
| 156 &rtHeightName); | 154 &rtHeightName); |
| 157 | 155 |
| 158 // The Adreno compiler seems to be very touchy about access to "gl_F
ragCoord". | 156 // The Adreno compiler seems to be very touchy about access to "gl_F
ragCoord". |
| 159 // Accessing glFragCoord.zw can cause a program to fail to link. Add
itionally, | 157 // Accessing glFragCoord.zw can cause a program to fail to link. Add
itionally, |
| 160 // depending on the surrounding code, accessing .xy with a uniform i
nvolved can | 158 // depending on the surrounding code, accessing .xy with a uniform i
nvolved can |
| 161 // do the same thing. Copying gl_FragCoord.xy into a temp vec2 befor
ehand | 159 // do the same thing. Copying gl_FragCoord.xy into a temp vec2 befor
ehand |
| 162 // (and only accessing .xy) seems to "fix" things. | 160 // (and only accessing .xy) seems to "fix" things. |
| 163 this->codePrependf("\tvec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n", | 161 this->codePrependf("\tvec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n", |
| 164 kCoordName, kTempName, rtHeightName, kTempName); | 162 kCoordName, kTempName, rtHeightName, kTempName); |
| 165 this->codePrependf("vec2 %s = gl_FragCoord.xy;", kTempName); | 163 this->codePrependf("vec2 %s = gl_FragCoord.xy;", kTempName); |
| 166 fSetupFragPosition = true; | 164 fSetupFragPosition = true; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); | 277 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); |
| 280 } | 278 } |
| 281 | 279 |
| 282 void GrGLFragmentBuilder::onAfterChildProcEmitCode() { | 280 void GrGLFragmentBuilder::onAfterChildProcEmitCode() { |
| 283 SkASSERT(fSubstageIndices.count() >= 2); | 281 SkASSERT(fSubstageIndices.count() >= 2); |
| 284 fSubstageIndices.pop_back(); | 282 fSubstageIndices.pop_back(); |
| 285 fSubstageIndices.back()++; | 283 fSubstageIndices.back()++; |
| 286 int removeAt = fMangleString.findLastOf('_'); | 284 int removeAt = fMangleString.findLastOf('_'); |
| 287 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 285 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
| 288 } | 286 } |
| OLD | NEW |