OLD | NEW |
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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 GLsizei height; | 353 GLsizei height; |
354 GLsizei depth; | 354 GLsizei depth; |
355 GLenum type = 0; | 355 GLenum type = 0; |
356 GLenum internal_format = 0; | 356 GLenum internal_format = 0; |
357 GLsizei base_level = tex->base_level(); | 357 GLsizei base_level = tex->base_level(); |
358 tex->GetLevelSize(target, base_level, &width, &height, &depth); | 358 tex->GetLevelSize(target, base_level, &width, &height, &depth); |
359 tex->GetLevelType(target, base_level, &type, &internal_format); | 359 tex->GetLevelType(target, base_level, &type, &internal_format); |
360 const GLint mipmap_levels = | 360 const GLint mipmap_levels = |
361 TextureManager::ComputeMipMapCount(target, width, height, depth); | 361 TextureManager::ComputeMipMapCount(target, width, height, depth); |
362 | 362 |
363 // bind srgb_decoder_textures_[1] to draw framebuffer | |
364 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | 363 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, | 364 if (feature_info_->ext_color_buffer_float_available() && |
366 GL_UNSIGNED_BYTE, nullptr); | 365 feature_info_->oes_texture_float_linear_available()) { |
| 366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, |
| 367 GL_UNSIGNED_BYTE, nullptr); |
| 368 } else { |
| 369 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, |
| 370 GL_UNSIGNED_BYTE, nullptr); |
| 371 } |
367 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_); | 372 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_); |
368 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 373 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
369 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); | 374 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); |
370 | 375 |
371 // bind texture with srgb format and render with srgb_converter_program_ | 376 // bind texture with srgb format and render with srgb_converter_program_ |
372 glUseProgram(srgb_converter_program_); | 377 glUseProgram(srgb_converter_program_); |
373 glViewport(0, 0, width, height); | 378 glViewport(0, 0, width, height); |
374 glDisable(GL_SCISSOR_TEST); | 379 glDisable(GL_SCISSOR_TEST); |
375 glDisable(GL_DEPTH_TEST); | 380 glDisable(GL_DEPTH_TEST); |
376 glDisable(GL_STENCIL_TEST); | 381 glDisable(GL_STENCIL_TEST); |
377 glDisable(GL_CULL_FACE); | 382 glDisable(GL_CULL_FACE); |
378 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 383 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
379 glDepthMask(GL_FALSE); | 384 glDepthMask(GL_FALSE); |
380 glDisable(GL_BLEND); | 385 glDisable(GL_BLEND); |
381 glDisable(GL_DITHER); | 386 glDisable(GL_DITHER); |
382 | 387 |
383 glBindVertexArrayOES(srgb_converter_vao_); | 388 glBindVertexArrayOES(srgb_converter_vao_); |
384 glActiveTexture(GL_TEXTURE0); | 389 glActiveTexture(GL_TEXTURE0); |
385 glBindTexture(GL_TEXTURE_2D, tex->service_id()); | 390 glBindTexture(GL_TEXTURE_2D, tex->service_id()); |
386 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
387 | 392 |
388 glDrawArrays(GL_TRIANGLES, 0, 6); | 393 glDrawArrays(GL_TRIANGLES, 0, 6); |
389 | 394 |
390 // generateMipmap for srgb_decoder_textures_[1] | |
391 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | 395 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
392 glGenerateMipmapEXT(GL_TEXTURE_2D); | 396 glGenerateMipmapEXT(GL_TEXTURE_2D); |
393 | 397 |
394 // bind tex with rgba format and render with srgb_converter_program_ | 398 // bind tex with rgba format and render with srgb_converter_program_ |
395 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); | 399 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); |
396 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | 400 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | 401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
398 GL_NEAREST_MIPMAP_NEAREST); | 402 GL_NEAREST_MIPMAP_NEAREST); |
399 width >>= 1; | 403 width >>= 1; |
400 height >>= 1; | 404 height >>= 1; |
(...skipping 23 matching lines...) Expand all Loading... |
424 decoder->RestoreActiveTexture(); | 428 decoder->RestoreActiveTexture(); |
425 decoder->RestoreProgramBindings(); | 429 decoder->RestoreProgramBindings(); |
426 decoder->RestoreBufferBindings(); | 430 decoder->RestoreBufferBindings(); |
427 decoder->RestoreFramebufferBindings(); | 431 decoder->RestoreFramebufferBindings(); |
428 decoder->RestoreGlobalState(); | 432 decoder->RestoreGlobalState(); |
429 decoder->RestoreTextureState(tex->service_id()); | 433 decoder->RestoreTextureState(tex->service_id()); |
430 } | 434 } |
431 | 435 |
432 } // namespace gles2. | 436 } // namespace gles2. |
433 } // namespace gpu | 437 } // namespace gpu |
OLD | NEW |