OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
9 | 9 |
10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 textureAccess.getParams(), | 122 textureAccess.getParams(), |
123 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | 123 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 /////////////////////////////////////////////////////////////////////////////// | 128 /////////////////////////////////////////////////////////////////////////////// |
129 | 129 |
130 void GrGLProgram::setData(const GrOptDrawState& optState, | 130 void GrGLProgram::setData(const GrOptDrawState& optState, |
131 GrGpu::DrawType drawType, | 131 GrGpu::DrawType drawType, |
132 const GrDeviceCoordTexture* dstCopy, | 132 const GrDeviceCoordTexture* dstCopy) { |
133 SharedGLState* sharedState) { | |
134 GrColor color = optState.getColor(); | 133 GrColor color = optState.getColor(); |
135 GrColor coverage = optState.getCoverageColor(); | 134 GrColor coverage = optState.getCoverageColor(); |
136 | 135 |
137 this->setColor(optState, color, sharedState); | 136 this->setColor(optState, color); |
138 this->setCoverage(optState, coverage, sharedState); | 137 this->setCoverage(optState, coverage); |
139 this->setMatrixAndRenderTargetHeight(drawType, optState); | 138 this->setMatrixAndRenderTargetHeight(drawType, optState); |
140 | 139 |
141 if (dstCopy) { | 140 if (dstCopy) { |
142 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 141 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
144 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 143 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
145 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 144 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
146 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 145 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
147 1.f / dstCopy->texture()->width(), | 146 1.f / dstCopy->texture()->width(), |
148 1.f / dstCopy->texture()->height()); | 147 1.f / dstCopy->texture()->height()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
195 transforms[t].fCurrentValue = matrix; | 194 transforms[t].fCurrentValue = matrix; |
196 } | 195 } |
197 } | 196 } |
198 } | 197 } |
199 | 198 |
200 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
201 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
202 } | 201 } |
203 | 202 |
204 void GrGLProgram::setColor(const GrOptDrawState& optState, | 203 void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { |
205 GrColor color, | |
206 SharedGLState* sharedState) { | |
207 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 204 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
208 if (!optState.hasColorVertexAttribute()) { | 205 switch (header.fColorInput) { |
209 switch (header.fColorInput) { | 206 case GrGLProgramDesc::kAttribute_ColorInput: |
210 case GrGLProgramDesc::kAttribute_ColorInput: | 207 // Attribute case is handled in GrGpuGL::setupGeometry |
211 SkASSERT(-1 != header.fColorAttributeIndex); | 208 break; |
212 if (sharedState->fConstAttribColor != color || | 209 case GrGLProgramDesc::kUniform_ColorInput: |
213 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { |
214 // OpenGL ES only supports the float varieties of glVertexAt
trib | 211 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m |
215 GrGLfloat c[4]; | 212 GrGLfloat c[4]; |
216 GrColorToRGBAFloat(color, c); | 213 GrColorToRGBAFloat(color, c); |
217 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1,
c); |
218 sharedState->fConstAttribColor = color; | 215 fColor = color; |
219 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; | 216 } |
220 } | 217 break; |
221 break; | 218 case GrGLProgramDesc::kAllOnes_ColorInput: |
222 case GrGLProgramDesc::kUniform_ColorInput: | 219 // Handled by shader creation |
223 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid(
)) { | 220 break; |
224 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 221 default: |
225 GrGLfloat c[4]; | 222 SkFAIL("Unexpected color type."); |
226 GrColorToRGBAFloat(color, c); | |
227 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni,
1, c); | |
228 fColor = color; | |
229 } | |
230 sharedState->fConstAttribColorIndex = -1; | |
231 break; | |
232 case GrGLProgramDesc::kAllOnes_ColorInput: | |
233 sharedState->fConstAttribColorIndex = -1; | |
234 break; | |
235 default: | |
236 SkFAIL("Unexpected color type."); | |
237 } | |
238 } else { | |
239 sharedState->fConstAttribColorIndex = -1; | |
240 } | 223 } |
241 } | 224 } |
242 | 225 |
243 void GrGLProgram::setCoverage(const GrOptDrawState& optState, | 226 void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage)
{ |
244 GrColor coverage, | |
245 SharedGLState* sharedState) { | |
246 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 227 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
247 if (!optState.hasCoverageVertexAttribute()) { | 228 switch (header.fCoverageInput) { |
248 switch (header.fCoverageInput) { | 229 case GrGLProgramDesc::kAttribute_ColorInput: |
249 case GrGLProgramDesc::kAttribute_ColorInput: | 230 // Attribute case is handled in GrGpuGL::setupGeometry |
250 if (sharedState->fConstAttribCoverage != coverage || | 231 break; |
251 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { | 232 case GrGLProgramDesc::kUniform_ColorInput: |
252 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 233 if (fCoverage != coverage) { |
253 GrGLfloat c[4]; | 234 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m |
254 GrColorToRGBAFloat(coverage, c); | 235 GrGLfloat c[4]; |
255 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 236 GrColorToRGBAFloat(coverage, c); |
256 sharedState->fConstAttribCoverage = coverage; | 237 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni,
1, c); |
257 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 238 fCoverage = coverage; |
258 } | 239 } |
259 break; | 240 break; |
260 case GrGLProgramDesc::kUniform_ColorInput: | 241 case GrGLProgramDesc::kAllOnes_ColorInput: |
261 if (fCoverage != coverage) { | 242 // Handled by shader creation |
262 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 243 break; |
263 GrGLfloat c[4]; | 244 default: |
264 GrColorToRGBAFloat(coverage, c); | 245 SkFAIL("Unexpected coverage type."); |
265 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageU
ni, 1, c); | |
266 fCoverage = coverage; | |
267 } | |
268 sharedState->fConstAttribCoverageIndex = -1; | |
269 break; | |
270 case GrGLProgramDesc::kAllOnes_ColorInput: | |
271 sharedState->fConstAttribCoverageIndex = -1; | |
272 break; | |
273 default: | |
274 SkFAIL("Unexpected coverage type."); | |
275 } | |
276 } else { | |
277 sharedState->fConstAttribCoverageIndex = -1; | |
278 } | 246 } |
279 } | 247 } |
280 | 248 |
281 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 249 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
282 const GrOptDrawState& optState)
{ | 250 const GrOptDrawState& optState)
{ |
283 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 251 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
284 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 252 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
285 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { | 253 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { |
286 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 254 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
287 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | 255 SkIntToScalar(optState.getRenderTarget()->hei
ght())); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 for (int t = 0; t < numTransforms; ++t) { | 378 for (int t = 0; t < numTransforms; ++t) { |
411 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 379 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
412 GrGLPathRendering::PathTexGenComponents components = | 380 GrGLPathRendering::PathTexGenComponents components = |
413 GrGLPathRendering::kST_PathTexGenComponents; | 381 GrGLPathRendering::kST_PathTexGenComponents; |
414 if (proc.isPerspectiveCoordTransform(t, false)) { | 382 if (proc.isPerspectiveCoordTransform(t, false)) { |
415 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 383 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
416 } | 384 } |
417 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
418 } | 386 } |
419 } | 387 } |
OLD | NEW |