| 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 "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
| 9 #include "GrGLBuffer.h" | 9 #include "GrGLBuffer.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return false; | 329 return false; |
| 330 } | 330 } |
| 331 | 331 |
| 332 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); | 332 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); |
| 333 const char* version = glslCaps->versionDeclString(); | 333 const char* version = glslCaps->versionDeclString(); |
| 334 | 334 |
| 335 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); | 335 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); |
| 336 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 336 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |
| 337 GrShaderVar::kUniform_TypeModifier); | 337 GrShaderVar::kUniform_TypeModifier); |
| 338 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
rm_TypeModifier); | 338 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
rm_TypeModifier); |
| 339 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
form_TypeModifier); | 339 GrGLSLShaderVar uTexture("u_texture", kTexture2DSampler_GrSLType, |
| 340 GrShaderVar::kUniform_TypeModifier); |
| 340 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); | 341 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); |
| 341 | 342 |
| 342 SkString vshaderTxt(version); | 343 SkString vshaderTxt(version); |
| 343 if (glslCaps->noperspectiveInterpolationSupport()) { | 344 if (glslCaps->noperspectiveInterpolationSupport()) { |
| 344 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
nString()) { | 345 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
nString()) { |
| 345 vshaderTxt.appendf("#extension %s : require\n", extension); | 346 vshaderTxt.appendf("#extension %s : require\n", extension); |
| 346 } | 347 } |
| 347 vTexCoord.addModifier("noperspective"); | 348 vTexCoord.addModifier("noperspective"); |
| 348 } | 349 } |
| 349 aVertex.appendDecl(glslCaps, &vshaderTxt); | 350 aVertex.appendDecl(glslCaps, &vshaderTxt); |
| (...skipping 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3622 if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) { | 3623 if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) { |
| 3623 return true; | 3624 return true; |
| 3624 } | 3625 } |
| 3625 } | 3626 } |
| 3626 | 3627 |
| 3627 return false; | 3628 return false; |
| 3628 } | 3629 } |
| 3629 | 3630 |
| 3630 bool GrGLGpu::createCopyProgram(int progIdx) { | 3631 bool GrGLGpu::createCopyProgram(int progIdx) { |
| 3631 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); | 3632 const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); |
| 3632 static const GrSLType kSamplerTypes[3] = { kSampler2D_GrSLType, kSamplerExte
rnal_GrSLType, | 3633 static const GrSLType kSamplerTypes[3] = { kTexture2DSampler_GrSLType, |
| 3633 kSampler2DRect_GrSLType }; | 3634 kTextureExternalSampler_GrSLType, |
| 3634 if (kSamplerExternal_GrSLType == kSamplerTypes[progIdx] && | 3635 kTexture2DRectSampler_GrSLType }; |
| 3636 if (kTextureExternalSampler_GrSLType == kSamplerTypes[progIdx] && |
| 3635 !this->glCaps().glslCaps()->externalTextureSupport()) { | 3637 !this->glCaps().glslCaps()->externalTextureSupport()) { |
| 3636 return false; | 3638 return false; |
| 3637 } | 3639 } |
| 3638 if (kSampler2DRect_GrSLType == kSamplerTypes[progIdx] && | 3640 if (kTexture2DRectSampler_GrSLType == kSamplerTypes[progIdx] && |
| 3639 !this->glCaps().rectangleTextureSupport()) { | 3641 !this->glCaps().rectangleTextureSupport()) { |
| 3640 return false; | 3642 return false; |
| 3641 } | 3643 } |
| 3642 | 3644 |
| 3643 if (!fCopyProgramArrayBuffer) { | 3645 if (!fCopyProgramArrayBuffer) { |
| 3644 static const GrGLfloat vdata[] = { | 3646 static const GrGLfloat vdata[] = { |
| 3645 0, 0, | 3647 0, 0, |
| 3646 0, 1, | 3648 0, 1, |
| 3647 1, 0, | 3649 1, 0, |
| 3648 1, 1 | 3650 1, 1 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3698 " gl_Position.zw = vec2(0, 1);" | 3700 " gl_Position.zw = vec2(0, 1);" |
| 3699 "}" | 3701 "}" |
| 3700 ); | 3702 ); |
| 3701 | 3703 |
| 3702 SkString fshaderTxt(version); | 3704 SkString fshaderTxt(version); |
| 3703 if (glslCaps->noperspectiveInterpolationSupport()) { | 3705 if (glslCaps->noperspectiveInterpolationSupport()) { |
| 3704 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
nString()) { | 3706 if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
nString()) { |
| 3705 fshaderTxt.appendf("#extension %s : require\n", extension); | 3707 fshaderTxt.appendf("#extension %s : require\n", extension); |
| 3706 } | 3708 } |
| 3707 } | 3709 } |
| 3708 if (kSamplerTypes[progIdx] == kSamplerExternal_GrSLType) { | 3710 if (kSamplerTypes[progIdx] == kTextureExternalSampler_GrSLType) { |
| 3709 fshaderTxt.appendf("#extension %s : require\n", | 3711 fshaderTxt.appendf("#extension %s : require\n", |
| 3710 glslCaps->externalTextureExtensionString()); | 3712 glslCaps->externalTextureExtensionString()); |
| 3711 } | 3713 } |
| 3712 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa
ps, | 3714 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa
ps, |
| 3713 &fshaderTxt); | 3715 &fshaderTxt); |
| 3714 vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 3716 vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 3715 vTexCoord.appendDecl(glslCaps, &fshaderTxt); | 3717 vTexCoord.appendDecl(glslCaps, &fshaderTxt); |
| 3716 fshaderTxt.append(";"); | 3718 fshaderTxt.append(";"); |
| 3717 uTexture.appendDecl(glslCaps, &fshaderTxt); | 3719 uTexture.appendDecl(glslCaps, &fshaderTxt); |
| 3718 fshaderTxt.append(";"); | 3720 fshaderTxt.append(";"); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3775 SkASSERT(!fMipmapPrograms[progIdx].fProgram); | 3777 SkASSERT(!fMipmapPrograms[progIdx].fProgram); |
| 3776 GL_CALL_RET(fMipmapPrograms[progIdx].fProgram, CreateProgram()); | 3778 GL_CALL_RET(fMipmapPrograms[progIdx].fProgram, CreateProgram()); |
| 3777 if (!fMipmapPrograms[progIdx].fProgram) { | 3779 if (!fMipmapPrograms[progIdx].fProgram) { |
| 3778 return false; | 3780 return false; |
| 3779 } | 3781 } |
| 3780 | 3782 |
| 3781 const char* version = glslCaps->versionDeclString(); | 3783 const char* version = glslCaps->versionDeclString(); |
| 3782 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); | 3784 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
_TypeModifier); |
| 3783 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 3785 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |
| 3784 GrShaderVar::kUniform_TypeModifier); | 3786 GrShaderVar::kUniform_TypeModifier); |
| 3785 GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
form_TypeModifier); | 3787 GrGLSLShaderVar uTexture("u_texture", kTexture2DSampler_GrSLType, |
| 3788 GrShaderVar::kUniform_TypeModifier); |
| 3786 // We need 1, 2, or 4 texture coordinates (depending on parity of each dimen
sion): | 3789 // We need 1, 2, or 4 texture coordinates (depending on parity of each dimen
sion): |
| 3787 GrGLSLShaderVar vTexCoords[] = { | 3790 GrGLSLShaderVar vTexCoords[] = { |
| 3788 GrGLSLShaderVar("v_texCoord0", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), | 3791 GrGLSLShaderVar("v_texCoord0", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), |
| 3789 GrGLSLShaderVar("v_texCoord1", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), | 3792 GrGLSLShaderVar("v_texCoord1", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), |
| 3790 GrGLSLShaderVar("v_texCoord2", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), | 3793 GrGLSLShaderVar("v_texCoord2", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), |
| 3791 GrGLSLShaderVar("v_texCoord3", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), | 3794 GrGLSLShaderVar("v_texCoord3", kVec2f_GrSLType, GrShaderVar::kVaryingOut
_TypeModifier), |
| 3792 }; | 3795 }; |
| 3793 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, | 3796 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, |
| 3794 GrShaderVar::kOut_TypeModifier); | 3797 GrShaderVar::kOut_TypeModifier); |
| 3795 | 3798 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3862 uTexture.appendDecl(glslCaps, &fshaderTxt); | 3865 uTexture.appendDecl(glslCaps, &fshaderTxt); |
| 3863 fshaderTxt.append(";"); | 3866 fshaderTxt.append(";"); |
| 3864 const char* fsOutName; | 3867 const char* fsOutName; |
| 3865 if (glslCaps->mustDeclareFragmentShaderOutput()) { | 3868 if (glslCaps->mustDeclareFragmentShaderOutput()) { |
| 3866 oFragColor.appendDecl(glslCaps, &fshaderTxt); | 3869 oFragColor.appendDecl(glslCaps, &fshaderTxt); |
| 3867 fshaderTxt.append(";"); | 3870 fshaderTxt.append(";"); |
| 3868 fsOutName = oFragColor.c_str(); | 3871 fsOutName = oFragColor.c_str(); |
| 3869 } else { | 3872 } else { |
| 3870 fsOutName = "gl_FragColor"; | 3873 fsOutName = "gl_FragColor"; |
| 3871 } | 3874 } |
| 3872 const char* sampleFunction = GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kS
ampler2D_GrSLType, | 3875 const char* sampleFunction = GrGLSLTexture2DFunctionName(kVec2f_GrSLType, |
| 3876 kTexture2DSampler_G
rSLType, |
| 3873 this->glslGeneratio
n()); | 3877 this->glslGeneratio
n()); |
| 3874 fshaderTxt.append( | 3878 fshaderTxt.append( |
| 3875 "// Mipmap Program FS\n" | 3879 "// Mipmap Program FS\n" |
| 3876 "void main() {" | 3880 "void main() {" |
| 3877 ); | 3881 ); |
| 3878 | 3882 |
| 3879 if (oddWidth && oddHeight) { | 3883 if (oddWidth && oddHeight) { |
| 3880 fshaderTxt.appendf( | 3884 fshaderTxt.appendf( |
| 3881 " %s = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1) + " | 3885 " %s = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1) + " |
| 3882 " %s(u_texture, v_texCoord2) + %s(u_texture, v_texCoord3)) *
0.25;", | 3886 " %s(u_texture, v_texCoord2) + %s(u_texture, v_texCoord3)) *
0.25;", |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4607 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4611 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 4608 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4612 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 4609 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4613 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 4610 copyParams->fWidth = texture->width(); | 4614 copyParams->fWidth = texture->width(); |
| 4611 copyParams->fHeight = texture->height(); | 4615 copyParams->fHeight = texture->height(); |
| 4612 return true; | 4616 return true; |
| 4613 } | 4617 } |
| 4614 } | 4618 } |
| 4615 return false; | 4619 return false; |
| 4616 } | 4620 } |
| OLD | NEW |