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

Side by Side Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp

Issue 1266773003: Implement support for dual source blending in ES (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/gpu/gl/builders/GrGLFragmentShaderBuilder.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 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 "GrGLProgramBuilder.h" 9 #include "GrGLProgramBuilder.h"
10 #include "gl/GrGLGpu.h" 10 #include "gl/GrGLGpu.h"
11 #include "gl/GrGLGLSL.h" 11 #include "gl/GrGLGLSL.h"
12 #include "glsl/GrGLSLCaps.h" 12 #include "glsl/GrGLSLCaps.h"
13 13
14 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) 14 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X)
15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X) 15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
16 16
17 const char* GrGLFragmentShaderBuilder::kDstTextureColorName = "_dstColor"; 17 const char* GrGLFragmentShaderBuilder::kDstTextureColorName = "_dstColor";
18 static const char* declared_color_output_name() { return "fsColorOut"; } 18 static const char* declared_color_output_name() { return "fsColorOut"; }
19 static const char* dual_source_output_name() { return "dualSourceOut"; } 19 static const char* declared_secondary_color_output_name() { return "fsSecondaryC olorOut"; }
20 20
21 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { 21 static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
22 SkASSERT(GrBlendEquationIsAdvanced(equation)); 22 SkASSERT(GrBlendEquationIsAdvanced(equation));
23 23
24 static const char* kLayoutQualifierNames[] = { 24 static const char* kLayoutQualifierNames[] = {
25 "blend_support_screen", 25 "blend_support_screen",
26 "blend_support_overlay", 26 "blend_support_overlay",
27 "blend_support_darken", 27 "blend_support_darken",
28 "blend_support_lighten", 28 "blend_support_lighten",
29 "blend_support_colordodge", 29 "blend_support_colordodge",
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 fCustomColorOutputIndex = fOutputs.count(); 233 fCustomColorOutputIndex = fOutputs.count();
234 fOutputs.push_back().set(kVec4f_GrSLType, 234 fOutputs.push_back().set(kVec4f_GrSLType,
235 GrGLShaderVar::kOut_TypeModifier, 235 GrGLShaderVar::kOut_TypeModifier,
236 declared_color_output_name()); 236 declared_color_output_name());
237 } 237 }
238 } 238 }
239 239
240 void GrGLFragmentShaderBuilder::enableSecondaryOutput() { 240 void GrGLFragmentShaderBuilder::enableSecondaryOutput() {
241 SkASSERT(!fHasSecondaryOutput); 241 SkASSERT(!fHasSecondaryOutput);
242 fHasSecondaryOutput = true; 242 fHasSecondaryOutput = true;
243 fOutputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kOut_TypeModifier, 243 if (kGLES_GrGLStandard == fProgramBuilder->gpu()->ctxInfo().standard()) {
244 dual_source_output_name()); 244 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, "GL_EXT_ble nd_func_extended");
245 }
246
247 // If the primary output is declared, we must declare also the secondary out put
248 // and vice versa, since it is not allowed to use a built-in gl_FragColor an d a custom
249 // output. The condition also co-incides with the condition in whici GLES SL 2.0
250 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a c ustom output.
251 const GrGLSLCaps& caps = *fProgramBuilder->gpu()->glCaps().glslCaps();
252 if (caps.mustDeclareFragmentShaderOutput()) {
253 fOutputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kOut_TypeModifi er,
254 declared_secondary_color_output_name());
255 }
245 } 256 }
246 257
247 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { 258 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const {
248 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ; 259 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ;
249 } 260 }
250 261
251 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { 262 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const {
252 return dual_source_output_name(); 263 const GrGLSLCaps& caps = *fProgramBuilder->gpu()->glCaps().glslCaps();
264 return caps.mustDeclareFragmentShaderOutput() ? declared_secondary_color_out put_name()
265 : "gl_SecondaryFragColorEXT";
253 } 266 }
254 267
255 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, 268 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId,
256 SkTDArray<GrGLuint>* sha derIds) { 269 SkTDArray<GrGLuint>* sha derIds) {
257 GrGLGpu* gpu = fProgramBuilder->gpu(); 270 GrGLGpu* gpu = fProgramBuilder->gpu();
258 this->versionDecl() = GrGLGetGLSLVersionDecl(gpu->ctxInfo()); 271 this->versionDecl() = GrGLGetGLSLVersionDecl(gpu->ctxInfo());
259 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, 272 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
260 gpu->glStandard(), 273 gpu->glStandard(),
261 &this->precisionQualifier()); 274 &this->precisionQualifier());
262 this->compileAndAppendLayoutQualifiers(); 275 this->compileAndAppendLayoutQualifiers();
263 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility , 276 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility ,
264 &this->uniforms()); 277 &this->uniforms());
265 this->appendDecls(fInputs, &this->inputs()); 278 this->appendDecls(fInputs, &this->inputs());
266 // We shouldn't have declared outputs on 1.10 279 // We shouldn't have declared outputs on 1.10
267 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()) ; 280 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()) ;
268 this->appendDecls(fOutputs, &this->outputs()); 281 this->appendDecls(fOutputs, &this->outputs());
269 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); 282 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds);
270 } 283 }
271 284
272 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID) { 285 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID) {
273 if (fHasCustomColorOutput && fProgramBuilder->gpu()->glCaps().bindFragDataLo cationSupport()) { 286 const GrGLCaps& caps = fProgramBuilder->gpu()->glCaps();
287 if (fHasCustomColorOutput && caps.bindFragDataLocationSupport()) {
274 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name()) ); 288 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name()) );
275 } 289 }
276 if (fHasSecondaryOutput) { 290 if (fHasSecondaryOutput && caps.glslCaps()->mustDeclareFragmentShaderOutput( )) {
277 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_ name())); 291 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
292 declared_secondary_color_output_name ()));
278 } 293 }
279 } 294 }
280 295
281 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec) { 296 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec) {
282 v->fFsIn = v->fVsOut; 297 v->fFsIn = v->fVsOut;
283 if (v->fGsOut) { 298 if (v->fGsOut) {
284 v->fFsIn = v->fGsOut; 299 v->fFsIn = v->fGsOut;
285 } 300 }
286 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v- >fFsIn, fsPrec); 301 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v- >fFsIn, fsPrec);
287 } 302 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLFragmentShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698