OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/bits.h" | 6 #include "base/bits.h" |
7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
8 #include "gpu/command_buffer/service/context_group.h" | 8 #include "gpu/command_buffer/service/context_group.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 #include "gpu/GLES2/gles2_command_buffer.h" | 10 #include "gpu/GLES2/gles2_command_buffer.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (have_context) { | 68 if (have_context) { |
69 TextureInfo* info = texture_infos_.begin()->second; | 69 TextureInfo* info = texture_infos_.begin()->second; |
70 if (!info->IsDeleted()) { | 70 if (!info->IsDeleted()) { |
71 GLuint service_id = info->service_id(); | 71 GLuint service_id = info->service_id(); |
72 glDeleteTextures(1, &service_id); | 72 glDeleteTextures(1, &service_id); |
73 info->MarkAsDeleted(); | 73 info->MarkAsDeleted(); |
74 } | 74 } |
75 } | 75 } |
76 texture_infos_.erase(texture_infos_.begin()); | 76 texture_infos_.erase(texture_infos_.begin()); |
77 } | 77 } |
| 78 if (have_context) { |
| 79 GLuint ids[] = { |
| 80 black_2d_texture_id_, |
| 81 black_cube_texture_id_, |
| 82 default_texture_2d_->service_id(), |
| 83 default_texture_cube_map_->service_id(), |
| 84 }; |
| 85 glDeleteTextures(arraysize(ids), ids); |
| 86 } |
78 } | 87 } |
79 | 88 |
80 bool TextureManager::TextureInfo::CanRender( | 89 bool TextureManager::TextureInfo::CanRender( |
81 const TextureManager* manager) const { | 90 const TextureManager* manager) const { |
82 DCHECK(manager); | 91 DCHECK(manager); |
83 if (target_ == 0 || IsDeleted()) { | 92 if (target_ == 0 || IsDeleted()) { |
84 return false; | 93 return false; |
85 } | 94 } |
86 bool needs_mips = NeedsMips(); | 95 bool needs_mips = NeedsMips(); |
87 if (npot() && !manager->npot_ok()) { | 96 if (npot() && !manager->npot_ok()) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 enable_float_linear_(enable_float_linear), | 354 enable_float_linear_(enable_float_linear), |
346 enable_half_float_linear_(enable_half_float_linear), | 355 enable_half_float_linear_(enable_half_float_linear), |
347 max_texture_size_(max_texture_size), | 356 max_texture_size_(max_texture_size), |
348 max_cube_map_texture_size_(max_cube_map_texture_size), | 357 max_cube_map_texture_size_(max_cube_map_texture_size), |
349 max_levels_(ComputeMipMapCount(max_texture_size, | 358 max_levels_(ComputeMipMapCount(max_texture_size, |
350 max_texture_size, | 359 max_texture_size, |
351 max_texture_size)), | 360 max_texture_size)), |
352 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, | 361 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, |
353 max_cube_map_texture_size, | 362 max_cube_map_texture_size, |
354 max_cube_map_texture_size)), | 363 max_cube_map_texture_size)), |
355 num_unrenderable_textures_(0) { | 364 num_unrenderable_textures_(0), |
356 default_texture_2d_ = TextureInfo::Ref(new TextureInfo(0)); | 365 black_2d_texture_id_(0), |
| 366 black_cube_texture_id_(0) { |
| 367 } |
| 368 |
| 369 bool TextureManager::Initialize() { |
| 370 // TODO(gman): The default textures have to be real textures, not the 0 |
| 371 // texture because we simulate non shared resources on top of shared |
| 372 // resources and all contexts that share resource share the same default |
| 373 // texture. |
| 374 |
| 375 // Make default textures and texture for replacing non-renderable textures. |
| 376 GLuint ids[4]; |
| 377 glGenTextures(arraysize(ids), ids); |
| 378 static uint8 black[] = {0, 0, 0, 255}; |
| 379 for (int ii = 0; ii < 2; ++ii) { |
| 380 glBindTexture(GL_TEXTURE_2D, ids[ii]); |
| 381 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
| 382 GL_UNSIGNED_BYTE, black); |
| 383 glBindTexture(GL_TEXTURE_CUBE_MAP, ids[2 + ii]); |
| 384 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
| 385 glTexImage2D(GLES2Util::IndexToGLFaceTarget(ii), 0, GL_RGBA, 1, 1, 0, |
| 386 GL_RGBA, GL_UNSIGNED_BYTE, black); |
| 387 } |
| 388 } |
| 389 glBindTexture(GL_TEXTURE_2D, 0); |
| 390 glBindTexture(GL_TEXTURE_CUBE_MAP, 0); |
| 391 |
| 392 default_texture_2d_ = TextureInfo::Ref(new TextureInfo(ids[1])); |
357 SetInfoTarget(default_texture_2d_, GL_TEXTURE_2D); | 393 SetInfoTarget(default_texture_2d_, GL_TEXTURE_2D); |
358 default_texture_2d_->SetLevelInfo( | 394 default_texture_2d_->SetLevelInfo( |
359 this, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 395 this, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
360 default_texture_cube_map_ = TextureInfo::Ref(new TextureInfo(0)); | 396 default_texture_cube_map_ = TextureInfo::Ref(new TextureInfo(ids[3])); |
361 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); | 397 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); |
362 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 398 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
363 default_texture_cube_map_->SetLevelInfo( | 399 default_texture_cube_map_->SetLevelInfo( |
364 this, GLES2Util::IndexToGLFaceTarget(ii), | 400 this, GLES2Util::IndexToGLFaceTarget(ii), |
365 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 401 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
366 } | 402 } |
| 403 |
| 404 black_2d_texture_id_ = ids[0]; |
| 405 black_cube_texture_id_ = ids[2]; |
| 406 |
| 407 return true; |
367 } | 408 } |
368 | 409 |
369 bool TextureManager::ValidForTarget( | 410 bool TextureManager::ValidForTarget( |
370 GLenum target, GLint level, | 411 GLenum target, GLint level, |
371 GLsizei width, GLsizei height, GLsizei depth) { | 412 GLsizei width, GLsizei height, GLsizei depth) { |
372 GLsizei max_size = MaxSizeForTarget(target); | 413 GLsizei max_size = MaxSizeForTarget(target); |
373 return level >= 0 && | 414 return level >= 0 && |
374 width >= 0 && | 415 width >= 0 && |
375 height >= 0 && | 416 height >= 0 && |
376 depth >= 0 && | 417 depth >= 0 && |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 return true; | 516 return true; |
476 } | 517 } |
477 } | 518 } |
478 return false; | 519 return false; |
479 } | 520 } |
480 | 521 |
481 } // namespace gles2 | 522 } // namespace gles2 |
482 } // namespace gpu | 523 } // namespace gpu |
483 | 524 |
484 | 525 |
OLD | NEW |