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