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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 bool can_render_; | 58 bool can_render_; |
59 bool can_render_to_; | 59 bool can_render_to_; |
60 bool npot_; | 60 bool npot_; |
61 | 61 |
62 // Since we will be hashing this signature structure, the padding must be | 62 // Since we will be hashing this signature structure, the padding must be |
63 // zero initialized. Although the C++11 specifications specify that this is | 63 // zero initialized. Although the C++11 specifications specify that this is |
64 // true, we will use a constructor with a memset to further enforce it instead | 64 // true, we will use a constructor with a memset to further enforce it instead |
65 // of relying on compilers adhering to this deep dark corner specification. | 65 // of relying on compilers adhering to this deep dark corner specification. |
66 TextureSignature(GLenum target, | 66 TextureSignature(GLenum target, |
67 GLint level, | 67 GLint level, |
68 GLenum min_filter, | 68 const SamplerState& sampler_state, |
69 GLenum mag_filter, | |
70 GLenum wrap_r, | |
71 GLenum wrap_s, | |
72 GLenum wrap_t, | |
73 GLenum usage, | 69 GLenum usage, |
74 GLenum internal_format, | 70 GLenum internal_format, |
75 GLenum compare_func, | |
76 GLenum compare_mode, | |
77 GLsizei width, | 71 GLsizei width, |
78 GLsizei height, | 72 GLsizei height, |
79 GLsizei depth, | 73 GLsizei depth, |
80 GLfloat max_lod, | |
81 GLfloat min_lod, | |
82 GLint base_level, | 74 GLint base_level, |
83 GLint border, | 75 GLint border, |
84 GLint max_level, | 76 GLint max_level, |
85 GLenum format, | 77 GLenum format, |
86 GLenum type, | 78 GLenum type, |
87 bool has_image, | 79 bool has_image, |
88 bool can_render, | 80 bool can_render, |
89 bool can_render_to, | 81 bool can_render_to, |
90 bool npot) { | 82 bool npot) { |
91 memset(this, 0, sizeof(TextureSignature)); | 83 memset(this, 0, sizeof(TextureSignature)); |
92 target_ = target; | 84 target_ = target; |
93 level_ = level; | 85 level_ = level; |
94 min_filter_ = min_filter; | 86 min_filter_ = sampler_state.min_filter; |
95 mag_filter_ = mag_filter; | 87 mag_filter_ = sampler_state.mag_filter; |
96 wrap_r_ = wrap_r; | 88 wrap_r_ = sampler_state.wrap_r; |
97 wrap_s_ = wrap_s; | 89 wrap_s_ = sampler_state.wrap_s; |
98 wrap_t_ = wrap_t; | 90 wrap_t_ = sampler_state.wrap_t; |
99 usage_ = usage; | 91 usage_ = usage; |
100 internal_format_ = internal_format; | 92 internal_format_ = internal_format; |
101 compare_func_ = compare_func; | 93 compare_func_ = sampler_state.compare_func; |
102 compare_mode_ = compare_mode; | 94 compare_mode_ = sampler_state.compare_mode; |
103 width_ = width; | 95 width_ = width; |
104 height_ = height; | 96 height_ = height; |
105 depth_ = depth; | 97 depth_ = depth; |
106 max_lod_ = max_lod; | 98 max_lod_ = sampler_state.max_lod; |
107 min_lod_ = min_lod; | 99 min_lod_ = sampler_state.min_lod; |
108 base_level_ = base_level; | 100 base_level_ = base_level; |
109 border_ = border; | 101 border_ = border; |
110 max_level_ = max_level; | 102 max_level_ = max_level; |
111 format_ = format; | 103 format_ = format; |
112 type_ = type; | 104 type_ = type; |
113 has_image_ = has_image; | 105 has_image_ = has_image; |
114 can_render_ = can_render; | 106 can_render_ = can_render; |
115 can_render_to_ = can_render_to; | 107 can_render_to_ = can_render_to; |
116 npot_ = npot; | 108 npot_ = npot; |
117 } | 109 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 TextureManager::~TextureManager() { | 268 TextureManager::~TextureManager() { |
277 for (unsigned int i = 0; i < destruction_observers_.size(); i++) | 269 for (unsigned int i = 0; i < destruction_observers_.size(); i++) |
278 destruction_observers_[i]->OnTextureManagerDestroying(this); | 270 destruction_observers_[i]->OnTextureManagerDestroying(this); |
279 | 271 |
280 DCHECK(textures_.empty()); | 272 DCHECK(textures_.empty()); |
281 | 273 |
282 // If this triggers, that means something is keeping a reference to | 274 // If this triggers, that means something is keeping a reference to |
283 // a Texture belonging to this. | 275 // a Texture belonging to this. |
284 CHECK_EQ(texture_count_, 0u); | 276 CHECK_EQ(texture_count_, 0u); |
285 | 277 |
286 DCHECK_EQ(0, num_unrenderable_textures_); | |
287 DCHECK_EQ(0, num_unsafe_textures_); | 278 DCHECK_EQ(0, num_unsafe_textures_); |
288 DCHECK_EQ(0, num_uncleared_mips_); | 279 DCHECK_EQ(0, num_uncleared_mips_); |
289 DCHECK_EQ(0, num_images_); | 280 DCHECK_EQ(0, num_images_); |
290 | 281 |
291 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 282 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
292 this); | 283 this); |
293 } | 284 } |
294 | 285 |
295 void TextureManager::Destroy(bool have_context) { | 286 void TextureManager::Destroy(bool have_context) { |
296 have_context_ = have_context; | 287 have_context_ = have_context; |
(...skipping 10 matching lines...) Expand all Loading... | |
307 } | 298 } |
308 | 299 |
309 Texture::Texture(GLuint service_id) | 300 Texture::Texture(GLuint service_id) |
310 : mailbox_manager_(NULL), | 301 : mailbox_manager_(NULL), |
311 memory_tracking_ref_(NULL), | 302 memory_tracking_ref_(NULL), |
312 service_id_(service_id), | 303 service_id_(service_id), |
313 cleared_(true), | 304 cleared_(true), |
314 num_uncleared_mips_(0), | 305 num_uncleared_mips_(0), |
315 num_npot_faces_(0), | 306 num_npot_faces_(0), |
316 target_(0), | 307 target_(0), |
317 min_filter_(GL_NEAREST_MIPMAP_LINEAR), | |
318 mag_filter_(GL_LINEAR), | |
319 wrap_r_(GL_REPEAT), | |
320 wrap_s_(GL_REPEAT), | |
321 wrap_t_(GL_REPEAT), | |
322 usage_(GL_NONE), | 308 usage_(GL_NONE), |
323 compare_func_(GL_LEQUAL), | |
324 compare_mode_(GL_NONE), | |
325 max_lod_(1000.0f), | |
326 min_lod_(-1000.0f), | |
327 base_level_(0), | 309 base_level_(0), |
328 max_level_(1000), | 310 max_level_(1000), |
329 max_level_set_(-1), | 311 max_level_set_(-1), |
330 texture_complete_(false), | 312 texture_complete_(false), |
331 texture_mips_dirty_(false), | 313 texture_mips_dirty_(false), |
332 cube_complete_(false), | 314 cube_complete_(false), |
333 texture_level0_dirty_(false), | 315 texture_level0_dirty_(false), |
334 npot_(false), | 316 npot_(false), |
335 has_been_bound_(false), | 317 has_been_bound_(false), |
336 framebuffer_attachment_count_(0), | 318 framebuffer_attachment_count_(0), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 } | 412 } |
431 const Texture::LevelInfo& first_face = | 413 const Texture::LevelInfo& first_face = |
432 face_infos_[0].level_infos[base_level_]; | 414 face_infos_[0].level_infos[base_level_]; |
433 if (first_face.width == 0 || | 415 if (first_face.width == 0 || |
434 first_face.height == 0 || | 416 first_face.height == 0 || |
435 first_face.depth == 0) { | 417 first_face.depth == 0) { |
436 return CAN_RENDER_NEVER; | 418 return CAN_RENDER_NEVER; |
437 } | 419 } |
438 } | 420 } |
439 | 421 |
440 bool needs_mips = NeedsMips(); | |
441 if (needs_mips) { | |
442 if (!texture_complete()) | |
443 return CAN_RENDER_NEVER; | |
444 } | |
445 | |
446 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) | 422 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) |
447 return CAN_RENDER_NEVER; | 423 return CAN_RENDER_NEVER; |
448 | 424 |
449 bool is_npot_compatible = !needs_mips && | 425 // Texture may be renderable, but it depends on the sampler it's used with, |
450 wrap_s_ == GL_CLAMP_TO_EDGE && | 426 // the context that's using it, and the extensions available. |
451 wrap_t_ == GL_CLAMP_TO_EDGE; | 427 return CAN_RENDER_NEEDS_VALIDATION; |
452 | |
453 if (!is_npot_compatible) { | |
454 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | |
455 return CAN_RENDER_NEVER; | |
456 else if (npot()) | |
457 return CAN_RENDER_ONLY_IF_NPOT; | |
458 } | |
459 | |
460 return CAN_RENDER_ALWAYS; | |
461 } | 428 } |
462 | 429 |
463 bool Texture::CanRender(const FeatureInfo* feature_info) const { | 430 bool Texture::CanRender(const FeatureInfo* feature_info) const { |
431 return CanRenderWithSampler(feature_info, sampler_state()); | |
432 } | |
433 | |
434 bool Texture::CanRenderWithSampler(const FeatureInfo* feature_info, | |
435 const SamplerState& sampler_state) const { | |
464 switch (can_render_condition_) { | 436 switch (can_render_condition_) { |
465 case CAN_RENDER_ALWAYS: | 437 case CAN_RENDER_ALWAYS: |
466 return true; | 438 return true; |
467 case CAN_RENDER_NEVER: | 439 case CAN_RENDER_NEVER: |
468 return false; | 440 return false; |
469 case CAN_RENDER_ONLY_IF_NPOT: | 441 case CAN_RENDER_NEEDS_VALIDATION: |
470 break; | 442 break; |
471 } | 443 } |
472 return feature_info->feature_flags().npot_ok; | 444 |
445 bool needs_mips = sampler_state.min_filter != GL_NEAREST && | |
446 sampler_state.min_filter != GL_LINEAR; | |
447 if (needs_mips && !texture_complete()) | |
448 return false; | |
449 | |
450 if (!feature_info->IsES3Enabled()) { | |
451 bool is_npot_compatible = !needs_mips && | |
452 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | |
453 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | |
454 | |
455 if (!is_npot_compatible) { | |
456 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | |
457 return false; | |
458 else if (npot()) | |
459 return feature_info->feature_flags().npot_ok; | |
460 } | |
461 } | |
462 | |
463 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) { | |
Zhenyao Mo
2015/12/14 22:48:33
You should be able to DCHECK here because this cas
| |
464 return false; | |
465 } | |
466 | |
467 const Texture::LevelInfo& first_level = | |
468 face_infos_[0].level_infos[base_level_]; | |
469 | |
470 if (first_level.type == GL_FLOAT && | |
471 !feature_info->feature_flags().enable_texture_float_linear && | |
472 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
473 sampler_state.mag_filter != GL_NEAREST)) { | |
474 return false; | |
475 } else if (first_level.type == GL_HALF_FLOAT_OES && | |
476 !feature_info->feature_flags().enable_texture_half_float_linear && | |
477 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
478 sampler_state.mag_filter != GL_NEAREST)) { | |
479 return false; | |
480 } | |
481 | |
482 return true; | |
473 } | 483 } |
474 | 484 |
475 void Texture::AddToSignature( | 485 void Texture::AddToSignature( |
476 const FeatureInfo* feature_info, | 486 const FeatureInfo* feature_info, |
477 GLenum target, | 487 GLenum target, |
478 GLint level, | 488 GLint level, |
479 std::string* signature) const { | 489 std::string* signature) const { |
480 DCHECK(feature_info); | 490 DCHECK(feature_info); |
481 DCHECK(signature); | 491 DCHECK(signature); |
482 DCHECK_GE(level, 0); | 492 DCHECK_GE(level, 0); |
483 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 493 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
484 DCHECK_LT(static_cast<size_t>(face_index), | 494 DCHECK_LT(static_cast<size_t>(face_index), |
485 face_infos_.size()); | 495 face_infos_.size()); |
486 DCHECK_LT(static_cast<size_t>(level), | 496 DCHECK_LT(static_cast<size_t>(level), |
487 face_infos_[face_index].level_infos.size()); | 497 face_infos_[face_index].level_infos.size()); |
488 | 498 |
489 const Texture::LevelInfo& info = | 499 const Texture::LevelInfo& info = |
490 face_infos_[face_index].level_infos[level]; | 500 face_infos_[face_index].level_infos[level]; |
491 | 501 |
492 TextureSignature signature_data(target, | 502 TextureSignature signature_data(target, |
493 level, | 503 level, |
494 min_filter_, | 504 sampler_state_, |
495 mag_filter_, | |
496 wrap_r_, | |
497 wrap_s_, | |
498 wrap_t_, | |
499 usage_, | 505 usage_, |
500 info.internal_format, | 506 info.internal_format, |
501 compare_func_, | |
502 compare_mode_, | |
503 info.width, | 507 info.width, |
504 info.height, | 508 info.height, |
505 info.depth, | 509 info.depth, |
506 max_lod_, | |
507 min_lod_, | |
508 base_level_, | 510 base_level_, |
509 info.border, | 511 info.border, |
510 max_level_, | 512 max_level_, |
511 info.format, | 513 info.format, |
512 info.type, | 514 info.type, |
513 info.image.get() != NULL, | 515 info.image.get() != NULL, |
514 CanRender(feature_info), | 516 CanRender(feature_info), |
515 CanRenderTo(), | 517 CanRenderTo(), |
516 npot_); | 518 npot_); |
517 | 519 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { | 560 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { |
559 DCHECK_EQ(0u, target_); // you can only set this once. | 561 DCHECK_EQ(0u, target_); // you can only set this once. |
560 target_ = target; | 562 target_ = target; |
561 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 563 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
562 face_infos_.resize(num_faces); | 564 face_infos_.resize(num_faces); |
563 for (size_t ii = 0; ii < num_faces; ++ii) { | 565 for (size_t ii = 0; ii < num_faces; ++ii) { |
564 face_infos_[ii].level_infos.resize(max_levels); | 566 face_infos_[ii].level_infos.resize(max_levels); |
565 } | 567 } |
566 | 568 |
567 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 569 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
568 min_filter_ = GL_LINEAR; | 570 sampler_state_.min_filter = GL_LINEAR; |
569 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; | 571 sampler_state_.wrap_s = sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; |
570 } | 572 } |
571 | 573 |
572 if (target == GL_TEXTURE_EXTERNAL_OES) { | 574 if (target == GL_TEXTURE_EXTERNAL_OES) { |
573 immutable_ = true; | 575 immutable_ = true; |
574 } | 576 } |
575 Update(feature_info); | 577 Update(feature_info); |
576 UpdateCanRenderCondition(); | 578 UpdateCanRenderCondition(); |
577 } | 579 } |
578 | 580 |
579 bool Texture::CanGenerateMipmaps( | 581 bool Texture::CanGenerateMipmaps( |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); | 732 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
731 if (cleared == was_cleared) | 733 if (cleared == was_cleared) |
732 return; | 734 return; |
733 int delta = cleared ? -1 : +1; | 735 int delta = cleared ? -1 : +1; |
734 num_uncleared_mips_ += delta; | 736 num_uncleared_mips_ += delta; |
735 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 737 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
736 (*it)->manager()->UpdateUnclearedMips(delta); | 738 (*it)->manager()->UpdateUnclearedMips(delta); |
737 } | 739 } |
738 | 740 |
739 void Texture::UpdateCanRenderCondition() { | 741 void Texture::UpdateCanRenderCondition() { |
740 CanRenderCondition can_render_condition = GetCanRenderCondition(); | 742 can_render_condition_ = GetCanRenderCondition(); |
741 if (can_render_condition_ == can_render_condition) | |
742 return; | |
743 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | |
744 (*it)->manager()->UpdateCanRenderCondition(can_render_condition_, | |
745 can_render_condition); | |
746 can_render_condition_ = can_render_condition; | |
747 } | 743 } |
748 | 744 |
749 void Texture::UpdateHasImages() { | 745 void Texture::UpdateHasImages() { |
750 if (face_infos_.empty()) | 746 if (face_infos_.empty()) |
751 return; | 747 return; |
752 | 748 |
753 bool has_images = false; | 749 bool has_images = false; |
754 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 750 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
755 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { | 751 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { |
756 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; | 752 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 case GL_TEXTURE_MIN_LOD: | 971 case GL_TEXTURE_MIN_LOD: |
976 case GL_TEXTURE_MAX_LOD: | 972 case GL_TEXTURE_MAX_LOD: |
977 { | 973 { |
978 GLfloat fparam = static_cast<GLfloat>(param); | 974 GLfloat fparam = static_cast<GLfloat>(param); |
979 return SetParameterf(feature_info, pname, fparam); | 975 return SetParameterf(feature_info, pname, fparam); |
980 } | 976 } |
981 case GL_TEXTURE_MIN_FILTER: | 977 case GL_TEXTURE_MIN_FILTER: |
982 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { | 978 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { |
983 return GL_INVALID_ENUM; | 979 return GL_INVALID_ENUM; |
984 } | 980 } |
985 min_filter_ = param; | 981 sampler_state_.min_filter = param; |
986 break; | 982 break; |
987 case GL_TEXTURE_MAG_FILTER: | 983 case GL_TEXTURE_MAG_FILTER: |
988 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { | 984 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { |
989 return GL_INVALID_ENUM; | 985 return GL_INVALID_ENUM; |
990 } | 986 } |
991 mag_filter_ = param; | 987 sampler_state_.mag_filter = param; |
992 break; | 988 break; |
993 case GL_TEXTURE_WRAP_R: | 989 case GL_TEXTURE_WRAP_R: |
994 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 990 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
995 return GL_INVALID_ENUM; | 991 return GL_INVALID_ENUM; |
996 } | 992 } |
997 wrap_r_ = param; | 993 sampler_state_.wrap_r = param; |
998 break; | 994 break; |
999 case GL_TEXTURE_WRAP_S: | 995 case GL_TEXTURE_WRAP_S: |
1000 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 996 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1001 return GL_INVALID_ENUM; | 997 return GL_INVALID_ENUM; |
1002 } | 998 } |
1003 wrap_s_ = param; | 999 sampler_state_.wrap_s = param; |
1004 break; | 1000 break; |
1005 case GL_TEXTURE_WRAP_T: | 1001 case GL_TEXTURE_WRAP_T: |
1006 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 1002 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1007 return GL_INVALID_ENUM; | 1003 return GL_INVALID_ENUM; |
1008 } | 1004 } |
1009 wrap_t_ = param; | 1005 sampler_state_.wrap_t = param; |
1010 break; | 1006 break; |
1011 case GL_TEXTURE_COMPARE_FUNC: | 1007 case GL_TEXTURE_COMPARE_FUNC: |
1012 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { | 1008 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { |
1013 return GL_INVALID_ENUM; | 1009 return GL_INVALID_ENUM; |
1014 } | 1010 } |
1015 compare_func_ = param; | 1011 sampler_state_.compare_func = param; |
1016 break; | 1012 break; |
1017 case GL_TEXTURE_COMPARE_MODE: | 1013 case GL_TEXTURE_COMPARE_MODE: |
1018 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { | 1014 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { |
1019 return GL_INVALID_ENUM; | 1015 return GL_INVALID_ENUM; |
1020 } | 1016 } |
1021 compare_mode_ = param; | 1017 sampler_state_.compare_mode = param; |
1022 break; | 1018 break; |
1023 case GL_TEXTURE_BASE_LEVEL: | 1019 case GL_TEXTURE_BASE_LEVEL: |
1024 if (param < 0) { | 1020 if (param < 0) { |
1025 return GL_INVALID_VALUE; | 1021 return GL_INVALID_VALUE; |
1026 } | 1022 } |
1027 UpdateBaseLevel(param); | 1023 UpdateBaseLevel(param); |
1028 break; | 1024 break; |
1029 case GL_TEXTURE_MAX_LEVEL: | 1025 case GL_TEXTURE_MAX_LEVEL: |
1030 if (param < 0) { | 1026 if (param < 0) { |
1031 return GL_INVALID_VALUE; | 1027 return GL_INVALID_VALUE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 case GL_TEXTURE_COMPARE_FUNC: | 1060 case GL_TEXTURE_COMPARE_FUNC: |
1065 case GL_TEXTURE_COMPARE_MODE: | 1061 case GL_TEXTURE_COMPARE_MODE: |
1066 case GL_TEXTURE_BASE_LEVEL: | 1062 case GL_TEXTURE_BASE_LEVEL: |
1067 case GL_TEXTURE_MAX_LEVEL: | 1063 case GL_TEXTURE_MAX_LEVEL: |
1068 case GL_TEXTURE_USAGE_ANGLE: | 1064 case GL_TEXTURE_USAGE_ANGLE: |
1069 { | 1065 { |
1070 GLint iparam = static_cast<GLint>(param); | 1066 GLint iparam = static_cast<GLint>(param); |
1071 return SetParameteri(feature_info, pname, iparam); | 1067 return SetParameteri(feature_info, pname, iparam); |
1072 } | 1068 } |
1073 case GL_TEXTURE_MIN_LOD: | 1069 case GL_TEXTURE_MIN_LOD: |
1074 min_lod_ = param; | 1070 sampler_state_.min_lod = param; |
1075 break; | 1071 break; |
1076 case GL_TEXTURE_MAX_LOD: | 1072 case GL_TEXTURE_MAX_LOD: |
1077 max_lod_ = param; | 1073 sampler_state_.max_lod = param; |
1078 break; | 1074 break; |
1079 case GL_TEXTURE_MAX_ANISOTROPY_EXT: | 1075 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
1080 if (param < 1.f) { | 1076 if (param < 1.f) { |
1081 return GL_INVALID_VALUE; | 1077 return GL_INVALID_VALUE; |
1082 } | 1078 } |
1083 break; | 1079 break; |
1084 default: | 1080 default: |
1085 NOTREACHED(); | 1081 NOTREACHED(); |
1086 return GL_INVALID_ENUM; | 1082 return GL_INVALID_ENUM; |
1087 } | 1083 } |
(...skipping 17 matching lines...) Expand all Loading... | |
1105 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; | 1101 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; |
1106 const GLsizei levels_needed = first_face.num_mip_levels; | 1102 const GLsizei levels_needed = first_face.num_mip_levels; |
1107 | 1103 |
1108 texture_complete_ = | 1104 texture_complete_ = |
1109 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 1105 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
1110 cube_complete_ = (face_infos_.size() == 6) && | 1106 cube_complete_ = (face_infos_.size() == 6) && |
1111 (first_level.width == first_level.height); | 1107 (first_level.width == first_level.height); |
1112 | 1108 |
1113 if (first_level.width == 0 || first_level.height == 0) { | 1109 if (first_level.width == 0 || first_level.height == 0) { |
1114 texture_complete_ = false; | 1110 texture_complete_ = false; |
1115 } else if (first_level.type == GL_FLOAT && | |
1116 !feature_info->feature_flags().enable_texture_float_linear && | |
1117 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | |
1118 mag_filter_ != GL_NEAREST)) { | |
1119 texture_complete_ = false; | |
1120 } else if (first_level.type == GL_HALF_FLOAT_OES && | |
1121 !feature_info->feature_flags().enable_texture_half_float_linear && | |
1122 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | |
1123 mag_filter_ != GL_NEAREST)) { | |
1124 texture_complete_ = false; | |
1125 } | 1111 } |
1126 | 1112 |
1127 bool texture_level0_complete = true; | 1113 bool texture_level0_complete = true; |
1128 if (cube_complete_ && texture_level0_dirty_) { | 1114 if (cube_complete_ && texture_level0_dirty_) { |
1129 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1115 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1130 const Texture::LevelInfo& face_base_level = | 1116 const Texture::LevelInfo& face_base_level = |
1131 face_infos_[ii].level_infos[base_level_]; | 1117 face_infos_[ii].level_infos[base_level_]; |
1132 if (!TextureFaceComplete(first_level, | 1118 if (!TextureFaceComplete(first_level, |
1133 ii, | 1119 ii, |
1134 face_base_level.target, | 1120 face_base_level.target, |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, | 1396 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
1411 max_cube_map_texture_size, | 1397 max_cube_map_texture_size, |
1412 max_cube_map_texture_size, | 1398 max_cube_map_texture_size, |
1413 max_cube_map_texture_size)), | 1399 max_cube_map_texture_size)), |
1414 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, | 1400 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, |
1415 // Same as GL_TEXTURE_2D_ARRAY | 1401 // Same as GL_TEXTURE_2D_ARRAY |
1416 max_3d_texture_size, | 1402 max_3d_texture_size, |
1417 max_3d_texture_size, | 1403 max_3d_texture_size, |
1418 max_3d_texture_size)), | 1404 max_3d_texture_size)), |
1419 use_default_textures_(use_default_textures), | 1405 use_default_textures_(use_default_textures), |
1420 num_unrenderable_textures_(0), | |
1421 num_unsafe_textures_(0), | 1406 num_unsafe_textures_(0), |
1422 num_uncleared_mips_(0), | 1407 num_uncleared_mips_(0), |
1423 num_images_(0), | 1408 num_images_(0), |
1424 texture_count_(0), | 1409 texture_count_(0), |
1425 have_context_(true) { | 1410 have_context_(true) { |
1426 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 1411 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
1427 black_texture_ids_[ii] = 0; | 1412 black_texture_ids_[ii] = 0; |
1428 } | 1413 } |
1429 } | 1414 } |
1430 | 1415 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 textures_.erase(it); | 1683 textures_.erase(it); |
1699 } | 1684 } |
1700 } | 1685 } |
1701 | 1686 |
1702 void TextureManager::StartTracking(TextureRef* ref) { | 1687 void TextureManager::StartTracking(TextureRef* ref) { |
1703 Texture* texture = ref->texture(); | 1688 Texture* texture = ref->texture(); |
1704 ++texture_count_; | 1689 ++texture_count_; |
1705 num_uncleared_mips_ += texture->num_uncleared_mips(); | 1690 num_uncleared_mips_ += texture->num_uncleared_mips(); |
1706 if (!texture->SafeToRenderFrom()) | 1691 if (!texture->SafeToRenderFrom()) |
1707 ++num_unsafe_textures_; | 1692 ++num_unsafe_textures_; |
1708 if (!texture->CanRender(feature_info_.get())) | |
1709 ++num_unrenderable_textures_; | |
1710 if (texture->HasImages()) | 1693 if (texture->HasImages()) |
1711 ++num_images_; | 1694 ++num_images_; |
1712 } | 1695 } |
1713 | 1696 |
1714 void TextureManager::StopTracking(TextureRef* ref) { | 1697 void TextureManager::StopTracking(TextureRef* ref) { |
1715 if (ref->num_observers()) { | 1698 if (ref->num_observers()) { |
1716 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { | 1699 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { |
1717 destruction_observers_[i]->OnTextureRefDestroying(ref); | 1700 destruction_observers_[i]->OnTextureRefDestroying(ref); |
1718 } | 1701 } |
1719 DCHECK_EQ(ref->num_observers(), 0); | 1702 DCHECK_EQ(ref->num_observers(), 0); |
1720 } | 1703 } |
1721 | 1704 |
1722 Texture* texture = ref->texture(); | 1705 Texture* texture = ref->texture(); |
1723 | 1706 |
1724 --texture_count_; | 1707 --texture_count_; |
1725 if (texture->HasImages()) { | 1708 if (texture->HasImages()) { |
1726 DCHECK_NE(0, num_images_); | 1709 DCHECK_NE(0, num_images_); |
1727 --num_images_; | 1710 --num_images_; |
1728 } | 1711 } |
1729 if (!texture->CanRender(feature_info_.get())) { | |
1730 DCHECK_NE(0, num_unrenderable_textures_); | |
1731 --num_unrenderable_textures_; | |
1732 } | |
1733 if (!texture->SafeToRenderFrom()) { | 1712 if (!texture->SafeToRenderFrom()) { |
1734 DCHECK_NE(0, num_unsafe_textures_); | 1713 DCHECK_NE(0, num_unsafe_textures_); |
1735 --num_unsafe_textures_; | 1714 --num_unsafe_textures_; |
1736 } | 1715 } |
1737 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1716 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
1738 DCHECK_GE(num_uncleared_mips_, 0); | 1717 DCHECK_GE(num_uncleared_mips_, 0); |
1739 } | 1718 } |
1740 | 1719 |
1741 MemoryTypeTracker* TextureManager::GetMemTracker() { | 1720 MemoryTypeTracker* TextureManager::GetMemTracker() { |
1742 return memory_type_tracker_.get(); | 1721 return memory_type_tracker_.get(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1790 void TextureManager::UpdateSafeToRenderFrom(int delta) { | 1769 void TextureManager::UpdateSafeToRenderFrom(int delta) { |
1791 num_unsafe_textures_ += delta; | 1770 num_unsafe_textures_ += delta; |
1792 DCHECK_GE(num_unsafe_textures_, 0); | 1771 DCHECK_GE(num_unsafe_textures_, 0); |
1793 } | 1772 } |
1794 | 1773 |
1795 void TextureManager::UpdateUnclearedMips(int delta) { | 1774 void TextureManager::UpdateUnclearedMips(int delta) { |
1796 num_uncleared_mips_ += delta; | 1775 num_uncleared_mips_ += delta; |
1797 DCHECK_GE(num_uncleared_mips_, 0); | 1776 DCHECK_GE(num_uncleared_mips_, 0); |
1798 } | 1777 } |
1799 | 1778 |
1800 void TextureManager::UpdateCanRenderCondition( | |
1801 Texture::CanRenderCondition old_condition, | |
1802 Texture::CanRenderCondition new_condition) { | |
1803 if (old_condition == Texture::CAN_RENDER_NEVER || | |
1804 (old_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && | |
1805 !feature_info_->feature_flags().npot_ok)) { | |
1806 DCHECK_GT(num_unrenderable_textures_, 0); | |
1807 --num_unrenderable_textures_; | |
1808 } | |
1809 if (new_condition == Texture::CAN_RENDER_NEVER || | |
1810 (new_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && | |
1811 !feature_info_->feature_flags().npot_ok)) | |
1812 ++num_unrenderable_textures_; | |
1813 } | |
1814 | |
1815 void TextureManager::UpdateNumImages(int delta) { | 1779 void TextureManager::UpdateNumImages(int delta) { |
1816 num_images_ += delta; | 1780 num_images_ += delta; |
1817 DCHECK_GE(num_images_, 0); | 1781 DCHECK_GE(num_images_, 0); |
1818 } | 1782 } |
1819 | 1783 |
1820 void TextureManager::IncFramebufferStateChangeCount() { | 1784 void TextureManager::IncFramebufferStateChangeCount() { |
1821 if (framebuffer_manager_) | 1785 if (framebuffer_manager_) |
1822 framebuffer_manager_->IncFramebufferStateChangeCount(); | 1786 framebuffer_manager_->IncFramebufferStateChangeCount(); |
1823 } | 1787 } |
1824 | 1788 |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2611 return GL_HALF_FLOAT_OES; | 2575 return GL_HALF_FLOAT_OES; |
2612 case GL_BGRA8_EXT: | 2576 case GL_BGRA8_EXT: |
2613 return GL_UNSIGNED_BYTE; | 2577 return GL_UNSIGNED_BYTE; |
2614 default: | 2578 default: |
2615 return GL_NONE; | 2579 return GL_NONE; |
2616 } | 2580 } |
2617 } | 2581 } |
2618 | 2582 |
2619 } // namespace gles2 | 2583 } // namespace gles2 |
2620 } // namespace gpu | 2584 } // namespace gpu |
OLD | NEW |