| 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 "GrGLShaderStringBuilder.h" |
| 9 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
| 10 #include "../GrGLGpu.h" | 11 #include "../GrGLGpu.h" |
| 11 | 12 |
| 12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
| 13 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) | 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) |
| 14 | 15 |
| 15 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; | 16 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; |
| 16 static const char* declared_color_output_name() { return "fsColorOut"; } | 17 static const char* declared_color_output_name() { return "fsColorOut"; } |
| 17 static const char* dual_source_output_name() { return "dualSourceOut"; } | 18 static const char* dual_source_output_name() { return "dualSourceOut"; } |
| 18 static void append_default_precision_qualifier(GrSLPrecision p, | 19 static void append_default_precision_qualifier(GrSLPrecision p, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 203 |
| 203 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 204 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
| 204 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; | 205 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; |
| 205 } | 206 } |
| 206 | 207 |
| 207 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 208 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
| 208 return dual_source_output_name(); | 209 return dual_source_output_name(); |
| 209 } | 210 } |
| 210 | 211 |
| 211 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 212 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 212 SkTDArray<GrGLuint>* sha
derIds) { | 213 SkTDArray<GrGLuint>* sha
derIds) const { |
| 213 GrGLGpu* gpu = fProgramBuilder->gpu(); | 214 GrGLGpu* gpu = fProgramBuilder->gpu(); |
| 214 this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); | 215 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); |
| 216 fragShaderSrc.append(fExtensions); |
| 215 append_default_precision_qualifier(kDefault_GrSLPrecision, | 217 append_default_precision_qualifier(kDefault_GrSLPrecision, |
| 216 gpu->glStandard(), | 218 gpu->glStandard(), |
| 217 &this->precisionQualifier()); | 219 &fragShaderSrc); |
| 218 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, | 220 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); |
| 219 &this->uniforms()); | 221 this->appendDecls(fInputs, &fragShaderSrc); |
| 220 this->appendDecls(fInputs, &this->inputs()); | |
| 221 // We shouldn't have declared outputs on 1.10 | 222 // We shouldn't have declared outputs on 1.10 |
| 222 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; | 223 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; |
| 223 this->appendDecls(fOutputs, &this->outputs()); | 224 this->appendDecls(fOutputs, &fragShaderSrc); |
| 224 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); | 225 fragShaderSrc.append(fFunctions); |
| 226 fragShaderSrc.append("void main() {\n"); |
| 227 fragShaderSrc.append(fCode); |
| 228 fragShaderSrc.append("}\n"); |
| 229 |
| 230 GrGLuint fragShaderId = GrGLCompileAndAttachShader(gpu->glContext(), program
Id, |
| 231 GR_GL_FRAGMENT_SHADER, fr
agShaderSrc, |
| 232 gpu->stats()); |
| 233 if (!fragShaderId) { |
| 234 return false; |
| 235 } |
| 236 |
| 237 *shaderIds->append() = fragShaderId; |
| 238 |
| 239 return true; |
| 225 } | 240 } |
| 226 | 241 |
| 227 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ | 242 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ |
| 228 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion | 243 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion |
| 229 if (fHasCustomColorOutput && | 244 if (fHasCustomColorOutput && |
| 230 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { | 245 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { |
| 231 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); | 246 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); |
| 232 } | 247 } |
| 233 if (fHasSecondaryOutput) { | 248 if (fHasSecondaryOutput) { |
| 234 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); | 249 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); |
| 235 } | 250 } |
| 236 } | 251 } |
| 237 | 252 |
| 238 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 253 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
| 239 v->fFsIn = v->fVsOut; | 254 v->fFsIn = v->fVsOut; |
| 240 if (v->fGsOut) { | 255 if (v->fGsOut) { |
| 241 v->fFsIn = v->fGsOut; | 256 v->fFsIn = v->fGsOut; |
| 242 } | 257 } |
| 243 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 258 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
| 244 } | 259 } |
| OLD | NEW |