| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | 49 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 50 combined.set(SkMatrix::kMTransY, | 50 combined.set(SkMatrix::kMTransY, |
| 51 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); | 51 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 52 } | 52 } |
| 53 return combined; | 53 return combined; |
| 54 } | 54 } |
| 55 | 55 |
| 56 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 56 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 57 | 57 |
| 58 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 58 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| 59 const GrGLProgramDesc& desc, | 59 const GrProgramDesc& desc, |
| 60 const BuiltinUniformHandles& builtinUniforms, | 60 const BuiltinUniformHandles& builtinUniforms, |
| 61 GrGLuint programID, | 61 GrGLuint programID, |
| 62 const UniformInfoArray& uniforms, | 62 const UniformInfoArray& uniforms, |
| 63 GrGLInstalledGeoProc* geometryProcessor, | 63 GrGLInstalledGeoProc* geometryProcessor, |
| 64 GrGLInstalledFragProcs* fragmentProcessors) | 64 GrGLInstalledFragProcs* fragmentProcessors) |
| 65 : fColor(GrColor_ILLEGAL) | 65 : fColor(GrColor_ILLEGAL) |
| 66 , fCoverage(GrColor_ILLEGAL) | 66 , fCoverage(GrColor_ILLEGAL) |
| 67 , fDstCopyTexUnit(-1) | 67 , fDstCopyTexUnit(-1) |
| 68 , fBuiltinUniformHandles(builtinUniforms) | 68 , fBuiltinUniformHandles(builtinUniforms) |
| 69 , fProgramID(programID) | 69 , fProgramID(programID) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 200 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 201 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 201 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void GrGLProgram::setColor(const GrOptDrawState& optState, | 204 void GrGLProgram::setColor(const GrOptDrawState& optState, |
| 205 GrColor color, | 205 GrColor color, |
| 206 SharedGLState* sharedState) { | 206 SharedGLState* sharedState) { |
| 207 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 207 const GrProgramDesc::KeyHeader& header = fDesc.header(); |
| 208 if (!optState.hasColorVertexAttribute()) { | 208 if (-1 != header.fColorAttributeIndex) { |
| 209 switch (header.fColorInput) { | 209 switch (header.fColorInput) { |
| 210 case GrGLProgramDesc::kAttribute_ColorInput: | 210 case GrProgramDesc::kAttribute_ColorInput: |
| 211 SkASSERT(-1 != header.fColorAttributeIndex); | |
| 212 if (sharedState->fConstAttribColor != color || | 211 if (sharedState->fConstAttribColor != color || |
| 213 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 212 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
| 214 // OpenGL ES only supports the float varieties of glVertexAt
trib | 213 // OpenGL ES only supports the float varieties of glVertexAt
trib |
| 215 GrGLfloat c[4]; | 214 GrGLfloat c[4]; |
| 216 GrColorToRGBAFloat(color, c); | 215 GrColorToRGBAFloat(color, c); |
| 217 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 216 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
| 218 sharedState->fConstAttribColor = color; | 217 sharedState->fConstAttribColor = color; |
| 219 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; | 218 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; |
| 220 } | 219 } |
| 221 break; | 220 break; |
| 222 case GrGLProgramDesc::kUniform_ColorInput: | 221 case GrProgramDesc::kUniform_ColorInput: |
| 223 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid(
)) { | 222 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid(
)) { |
| 224 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 223 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 225 GrGLfloat c[4]; | 224 GrGLfloat c[4]; |
| 226 GrColorToRGBAFloat(color, c); | 225 GrColorToRGBAFloat(color, c); |
| 227 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni,
1, c); | 226 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni,
1, c); |
| 228 fColor = color; | 227 fColor = color; |
| 229 } | 228 } |
| 230 sharedState->fConstAttribColorIndex = -1; | 229 sharedState->fConstAttribColorIndex = -1; |
| 231 break; | 230 break; |
| 232 case GrGLProgramDesc::kAllOnes_ColorInput: | 231 case GrProgramDesc::kAllOnes_ColorInput: |
| 233 sharedState->fConstAttribColorIndex = -1; | 232 sharedState->fConstAttribColorIndex = -1; |
| 234 break; | 233 break; |
| 235 default: | 234 default: |
| 236 SkFAIL("Unexpected color type."); | 235 SkFAIL("Unexpected color type."); |
| 237 } | 236 } |
| 238 } else { | 237 } else { |
| 239 sharedState->fConstAttribColorIndex = -1; | 238 sharedState->fConstAttribColorIndex = -1; |
| 240 } | 239 } |
| 241 } | 240 } |
| 242 | 241 |
| 243 void GrGLProgram::setCoverage(const GrOptDrawState& optState, | 242 void GrGLProgram::setCoverage(const GrOptDrawState& optState, |
| 244 GrColor coverage, | 243 GrColor coverage, |
| 245 SharedGLState* sharedState) { | 244 SharedGLState* sharedState) { |
| 246 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 245 const GrProgramDesc::KeyHeader& header = fDesc.header(); |
| 247 if (!optState.hasCoverageVertexAttribute()) { | 246 if (-1 != header.fCoverageAttributeIndex) { |
| 248 switch (header.fCoverageInput) { | 247 switch (header.fCoverageInput) { |
| 249 case GrGLProgramDesc::kAttribute_ColorInput: | 248 case GrProgramDesc::kAttribute_ColorInput: |
| 250 if (sharedState->fConstAttribCoverage != coverage || | 249 if (sharedState->fConstAttribCoverage != coverage || |
| 251 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { | 250 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { |
| 252 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 251 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
| 253 GrGLfloat c[4]; | 252 GrGLfloat c[4]; |
| 254 GrColorToRGBAFloat(coverage, c); | 253 GrColorToRGBAFloat(coverage, c); |
| 255 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 254 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
| 256 sharedState->fConstAttribCoverage = coverage; | 255 sharedState->fConstAttribCoverage = coverage; |
| 257 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 256 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
| 258 } | 257 } |
| 259 break; | 258 break; |
| 260 case GrGLProgramDesc::kUniform_ColorInput: | 259 case GrProgramDesc::kUniform_ColorInput: |
| 261 if (fCoverage != coverage) { | 260 if (fCoverage != coverage) { |
| 262 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 261 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 263 GrGLfloat c[4]; | 262 GrGLfloat c[4]; |
| 264 GrColorToRGBAFloat(coverage, c); | 263 GrColorToRGBAFloat(coverage, c); |
| 265 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageU
ni, 1, c); | 264 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageU
ni, 1, c); |
| 266 fCoverage = coverage; | 265 fCoverage = coverage; |
| 267 } | 266 } |
| 268 sharedState->fConstAttribCoverageIndex = -1; | 267 sharedState->fConstAttribCoverageIndex = -1; |
| 269 break; | 268 break; |
| 270 case GrGLProgramDesc::kAllOnes_ColorInput: | 269 case GrProgramDesc::kAllOnes_ColorInput: |
| 271 sharedState->fConstAttribCoverageIndex = -1; | 270 sharedState->fConstAttribCoverageIndex = -1; |
| 272 break; | 271 break; |
| 273 default: | 272 default: |
| 274 SkFAIL("Unexpected coverage type."); | 273 SkFAIL("Unexpected coverage type."); |
| 275 } | 274 } |
| 276 } else { | 275 } else { |
| 277 sharedState->fConstAttribCoverageIndex = -1; | 276 sharedState->fConstAttribCoverageIndex = -1; |
| 278 } | 277 } |
| 279 } | 278 } |
| 280 | 279 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 311 | 310 |
| 312 GrGLfloat rtAdjustmentVec[4]; | 311 GrGLfloat rtAdjustmentVec[4]; |
| 313 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 312 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 314 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 313 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
| 315 } | 314 } |
| 316 } | 315 } |
| 317 | 316 |
| 318 ////////////////////////////////////////////////////////////////////////////////
///////// | 317 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 319 | 318 |
| 320 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | 319 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, |
| 321 const GrGLProgramDesc& desc, | 320 const GrProgramDesc& desc, |
| 322 const BuiltinUniformHandles& builtinUni
forms, | 321 const BuiltinUniformHandles& builtinUni
forms, |
| 323 GrGLuint programID, | 322 GrGLuint programID, |
| 324 const UniformInfoArray& uniforms, | 323 const UniformInfoArray& uniforms, |
| 325 GrGLInstalledFragProcs* fragmentProcess
ors) | 324 GrGLInstalledFragProcs* fragmentProcess
ors) |
| 326 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { | 325 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { |
| 327 } | 326 } |
| 328 | 327 |
| 329 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, | 328 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, |
| 330 const GrOptDrawState&
optState) { | 329 const GrOptDrawState&
optState) { |
| 331 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 330 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 332 const GrRenderTarget* rt = optState.getRenderTarget(); | 331 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 333 SkISize size; | 332 SkISize size; |
| 334 size.set(rt->width(), rt->height()); | 333 size.set(rt->width(), rt->height()); |
| 335 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); | 334 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); |
| 336 } | 335 } |
| 337 | 336 |
| 338 ////////////////////////////////////////////////////////////////////////////////
///////// | 337 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 339 | 338 |
| 340 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | 339 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, |
| 341 const GrGLProgramDesc& desc, | 340 const GrProgramDesc& desc, |
| 342 const BuiltinUniformHandles& builtinUniforms, | 341 const BuiltinUniformHandles& builtinUniforms, |
| 343 GrGLuint programID, | 342 GrGLuint programID, |
| 344 const UniformInfoArray& uniforms, | 343 const UniformInfoArray& uniforms, |
| 345 GrGLInstalledFragProcs* fragmentProcessors, | 344 GrGLInstalledFragProcs* fragmentProcessors, |
| 346 const SeparableVaryingInfoArray& separableVaryi
ngs) | 345 const SeparableVaryingInfoArray& separableVaryi
ngs) |
| 347 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcess
ors) { | 346 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcess
ors) { |
| 348 int count = separableVaryings.count(); | 347 int count = separableVaryings.count(); |
| 349 fVaryings.push_back_n(count); | 348 fVaryings.push_back_n(count); |
| 350 for (int i = 0; i < count; i++) { | 349 for (int i = 0; i < count; i++) { |
| 351 Varying& varying = fVaryings[i]; | 350 Varying& varying = fVaryings[i]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 380 fragmentIn
put.fLocation, | 379 fragmentIn
put.fLocation, |
| 381 GR_GL_OBJE
CT_LINEAR, | 380 GR_GL_OBJE
CT_LINEAR, |
| 382 components
, | 381 components
, |
| 383 transform)
; | 382 transform)
; |
| 384 } | 383 } |
| 385 } | 384 } |
| 386 | 385 |
| 387 ////////////////////////////////////////////////////////////////////////////////
////// | 386 ////////////////////////////////////////////////////////////////////////////////
////// |
| 388 | 387 |
| 389 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, | 388 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, |
| 390 const GrGLProgramDesc& desc, | 389 const GrProgramDesc& desc, |
| 391 const BuiltinUniformHandles& builti
nUniforms, | 390 const BuiltinUniformHandles& builti
nUniforms, |
| 392 GrGLuint programID, | 391 GrGLuint programID, |
| 393 const UniformInfoArray& uniforms, | 392 const UniformInfoArray& uniforms, |
| 394 GrGLInstalledFragProcs* fps, | 393 GrGLInstalledFragProcs* fps, |
| 395 int texCoordSetCnt) | 394 int texCoordSetCnt) |
| 396 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) | 395 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) |
| 397 , fTexCoordSetCnt(texCoordSetCnt) { | 396 , fTexCoordSetCnt(texCoordSetCnt) { |
| 398 } | 397 } |
| 399 | 398 |
| 400 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 399 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 401 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 400 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 402 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 401 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 403 } | 402 } |
| 404 | 403 |
| 405 void | 404 void |
| 406 GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstall
edFragProc* ip) { | 405 GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstall
edFragProc* ip) { |
| 407 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 406 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
| 408 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 407 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 409 int numTransforms = proc.getProcessor()->numTransforms(); | 408 int numTransforms = proc.getProcessor()->numTransforms(); |
| 410 for (int t = 0; t < numTransforms; ++t) { | 409 for (int t = 0; t < numTransforms; ++t) { |
| 411 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 410 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| 412 GrGLPathRendering::PathTexGenComponents components = | 411 GrGLPathRendering::PathTexGenComponents components = |
| 413 GrGLPathRendering::kST_PathTexGenComponents; | 412 GrGLPathRendering::kST_PathTexGenComponents; |
| 414 if (proc.isPerspectiveCoordTransform(t, false)) { | 413 if (proc.isPerspectiveCoordTransform(t, false)) { |
| 415 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 414 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 416 } | 415 } |
| 417 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 416 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 418 } | 417 } |
| 419 } | 418 } |
| OLD | NEW |