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 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 | 650 |
651 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 651 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
652 const GrGLInterface* interface) { | 652 const GrGLInterface* interface) { |
653 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 653 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
654 return GR_GL_GET_ERROR(interface); | 654 return GR_GL_GET_ERROR(interface); |
655 } else { | 655 } else { |
656 return CHECK_ALLOC_ERROR(interface); | 656 return CHECK_ALLOC_ERROR(interface); |
657 } | 657 } |
658 } | 658 } |
659 | 659 |
660 /** | |
661 * Determines if sized internal formats are available for the texture being crea ted. | |
662 * | |
663 * @param useTexStorage The result of a call to can_use_tex_storage(). | |
jvanverth1
2015/12/15 15:35:41
These param comments don't match this function.
bsalomon
2015/12/15 17:09:47
D'oh! Forgot to update when I changed the params.
| |
664 * @param caps The capabilities of the GL device. | |
665 * @param standard The GL standard in use. | |
666 * @param version The GL version in use. | |
667 * @param dataConfig The pixel configuration for the texture being created. | |
668 */ | |
669 static bool use_sized_format_for_texture(bool useTexStorage, const GrGLContextIn fo& info, | |
670 GrPixelConfig textureConfig) { | |
671 // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized | |
672 // format for glTexImage, unlike ES3 and desktop. | |
673 bool useSizedFormat = useTexStorage; | |
674 if (kGL_GrGLStandard == info.standard() || | |
675 (info.version() >= GR_GL_VER(3, 0) && | |
676 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B GRA8888" enabled | |
677 (kBGRA_8888_GrPixelConfig != textureConfig || !info.caps()->bgraIsInter nalFormat()))) { | |
678 useSizedFormat = true; | |
679 } | |
680 return useSizedFormat; | |
681 } | |
682 | |
660 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 683 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
661 GrGLenum target, | 684 GrGLenum target, |
662 bool isNewTexture, | 685 bool isNewTexture, |
663 int left, int top, int width, int height, | 686 int left, int top, int width, int height, |
664 GrPixelConfig dataConfig, | 687 GrPixelConfig dataConfig, |
665 const void* data, | 688 const void* data, |
666 size_t rowBytes) { | 689 size_t rowBytes) { |
667 SkASSERT(data || isNewTexture); | 690 SkASSERT(data || isNewTexture); |
668 | 691 |
669 // If we're uploading compressed data then we should be using uploadCompress edTexData | 692 // If we're uploading compressed data then we should be using uploadCompress edTexData |
(...skipping 27 matching lines...) Expand all Loading... | |
697 // 565 we always use an unsized internal format to let the system pick | 720 // 565 we always use an unsized internal format to let the system pick |
698 // the best sized format to convert the 565 data to. Since TexStorage | 721 // the best sized format to convert the 565 data to. Since TexStorage |
699 // only allows sized internal formats we will instead use TexImage2D. | 722 // only allows sized internal formats we will instead use TexImage2D. |
700 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; | 723 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
701 } | 724 } |
702 | 725 |
703 GrGLenum internalFormat = 0x0; // suppress warning | 726 GrGLenum internalFormat = 0x0; // suppress warning |
704 GrGLenum externalFormat = 0x0; // suppress warning | 727 GrGLenum externalFormat = 0x0; // suppress warning |
705 GrGLenum externalType = 0x0; // suppress warning | 728 GrGLenum externalType = 0x0; // suppress warning |
706 | 729 |
707 // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized | 730 bool useSizedFormat = use_sized_format_for_texture(useTexStorage, this->ctxI nfo(), |
708 // format for glTexImage, unlike ES3 and desktop. | 731 desc.fConfig); |
jvanverth1
2015/12/15 15:35:41
Nit: tab one space?
bsalomon
2015/12/15 17:09:47
Done.
| |
709 bool useSizedFormat = useTexStorage; | 732 |
710 if (kGL_GrGLStandard == this->glStandard() || | 733 if (!this->configToGLFormats(desc.fConfig, useSizedFormat, &internalFormat, |
711 (this->glVersion() >= GR_GL_VER(3, 0) && | 734 &externalFormat, &externalType)) { |
712 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B GRA8888" enabled | 735 return false; |
713 (kBGRA_8888_GrPixelConfig != dataConfig || !this->glCaps().bgraIsIntern alFormat()))) { | |
714 useSizedFormat = true; | |
715 } | 736 } |
716 | 737 |
717 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, | 738 if (dataConfig != desc.fConfig) { |
718 &externalFormat, &externalType)) { | 739 // call this again if we're going to upload a different config than the texture's config. |
719 return false; | 740 if (!this->configToGLFormats(dataConfig, false, nullptr, &externalFormat , |
741 &externalType)) { | |
742 return false; | |
743 } | |
720 } | 744 } |
721 | 745 |
722 /* | 746 /* |
723 * check whether to allocate a temporary buffer for flipping y or | 747 * check whether to allocate a temporary buffer for flipping y or |
724 * because our srcData has extra bytes past each row. If so, we need | 748 * because our srcData has extra bytes past each row. If so, we need |
725 * to trim those off here, since GL ES may not let us specify | 749 * to trim those off here, since GL ES may not let us specify |
726 * GL_UNPACK_ROW_LENGTH. | 750 * GL_UNPACK_ROW_LENGTH. |
727 */ | 751 */ |
728 bool restoreGLRowLength = false; | 752 bool restoreGLRowLength = false; |
729 bool swFlipY = false; | 753 bool swFlipY = false; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1277 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1254 GR_GL_TEXTURE_WRAP_S, | 1278 GR_GL_TEXTURE_WRAP_S, |
1255 GR_GL_CLAMP_TO_EDGE)); | 1279 GR_GL_CLAMP_TO_EDGE)); |
1256 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1280 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1257 GR_GL_TEXTURE_WRAP_T, | 1281 GR_GL_TEXTURE_WRAP_T, |
1258 GR_GL_CLAMP_TO_EDGE)); | 1282 GR_GL_CLAMP_TO_EDGE)); |
1259 | 1283 |
1260 GrGLenum internalFormat = 0x0; // suppress warning | 1284 GrGLenum internalFormat = 0x0; // suppress warning |
1261 GrGLenum externalFormat = 0x0; // suppress warning | 1285 GrGLenum externalFormat = 0x0; // suppress warning |
1262 GrGLenum externalType = 0x0; // suppress warning | 1286 GrGLenum externalType = 0x0; // suppress warning |
1263 bool useSizedFormat = false; | 1287 bool useSizedFormat = use_sized_format_for_texture(false, this->ctxInfo( ), config); |
1264 if (kGL_GrGLStandard == this->glStandard() || | |
1265 (this->glVersion() >= GR_GL_VER(3, 0) && | |
1266 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_form at_BGRA8888" enabled | |
1267 (kBGRA_8888_GrPixelConfig != config || !this->glCaps().bgraIsIntern alFormat()))) { | |
1268 useSizedFormat = true; | |
1269 } | |
1270 if (!this->configToGLFormats(config, useSizedFormat, &internalFormat, | 1288 if (!this->configToGLFormats(config, useSizedFormat, &internalFormat, |
1271 &externalFormat, &externalType)) { | 1289 &externalFormat, &externalType)) { |
1272 GL_CALL(DeleteTextures(1, &colorID)); | 1290 GL_CALL(DeleteTextures(1, &colorID)); |
1273 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex; | 1291 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex; |
1274 return kUnsupportedStencilIndex; | 1292 return kUnsupportedStencilIndex; |
1275 } | 1293 } |
1276 | 1294 |
1277 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1295 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1278 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, | 1296 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, |
1279 0, internalFormat, | 1297 0, internalFormat, |
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3521 GL_CALL(BindTexture(info->fTarget, info->fID)); | 3539 GL_CALL(BindTexture(info->fTarget, info->fID)); |
3522 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST )); | 3540 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST )); |
3523 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST )); | 3541 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST )); |
3524 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_ED GE)); | 3542 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_ED GE)); |
3525 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_ED GE)); | 3543 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_ED GE)); |
3526 | 3544 |
3527 GrGLenum internalFormat = 0x0; // suppress warning | 3545 GrGLenum internalFormat = 0x0; // suppress warning |
3528 GrGLenum externalFormat = 0x0; // suppress warning | 3546 GrGLenum externalFormat = 0x0; // suppress warning |
3529 GrGLenum externalType = 0x0; // suppress warning | 3547 GrGLenum externalType = 0x0; // suppress warning |
3530 | 3548 |
3531 this->configToGLFormats(config, false, &internalFormat, &externalFormat, &ex ternalType); | 3549 bool useSizedFormat = use_sized_format_for_texture(false, this->ctxInfo(), c onfig); |
3550 this->configToGLFormats(config, useSizedFormat, &internalFormat, &externalFo rmat, | |
3551 &externalType); | |
3532 | 3552 |
3533 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat , | 3553 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat , |
3534 externalType, pixels)); | 3554 externalType, pixels)); |
3535 | 3555 |
3536 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 3556 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
3537 GrGLuint id = info->fID; | 3557 GrGLuint id = info->fID; |
3538 delete info; | 3558 delete info; |
3539 return id; | 3559 return id; |
3540 #else | 3560 #else |
3541 return reinterpret_cast<GrBackendObject>(info); | 3561 return reinterpret_cast<GrBackendObject>(info); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3627 this->setVertexArrayID(gpu, 0); | 3647 this->setVertexArrayID(gpu, 0); |
3628 } | 3648 } |
3629 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3649 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3630 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3650 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3631 fDefaultVertexArrayAttribState.resize(attrCount); | 3651 fDefaultVertexArrayAttribState.resize(attrCount); |
3632 } | 3652 } |
3633 attribState = &fDefaultVertexArrayAttribState; | 3653 attribState = &fDefaultVertexArrayAttribState; |
3634 } | 3654 } |
3635 return attribState; | 3655 return attribState; |
3636 } | 3656 } |
OLD | NEW |