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 SamplerState sampler_state, |
piman
2015/12/14 14:04:14
nit: const SamplerState&
| |
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 { | |
436 DCHECK(sampler_state); | |
437 | |
464 switch (can_render_condition_) { | 438 switch (can_render_condition_) { |
465 case CAN_RENDER_ALWAYS: | 439 case CAN_RENDER_ALWAYS: |
466 return true; | 440 return true; |
467 case CAN_RENDER_NEVER: | 441 case CAN_RENDER_NEVER: |
468 return false; | 442 return false; |
469 case CAN_RENDER_ONLY_IF_NPOT: | 443 case CAN_RENDER_NEEDS_VALIDATION: |
470 break; | 444 break; |
471 } | 445 } |
472 return feature_info->feature_flags().npot_ok; | 446 |
447 bool needs_mips = sampler_state->min_filter != GL_NEAREST && | |
448 sampler_state->min_filter != GL_LINEAR; | |
449 if (needs_mips && !texture_complete()) | |
450 return false; | |
451 | |
452 if (!feature_info->IsES3Enabled()) { | |
453 bool is_npot_compatible = !needs_mips && | |
454 sampler_state_.wrap_s == GL_CLAMP_TO_EDGE && | |
455 sampler_state_.wrap_t == GL_CLAMP_TO_EDGE; | |
456 | |
457 if (!is_npot_compatible) { | |
458 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | |
459 return false; | |
460 else if (npot()) | |
461 return feature_info->feature_flags().npot_ok; | |
462 } | |
463 } | |
464 | |
465 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) { | |
466 return false; | |
467 } | |
468 | |
469 const Texture::LevelInfo& first_level = | |
470 face_infos_[0].level_infos[base_level_]; | |
471 | |
472 if (first_level.type == GL_FLOAT && | |
473 !feature_info->feature_flags().enable_texture_float_linear && | |
474 (sampler_state->min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
475 sampler_state->mag_filter != GL_NEAREST)) { | |
476 return false; | |
477 } else if (first_level.type == GL_HALF_FLOAT_OES && | |
478 !feature_info->feature_flags().enable_texture_half_float_linear && | |
479 (sampler_state->min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
480 sampler_state->mag_filter != GL_NEAREST)) { | |
481 return false; | |
482 } | |
483 | |
484 return true; | |
473 } | 485 } |
474 | 486 |
475 void Texture::AddToSignature( | 487 void Texture::AddToSignature( |
476 const FeatureInfo* feature_info, | 488 const FeatureInfo* feature_info, |
477 GLenum target, | 489 GLenum target, |
478 GLint level, | 490 GLint level, |
479 std::string* signature) const { | 491 std::string* signature) const { |
480 DCHECK(feature_info); | 492 DCHECK(feature_info); |
481 DCHECK(signature); | 493 DCHECK(signature); |
482 DCHECK_GE(level, 0); | 494 DCHECK_GE(level, 0); |
483 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 495 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
484 DCHECK_LT(static_cast<size_t>(face_index), | 496 DCHECK_LT(static_cast<size_t>(face_index), |
485 face_infos_.size()); | 497 face_infos_.size()); |
486 DCHECK_LT(static_cast<size_t>(level), | 498 DCHECK_LT(static_cast<size_t>(level), |
487 face_infos_[face_index].level_infos.size()); | 499 face_infos_[face_index].level_infos.size()); |
488 | 500 |
489 const Texture::LevelInfo& info = | 501 const Texture::LevelInfo& info = |
490 face_infos_[face_index].level_infos[level]; | 502 face_infos_[face_index].level_infos[level]; |
491 | 503 |
492 TextureSignature signature_data(target, | 504 TextureSignature signature_data(target, |
493 level, | 505 level, |
494 min_filter_, | 506 sampler_state_, |
495 mag_filter_, | |
496 wrap_r_, | |
497 wrap_s_, | |
498 wrap_t_, | |
499 usage_, | 507 usage_, |
500 info.internal_format, | 508 info.internal_format, |
501 compare_func_, | |
502 compare_mode_, | |
503 info.width, | 509 info.width, |
504 info.height, | 510 info.height, |
505 info.depth, | 511 info.depth, |
506 max_lod_, | |
507 min_lod_, | |
508 base_level_, | 512 base_level_, |
509 info.border, | 513 info.border, |
510 max_level_, | 514 max_level_, |
511 info.format, | 515 info.format, |
512 info.type, | 516 info.type, |
513 info.image.get() != NULL, | 517 info.image.get() != NULL, |
514 CanRender(feature_info), | 518 CanRender(feature_info), |
515 CanRenderTo(), | 519 CanRenderTo(), |
516 npot_); | 520 npot_); |
517 | 521 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { | 562 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { |
559 DCHECK_EQ(0u, target_); // you can only set this once. | 563 DCHECK_EQ(0u, target_); // you can only set this once. |
560 target_ = target; | 564 target_ = target; |
561 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 565 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
562 face_infos_.resize(num_faces); | 566 face_infos_.resize(num_faces); |
563 for (size_t ii = 0; ii < num_faces; ++ii) { | 567 for (size_t ii = 0; ii < num_faces; ++ii) { |
564 face_infos_[ii].level_infos.resize(max_levels); | 568 face_infos_[ii].level_infos.resize(max_levels); |
565 } | 569 } |
566 | 570 |
567 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 571 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
568 min_filter_ = GL_LINEAR; | 572 sampler_state_.min_filter = GL_LINEAR; |
569 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; | 573 sampler_state_.wrap_s = sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; |
570 } | 574 } |
571 | 575 |
572 if (target == GL_TEXTURE_EXTERNAL_OES) { | 576 if (target == GL_TEXTURE_EXTERNAL_OES) { |
573 immutable_ = true; | 577 immutable_ = true; |
574 } | 578 } |
575 Update(feature_info); | 579 Update(feature_info); |
576 UpdateCanRenderCondition(); | 580 UpdateCanRenderCondition(); |
577 } | 581 } |
578 | 582 |
579 bool Texture::CanGenerateMipmaps( | 583 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); | 734 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
731 if (cleared == was_cleared) | 735 if (cleared == was_cleared) |
732 return; | 736 return; |
733 int delta = cleared ? -1 : +1; | 737 int delta = cleared ? -1 : +1; |
734 num_uncleared_mips_ += delta; | 738 num_uncleared_mips_ += delta; |
735 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 739 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
736 (*it)->manager()->UpdateUnclearedMips(delta); | 740 (*it)->manager()->UpdateUnclearedMips(delta); |
737 } | 741 } |
738 | 742 |
739 void Texture::UpdateCanRenderCondition() { | 743 void Texture::UpdateCanRenderCondition() { |
740 CanRenderCondition can_render_condition = GetCanRenderCondition(); | 744 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 } | 745 } |
748 | 746 |
749 void Texture::UpdateHasImages() { | 747 void Texture::UpdateHasImages() { |
750 if (face_infos_.empty()) | 748 if (face_infos_.empty()) |
751 return; | 749 return; |
752 | 750 |
753 bool has_images = false; | 751 bool has_images = false; |
754 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 752 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
755 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { | 753 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { |
756 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; | 754 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: | 973 case GL_TEXTURE_MIN_LOD: |
976 case GL_TEXTURE_MAX_LOD: | 974 case GL_TEXTURE_MAX_LOD: |
977 { | 975 { |
978 GLfloat fparam = static_cast<GLfloat>(param); | 976 GLfloat fparam = static_cast<GLfloat>(param); |
979 return SetParameterf(feature_info, pname, fparam); | 977 return SetParameterf(feature_info, pname, fparam); |
980 } | 978 } |
981 case GL_TEXTURE_MIN_FILTER: | 979 case GL_TEXTURE_MIN_FILTER: |
982 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { | 980 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { |
983 return GL_INVALID_ENUM; | 981 return GL_INVALID_ENUM; |
984 } | 982 } |
985 min_filter_ = param; | 983 sampler_state_.min_filter = param; |
986 break; | 984 break; |
987 case GL_TEXTURE_MAG_FILTER: | 985 case GL_TEXTURE_MAG_FILTER: |
988 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { | 986 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { |
989 return GL_INVALID_ENUM; | 987 return GL_INVALID_ENUM; |
990 } | 988 } |
991 mag_filter_ = param; | 989 sampler_state_.mag_filter = param; |
992 break; | 990 break; |
993 case GL_TEXTURE_WRAP_R: | 991 case GL_TEXTURE_WRAP_R: |
994 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 992 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
995 return GL_INVALID_ENUM; | 993 return GL_INVALID_ENUM; |
996 } | 994 } |
997 wrap_r_ = param; | 995 sampler_state_.wrap_r = param; |
998 break; | 996 break; |
999 case GL_TEXTURE_WRAP_S: | 997 case GL_TEXTURE_WRAP_S: |
1000 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 998 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1001 return GL_INVALID_ENUM; | 999 return GL_INVALID_ENUM; |
1002 } | 1000 } |
1003 wrap_s_ = param; | 1001 sampler_state_.wrap_s = param; |
1004 break; | 1002 break; |
1005 case GL_TEXTURE_WRAP_T: | 1003 case GL_TEXTURE_WRAP_T: |
1006 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 1004 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1007 return GL_INVALID_ENUM; | 1005 return GL_INVALID_ENUM; |
1008 } | 1006 } |
1009 wrap_t_ = param; | 1007 sampler_state_.wrap_t = param; |
1010 break; | 1008 break; |
1011 case GL_TEXTURE_COMPARE_FUNC: | 1009 case GL_TEXTURE_COMPARE_FUNC: |
1012 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { | 1010 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { |
1013 return GL_INVALID_ENUM; | 1011 return GL_INVALID_ENUM; |
1014 } | 1012 } |
1015 compare_func_ = param; | 1013 sampler_state_.compare_func = param; |
1016 break; | 1014 break; |
1017 case GL_TEXTURE_COMPARE_MODE: | 1015 case GL_TEXTURE_COMPARE_MODE: |
1018 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { | 1016 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { |
1019 return GL_INVALID_ENUM; | 1017 return GL_INVALID_ENUM; |
1020 } | 1018 } |
1021 compare_mode_ = param; | 1019 sampler_state_.compare_mode = param; |
1022 break; | 1020 break; |
1023 case GL_TEXTURE_BASE_LEVEL: | 1021 case GL_TEXTURE_BASE_LEVEL: |
1024 if (param < 0) { | 1022 if (param < 0) { |
1025 return GL_INVALID_VALUE; | 1023 return GL_INVALID_VALUE; |
1026 } | 1024 } |
1027 UpdateBaseLevel(param); | 1025 UpdateBaseLevel(param); |
1028 break; | 1026 break; |
1029 case GL_TEXTURE_MAX_LEVEL: | 1027 case GL_TEXTURE_MAX_LEVEL: |
1030 if (param < 0) { | 1028 if (param < 0) { |
1031 return GL_INVALID_VALUE; | 1029 return GL_INVALID_VALUE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 case GL_TEXTURE_COMPARE_FUNC: | 1062 case GL_TEXTURE_COMPARE_FUNC: |
1065 case GL_TEXTURE_COMPARE_MODE: | 1063 case GL_TEXTURE_COMPARE_MODE: |
1066 case GL_TEXTURE_BASE_LEVEL: | 1064 case GL_TEXTURE_BASE_LEVEL: |
1067 case GL_TEXTURE_MAX_LEVEL: | 1065 case GL_TEXTURE_MAX_LEVEL: |
1068 case GL_TEXTURE_USAGE_ANGLE: | 1066 case GL_TEXTURE_USAGE_ANGLE: |
1069 { | 1067 { |
1070 GLint iparam = static_cast<GLint>(param); | 1068 GLint iparam = static_cast<GLint>(param); |
1071 return SetParameteri(feature_info, pname, iparam); | 1069 return SetParameteri(feature_info, pname, iparam); |
1072 } | 1070 } |
1073 case GL_TEXTURE_MIN_LOD: | 1071 case GL_TEXTURE_MIN_LOD: |
1074 min_lod_ = param; | 1072 sampler_state_.min_lod = param; |
1075 break; | 1073 break; |
1076 case GL_TEXTURE_MAX_LOD: | 1074 case GL_TEXTURE_MAX_LOD: |
1077 max_lod_ = param; | 1075 sampler_state_.max_lod = param; |
1078 break; | 1076 break; |
1079 case GL_TEXTURE_MAX_ANISOTROPY_EXT: | 1077 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
1080 if (param < 1.f) { | 1078 if (param < 1.f) { |
1081 return GL_INVALID_VALUE; | 1079 return GL_INVALID_VALUE; |
1082 } | 1080 } |
1083 break; | 1081 break; |
1084 default: | 1082 default: |
1085 NOTREACHED(); | 1083 NOTREACHED(); |
1086 return GL_INVALID_ENUM; | 1084 return GL_INVALID_ENUM; |
1087 } | 1085 } |
(...skipping 17 matching lines...) Expand all Loading... | |
1105 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; | 1103 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; |
1106 const GLsizei levels_needed = first_face.num_mip_levels; | 1104 const GLsizei levels_needed = first_face.num_mip_levels; |
1107 | 1105 |
1108 texture_complete_ = | 1106 texture_complete_ = |
1109 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 1107 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
1110 cube_complete_ = (face_infos_.size() == 6) && | 1108 cube_complete_ = (face_infos_.size() == 6) && |
1111 (first_level.width == first_level.height); | 1109 (first_level.width == first_level.height); |
1112 | 1110 |
1113 if (first_level.width == 0 || first_level.height == 0) { | 1111 if (first_level.width == 0 || first_level.height == 0) { |
1114 texture_complete_ = false; | 1112 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 } | 1113 } |
1126 | 1114 |
1127 bool texture_level0_complete = true; | 1115 bool texture_level0_complete = true; |
1128 if (cube_complete_ && texture_level0_dirty_) { | 1116 if (cube_complete_ && texture_level0_dirty_) { |
1129 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1117 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1130 const Texture::LevelInfo& face_base_level = | 1118 const Texture::LevelInfo& face_base_level = |
1131 face_infos_[ii].level_infos[base_level_]; | 1119 face_infos_[ii].level_infos[base_level_]; |
1132 if (!TextureFaceComplete(first_level, | 1120 if (!TextureFaceComplete(first_level, |
1133 ii, | 1121 ii, |
1134 face_base_level.target, | 1122 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, | 1398 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
1411 max_cube_map_texture_size, | 1399 max_cube_map_texture_size, |
1412 max_cube_map_texture_size, | 1400 max_cube_map_texture_size, |
1413 max_cube_map_texture_size)), | 1401 max_cube_map_texture_size)), |
1414 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, | 1402 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, |
1415 // Same as GL_TEXTURE_2D_ARRAY | 1403 // Same as GL_TEXTURE_2D_ARRAY |
1416 max_3d_texture_size, | 1404 max_3d_texture_size, |
1417 max_3d_texture_size, | 1405 max_3d_texture_size, |
1418 max_3d_texture_size)), | 1406 max_3d_texture_size)), |
1419 use_default_textures_(use_default_textures), | 1407 use_default_textures_(use_default_textures), |
1420 num_unrenderable_textures_(0), | |
1421 num_unsafe_textures_(0), | 1408 num_unsafe_textures_(0), |
1422 num_uncleared_mips_(0), | 1409 num_uncleared_mips_(0), |
1423 num_images_(0), | 1410 num_images_(0), |
1424 texture_count_(0), | 1411 texture_count_(0), |
1425 have_context_(true) { | 1412 have_context_(true) { |
1426 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 1413 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
1427 black_texture_ids_[ii] = 0; | 1414 black_texture_ids_[ii] = 0; |
1428 } | 1415 } |
1429 } | 1416 } |
1430 | 1417 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 textures_.erase(it); | 1685 textures_.erase(it); |
1699 } | 1686 } |
1700 } | 1687 } |
1701 | 1688 |
1702 void TextureManager::StartTracking(TextureRef* ref) { | 1689 void TextureManager::StartTracking(TextureRef* ref) { |
1703 Texture* texture = ref->texture(); | 1690 Texture* texture = ref->texture(); |
1704 ++texture_count_; | 1691 ++texture_count_; |
1705 num_uncleared_mips_ += texture->num_uncleared_mips(); | 1692 num_uncleared_mips_ += texture->num_uncleared_mips(); |
1706 if (!texture->SafeToRenderFrom()) | 1693 if (!texture->SafeToRenderFrom()) |
1707 ++num_unsafe_textures_; | 1694 ++num_unsafe_textures_; |
1708 if (!texture->CanRender(feature_info_.get())) | |
1709 ++num_unrenderable_textures_; | |
1710 if (texture->HasImages()) | 1695 if (texture->HasImages()) |
1711 ++num_images_; | 1696 ++num_images_; |
1712 } | 1697 } |
1713 | 1698 |
1714 void TextureManager::StopTracking(TextureRef* ref) { | 1699 void TextureManager::StopTracking(TextureRef* ref) { |
1715 if (ref->num_observers()) { | 1700 if (ref->num_observers()) { |
1716 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { | 1701 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { |
1717 destruction_observers_[i]->OnTextureRefDestroying(ref); | 1702 destruction_observers_[i]->OnTextureRefDestroying(ref); |
1718 } | 1703 } |
1719 DCHECK_EQ(ref->num_observers(), 0); | 1704 DCHECK_EQ(ref->num_observers(), 0); |
1720 } | 1705 } |
1721 | 1706 |
1722 Texture* texture = ref->texture(); | 1707 Texture* texture = ref->texture(); |
1723 | 1708 |
1724 --texture_count_; | 1709 --texture_count_; |
1725 if (texture->HasImages()) { | 1710 if (texture->HasImages()) { |
1726 DCHECK_NE(0, num_images_); | 1711 DCHECK_NE(0, num_images_); |
1727 --num_images_; | 1712 --num_images_; |
1728 } | 1713 } |
1729 if (!texture->CanRender(feature_info_.get())) { | |
1730 DCHECK_NE(0, num_unrenderable_textures_); | |
1731 --num_unrenderable_textures_; | |
1732 } | |
1733 if (!texture->SafeToRenderFrom()) { | 1714 if (!texture->SafeToRenderFrom()) { |
1734 DCHECK_NE(0, num_unsafe_textures_); | 1715 DCHECK_NE(0, num_unsafe_textures_); |
1735 --num_unsafe_textures_; | 1716 --num_unsafe_textures_; |
1736 } | 1717 } |
1737 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1718 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
1738 DCHECK_GE(num_uncleared_mips_, 0); | 1719 DCHECK_GE(num_uncleared_mips_, 0); |
1739 } | 1720 } |
1740 | 1721 |
1741 MemoryTypeTracker* TextureManager::GetMemTracker() { | 1722 MemoryTypeTracker* TextureManager::GetMemTracker() { |
1742 return memory_type_tracker_.get(); | 1723 return memory_type_tracker_.get(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1790 void TextureManager::UpdateSafeToRenderFrom(int delta) { | 1771 void TextureManager::UpdateSafeToRenderFrom(int delta) { |
1791 num_unsafe_textures_ += delta; | 1772 num_unsafe_textures_ += delta; |
1792 DCHECK_GE(num_unsafe_textures_, 0); | 1773 DCHECK_GE(num_unsafe_textures_, 0); |
1793 } | 1774 } |
1794 | 1775 |
1795 void TextureManager::UpdateUnclearedMips(int delta) { | 1776 void TextureManager::UpdateUnclearedMips(int delta) { |
1796 num_uncleared_mips_ += delta; | 1777 num_uncleared_mips_ += delta; |
1797 DCHECK_GE(num_uncleared_mips_, 0); | 1778 DCHECK_GE(num_uncleared_mips_, 0); |
1798 } | 1779 } |
1799 | 1780 |
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) { | 1781 void TextureManager::UpdateNumImages(int delta) { |
1816 num_images_ += delta; | 1782 num_images_ += delta; |
1817 DCHECK_GE(num_images_, 0); | 1783 DCHECK_GE(num_images_, 0); |
1818 } | 1784 } |
1819 | 1785 |
1820 void TextureManager::IncFramebufferStateChangeCount() { | 1786 void TextureManager::IncFramebufferStateChangeCount() { |
1821 if (framebuffer_manager_) | 1787 if (framebuffer_manager_) |
1822 framebuffer_manager_->IncFramebufferStateChangeCount(); | 1788 framebuffer_manager_->IncFramebufferStateChangeCount(); |
1823 } | 1789 } |
1824 | 1790 |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2611 return GL_HALF_FLOAT_OES; | 2577 return GL_HALF_FLOAT_OES; |
2612 case GL_BGRA8_EXT: | 2578 case GL_BGRA8_EXT: |
2613 return GL_UNSIGNED_BYTE; | 2579 return GL_UNSIGNED_BYTE; |
2614 default: | 2580 default: |
2615 return GL_NONE; | 2581 return GL_NONE; |
2616 } | 2582 } |
2617 } | 2583 } |
2618 | 2584 |
2619 } // namespace gles2 | 2585 } // namespace gles2 |
2620 } // namespace gpu | 2586 } // namespace gpu |
OLD | NEW |