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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 break; | 100 break; |
101 // The prog will write a coverage value to the secondary | 101 // The prog will write a coverage value to the secondary |
102 // output and the dst is blended by one minus that value. | 102 // output and the dst is blended by one minus that value. |
103 case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: | 103 case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: |
104 case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: | 104 case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: |
105 case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: | 105 case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: |
106 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 106 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
107 break; | 107 break; |
108 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: | 108 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: |
109 // We should only have set this if the blend was specified as (1, 0) | 109 // We should only have set this if the blend was specified as (1, 0) |
110 GrAssert(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds
tCoeff); | 110 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds
tCoeff); |
111 break; | 111 break; |
112 default: | 112 default: |
113 GrCrash("Unexpected coverage output"); | 113 GrCrash("Unexpected coverage output"); |
114 break; | 114 break; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 namespace { | 118 namespace { |
119 // given two blend coefficients determine whether the src | 119 // given two blend coefficients determine whether the src |
120 // and/or dst computation can be omitted. | 120 // and/or dst computation can be omitted. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 default: | 275 default: |
276 GrCrash("Unknown color type."); | 276 GrCrash("Unknown color type."); |
277 return kNone_GrSLConstantVec; | 277 return kNone_GrSLConstantVec; |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 void GrGLProgram::genGeometryShader(GrGLShaderBuilder* builder) const { | 281 void GrGLProgram::genGeometryShader(GrGLShaderBuilder* builder) const { |
282 #if GR_GL_EXPERIMENTAL_GS | 282 #if GR_GL_EXPERIMENTAL_GS |
283 // TODO: The builder should add all this glue code. | 283 // TODO: The builder should add all this glue code. |
284 if (fDesc.getHeader().fExperimentalGS) { | 284 if (fDesc.getHeader().fExperimentalGS) { |
285 GrAssert(fContext.info().glslGeneration() >= k150_GrGLSLGeneration); | 285 SkASSERT(fContext.info().glslGeneration() >= k150_GrGLSLGeneration); |
286 builder->fGSHeader.append("layout(triangles) in;\n" | 286 builder->fGSHeader.append("layout(triangles) in;\n" |
287 "layout(triangle_strip, max_vertices = 6) out
;\n"); | 287 "layout(triangle_strip, max_vertices = 6) out
;\n"); |
288 builder->gsCodeAppend("\tfor (int i = 0; i < 3; ++i) {\n" | 288 builder->gsCodeAppend("\tfor (int i = 0; i < 3; ++i) {\n" |
289 "\t\tgl_Position = gl_in[i].gl_Position;\n"); | 289 "\t\tgl_Position = gl_in[i].gl_Position;\n"); |
290 if (fDesc.getHeader().fEmitsPointSize) { | 290 if (fDesc.getHeader().fEmitsPointSize) { |
291 builder->gsCodeAppend("\t\tgl_PointSize = 1.0;\n"); | 291 builder->gsCodeAppend("\t\tgl_PointSize = 1.0;\n"); |
292 } | 292 } |
293 GrAssert(builder->fGSInputs.count() == builder->fGSOutputs.count()); | 293 SkASSERT(builder->fGSInputs.count() == builder->fGSOutputs.count()); |
294 int count = builder->fGSInputs.count(); | 294 int count = builder->fGSInputs.count(); |
295 for (int i = 0; i < count; ++i) { | 295 for (int i = 0; i < count; ++i) { |
296 builder->gsCodeAppendf("\t\t%s = %s[i];\n", | 296 builder->gsCodeAppendf("\t\t%s = %s[i];\n", |
297 builder->fGSOutputs[i].getName().c_str(), | 297 builder->fGSOutputs[i].getName().c_str(), |
298 builder->fGSInputs[i].getName().c_str()); | 298 builder->fGSInputs[i].getName().c_str()); |
299 } | 299 } |
300 builder->gsCodeAppend("\t\tEmitVertex();\n" | 300 builder->gsCodeAppend("\t\tEmitVertex();\n" |
301 "\t}\n" | 301 "\t}\n" |
302 "\tEndPrimitive();\n"); | 302 "\tEndPrimitive();\n"); |
303 } | 303 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger | 357 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
358 if (infoLen > 0) { | 358 if (infoLen > 0) { |
359 // retrieve length even though we don't need it to workaround bug in
chrome cmd buffer | 359 // retrieve length even though we don't need it to workaround bug in
chrome cmd buffer |
360 // param validation. | 360 // param validation. |
361 GrGLsizei length = GR_GL_INIT_ZERO; | 361 GrGLsizei length = GR_GL_INIT_ZERO; |
362 GR_GL_CALL(gli, GetShaderInfoLog(shader, infoLen+1, | 362 GR_GL_CALL(gli, GetShaderInfoLog(shader, infoLen+1, |
363 &length, (char*)log.get())); | 363 &length, (char*)log.get())); |
364 print_shader(stringCnt, strings, stringLengths); | 364 print_shader(stringCnt, strings, stringLengths); |
365 GrPrintf("\n%s", log.get()); | 365 GrPrintf("\n%s", log.get()); |
366 } | 366 } |
367 GrAssert(!"Shader compilation failed!"); | 367 SkASSERT(!"Shader compilation failed!"); |
368 GR_GL_CALL(gli, DeleteShader(shader)); | 368 GR_GL_CALL(gli, DeleteShader(shader)); |
369 return 0; | 369 return 0; |
370 } | 370 } |
371 return shader; | 371 return shader; |
372 } | 372 } |
373 | 373 |
374 // helper version of above for when shader is already flattened into a single Sk
String | 374 // helper version of above for when shader is already flattened into a single Sk
String |
375 GrGLuint compile_shader(const GrGLContext& gl, GrGLenum type, const SkString& sh
ader) { | 375 GrGLuint compile_shader(const GrGLContext& gl, GrGLenum type, const SkString& sh
ader) { |
376 const GrGLchar* str = shader.c_str(); | 376 const GrGLchar* str = shader.c_str(); |
377 int length = shader.size(); | 377 int length = shader.size(); |
378 return compile_shader(gl, type, 1, &str, &length); | 378 return compile_shader(gl, type, 1, &str, &length); |
379 } | 379 } |
380 | 380 |
381 void expand_known_value4f(SkString* string, GrSLConstantVec vec) { | 381 void expand_known_value4f(SkString* string, GrSLConstantVec vec) { |
382 GrAssert(string->isEmpty() == (vec != kNone_GrSLConstantVec)); | 382 SkASSERT(string->isEmpty() == (vec != kNone_GrSLConstantVec)); |
383 switch (vec) { | 383 switch (vec) { |
384 case kNone_GrSLConstantVec: | 384 case kNone_GrSLConstantVec: |
385 break; | 385 break; |
386 case kZeros_GrSLConstantVec: | 386 case kZeros_GrSLConstantVec: |
387 *string = GrGLSLZerosVecf(4); | 387 *string = GrGLSLZerosVecf(4); |
388 break; | 388 break; |
389 case kOnes_GrSLConstantVec: | 389 case kOnes_GrSLConstantVec: |
390 *string = GrGLSLOnesVecf(4); | 390 *string = GrGLSLOnesVecf(4); |
391 break; | 391 break; |
392 } | 392 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } | 430 } |
431 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ | 431 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ |
432 return false; | 432 return false; |
433 } | 433 } |
434 | 434 |
435 return true; | 435 return true; |
436 } | 436 } |
437 | 437 |
438 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], | 438 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], |
439 const GrEffectStage* coverageStages[]) { | 439 const GrEffectStage* coverageStages[]) { |
440 GrAssert(0 == fProgramID); | 440 SkASSERT(0 == fProgramID); |
441 | 441 |
442 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 442 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
443 | 443 |
444 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); | 444 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); |
445 | 445 |
446 // the dual source output has no canonical var name, have to | 446 // the dual source output has no canonical var name, have to |
447 // declare an output, which is incompatible with gl_FragColor/gl_FragData. | 447 // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
448 bool dualSourceOutputWritten = false; | 448 bool dualSourceOutputWritten = false; |
449 | 449 |
450 GrGLShaderVar colorOutput; | 450 GrGLShaderVar colorOutput; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 if (infoLen > 0) { | 735 if (infoLen > 0) { |
736 // retrieve length even though we don't need it to workaround | 736 // retrieve length even though we don't need it to workaround |
737 // bug in chrome cmd buffer param validation. | 737 // bug in chrome cmd buffer param validation. |
738 GrGLsizei length = GR_GL_INIT_ZERO; | 738 GrGLsizei length = GR_GL_INIT_ZERO; |
739 GL_CALL(GetProgramInfoLog(fProgramID, | 739 GL_CALL(GetProgramInfoLog(fProgramID, |
740 infoLen+1, | 740 infoLen+1, |
741 &length, | 741 &length, |
742 (char*)log.get())); | 742 (char*)log.get())); |
743 GrPrintf((char*)log.get()); | 743 GrPrintf((char*)log.get()); |
744 } | 744 } |
745 GrAssert(!"Error linking program"); | 745 SkASSERT(!"Error linking program"); |
746 GL_CALL(DeleteProgram(fProgramID)); | 746 GL_CALL(DeleteProgram(fProgramID)); |
747 fProgramID = 0; | 747 fProgramID = 0; |
748 return false; | 748 return false; |
749 } | 749 } |
750 return true; | 750 return true; |
751 } | 751 } |
752 | 752 |
753 void GrGLProgram::initSamplerUniforms() { | 753 void GrGLProgram::initSamplerUniforms() { |
754 GL_CALL(UseProgram(fProgramID)); | 754 GL_CALL(UseProgram(fProgramID)); |
755 GrGLint texUnitIdx = 0; | 755 GrGLint texUnitIdx = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
785 const GrEffectStage& stage, | 785 const GrEffectStage& stage, |
786 const EffectAndSamplers& effect) { | 786 const EffectAndSamplers& effect) { |
787 | 787 |
788 // Let the GrGLEffect set its data. | 788 // Let the GrGLEffect set its data. |
789 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; | 789 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; |
790 GrDrawEffect drawEffect(stage, explicitLocalCoords); | 790 GrDrawEffect drawEffect(stage, explicitLocalCoords); |
791 effect.fGLEffect->setData(fUniformManager, drawEffect); | 791 effect.fGLEffect->setData(fUniformManager, drawEffect); |
792 | 792 |
793 // Bind the texures for the effect. | 793 // Bind the texures for the effect. |
794 int numSamplers = effect.fSamplerUnis.count(); | 794 int numSamplers = effect.fSamplerUnis.count(); |
795 GrAssert((*stage.getEffect())->numTextures() == numSamplers); | 795 SkASSERT((*stage.getEffect())->numTextures() == numSamplers); |
796 for (int s = 0; s < numSamplers; ++s) { | 796 for (int s = 0; s < numSamplers; ++s) { |
797 UniformHandle handle = effect.fSamplerUnis[s]; | 797 UniformHandle handle = effect.fSamplerUnis[s]; |
798 if (handle.isValid()) { | 798 if (handle.isValid()) { |
799 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); | 799 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); |
800 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); | 800 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); |
801 int unit = effect.fTextureUnits[s]; | 801 int unit = effect.fTextureUnits[s]; |
802 gpu->bindTexture(unit, access.getParams(), texture); | 802 gpu->bindTexture(unit, access.getParams(), texture); |
803 } | 803 } |
804 } | 804 } |
805 } | 805 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, | 843 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, |
844 static_cast<GrGLfloat>(dstCopy->offset().fX), | 844 static_cast<GrGLfloat>(dstCopy->offset().fX), |
845 static_cast<GrGLfloat>(dstCopy->offset().fY)); | 845 static_cast<GrGLfloat>(dstCopy->offset().fY)); |
846 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, | 846 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, |
847 1.f / dstCopy->texture()->width(), | 847 1.f / dstCopy->texture()->width(), |
848 1.f / dstCopy->texture()->height()); | 848 1.f / dstCopy->texture()->height()); |
849 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 849 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
850 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. | 850 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. |
851 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 851 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
852 } else { | 852 } else { |
853 GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid()); | 853 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
854 GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid()); | 854 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
855 } | 855 } |
856 } else { | 856 } else { |
857 GrAssert(!fUniformHandles.fDstCopyTopLeftUni.isValid()); | 857 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); |
858 GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid()); | 858 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
859 GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid()); | 859 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
860 } | 860 } |
861 | 861 |
862 for (int e = 0; e < fColorEffects.count(); ++e) { | 862 for (int e = 0; e < fColorEffects.count(); ++e) { |
863 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. | 863 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. |
864 // This can be removed when the color filter is an effect. | 864 // This can be removed when the color filter is an effect. |
865 if (NULL != fColorEffects[e].fGLEffect) { | 865 if (NULL != fColorEffects[e].fGLEffect) { |
866 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); | 866 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); |
867 } | 867 } |
868 } | 868 } |
869 | 869 |
870 for (int e = 0; e < fCoverageEffects.count(); ++e) { | 870 for (int e = 0; e < fCoverageEffects.count(); ++e) { |
871 if (NULL != fCoverageEffects[e].fGLEffect) { | 871 if (NULL != fCoverageEffects[e].fGLEffect) { |
872 this->setEffectData(gpu, *coverageStages[e], fCoverageEffects[e]); | 872 this->setEffectData(gpu, *coverageStages[e], fCoverageEffects[e]); |
873 } | 873 } |
874 } | 874 } |
875 } | 875 } |
876 | 876 |
877 void GrGLProgram::setColor(const GrDrawState& drawState, | 877 void GrGLProgram::setColor(const GrDrawState& drawState, |
878 GrColor color, | 878 GrColor color, |
879 SharedGLState* sharedState) { | 879 SharedGLState* sharedState) { |
880 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 880 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
881 if (!drawState.hasColorVertexAttribute()) { | 881 if (!drawState.hasColorVertexAttribute()) { |
882 switch (header.fColorInput) { | 882 switch (header.fColorInput) { |
883 case GrGLProgramDesc::kAttribute_ColorInput: | 883 case GrGLProgramDesc::kAttribute_ColorInput: |
884 GrAssert(-1 != header.fColorAttributeIndex); | 884 SkASSERT(-1 != header.fColorAttributeIndex); |
885 if (sharedState->fConstAttribColor != color || | 885 if (sharedState->fConstAttribColor != color || |
886 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 886 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
887 // OpenGL ES only supports the float varieties of glVertexAt
trib | 887 // OpenGL ES only supports the float varieties of glVertexAt
trib |
888 GrGLfloat c[4]; | 888 GrGLfloat c[4]; |
889 GrColorToRGBAFloat(color, c); | 889 GrColorToRGBAFloat(color, c); |
890 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 890 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
891 sharedState->fConstAttribColor = color; | 891 sharedState->fConstAttribColor = color; |
892 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; | 892 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; |
893 } | 893 } |
894 break; | 894 break; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 SkScalarToFloat(m[SkMatrix::kMTransX]), | 992 SkScalarToFloat(m[SkMatrix::kMTransX]), |
993 SkScalarToFloat(m[SkMatrix::kMTransY]), | 993 SkScalarToFloat(m[SkMatrix::kMTransY]), |
994 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 994 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
995 }; | 995 }; |
996 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 996 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
997 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 997 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
998 fMatrixState.fRenderTargetSize = size; | 998 fMatrixState.fRenderTargetSize = size; |
999 fMatrixState.fRenderTargetOrigin = rt->origin(); | 999 fMatrixState.fRenderTargetOrigin = rt->origin(); |
1000 } | 1000 } |
1001 } | 1001 } |
OLD | NEW |