Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc

Issue 2841503002: Fix immutable tex srgb emulation issue of generateMipmap (Closed)
Patch Set: Fix immutable tex srgb emulation issue of generateMipmap Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/gles2_cmd_srgb_converter.h" 5 #include "gpu/command_buffer/service/gles2_cmd_srgb_converter.h"
6 6
7 #include "gpu/command_buffer/service/texture_manager.h" 7 #include "gpu/command_buffer/service/texture_manager.h"
8 #include "ui/gl/gl_version_info.h" 8 #include "ui/gl/gl_version_info.h"
9 9
10 namespace { 10 namespace {
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 GLsizei width; 408 GLsizei width;
409 GLsizei height; 409 GLsizei height;
410 GLsizei depth; 410 GLsizei depth;
411 GLenum type = 0; 411 GLenum type = 0;
412 GLenum internal_format = 0; 412 GLenum internal_format = 0;
413 GLenum format = 0; 413 GLenum format = 0;
414 GLsizei base_level = tex->base_level(); 414 GLsizei base_level = tex->base_level();
415 tex->GetLevelSize(target, base_level, &width, &height, &depth); 415 tex->GetLevelSize(target, base_level, &width, &height, &depth);
416 tex->GetLevelType(target, base_level, &type, &internal_format); 416 tex->GetLevelType(target, base_level, &type, &internal_format);
417 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); 417 format = TextureManager::ExtractFormatFromStorageFormat(internal_format);
418 const GLint mipmap_levels = 418 GLint mipmap_levels;
419 TextureManager::ComputeMipMapCount(target, width, height, depth); 419 if (tex->IsImmutable()) {
420 mipmap_levels = tex->GetImmutableLevels();
421 } else {
422 mipmap_levels =
423 TextureManager::ComputeMipMapCount(target, width, height, depth);
424 }
420 425
421 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 426 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
422 if (feature_info_->ext_color_buffer_float_available() && 427 if (feature_info_->ext_color_buffer_float_available() &&
423 feature_info_->oes_texture_float_linear_available()) { 428 feature_info_->oes_texture_float_linear_available()) {
424 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, 429 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA,
425 GL_FLOAT, nullptr); 430 GL_FLOAT, nullptr);
426 } else { 431 } else {
427 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, 432 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
428 GL_UNSIGNED_BYTE, nullptr); 433 GL_UNSIGNED_BYTE, nullptr);
429 } 434 }
(...skipping 21 matching lines...) Expand all
451 glDrawArrays(GL_TRIANGLES, 0, 6); 456 glDrawArrays(GL_TRIANGLES, 0, 6);
452 457
453 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 458 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
454 glGenerateMipmapEXT(GL_TEXTURE_2D); 459 glGenerateMipmapEXT(GL_TEXTURE_2D);
455 460
456 // bind tex with rgba format and render with srgb_converter_program_ 461 // bind tex with rgba format and render with srgb_converter_program_
457 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); 462 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_);
458 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 463 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
460 GL_NEAREST_MIPMAP_NEAREST); 465 GL_NEAREST_MIPMAP_NEAREST);
461 width >>= 1; 466
462 height >>= 1; 467 width = (width == 1) ? 1 : width >> 1;
468 height = (height == 1) ? 1 : height >> 1;
463 469
464 // TODO(yizhou): An optimization. Attach 1 level at a time, once for every 470 // TODO(yizhou): An optimization. Attach 1 level at a time, once for every
465 // iteration of the loop. 471 // iteration of the loop.
466 for (GLint level = base_level + 1; level < base_level + mipmap_levels; 472 for (GLint level = base_level + 1; level < base_level + mipmap_levels;
qiankun 2017/04/24 11:37:58 When base_level + mipmap_levels is larger than tex
yizhou.jiang 2017/04/25 04:47:56 Done.
467 ++level) { 473 ++level) {
468 // copy mipmaps level by level from srgb_converter_textures_[1] to tex 474 // copy mipmaps level by level from srgb_converter_textures_[1] to tex
469 // generate mipmap for tex manually 475 // generate mipmap for tex manually
470 glBindTexture(GL_TEXTURE_2D, tex->service_id()); 476 glBindTexture(GL_TEXTURE_2D, tex->service_id());
471 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0, 477 if (!tex->IsImmutable()) {
472 format, type, nullptr); 478 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0,
479 format, type, nullptr);
480 }
473 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 481 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
474 GL_TEXTURE_2D, tex->service_id(), level); 482 GL_TEXTURE_2D, tex->service_id(), level);
475 483
476 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 484 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
477 glViewport(0, 0, width, height); 485 glViewport(0, 0, width, height);
478 glDrawArrays(GL_TRIANGLES, 0, 6); 486 glDrawArrays(GL_TRIANGLES, 0, 6);
479 width >>= 1; 487 width = (width == 1) ? 1 : width >> 1;
480 height >>= 1; 488 height = (height == 1) ? 1 : height >> 1;
481 } 489 }
482 490
483 // Restore state 491 // Restore state
484 decoder->RestoreAllAttributes(); 492 decoder->RestoreAllAttributes();
485 decoder->RestoreTextureUnitBindings(0); 493 decoder->RestoreTextureUnitBindings(0);
486 decoder->RestoreActiveTexture(); 494 decoder->RestoreActiveTexture();
487 decoder->RestoreProgramBindings(); 495 decoder->RestoreProgramBindings();
488 decoder->RestoreBufferBindings(); 496 decoder->RestoreBufferBindings();
489 decoder->RestoreFramebufferBindings(); 497 decoder->RestoreFramebufferBindings();
490 decoder->RestoreGlobalState(); 498 decoder->RestoreGlobalState();
491 decoder->RestoreTextureState(tex->service_id()); 499 decoder->RestoreTextureState(tex->service_id());
492 } 500 }
493 501
494 } // namespace gles2. 502 } // namespace gles2.
495 } // namespace gpu 503 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698