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(). |
| 664 * @param info Info about the GL context. |
| 665 * @param textureConfig The pixel configuration for the texture being created. |
| 666 */ |
| 667 static bool use_sized_format_for_texture(bool useTexStorage, const GrGLContextIn
fo& info, |
| 668 GrPixelConfig textureConfig) { |
| 669 // glTexStorage requires sized internal formats on both desktop and ES. ES2
requires an unsized |
| 670 // format for glTexImage, unlike ES3 and desktop. |
| 671 bool useSizedFormat = useTexStorage; |
| 672 if (kGL_GrGLStandard == info.standard() || |
| 673 (info.version() >= GR_GL_VER(3, 0) && |
| 674 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B
GRA8888" enabled |
| 675 (kBGRA_8888_GrPixelConfig != textureConfig || !info.caps()->bgraIsInter
nalFormat()))) { |
| 676 useSizedFormat = true; |
| 677 } |
| 678 return useSizedFormat; |
| 679 } |
| 680 |
660 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 681 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
661 GrGLenum target, | 682 GrGLenum target, |
662 bool isNewTexture, | 683 bool isNewTexture, |
663 int left, int top, int width, int height, | 684 int left, int top, int width, int height, |
664 GrPixelConfig dataConfig, | 685 GrPixelConfig dataConfig, |
665 const void* data, | 686 const void* data, |
666 size_t rowBytes) { | 687 size_t rowBytes) { |
667 SkASSERT(data || isNewTexture); | 688 SkASSERT(data || isNewTexture); |
668 | 689 |
669 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 690 // 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 | 718 // 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 | 719 // the best sized format to convert the 565 data to. Since TexStorage |
699 // only allows sized internal formats we will instead use TexImage2D. | 720 // only allows sized internal formats we will instead use TexImage2D. |
700 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; | 721 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
701 } | 722 } |
702 | 723 |
703 GrGLenum internalFormat = 0x0; // suppress warning | 724 GrGLenum internalFormat = 0x0; // suppress warning |
704 GrGLenum externalFormat = 0x0; // suppress warning | 725 GrGLenum externalFormat = 0x0; // suppress warning |
705 GrGLenum externalType = 0x0; // suppress warning | 726 GrGLenum externalType = 0x0; // suppress warning |
706 | 727 |
707 // glTexStorage requires sized internal formats on both desktop and ES. ES2
requires an unsized | 728 bool useSizedFormat = use_sized_format_for_texture(useTexStorage, this->ctxI
nfo(), |
708 // format for glTexImage, unlike ES3 and desktop. | 729 desc.fConfig); |
709 bool useSizedFormat = useTexStorage; | 730 |
710 if (kGL_GrGLStandard == this->glStandard() || | 731 if (!this->configToGLFormats(desc.fConfig, useSizedFormat, &internalFormat, |
711 (this->glVersion() >= GR_GL_VER(3, 0) && | 732 &externalFormat, &externalType)) { |
712 // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_B
GRA8888" enabled | 733 return false; |
713 (kBGRA_8888_GrPixelConfig != dataConfig || !this->glCaps().bgraIsIntern
alFormat()))) { | |
714 useSizedFormat = true; | |
715 } | 734 } |
716 | 735 |
717 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, | 736 if (dataConfig != desc.fConfig) { |
718 &externalFormat, &externalType)) { | 737 // call this again if we're going to upload a different config than the
texture's config. |
719 return false; | 738 if (!this->configToGLFormats(dataConfig, false, nullptr, &externalFormat
, |
| 739 &externalType)) { |
| 740 return false; |
| 741 } |
720 } | 742 } |
721 | 743 |
722 /* | 744 /* |
723 * check whether to allocate a temporary buffer for flipping y or | 745 * 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 | 746 * 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 | 747 * to trim those off here, since GL ES may not let us specify |
726 * GL_UNPACK_ROW_LENGTH. | 748 * GL_UNPACK_ROW_LENGTH. |
727 */ | 749 */ |
728 bool restoreGLRowLength = false; | 750 bool restoreGLRowLength = false; |
729 bool swFlipY = false; | 751 bool swFlipY = false; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1275 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1254 GR_GL_TEXTURE_WRAP_S, | 1276 GR_GL_TEXTURE_WRAP_S, |
1255 GR_GL_CLAMP_TO_EDGE)); | 1277 GR_GL_CLAMP_TO_EDGE)); |
1256 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1278 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1257 GR_GL_TEXTURE_WRAP_T, | 1279 GR_GL_TEXTURE_WRAP_T, |
1258 GR_GL_CLAMP_TO_EDGE)); | 1280 GR_GL_CLAMP_TO_EDGE)); |
1259 | 1281 |
1260 GrGLenum internalFormat = 0x0; // suppress warning | 1282 GrGLenum internalFormat = 0x0; // suppress warning |
1261 GrGLenum externalFormat = 0x0; // suppress warning | 1283 GrGLenum externalFormat = 0x0; // suppress warning |
1262 GrGLenum externalType = 0x0; // suppress warning | 1284 GrGLenum externalType = 0x0; // suppress warning |
1263 bool useSizedFormat = false; | 1285 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, | 1286 if (!this->configToGLFormats(config, useSizedFormat, &internalFormat, |
1271 &externalFormat, &externalType)) { | 1287 &externalFormat, &externalType)) { |
1272 GL_CALL(DeleteTextures(1, &colorID)); | 1288 GL_CALL(DeleteTextures(1, &colorID)); |
1273 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex; | 1289 fPixelConfigToStencilIndex[config] = kUnsupportedStencilIndex; |
1274 return kUnsupportedStencilIndex; | 1290 return kUnsupportedStencilIndex; |
1275 } | 1291 } |
1276 | 1292 |
1277 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1293 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1278 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, | 1294 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, |
1279 0, internalFormat, | 1295 0, internalFormat, |
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3521 GL_CALL(BindTexture(info->fTarget, info->fID)); | 3537 GL_CALL(BindTexture(info->fTarget, info->fID)); |
3522 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST
)); | 3538 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
)); | 3539 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)); | 3540 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)); | 3541 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_ED
GE)); |
3526 | 3542 |
3527 GrGLenum internalFormat = 0x0; // suppress warning | 3543 GrGLenum internalFormat = 0x0; // suppress warning |
3528 GrGLenum externalFormat = 0x0; // suppress warning | 3544 GrGLenum externalFormat = 0x0; // suppress warning |
3529 GrGLenum externalType = 0x0; // suppress warning | 3545 GrGLenum externalType = 0x0; // suppress warning |
3530 | 3546 |
3531 this->configToGLFormats(config, false, &internalFormat, &externalFormat, &ex
ternalType); | 3547 bool useSizedFormat = use_sized_format_for_texture(false, this->ctxInfo(), c
onfig); |
| 3548 this->configToGLFormats(config, useSizedFormat, &internalFormat, &externalFo
rmat, |
| 3549 &externalType); |
3532 | 3550 |
3533 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat
, | 3551 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat
, |
3534 externalType, pixels)); | 3552 externalType, pixels)); |
3535 | 3553 |
3536 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 3554 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
3537 GrGLuint id = info->fID; | 3555 GrGLuint id = info->fID; |
3538 delete info; | 3556 delete info; |
3539 return id; | 3557 return id; |
3540 #else | 3558 #else |
3541 return reinterpret_cast<GrBackendObject>(info); | 3559 return reinterpret_cast<GrBackendObject>(info); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 this->setVertexArrayID(gpu, 0); | 3645 this->setVertexArrayID(gpu, 0); |
3628 } | 3646 } |
3629 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3647 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3630 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3648 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3631 fDefaultVertexArrayAttribState.resize(attrCount); | 3649 fDefaultVertexArrayAttribState.resize(attrCount); |
3632 } | 3650 } |
3633 attribState = &fDefaultVertexArrayAttribState; | 3651 attribState = &fDefaultVertexArrayAttribState; |
3634 } | 3652 } |
3635 return attribState; | 3653 return attribState; |
3636 } | 3654 } |
OLD | NEW |