| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 SkString sum; | 216 SkString sum; |
| 217 GrGLSLAddf<4>(&sum, colorStr.c_str(), constStr.c_str()); | 217 GrGLSLAddf<4>(&sum, colorStr.c_str(), constStr.c_str()); |
| 218 builder->fsCodeAppendf("\t%s = %s;\n", outputVar, sum.c_str()); | 218 builder->fsCodeAppendf("\t%s = %s;\n", outputVar, sum.c_str()); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 GrSLConstantVec GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString*
inColor) { | 222 GrSLConstantVec GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString*
inColor) { |
| 223 switch (fDesc.getHeader().fColorInput) { | 223 switch (fDesc.getHeader().fColorInput) { |
| 224 case GrGLProgramDesc::kAttribute_ColorInput: { | 224 case GrGLProgramDesc::kAttribute_ColorInput: { |
| 225 builder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); | 225 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex
Builder(); |
| 226 SkASSERT(NULL != vertexBuilder); |
| 227 vertexBuilder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); |
| 226 const char *vsName, *fsName; | 228 const char *vsName, *fsName; |
| 227 builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); | 229 vertexBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName
); |
| 228 builder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); | 230 vertexBuilder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
| 229 *inColor = fsName; | 231 *inColor = fsName; |
| 230 return kNone_GrSLConstantVec; | 232 return kNone_GrSLConstantVec; |
| 231 } | 233 } |
| 232 case GrGLProgramDesc::kUniform_ColorInput: { | 234 case GrGLProgramDesc::kUniform_ColorInput: { |
| 233 const char* name; | 235 const char* name; |
| 234 fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::k
Fragment_Visibility, | 236 fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::k
Fragment_Visibility, |
| 235 kVec4f_GrSLType, "Co
lor", &name); | 237 kVec4f_GrSLType, "Co
lor", &name); |
| 236 *inColor = name; | 238 *inColor = name; |
| 237 return kNone_GrSLConstantVec; | 239 return kNone_GrSLConstantVec; |
| 238 } | 240 } |
| 239 case GrGLProgramDesc::kTransBlack_ColorInput: | 241 case GrGLProgramDesc::kTransBlack_ColorInput: |
| 240 inColor->reset(); | 242 inColor->reset(); |
| 241 return kZeros_GrSLConstantVec; | 243 return kZeros_GrSLConstantVec; |
| 242 case GrGLProgramDesc::kSolidWhite_ColorInput: | 244 case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 243 inColor->reset(); | 245 inColor->reset(); |
| 244 return kOnes_GrSLConstantVec; | 246 return kOnes_GrSLConstantVec; |
| 245 default: | 247 default: |
| 246 GrCrash("Unknown color type."); | 248 GrCrash("Unknown color type."); |
| 247 return kNone_GrSLConstantVec; | 249 return kNone_GrSLConstantVec; |
| 248 } | 250 } |
| 249 } | 251 } |
| 250 | 252 |
| 251 GrSLConstantVec GrGLProgram::genInputCoverage(GrGLShaderBuilder* builder, SkStri
ng* inCoverage) { | 253 GrSLConstantVec GrGLProgram::genInputCoverage(GrGLShaderBuilder* builder, SkStri
ng* inCoverage) { |
| 252 switch (fDesc.getHeader().fCoverageInput) { | 254 switch (fDesc.getHeader().fCoverageInput) { |
| 253 case GrGLProgramDesc::kAttribute_ColorInput: { | 255 case GrGLProgramDesc::kAttribute_ColorInput: { |
| 254 builder->addAttribute(kVec4f_GrSLType, COV_ATTR_NAME); | 256 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex
Builder(); |
| 257 SkASSERT(NULL != vertexBuilder); |
| 258 vertexBuilder->addAttribute(kVec4f_GrSLType, COV_ATTR_NAME); |
| 255 const char *vsName, *fsName; | 259 const char *vsName, *fsName; |
| 256 builder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); | 260 vertexBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsN
ame); |
| 257 builder->vsCodeAppendf("\t%s = " COV_ATTR_NAME ";\n", vsName); | 261 vertexBuilder->vsCodeAppendf("\t%s = " COV_ATTR_NAME ";\n", vsName); |
| 258 *inCoverage = fsName; | 262 *inCoverage = fsName; |
| 259 return kNone_GrSLConstantVec; | 263 return kNone_GrSLConstantVec; |
| 260 } | 264 } |
| 261 case GrGLProgramDesc::kUniform_ColorInput: { | 265 case GrGLProgramDesc::kUniform_ColorInput: { |
| 262 const char* name; | 266 const char* name; |
| 263 fUniformHandles.fCoverageUni = | 267 fUniformHandles.fCoverageUni = |
| 264 builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 268 builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 265 kVec4f_GrSLType, "Coverage", &name); | 269 kVec4f_GrSLType, "Coverage", &name); |
| 266 *inCoverage = name; | 270 *inCoverage = name; |
| 267 return kNone_GrSLConstantVec; | 271 return kNone_GrSLConstantVec; |
| 268 } | 272 } |
| 269 case GrGLProgramDesc::kTransBlack_ColorInput: | 273 case GrGLProgramDesc::kTransBlack_ColorInput: |
| 270 inCoverage->reset(); | 274 inCoverage->reset(); |
| 271 return kZeros_GrSLConstantVec; | 275 return kZeros_GrSLConstantVec; |
| 272 case GrGLProgramDesc::kSolidWhite_ColorInput: | 276 case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 273 inCoverage->reset(); | 277 inCoverage->reset(); |
| 274 return kOnes_GrSLConstantVec; | 278 return kOnes_GrSLConstantVec; |
| 275 default: | 279 default: |
| 276 GrCrash("Unknown color type."); | 280 GrCrash("Unknown color type."); |
| 277 return kNone_GrSLConstantVec; | 281 return kNone_GrSLConstantVec; |
| 278 } | 282 } |
| 279 } | 283 } |
| 280 | 284 |
| 281 void GrGLProgram::genGeometryShader(GrGLShaderBuilder* builder) const { | 285 void GrGLProgram::genGeometryShader(GrGLShaderBuilder::VertexBuilder* vertexBuil
der) const { |
| 282 #if GR_GL_EXPERIMENTAL_GS | 286 #if GR_GL_EXPERIMENTAL_GS |
| 283 // TODO: The builder should add all this glue code. | 287 // TODO: The builder should add all this glue code. |
| 284 if (fDesc.getHeader().fExperimentalGS) { | 288 if (fDesc.getHeader().fExperimentalGS) { |
| 285 SkASSERT(fContext.info().glslGeneration() >= k150_GrGLSLGeneration); | 289 SkASSERT(fContext.info().glslGeneration() >= k150_GrGLSLGeneration); |
| 286 builder->fGSHeader.append("layout(triangles) in;\n" | 290 vertexBuilder->fGSHeader.append("layout(triangles) in;\n" |
| 287 "layout(triangle_strip, max_vertices = 6) out
;\n"); | 291 "layout(triangle_strip, max_vertices = 6
) out;\n"); |
| 288 builder->gsCodeAppend("\tfor (int i = 0; i < 3; ++i) {\n" | 292 vertexBuilder->gsCodeAppend("\tfor (int i = 0; i < 3; ++i) {\n" |
| 289 "\t\tgl_Position = gl_in[i].gl_Position;\n"); | 293 "\t\tgl_Position = gl_in[i].gl_Position;\n")
; |
| 290 if (fDesc.getHeader().fEmitsPointSize) { | 294 if (fDesc.getHeader().fEmitsPointSize) { |
| 291 builder->gsCodeAppend("\t\tgl_PointSize = 1.0;\n"); | 295 vertexBuilder->gsCodeAppend("\t\tgl_PointSize = 1.0;\n"); |
| 292 } | 296 } |
| 293 SkASSERT(builder->fGSInputs.count() == builder->fGSOutputs.count()); | 297 SkASSERT(vertexBuilder->fGSInputs.count() == vertexBuilder->fGSOutputs.c
ount()); |
| 294 int count = builder->fGSInputs.count(); | 298 int count = vertexBuilder->fGSInputs.count(); |
| 295 for (int i = 0; i < count; ++i) { | 299 for (int i = 0; i < count; ++i) { |
| 296 builder->gsCodeAppendf("\t\t%s = %s[i];\n", | 300 vertexBuilder->gsCodeAppendf("\t\t%s = %s[i];\n", |
| 297 builder->fGSOutputs[i].getName().c_str(), | 301 vertexBuilder->fGSOutputs[i].getName().
c_str(), |
| 298 builder->fGSInputs[i].getName().c_str()); | 302 vertexBuilder->fGSInputs[i].getName().c
_str()); |
| 299 } | 303 } |
| 300 builder->gsCodeAppend("\t\tEmitVertex();\n" | 304 vertexBuilder->gsCodeAppend("\t\tEmitVertex();\n" |
| 301 "\t}\n" | 305 "\t}\n" |
| 302 "\tEndPrimitive();\n"); | 306 "\tEndPrimitive();\n"); |
| 303 } | 307 } |
| 304 #endif | 308 #endif |
| 305 } | 309 } |
| 306 | 310 |
| 307 const char* GrGLProgram::adjustInColor(const SkString& inColor) const { | 311 const char* GrGLProgram::adjustInColor(const SkString& inColor) const { |
| 308 if (inColor.size()) { | 312 if (inColor.size()) { |
| 309 return inColor.c_str(); | 313 return inColor.c_str(); |
| 310 } else { | 314 } else { |
| 311 if (GrGLProgramDesc::kSolidWhite_ColorInput == fDesc.getHeader().fColorI
nput) { | 315 if (GrGLProgramDesc::kSolidWhite_ColorInput == fDesc.getHeader().fColorI
nput) { |
| 312 return GrGLSLOnesVecf(4); | 316 return GrGLSLOnesVecf(4); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 *string = GrGLSLOnesVecf(4); | 394 *string = GrGLSLOnesVecf(4); |
| 391 break; | 395 break; |
| 392 } | 396 } |
| 393 } | 397 } |
| 394 | 398 |
| 395 } | 399 } |
| 396 | 400 |
| 397 // compiles all the shaders from builder and stores the shader IDs | 401 // compiles all the shaders from builder and stores the shader IDs |
| 398 bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { | 402 bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { |
| 399 | 403 |
| 404 SkASSERT(!fVShaderID); |
| 405 SkASSERT(!fGShaderID); |
| 406 SkASSERT(!fFShaderID); |
| 407 |
| 400 SkString shader; | 408 SkString shader; |
| 401 | 409 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild
er()) { |
| 402 builder.vsGetShader(&shader); | 410 vertexBuilder->vsGetShader(&shader); |
| 403 if (c_PrintShaders) { | |
| 404 GrPrintf(shader.c_str()); | |
| 405 GrPrintf("\n"); | |
| 406 } | |
| 407 | |
| 408 if (!(fVShaderID = compile_shader(fContext, GR_GL_VERTEX_SHADER, shader))) { | |
| 409 return false; | |
| 410 } | |
| 411 | |
| 412 fGShaderID = 0; | |
| 413 #if GR_GL_EXPERIMENTAL_GS | |
| 414 if (fDesc.getHeader().fExperimentalGS) { | |
| 415 builder.gsGetShader(&shader); | |
| 416 if (c_PrintShaders) { | 411 if (c_PrintShaders) { |
| 417 GrPrintf(shader.c_str()); | 412 GrPrintf(shader.c_str()); |
| 418 GrPrintf("\n"); | 413 GrPrintf("\n"); |
| 419 } | 414 } |
| 420 if (!(fGShaderID = compile_shader(fContext, GR_GL_GEOMETRY_SHADER, shade
r))) { | 415 if (!(fVShaderID = compile_shader(fContext, GR_GL_VERTEX_SHADER, shader)
)) { |
| 421 return false; | 416 return false; |
| 422 } | 417 } |
| 418 |
| 419 #if GR_GL_EXPERIMENTAL_GS |
| 420 if (fDesc.getHeader().fExperimentalGS) { |
| 421 vertexBuilder->gsGetShader(&shader); |
| 422 if (c_PrintShaders) { |
| 423 GrPrintf(shader.c_str()); |
| 424 GrPrintf("\n"); |
| 425 } |
| 426 if (!(fGShaderID = compile_shader(fContext, GR_GL_GEOMETRY_SHADER, s
hader))) { |
| 427 return false; |
| 428 } |
| 429 } |
| 430 #endif |
| 423 } | 431 } |
| 424 #endif | |
| 425 | 432 |
| 426 builder.fsGetShader(&shader); | 433 builder.fsGetShader(&shader); |
| 427 if (c_PrintShaders) { | 434 if (c_PrintShaders) { |
| 428 GrPrintf(shader.c_str()); | 435 GrPrintf(shader.c_str()); |
| 429 GrPrintf("\n"); | 436 GrPrintf("\n"); |
| 430 } | 437 } |
| 431 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ | 438 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ |
| 432 return false; | 439 return false; |
| 433 } | 440 } |
| 434 | 441 |
| 435 return true; | 442 return true; |
| 436 } | 443 } |
| 437 | 444 |
| 438 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], | 445 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], |
| 439 const GrEffectStage* coverageStages[]) { | 446 const GrEffectStage* coverageStages[]) { |
| 440 SkASSERT(0 == fProgramID); | 447 SkASSERT(0 == fProgramID); |
| 441 | 448 |
| 442 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 449 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 443 | 450 |
| 444 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); | 451 bool needsVertexShader = true; |
| 452 |
| 453 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc, needsVert
exShader); |
| 454 |
| 455 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild
er()) { |
| 456 const char* viewMName; |
| 457 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::k
Vertex_Visibility, |
| 458 kMat33f_GrSLType, "V
iewM", &viewMName); |
| 459 |
| 460 vertexBuilder->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" |
| 461 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\
n", |
| 462 viewMName, vertexBuilder->positionAttribute
().c_str()); |
| 463 |
| 464 // we output point size in the GS if present |
| 465 if (header.fEmitsPointSize |
| 466 #if GR_GL_EXPERIMENTAL_GS |
| 467 && !header.fExperimentalGS |
| 468 #endif |
| 469 ) { |
| 470 vertexBuilder->vsCodeAppend("\tgl_PointSize = 1.0;\n"); |
| 471 } |
| 472 } |
| 445 | 473 |
| 446 // the dual source output has no canonical var name, have to | 474 // the dual source output has no canonical var name, have to |
| 447 // declare an output, which is incompatible with gl_FragColor/gl_FragData. | 475 // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
| 448 bool dualSourceOutputWritten = false; | 476 bool dualSourceOutputWritten = false; |
| 449 | 477 |
| 450 GrGLShaderVar colorOutput; | 478 GrGLShaderVar colorOutput; |
| 451 bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneratio
n(), | 479 bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneratio
n(), |
| 452 declared_color_output_name(), | 480 declared_color_output_name(), |
| 453 &colorOutput); | 481 &colorOutput); |
| 454 if (isColorDeclared) { | 482 if (isColorDeclared) { |
| 455 builder.fFSOutputs.push_back(colorOutput); | 483 builder.fsOutputAppend(colorOutput); |
| 456 } | 484 } |
| 457 | 485 |
| 458 const char* viewMName; | |
| 459 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVert
ex_Visibility, | |
| 460 kMat33f_GrSLType, "ViewM
", &viewMName); | |
| 461 | |
| 462 | |
| 463 builder.vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" | |
| 464 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n", | |
| 465 viewMName, builder.positionAttribute().getName().c_str
()); | |
| 466 | |
| 467 // incoming color to current stage being processed. | 486 // incoming color to current stage being processed. |
| 468 SkString inColor; | 487 SkString inColor; |
| 469 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor); | 488 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor); |
| 470 | 489 |
| 471 // we output point size in the GS if present | |
| 472 if (header.fEmitsPointSize | |
| 473 #if GR_GL_EXPERIMENTAL_GS | |
| 474 && !header.fExperimentalGS | |
| 475 #endif | |
| 476 ) { | |
| 477 builder.vsCodeAppend("\tgl_PointSize = 1.0;\n"); | |
| 478 } | |
| 479 | |
| 480 // Get the coeffs for the Mode-based color filter, determine if color is nee
ded. | 490 // Get the coeffs for the Mode-based color filter, determine if color is nee
ded. |
| 481 SkXfermode::Coeff colorCoeff; | 491 SkXfermode::Coeff colorCoeff; |
| 482 SkXfermode::Coeff filterColorCoeff; | 492 SkXfermode::Coeff filterColorCoeff; |
| 483 SkAssertResult( | 493 SkAssertResult( |
| 484 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), | 494 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), |
| 485 &filterColorCoeff, | 495 &filterColorCoeff, |
| 486 &colorCoeff)); | 496 &colorCoeff)); |
| 487 bool needColor, needFilterColor; | 497 bool needColor, needFilterColor; |
| 488 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); | 498 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); |
| 489 | 499 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 builder.fsCodeAppend("\tdiscard;\n"); | 570 builder.fsCodeAppend("\tdiscard;\n"); |
| 561 } else { | 571 } else { |
| 562 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\
t\tdiscard;\n\t}\n", | 572 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\
t\tdiscard;\n\t}\n", |
| 563 inCoverage.c_str()); | 573 inCoverage.c_str()); |
| 564 } | 574 } |
| 565 } | 575 } |
| 566 | 576 |
| 567 GrGLProgramDesc::CoverageOutput coverageOutput = | 577 GrGLProgramDesc::CoverageOutput coverageOutput = |
| 568 static_cast<GrGLProgramDesc::CoverageOutput>(header.fCoverageOutput); | 578 static_cast<GrGLProgramDesc::CoverageOutput>(header.fCoverageOutput); |
| 569 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(coverageOutput)) { | 579 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(coverageOutput)) { |
| 570 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, | 580 builder.fsOutputAppend().set(kVec4f_GrSLType, |
| 571 GrGLShaderVar::kOut_TypeModifier, | 581 GrGLShaderVar::kOut_TypeModifier, |
| 572 dual_source_output_name()); | 582 dual_source_output_name()); |
| 573 // default coeff to ones for kCoverage_DualSrcOutput | 583 // default coeff to ones for kCoverage_DualSrcOutput |
| 574 SkString coeff; | 584 SkString coeff; |
| 575 GrSLConstantVec knownCoeffValue = kOnes_GrSLConstantVec; | 585 GrSLConstantVec knownCoeffValue = kOnes_GrSLConstantVec; |
| 576 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCov
erageOutput) { | 586 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCov
erageOutput) { |
| 577 // Get (1-A) into coeff | 587 // Get (1-A) into coeff |
| 578 SkString inColorAlpha; | 588 SkString inColorAlpha; |
| 579 GrGLSLGetComponent4f(&inColorAlpha, | 589 GrGLSLGetComponent4f(&inColorAlpha, |
| 580 inColor.c_str(), | 590 inColor.c_str(), |
| 581 kA_GrColorComponentFlag, | 591 kA_GrColorComponentFlag, |
| 582 knownColorValue, | 592 knownColorValue, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 knownDstContributionValue, | 654 knownDstContributionValue, |
| 645 false); | 655 false); |
| 646 } else { | 656 } else { |
| 647 expand_known_value4f(&fragColor, knownFragColorValue); | 657 expand_known_value4f(&fragColor, knownFragColorValue); |
| 648 } | 658 } |
| 649 builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), fragCol
or.c_str()); | 659 builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), fragCol
or.c_str()); |
| 650 | 660 |
| 651 /////////////////////////////////////////////////////////////////////////// | 661 /////////////////////////////////////////////////////////////////////////// |
| 652 // insert GS | 662 // insert GS |
| 653 #ifdef SK_DEBUG | 663 #ifdef SK_DEBUG |
| 654 this->genGeometryShader(&builder); | 664 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild
er()) { |
| 665 this->genGeometryShader(vertexBuilder); |
| 666 } |
| 655 #endif | 667 #endif |
| 656 | 668 |
| 657 /////////////////////////////////////////////////////////////////////////// | 669 /////////////////////////////////////////////////////////////////////////// |
| 658 // compile and setup attribs and unis | 670 // compile and setup attribs and unis |
| 659 | 671 |
| 660 if (!this->compileShaders(builder)) { | 672 if (!this->compileShaders(builder)) { |
| 661 return false; | 673 return false; |
| 662 } | 674 } |
| 663 | 675 |
| 664 if (!this->bindOutputsAttribsAndLinkProgram(builder, | 676 if (!this->bindOutputsAttribsAndLinkProgram(builder, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 679 } | 691 } |
| 680 | 692 |
| 681 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
der, | 693 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
der, |
| 682 bool bindColorOut, | 694 bool bindColorOut, |
| 683 bool bindDualSrcOut) { | 695 bool bindDualSrcOut) { |
| 684 GL_CALL_RET(fProgramID, CreateProgram()); | 696 GL_CALL_RET(fProgramID, CreateProgram()); |
| 685 if (!fProgramID) { | 697 if (!fProgramID) { |
| 686 return false; | 698 return false; |
| 687 } | 699 } |
| 688 | 700 |
| 689 GL_CALL(AttachShader(fProgramID, fVShaderID)); | 701 if (fVShaderID) { |
| 702 GL_CALL(AttachShader(fProgramID, fVShaderID)); |
| 703 } |
| 690 if (fGShaderID) { | 704 if (fGShaderID) { |
| 691 GL_CALL(AttachShader(fProgramID, fGShaderID)); | 705 GL_CALL(AttachShader(fProgramID, fGShaderID)); |
| 692 } | 706 } |
| 693 GL_CALL(AttachShader(fProgramID, fFShaderID)); | 707 GL_CALL(AttachShader(fProgramID, fFShaderID)); |
| 694 | 708 |
| 695 if (bindColorOut) { | 709 if (bindColorOut) { |
| 696 GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
)); | 710 GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
)); |
| 697 } | 711 } |
| 698 if (bindDualSrcOut) { | 712 if (bindDualSrcOut) { |
| 699 GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
_name())); | 713 GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
_name())); |
| 700 } | 714 } |
| 701 | 715 |
| 702 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 716 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 703 | 717 |
| 704 // Bind the attrib locations to same values for all shaders | 718 // Bind the attrib locations to same values for all shaders |
| 705 GL_CALL(BindAttribLocation(fProgramID, | 719 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild
er()) { |
| 706 header.fPositionAttributeIndex, | |
| 707 builder.positionAttribute().c_str())); | |
| 708 if (-1 != header.fLocalCoordAttributeIndex) { | |
| 709 GL_CALL(BindAttribLocation(fProgramID, | 720 GL_CALL(BindAttribLocation(fProgramID, |
| 710 header.fLocalCoordAttributeIndex, | 721 header.fPositionAttributeIndex, |
| 711 builder.localCoordsAttribute().c_str())); | 722 vertexBuilder->positionAttribute().c_str())); |
| 712 } | 723 if (-1 != header.fLocalCoordAttributeIndex) { |
| 713 if (-1 != header.fColorAttributeIndex) { | 724 GL_CALL(BindAttribLocation(fProgramID, |
| 714 GL_CALL(BindAttribLocation(fProgramID, header.fColorAttributeIndex, COL_
ATTR_NAME)); | 725 header.fLocalCoordAttributeIndex, |
| 715 } | 726 vertexBuilder->localCoordsAttribute().c_s
tr())); |
| 716 if (-1 != header.fCoverageAttributeIndex) { | 727 } |
| 717 GL_CALL(BindAttribLocation(fProgramID, header.fCoverageAttributeIndex, C
OV_ATTR_NAME)); | 728 if (-1 != header.fColorAttributeIndex) { |
| 718 } | 729 GL_CALL(BindAttribLocation(fProgramID, header.fColorAttributeIndex,
COL_ATTR_NAME)); |
| 730 } |
| 731 if (-1 != header.fCoverageAttributeIndex) { |
| 732 GL_CALL(BindAttribLocation(fProgramID, header.fCoverageAttributeInde
x, COV_ATTR_NAME)); |
| 733 } |
| 719 | 734 |
| 720 const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttribu
tes().end(); | 735 const GrGLShaderBuilder::VertexBuilder::AttributePair* attribEnd = verte
xBuilder->getEffectAttributes().end(); |
| 721 for (const GrGLShaderBuilder::AttributePair* attrib = builder.getEffectAttri
butes().begin(); | 736 for (const GrGLShaderBuilder::VertexBuilder::AttributePair* attrib = ver
texBuilder->getEffectAttributes().begin(); |
| 722 attrib != attribEnd; | 737 attrib != attribEnd; |
| 723 ++attrib) { | 738 ++attrib) { |
| 724 GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName.c_
str())); | 739 GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fNam
e.c_str())); |
| 740 } |
| 725 } | 741 } |
| 726 | 742 |
| 727 GL_CALL(LinkProgram(fProgramID)); | 743 GL_CALL(LinkProgram(fProgramID)); |
| 728 | 744 |
| 729 GrGLint linked = GR_GL_INIT_ZERO; | 745 GrGLint linked = GR_GL_INIT_ZERO; |
| 730 GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); | 746 GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); |
| 731 if (!linked) { | 747 if (!linked) { |
| 732 GrGLint infoLen = GR_GL_INIT_ZERO; | 748 GrGLint infoLen = GR_GL_INIT_ZERO; |
| 733 GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); | 749 GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
| 734 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger | 750 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 SkScalarToFloat(m[SkMatrix::kMTransX]), | 1008 SkScalarToFloat(m[SkMatrix::kMTransX]), |
| 993 SkScalarToFloat(m[SkMatrix::kMTransY]), | 1009 SkScalarToFloat(m[SkMatrix::kMTransY]), |
| 994 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 1010 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
| 995 }; | 1011 }; |
| 996 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 1012 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
| 997 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 1013 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 998 fMatrixState.fRenderTargetSize = size; | 1014 fMatrixState.fRenderTargetSize = size; |
| 999 fMatrixState.fRenderTargetOrigin = rt->origin(); | 1015 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 1000 } | 1016 } |
| 1001 } | 1017 } |
| OLD | NEW |