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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 // At least some versions of the desktop ES3 drivers for NVIDIA won't accept GL_RED in | 585 // At least some versions of the desktop ES3 drivers for NVIDIA won't accept GL_RED in |
586 // glTexImage2D for the internal format but will accept GL_R8. | 586 // glTexImage2D for the internal format but will accept GL_R8. |
587 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() && | 587 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() && |
588 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V ER(3, 0)) { | 588 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V ER(3, 0)) { |
589 useSizedFormat = true; | 589 useSizedFormat = true; |
590 } | 590 } |
591 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, | 591 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, |
592 &externalFormat, &externalType)) { | 592 &externalFormat, &externalType)) { |
593 return false; | 593 return false; |
594 } | 594 } |
595 | |
596 bool is3DTexture = SkToBool(desc.fFlags & k3DTexture_GrTextureFlagBit); | |
597 if (is3DTexture && !this->glCaps().has3DTexImageSupport()) { | |
598 return false; | |
599 } | |
595 | 600 |
596 /* | 601 /* |
597 * check whether to allocate a temporary buffer for flipping y or | 602 * check whether to allocate a temporary buffer for flipping y or |
598 * because our srcData has extra bytes past each row. If so, we need | 603 * because our srcData has extra bytes past each row. If so, we need |
599 * to trim those off here, since GL ES may not let us specify | 604 * to trim those off here, since GL ES may not let us specify |
600 * GL_UNPACK_ROW_LENGTH. | 605 * GL_UNPACK_ROW_LENGTH. |
601 */ | 606 */ |
602 bool restoreGLRowLength = false; | 607 bool restoreGLRowLength = false; |
603 bool swFlipY = false; | 608 bool swFlipY = false; |
604 bool glFlipY = false; | 609 bool glFlipY = false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 0 == left && 0 == top && | 655 0 == left && 0 == top && |
651 desc.fWidth == width && desc.fHeight == height) { | 656 desc.fWidth == width && desc.fHeight == height) { |
652 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 657 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
653 if (useTexStorage) { | 658 if (useTexStorage) { |
654 // We never resize or change formats of textures. | 659 // We never resize or change formats of textures. |
655 GL_ALLOC_CALL(this->glInterface(), | 660 GL_ALLOC_CALL(this->glInterface(), |
656 TexStorage2D(GR_GL_TEXTURE_2D, | 661 TexStorage2D(GR_GL_TEXTURE_2D, |
657 1, // levels | 662 1, // levels |
658 internalFormat, | 663 internalFormat, |
659 desc.fWidth, desc.fHeight)); | 664 desc.fWidth, desc.fHeight)); |
665 } else if (is3DTexture) { | |
666 GL_ALLOC_CALL(this->glInterface(), | |
667 TexImage3D(GR_GL_TEXTURE_3D, | |
668 0, // level | |
669 internalFormat, | |
670 desc.fWidth, desc.fHeight, | |
671 desc.fWidth, // FIXME: width is used as dep th | |
bsalomon
2014/09/19 13:47:04
Why not just add a depth to fDesc and get rid of t
sugoi1
2014/09/24 19:12:48
Done.
| |
672 0, // border | |
673 externalFormat, externalType, | |
674 data)); | |
660 } else { | 675 } else { |
661 GL_ALLOC_CALL(this->glInterface(), | 676 GL_ALLOC_CALL(this->glInterface(), |
662 TexImage2D(GR_GL_TEXTURE_2D, | 677 TexImage2D(GR_GL_TEXTURE_2D, |
663 0, // level | 678 0, // level |
664 internalFormat, | 679 internalFormat, |
665 desc.fWidth, desc.fHeight, | 680 desc.fWidth, desc.fHeight, |
666 0, // border | 681 0, // border |
667 externalFormat, externalType, | 682 externalFormat, externalType, |
668 data)); | 683 data)); |
669 } | 684 } |
670 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 685 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
671 if (error != GR_GL_NO_ERROR) { | 686 if (error != GR_GL_NO_ERROR) { |
672 succeeded = false; | 687 succeeded = false; |
673 } else { | 688 } else { |
674 // if we have data and we used TexStorage to create the texture, we | 689 // if we have data and we used TexStorage to create the texture, we |
675 // now upload with TexSubImage. | 690 // now upload with TexSubImage. |
676 if (data && useTexStorage) { | 691 if (data && useTexStorage) { |
677 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 692 if (is3DTexture) { |
678 0, // level | 693 GL_CALL(TexSubImage3D(GR_GL_TEXTURE_3D, |
679 left, top, | 694 0, // level, |
680 width, height, | 695 left, top, |
681 externalFormat, externalType, | 696 left, // FIXME: left used as Z offset |
682 data)); | 697 desc.fWidth, desc.fHeight, |
698 desc.fWidth, // FIXME: width is used a s depth | |
699 externalFormat, externalType, | |
700 data)); | |
701 } else { | |
702 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | |
703 0, // level | |
704 left, top, | |
705 width, height, | |
706 externalFormat, externalType, | |
707 data)); | |
708 } | |
683 } | 709 } |
684 } | 710 } |
685 } else { | 711 } else { |
686 if (swFlipY || glFlipY) { | 712 if (swFlipY || glFlipY) { |
687 top = desc.fHeight - (top + height); | 713 top = desc.fHeight - (top + height); |
688 } | 714 } |
689 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 715 if (is3DTexture) { |
690 0, // level | 716 GL_CALL(TexSubImage3D(GR_GL_TEXTURE_3D, |
691 left, top, | 717 0, // level, |
692 width, height, | 718 left, top, |
693 externalFormat, externalType, data)); | 719 left, // FIXME: left used as Z offset |
720 desc.fWidth, desc.fHeight, | |
721 desc.fWidth, // FIXME: width is used as depth | |
722 externalFormat, externalType, | |
723 data)); | |
724 } else { | |
725 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | |
726 0, // level | |
727 left, top, | |
728 width, height, | |
729 externalFormat, externalType, data)); | |
730 } | |
694 } | 731 } |
695 | 732 |
696 if (restoreGLRowLength) { | 733 if (restoreGLRowLength) { |
697 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 734 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
698 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 735 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
699 } | 736 } |
700 if (glFlipY) { | 737 if (glFlipY) { |
701 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 738 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
702 } | 739 } |
703 return succeeded; | 740 return succeeded; |
(...skipping 30 matching lines...) Expand all Loading... | |
734 SkASSERT(height <= desc.fHeight); | 771 SkASSERT(height <= desc.fHeight); |
735 } | 772 } |
736 #endif | 773 #endif |
737 | 774 |
738 // Make sure that the width and height that we pass to OpenGL | 775 // Make sure that the width and height that we pass to OpenGL |
739 // is a multiple of the block size. | 776 // is a multiple of the block size. |
740 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); | 777 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
741 | 778 |
742 // We only need the internal format for compressed 2D textures. | 779 // We only need the internal format for compressed 2D textures. |
743 GrGLenum internalFormat = 0; | 780 GrGLenum internalFormat = 0; |
744 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { | 781 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L) || |
782 // Compressed 3D textures not supported | |
783 SkToBool(desc.fFlags & k3DTexture_GrTextureFlagBit)) { | |
745 return false; | 784 return false; |
746 } | 785 } |
747 | 786 |
748 if (isNewTexture) { | 787 if (isNewTexture) { |
749 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 788 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
750 GL_ALLOC_CALL(this->glInterface(), | 789 GL_ALLOC_CALL(this->glInterface(), |
751 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 790 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
752 0, // level | 791 0, // level |
753 internalFormat, | 792 internalFormat, |
754 width, height, | 793 width, height, |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2597 this->setVertexArrayID(gpu, 0); | 2636 this->setVertexArrayID(gpu, 0); |
2598 } | 2637 } |
2599 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2638 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2600 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2639 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2601 fDefaultVertexArrayAttribState.resize(attrCount); | 2640 fDefaultVertexArrayAttribState.resize(attrCount); |
2602 } | 2641 } |
2603 attribState = &fDefaultVertexArrayAttribState; | 2642 attribState = &fDefaultVertexArrayAttribState; |
2604 } | 2643 } |
2605 return attribState; | 2644 return attribState; |
2606 } | 2645 } |
OLD | NEW |