OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 Texture::FaceInfo::~FaceInfo() { | 419 Texture::FaceInfo::~FaceInfo() { |
420 } | 420 } |
421 | 421 |
422 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { | 422 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { |
423 if (target_ == 0) | 423 if (target_ == 0) |
424 return CAN_RENDER_ALWAYS; | 424 return CAN_RENDER_ALWAYS; |
425 | 425 |
426 if (target_ != GL_TEXTURE_EXTERNAL_OES) { | 426 if (target_ != GL_TEXTURE_EXTERNAL_OES) { |
427 if (face_infos_.empty()) { | 427 if (face_infos_.empty() || |
| 428 static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) { |
428 return CAN_RENDER_NEVER; | 429 return CAN_RENDER_NEVER; |
429 } | 430 } |
430 | 431 const Texture::LevelInfo& first_face = |
431 const Texture::LevelInfo& first_face = face_infos_[0].level_infos[0]; | 432 face_infos_[0].level_infos[base_level_]; |
432 if (first_face.width == 0 || | 433 if (first_face.width == 0 || |
433 first_face.height == 0 || | 434 first_face.height == 0 || |
434 first_face.depth == 0) { | 435 first_face.depth == 0) { |
435 return CAN_RENDER_NEVER; | 436 return CAN_RENDER_NEVER; |
436 } | 437 } |
437 } | 438 } |
438 | 439 |
439 bool needs_mips = NeedsMips(); | 440 bool needs_mips = NeedsMips(); |
440 if (needs_mips) { | 441 if (needs_mips) { |
441 if (!texture_complete()) | 442 if (!texture_complete()) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 mailbox_manager_ = mailbox_manager; | 525 mailbox_manager_ = mailbox_manager; |
525 } | 526 } |
526 | 527 |
527 bool Texture::MarkMipmapsGenerated( | 528 bool Texture::MarkMipmapsGenerated( |
528 const FeatureInfo* feature_info) { | 529 const FeatureInfo* feature_info) { |
529 if (!CanGenerateMipmaps(feature_info)) { | 530 if (!CanGenerateMipmaps(feature_info)) { |
530 return false; | 531 return false; |
531 } | 532 } |
532 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 533 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
533 const Texture::FaceInfo& face_info = face_infos_[ii]; | 534 const Texture::FaceInfo& face_info = face_infos_[ii]; |
534 const Texture::LevelInfo& level0_info = face_info.level_infos[0]; | 535 const Texture::LevelInfo& level0_info = face_info.level_infos[base_level_]; |
535 GLsizei width = level0_info.width; | 536 GLsizei width = level0_info.width; |
536 GLsizei height = level0_info.height; | 537 GLsizei height = level0_info.height; |
537 GLsizei depth = level0_info.depth; | 538 GLsizei depth = level0_info.depth; |
538 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : | 539 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : |
539 GLES2Util::IndexToGLFaceTarget(ii); | 540 GLES2Util::IndexToGLFaceTarget(ii); |
540 | 541 |
541 const GLsizei num_mips = face_info.num_mip_levels; | 542 const GLsizei num_mips = face_info.num_mip_levels; |
542 for (GLsizei level = 1; level < num_mips; ++level) { | 543 for (GLsizei level = base_level_ + 1; |
| 544 level < base_level_ + num_mips; ++level) { |
543 width = std::max(1, width >> 1); | 545 width = std::max(1, width >> 1); |
544 height = std::max(1, height >> 1); | 546 height = std::max(1, height >> 1); |
545 depth = std::max(1, depth >> 1); | 547 depth = std::max(1, depth >> 1); |
546 SetLevelInfo(feature_info, target, level, level0_info.internal_format, | 548 SetLevelInfo(feature_info, target, level, level0_info.internal_format, |
547 width, height, depth, level0_info.border, level0_info.format, | 549 width, height, depth, level0_info.border, level0_info.format, |
548 level0_info.type, gfx::Rect(width, height)); | 550 level0_info.type, gfx::Rect(width, height)); |
549 } | 551 } |
550 } | 552 } |
551 | 553 |
552 return true; | 554 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 if (face_index != 0) { | 634 if (face_index != 0) { |
633 complete &= (width == first_face.width && | 635 complete &= (width == first_face.width && |
634 height == first_face.height && | 636 height == first_face.height && |
635 internal_format == first_face.internal_format && | 637 internal_format == first_face.internal_format && |
636 format == first_face.format && | 638 format == first_face.format && |
637 type == first_face.type); | 639 type == first_face.type); |
638 } | 640 } |
639 return complete; | 641 return complete; |
640 } | 642 } |
641 | 643 |
642 bool Texture::TextureMipComplete(const Texture::LevelInfo& level0_face, | 644 bool Texture::TextureMipComplete(const Texture::LevelInfo& base_level_face, |
643 GLenum target, | 645 GLenum target, |
644 GLint level, | 646 GLint level_diff, |
645 GLenum internal_format, | 647 GLenum internal_format, |
646 GLsizei width, | 648 GLsizei width, |
647 GLsizei height, | 649 GLsizei height, |
648 GLsizei depth, | 650 GLsizei depth, |
649 GLenum format, | 651 GLenum format, |
650 GLenum type) { | 652 GLenum type) { |
651 bool complete = (target != 0); | 653 bool complete = (target != 0); |
652 if (level != 0) { | 654 if (level_diff > 0) { |
653 const GLsizei mip_width = std::max(1, level0_face.width >> level); | 655 const GLsizei mip_width = std::max(1, base_level_face.width >> level_diff); |
654 const GLsizei mip_height = std::max(1, level0_face.height >> level); | 656 const GLsizei mip_height = |
655 const GLsizei mip_depth = std::max(1, level0_face.depth >> level); | 657 std::max(1, base_level_face.height >> level_diff); |
| 658 const GLsizei mip_depth = std::max(1, base_level_face.depth >> level_diff); |
656 | 659 |
657 complete &= (width == mip_width && | 660 complete &= (width == mip_width && |
658 height == mip_height && | 661 height == mip_height && |
659 depth == mip_depth && | 662 depth == mip_depth && |
660 internal_format == level0_face.internal_format && | 663 internal_format == base_level_face.internal_format && |
661 format == level0_face.format && | 664 format == base_level_face.format && |
662 type == level0_face.type); | 665 type == base_level_face.type); |
663 } | 666 } |
664 return complete; | 667 return complete; |
665 } | 668 } |
666 | 669 |
667 void Texture::SetLevelClearedRect(GLenum target, | 670 void Texture::SetLevelClearedRect(GLenum target, |
668 GLint level, | 671 GLint level, |
669 const gfx::Rect& cleared_rect) { | 672 const gfx::Rect& cleared_rect) { |
670 DCHECK_GE(level, 0); | 673 DCHECK_GE(level, 0); |
671 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 674 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
672 DCHECK_LT(static_cast<size_t>(face_index), | 675 DCHECK_LT(static_cast<size_t>(face_index), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 int delta = has_images ? +1 : -1; | 767 int delta = has_images ? +1 : -1; |
765 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 768 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
766 (*it)->manager()->UpdateNumImages(delta); | 769 (*it)->manager()->UpdateNumImages(delta); |
767 } | 770 } |
768 | 771 |
769 void Texture::IncAllFramebufferStateChangeCount() { | 772 void Texture::IncAllFramebufferStateChangeCount() { |
770 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 773 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
771 (*it)->manager()->IncFramebufferStateChangeCount(); | 774 (*it)->manager()->IncFramebufferStateChangeCount(); |
772 } | 775 } |
773 | 776 |
| 777 void Texture::UpdateBaseLevel(GLint base_level) { |
| 778 if (base_level_ == base_level) |
| 779 return; |
| 780 base_level_ = base_level; |
| 781 |
| 782 UpdateNumMipLevels(); |
| 783 } |
| 784 |
| 785 void Texture::UpdateMaxLevel(GLint max_level) { |
| 786 if (max_level_ == max_level) |
| 787 return; |
| 788 max_level_ = max_level; |
| 789 |
| 790 UpdateNumMipLevels(); |
| 791 } |
| 792 |
| 793 void Texture::UpdateNumMipLevels() { |
| 794 if (face_infos_.empty()) |
| 795 return; |
| 796 |
| 797 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
| 798 Texture::FaceInfo& face_info = face_infos_[ii]; |
| 799 if (static_cast<size_t>(base_level_) >= face_info.level_infos.size()) |
| 800 continue; |
| 801 const Texture::LevelInfo& info = face_info.level_infos[base_level_]; |
| 802 face_info.num_mip_levels = std::min( |
| 803 std::max(0, max_level_ - base_level_ + 1), |
| 804 TextureManager::ComputeMipMapCount( |
| 805 target_, info.width, info.height, info.depth)); |
| 806 } |
| 807 |
| 808 // mipmap-completeness needs to be re-evaluated. |
| 809 texture_mips_dirty_ = true; |
| 810 } |
| 811 |
774 void Texture::SetLevelInfo(const FeatureInfo* feature_info, | 812 void Texture::SetLevelInfo(const FeatureInfo* feature_info, |
775 GLenum target, | 813 GLenum target, |
776 GLint level, | 814 GLint level, |
777 GLenum internal_format, | 815 GLenum internal_format, |
778 GLsizei width, | 816 GLsizei width, |
779 GLsizei height, | 817 GLsizei height, |
780 GLsizei depth, | 818 GLsizei depth, |
781 GLint border, | 819 GLint border, |
782 GLenum format, | 820 GLenum format, |
783 GLenum type, | 821 GLenum type, |
(...skipping 13 matching lines...) Expand all Loading... |
797 // Update counters only if any attributes have changed. Counters are | 835 // Update counters only if any attributes have changed. Counters are |
798 // comparisons between the old and new values so it must be done before any | 836 // comparisons between the old and new values so it must be done before any |
799 // assignment has been done to the LevelInfo. | 837 // assignment has been done to the LevelInfo. |
800 if (info.target != target || | 838 if (info.target != target || |
801 info.internal_format != internal_format || | 839 info.internal_format != internal_format || |
802 info.width != width || | 840 info.width != width || |
803 info.height != height || | 841 info.height != height || |
804 info.depth != depth || | 842 info.depth != depth || |
805 info.format != format || | 843 info.format != format || |
806 info.type != type) { | 844 info.type != type) { |
807 if (level == 0) { | 845 if (level == base_level_) { |
808 // Calculate the mip level count. | 846 // Calculate the mip level count. |
809 face_infos_[face_index].num_mip_levels = | 847 face_infos_[face_index].num_mip_levels = std::min( |
810 TextureManager::ComputeMipMapCount(target_, width, height, depth); | 848 std::max(0, max_level_ - base_level_ + 1), |
| 849 TextureManager::ComputeMipMapCount(target_, width, height, depth)); |
811 | 850 |
812 // Update NPOT face count for the first level. | 851 // Update NPOT face count for the first level. |
813 bool prev_npot = TextureIsNPOT(info.width, info.height, info.depth); | 852 bool prev_npot = TextureIsNPOT(info.width, info.height, info.depth); |
814 bool now_npot = TextureIsNPOT(width, height, depth); | 853 bool now_npot = TextureIsNPOT(width, height, depth); |
815 if (prev_npot != now_npot) | 854 if (prev_npot != now_npot) |
816 num_npot_faces_ += now_npot ? 1 : -1; | 855 num_npot_faces_ += now_npot ? 1 : -1; |
817 | 856 |
818 // Signify that level 0 has been changed, so they need to be reverified. | 857 // Signify that level 0 has been changed, so they need to be reverified. |
819 texture_level0_dirty_ = true; | 858 texture_level0_dirty_ = true; |
820 } | 859 } |
821 | 860 |
822 // Signify that at least one of the mips has changed. | 861 // Signify that at least one of the mips has changed. |
823 texture_mips_dirty_ = true; | 862 texture_mips_dirty_ = true; |
824 } | 863 } |
825 | 864 |
826 info.target = target; | 865 info.target = target; |
827 info.level = level; | 866 info.level = level; |
828 info.internal_format = internal_format; | 867 info.internal_format = internal_format; |
829 info.depth = depth; | 868 info.depth = depth; |
830 info.border = border; | 869 info.border = border; |
831 info.format = format; | 870 info.format = format; |
832 info.type = type; | 871 info.type = type; |
833 info.image = 0; | 872 info.image = 0; |
834 info.image_state = UNBOUND; | 873 info.image_state = UNBOUND; |
835 | 874 |
836 UpdateMipCleared(&info, width, height, cleared_rect); | 875 UpdateMipCleared(&info, width, height, cleared_rect); |
837 | 876 |
838 estimated_size_ -= info.estimated_size; | 877 estimated_size_ -= info.estimated_size; |
839 GLES2Util::ComputeImageDataSizes( | 878 GLES2Util::ComputeImageDataSizes( |
840 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); | 879 width, height, depth, format, type, 4, &info.estimated_size, NULL, NULL); |
841 estimated_size_ += info.estimated_size; | 880 estimated_size_ += info.estimated_size; |
842 | 881 |
843 max_level_set_ = std::max(max_level_set_, level); | 882 max_level_set_ = std::max(max_level_set_, level); |
844 Update(feature_info); | 883 Update(feature_info); |
845 UpdateCleared(); | 884 UpdateCleared(); |
846 UpdateCanRenderCondition(); | 885 UpdateCanRenderCondition(); |
847 UpdateHasImages(); | 886 UpdateHasImages(); |
848 if (IsAttachedToFramebuffer()) { | 887 if (IsAttachedToFramebuffer()) { |
849 // TODO(gman): If textures tracked which framebuffers they were attached to | 888 // TODO(gman): If textures tracked which framebuffers they were attached to |
850 // we could just mark those framebuffers as not complete. | 889 // we could just mark those framebuffers as not complete. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 case GL_TEXTURE_COMPARE_MODE: | 1017 case GL_TEXTURE_COMPARE_MODE: |
979 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { | 1018 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { |
980 return GL_INVALID_ENUM; | 1019 return GL_INVALID_ENUM; |
981 } | 1020 } |
982 compare_mode_ = param; | 1021 compare_mode_ = param; |
983 break; | 1022 break; |
984 case GL_TEXTURE_BASE_LEVEL: | 1023 case GL_TEXTURE_BASE_LEVEL: |
985 if (param < 0) { | 1024 if (param < 0) { |
986 return GL_INVALID_VALUE; | 1025 return GL_INVALID_VALUE; |
987 } | 1026 } |
988 base_level_ = param; | 1027 UpdateBaseLevel(param); |
989 break; | 1028 break; |
990 case GL_TEXTURE_MAX_LEVEL: | 1029 case GL_TEXTURE_MAX_LEVEL: |
991 if (param < 0) { | 1030 if (param < 0) { |
992 return GL_INVALID_VALUE; | 1031 return GL_INVALID_VALUE; |
993 } | 1032 } |
994 max_level_ = param; | 1033 UpdateMaxLevel(param); |
995 break; | 1034 break; |
996 case GL_TEXTURE_MAX_ANISOTROPY_EXT: | 1035 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
997 if (param < 1) { | 1036 if (param < 1) { |
998 return GL_INVALID_VALUE; | 1037 return GL_INVALID_VALUE; |
999 } | 1038 } |
1000 break; | 1039 break; |
1001 case GL_TEXTURE_USAGE_ANGLE: | 1040 case GL_TEXTURE_USAGE_ANGLE: |
1002 if (!feature_info->validators()->texture_usage.IsValid(param)) { | 1041 if (!feature_info->validators()->texture_usage.IsValid(param)) { |
1003 return GL_INVALID_ENUM; | 1042 return GL_INVALID_ENUM; |
1004 } | 1043 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 return GL_INVALID_ENUM; | 1086 return GL_INVALID_ENUM; |
1048 } | 1087 } |
1049 return GL_NO_ERROR; | 1088 return GL_NO_ERROR; |
1050 } | 1089 } |
1051 | 1090 |
1052 void Texture::Update(const FeatureInfo* feature_info) { | 1091 void Texture::Update(const FeatureInfo* feature_info) { |
1053 // Update npot status. | 1092 // Update npot status. |
1054 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others | 1093 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others |
1055 npot_ = (target_ == GL_TEXTURE_EXTERNAL_OES) || (num_npot_faces_ > 0); | 1094 npot_ = (target_ == GL_TEXTURE_EXTERNAL_OES) || (num_npot_faces_ > 0); |
1056 | 1095 |
1057 if (face_infos_.empty()) { | 1096 if (face_infos_.empty() || |
| 1097 static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) { |
1058 texture_complete_ = false; | 1098 texture_complete_ = false; |
1059 cube_complete_ = false; | 1099 cube_complete_ = false; |
1060 return; | 1100 return; |
1061 } | 1101 } |
1062 | 1102 |
1063 // Update texture_complete and cube_complete status. | 1103 // Update texture_complete and cube_complete status. |
1064 const Texture::FaceInfo& first_face = face_infos_[0]; | 1104 const Texture::FaceInfo& first_face = face_infos_[0]; |
1065 const Texture::LevelInfo& first_level = first_face.level_infos[0]; | 1105 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; |
1066 const GLsizei levels_needed = first_face.num_mip_levels; | 1106 const GLsizei levels_needed = first_face.num_mip_levels; |
1067 | 1107 |
1068 texture_complete_ = | 1108 texture_complete_ = |
1069 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 1109 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
1070 cube_complete_ = (face_infos_.size() == 6) && | 1110 cube_complete_ = (face_infos_.size() == 6) && |
1071 (first_level.width == first_level.height); | 1111 (first_level.width == first_level.height); |
1072 | 1112 |
1073 if (first_level.width == 0 || first_level.height == 0) { | 1113 if (first_level.width == 0 || first_level.height == 0) { |
1074 texture_complete_ = false; | 1114 texture_complete_ = false; |
1075 } else if (first_level.type == GL_FLOAT && | 1115 } else if (first_level.type == GL_FLOAT && |
1076 !feature_info->feature_flags().enable_texture_float_linear && | 1116 !feature_info->feature_flags().enable_texture_float_linear && |
1077 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 1117 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
1078 mag_filter_ != GL_NEAREST)) { | 1118 mag_filter_ != GL_NEAREST)) { |
1079 texture_complete_ = false; | 1119 texture_complete_ = false; |
1080 } else if (first_level.type == GL_HALF_FLOAT_OES && | 1120 } else if (first_level.type == GL_HALF_FLOAT_OES && |
1081 !feature_info->feature_flags().enable_texture_half_float_linear && | 1121 !feature_info->feature_flags().enable_texture_half_float_linear && |
1082 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 1122 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
1083 mag_filter_ != GL_NEAREST)) { | 1123 mag_filter_ != GL_NEAREST)) { |
1084 texture_complete_ = false; | 1124 texture_complete_ = false; |
1085 } | 1125 } |
1086 | 1126 |
1087 bool texture_level0_complete = true; | 1127 bool texture_level0_complete = true; |
1088 if (cube_complete_ && texture_level0_dirty_) { | 1128 if (cube_complete_ && texture_level0_dirty_) { |
1089 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1129 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1090 const Texture::LevelInfo& level0 = face_infos_[ii].level_infos[0]; | 1130 const Texture::LevelInfo& face_base_level = |
| 1131 face_infos_[ii].level_infos[base_level_]; |
1091 if (!TextureFaceComplete(first_level, | 1132 if (!TextureFaceComplete(first_level, |
1092 ii, | 1133 ii, |
1093 level0.target, | 1134 face_base_level.target, |
1094 level0.internal_format, | 1135 face_base_level.internal_format, |
1095 level0.width, | 1136 face_base_level.width, |
1096 level0.height, | 1137 face_base_level.height, |
1097 level0.depth, | 1138 face_base_level.depth, |
1098 level0.format, | 1139 face_base_level.format, |
1099 level0.type)) { | 1140 face_base_level.type)) { |
1100 texture_level0_complete = false; | 1141 texture_level0_complete = false; |
1101 break; | 1142 break; |
1102 } | 1143 } |
1103 } | 1144 } |
1104 texture_level0_dirty_ = false; | 1145 texture_level0_dirty_ = false; |
1105 } | 1146 } |
1106 cube_complete_ &= texture_level0_complete; | 1147 cube_complete_ &= texture_level0_complete; |
1107 | 1148 |
1108 bool texture_mips_complete = true; | 1149 bool texture_mips_complete = true; |
1109 if (texture_complete_ && texture_mips_dirty_) { | 1150 if (texture_complete_ && texture_mips_dirty_) { |
1110 for (size_t ii = 0; ii < face_infos_.size() && texture_mips_complete; | 1151 for (size_t ii = 0; ii < face_infos_.size() && texture_mips_complete; |
1111 ++ii) { | 1152 ++ii) { |
1112 const Texture::FaceInfo& face_info = face_infos_[ii]; | 1153 const Texture::FaceInfo& face_info = face_infos_[ii]; |
1113 const Texture::LevelInfo& level0 = face_info.level_infos[0]; | 1154 const Texture::LevelInfo& base_level_info = |
| 1155 face_info.level_infos[base_level_]; |
1114 for (GLsizei jj = 1; jj < levels_needed; ++jj) { | 1156 for (GLsizei jj = 1; jj < levels_needed; ++jj) { |
1115 const Texture::LevelInfo& level_info = face_infos_[ii].level_infos[jj]; | 1157 const Texture::LevelInfo& level_info = |
1116 if (!TextureMipComplete(level0, | 1158 face_infos_[ii].level_infos[base_level_ + jj]; |
| 1159 if (!TextureMipComplete(base_level_info, |
1117 level_info.target, | 1160 level_info.target, |
1118 jj, | 1161 jj, // level - base_level_ |
1119 level_info.internal_format, | 1162 level_info.internal_format, |
1120 level_info.width, | 1163 level_info.width, |
1121 level_info.height, | 1164 level_info.height, |
1122 level_info.depth, | 1165 level_info.depth, |
1123 level_info.format, | 1166 level_info.format, |
1124 level_info.type)) { | 1167 level_info.type)) { |
1125 texture_mips_complete = false; | 1168 texture_mips_complete = false; |
1126 break; | 1169 break; |
1127 } | 1170 } |
1128 } | 1171 } |
1129 } | 1172 } |
1130 texture_mips_dirty_ = false; | 1173 texture_mips_dirty_ = false; |
1131 } | 1174 } |
1132 texture_complete_ &= texture_mips_complete; | 1175 texture_complete_ &= texture_mips_complete; |
1133 } | 1176 } |
1134 | 1177 |
1135 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { | 1178 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { |
1136 DCHECK(decoder); | 1179 DCHECK(decoder); |
1137 if (cleared_) { | 1180 if (cleared_) { |
1138 return true; | 1181 return true; |
1139 } | 1182 } |
1140 | 1183 |
1141 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1184 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1142 const Texture::FaceInfo& face_info = face_infos_[ii]; | 1185 const Texture::FaceInfo& face_info = face_infos_[ii]; |
1143 for (GLint jj = 0; jj < face_info.num_mip_levels; ++jj) { | 1186 for (GLint jj = base_level_; |
| 1187 jj < base_level_ + face_info.num_mip_levels; ++jj) { |
1144 const Texture::LevelInfo& info = face_info.level_infos[jj]; | 1188 const Texture::LevelInfo& info = face_info.level_infos[jj]; |
1145 if (info.target != 0) { | 1189 if (info.target != 0) { |
1146 if (!ClearLevel(decoder, info.target, jj)) { | 1190 if (!ClearLevel(decoder, info.target, jj)) { |
1147 return false; | 1191 return false; |
1148 } | 1192 } |
1149 } | 1193 } |
1150 } | 1194 } |
1151 } | 1195 } |
1152 UpdateSafeToRenderFrom(true); | 1196 UpdateSafeToRenderFrom(true); |
1153 return true; | 1197 return true; |
1154 } | 1198 } |
1155 | 1199 |
1156 gfx::Rect Texture::GetLevelClearedRect(GLenum target, GLint level) const { | 1200 gfx::Rect Texture::GetLevelClearedRect(GLenum target, GLint level) const { |
1157 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1201 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1158 if (face_index >= face_infos_.size() || | 1202 if (face_index >= face_infos_.size() || |
1159 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1203 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
1160 return gfx::Rect(); | 1204 return gfx::Rect(); |
1161 } | 1205 } |
1162 | 1206 |
1163 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1207 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
1164 | 1208 |
1165 return info.cleared_rect; | 1209 return info.cleared_rect; |
1166 } | 1210 } |
1167 | 1211 |
1168 bool Texture::IsLevelCleared(GLenum target, GLint level) const { | 1212 bool Texture::IsLevelCleared(GLenum target, GLint level) const { |
1169 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1213 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1170 if (face_index >= face_infos_.size() || | 1214 if (face_index >= face_infos_.size() || |
| 1215 level < base_level_ || |
1171 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1216 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
1172 return true; | 1217 return true; |
1173 } | 1218 } |
1174 | 1219 |
1175 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1220 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
1176 | 1221 |
1177 return info.cleared_rect == gfx::Rect(info.width, info.height); | 1222 return info.cleared_rect == gfx::Rect(info.width, info.height); |
1178 } | 1223 } |
1179 | 1224 |
1180 void Texture::InitTextureMaxAnisotropyIfNeeded(GLenum target) { | 1225 void Texture::InitTextureMaxAnisotropyIfNeeded(GLenum target) { |
1181 if (texture_max_anisotropy_initialized_) | 1226 if (texture_max_anisotropy_initialized_) |
1182 return; | 1227 return; |
1183 texture_max_anisotropy_initialized_ = true; | 1228 texture_max_anisotropy_initialized_ = true; |
1184 GLfloat params[] = { 1.0f }; | 1229 GLfloat params[] = { 1.0f }; |
1185 glTexParameterfv(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, params); | 1230 glTexParameterfv(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, params); |
1186 } | 1231 } |
1187 | 1232 |
1188 bool Texture::ClearLevel( | 1233 bool Texture::ClearLevel( |
1189 GLES2Decoder* decoder, GLenum target, GLint level) { | 1234 GLES2Decoder* decoder, GLenum target, GLint level) { |
1190 DCHECK(decoder); | 1235 DCHECK(decoder); |
1191 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1236 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1192 if (face_index >= face_infos_.size() || | 1237 if (face_index >= face_infos_.size() || |
| 1238 level < base_level_ || |
1193 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1239 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
1194 return true; | 1240 return true; |
1195 } | 1241 } |
1196 | 1242 |
1197 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1243 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
1198 | 1244 |
1199 DCHECK(target == info.target); | 1245 DCHECK(target == info.target); |
1200 | 1246 |
1201 if (info.target == 0 || | 1247 if (info.target == 0 || |
1202 info.cleared_rect == gfx::Rect(info.width, info.height) || | 1248 info.cleared_rect == gfx::Rect(info.width, info.height) || |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 return GL_HALF_FLOAT_OES; | 2611 return GL_HALF_FLOAT_OES; |
2566 case GL_BGRA8_EXT: | 2612 case GL_BGRA8_EXT: |
2567 return GL_UNSIGNED_BYTE; | 2613 return GL_UNSIGNED_BYTE; |
2568 default: | 2614 default: |
2569 return GL_NONE; | 2615 return GL_NONE; |
2570 } | 2616 } |
2571 } | 2617 } |
2572 | 2618 |
2573 } // namespace gles2 | 2619 } // namespace gles2 |
2574 } // namespace gpu | 2620 } // namespace gpu |
OLD | NEW |