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 "GrGLShaderStringBuilder.h" |
10 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 const GrGLProgramDesc& desc
) | 73 const GrGLProgramDesc& desc
) |
74 : INHERITED(program) | 74 : INHERITED(program) |
75 , fHasCustomColorOutput(false) | 75 , fHasCustomColorOutput(false) |
76 , fHasSecondaryOutput(false) | 76 , fHasSecondaryOutput(false) |
77 , fSetupFragPosition(false) | 77 , fSetupFragPosition(false) |
78 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey){ | 78 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey){ |
79 } | 79 } |
80 | 80 |
81 const char* GrGLFragmentShaderBuilder::dstColor() { | 81 const char* GrGLFragmentShaderBuilder::dstColor() { |
82 if (fProgramBuilder->fCodeStage.inStageCode()) { | 82 if (fProgramBuilder->fCodeStage.inStageCode()) { |
83 const GrEffect* effect = fProgramBuilder->fCodeStage.effectStage()->getE
ffect(); | 83 const GrProcessor* effect = fProgramBuilder->fCodeStage.effectStage()->g
etProcessor(); |
84 if (!effect->willReadDstColor()) { | 84 // TODO GPs can't read dst color, and full program builder only returns
a pointer to the |
85 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " | 85 // base fragment shader builder which does not have this function. Unfo
rtunately, |
| 86 // the code stage class only has a GrProcessor pointer so this is requir
ed for the time |
| 87 // being |
| 88 if (!static_cast<const GrFragmentProcessor*>(effect)->willReadDstColor()
) { |
| 89 SkDEBUGFAIL("GrGLProcessor asked for dst color but its generating Gr
Processor " |
86 "did not request access."); | 90 "did not request access."); |
87 return ""; | 91 return ""; |
88 } | 92 } |
89 } | 93 } |
90 | 94 |
91 GrGpuGL* gpu = fProgramBuilder->gpu(); | 95 GrGpuGL* gpu = fProgramBuilder->gpu(); |
92 if (gpu->glCaps().fbFetchSupport()) { | 96 if (gpu->glCaps().fbFetchSupport()) { |
93 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), | 97 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), |
94 gpu->glCaps().fbFetchExtensionString()); | 98 gpu->glCaps().fbFetchExtensionString()); |
95 return gpu->glCaps().fbFetchColorName(); | 99 return gpu->glCaps().fbFetchColorName(); |
(...skipping 16 matching lines...) Expand all Loading... |
112 "GL_OES_standard_derivatives"); | 116 "GL_OES_standard_derivatives"); |
113 } | 117 } |
114 return true; | 118 return true; |
115 } | 119 } |
116 default: | 120 default: |
117 SkFAIL("Unexpected GLSLFeature requested."); | 121 SkFAIL("Unexpected GLSLFeature requested."); |
118 return false; | 122 return false; |
119 } | 123 } |
120 } | 124 } |
121 | 125 |
122 SkString GrGLFragmentShaderBuilder::ensureFSCoords2D(const TransformedCoordsArra
y& coords, int index) { | 126 SkString GrGLFragmentShaderBuilder::ensureFSCoords2D( |
| 127 const GrGLProcessor::TransformedCoordsArray& coords, int index) { |
123 if (kVec3f_GrSLType != coords[index].getType()) { | 128 if (kVec3f_GrSLType != coords[index].getType()) { |
124 SkASSERT(kVec2f_GrSLType == coords[index].getType()); | 129 SkASSERT(kVec2f_GrSLType == coords[index].getType()); |
125 return coords[index].getName(); | 130 return coords[index].getName(); |
126 } | 131 } |
127 | 132 |
128 SkString coords2D("coords2D"); | 133 SkString coords2D("coords2D"); |
129 if (0 != index) { | 134 if (0 != index) { |
130 coords2D.appendf("_%i", index); | 135 coords2D.appendf("_%i", index); |
131 } | 136 } |
132 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", | 137 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", |
133 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); | 138 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); |
134 return coords2D; | 139 return coords2D; |
135 } | 140 } |
136 | 141 |
137 const char* GrGLFragmentShaderBuilder::fragmentPosition() { | 142 const char* GrGLFragmentShaderBuilder::fragmentPosition() { |
138 GrGLProgramBuilder::CodeStage* cs = &fProgramBuilder->fCodeStage; | 143 GrGLProgramBuilder::CodeStage* cs = &fProgramBuilder->fCodeStage; |
139 if (cs->inStageCode()) { | 144 if (cs->inStageCode()) { |
140 const GrEffect* effect = cs->effectStage()->getEffect(); | 145 const GrProcessor* effect = cs->effectStage()->getProcessor(); |
141 if (!effect->willReadFragmentPosition()) { | 146 if (!effect->willReadFragmentPosition()) { |
142 SkDEBUGFAIL("GrGLEffect asked for frag position but its generating G
rEffect " | 147 SkDEBUGFAIL("GrGLProcessor asked for frag position but its generatin
g GrProcessor " |
143 "did not request access."); | 148 "did not request access."); |
144 return ""; | 149 return ""; |
145 } | 150 } |
146 } | 151 } |
147 | 152 |
148 GrGpuGL* gpu = fProgramBuilder->gpu(); | 153 GrGpuGL* gpu = fProgramBuilder->gpu(); |
149 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers | 154 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers |
150 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the | 155 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the |
151 // declaration varies in earlier GLSL specs. So it is simpler to omit it. | 156 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
152 if (fTopLeftFragPosRead) { | 157 if (fTopLeftFragPosRead) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 dual_source_output_name()); | 359 dual_source_output_name()); |
355 fHasSecondaryOutput = true; | 360 fHasSecondaryOutput = true; |
356 } | 361 } |
357 return dual_source_output_name(); | 362 return dual_source_output_name(); |
358 } | 363 } |
359 | 364 |
360 const char* GrGLFragmentShaderBuilder::getColorOutputName() const { | 365 const char* GrGLFragmentShaderBuilder::getColorOutputName() const { |
361 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; | 366 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; |
362 } | 367 } |
363 | 368 |
OLD | NEW |