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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // Restore state | 315 // Restore state |
316 decoder->RestoreAllAttributes(); | 316 decoder->RestoreAllAttributes(); |
317 decoder->RestoreTextureUnitBindings(0); | 317 decoder->RestoreTextureUnitBindings(0); |
318 decoder->RestoreActiveTexture(); | 318 decoder->RestoreActiveTexture(); |
319 decoder->RestoreProgramBindings(); | 319 decoder->RestoreProgramBindings(); |
320 decoder->RestoreBufferBindings(); | 320 decoder->RestoreBufferBindings(); |
321 decoder->RestoreFramebufferBindings(); | 321 decoder->RestoreFramebufferBindings(); |
322 decoder->RestoreGlobalState(); | 322 decoder->RestoreGlobalState(); |
323 } | 323 } |
324 | 324 |
| 325 void SRGBConverter::SRGBGenerateMipmap(const gles2::GLES2Decoder* decoder, |
| 326 Texture* tex, |
| 327 GLenum target) { |
| 328 DCHECK(srgb_converter_initialized_); |
| 329 |
| 330 GLsizei width; |
| 331 GLsizei height; |
| 332 GLsizei depth; |
| 333 GLenum type = 0; |
| 334 GLenum internal_format = 0; |
| 335 GLsizei base_level = tex->base_level(); |
| 336 tex->GetLevelSize(target, base_level, &width, &height, &depth); |
| 337 tex->GetLevelType(target, 0, &type, &internal_format); |
| 338 const GLint mipmap_level = |
| 339 TextureManager::ComputeMipMapCount(target, width, height, depth); |
| 340 |
| 341 // copy tex to srgb_decoder_textures_[0] with srgb format |
| 342 glBindTexture(target, tex->service_id()); |
| 343 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, srgb_decoder_fbo_); |
| 344 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 345 GL_TEXTURE_2D, tex->service_id(), 0); |
| 346 |
| 347 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); |
| 348 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, GL_SRGB, |
| 349 GL_UNSIGNED_BYTE, nullptr); |
| 350 glCopyTexImage2D(GL_TEXTURE_2D, 0, internal_format, 0, 0, width, height, 0); |
| 351 |
| 352 // bind srgb_decoder_textures_[1] to draw framebuffer |
| 353 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
| 354 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, |
| 355 GL_UNSIGNED_BYTE, nullptr); |
| 356 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_); |
| 357 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 358 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); |
| 359 |
| 360 // bind texture with srgb format and render with srgb_converter_program_ |
| 361 glUseProgram(srgb_converter_program_); |
| 362 glViewport(0, 0, width, height); |
| 363 glDisable(GL_SCISSOR_TEST); |
| 364 glDisable(GL_DEPTH_TEST); |
| 365 glDisable(GL_STENCIL_TEST); |
| 366 glDisable(GL_CULL_FACE); |
| 367 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 368 glDepthMask(GL_FALSE); |
| 369 glDisable(GL_BLEND); |
| 370 glDisable(GL_DITHER); |
| 371 |
| 372 glBindVertexArrayOES(srgb_converter_vao_); |
| 373 glActiveTexture(GL_TEXTURE0); |
| 374 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); |
| 375 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 376 |
| 377 // generateMipmap for tex and srgb_decoder_textures_[1] |
| 378 glBindTexture(GL_TEXTURE_2D, tex->service_id()); |
| 379 glGenerateMipmapEXT(GL_TEXTURE_2D); |
| 380 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
| 381 glGenerateMipmapEXT(GL_TEXTURE_2D); |
| 382 |
| 383 // bind tex with rgba format and render with srgb_converter_program_ |
| 384 glUseProgram(srgb_converter_program_); |
| 385 glBindVertexArrayOES(srgb_converter_vao_); |
| 386 |
| 387 for (GLint level = base_level; level < mipmap_level; level++) { |
| 388 glBindTexture(GL_TEXTURE_2D, tex->service_id()); |
| 389 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); |
| 390 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 391 GL_TEXTURE_2D, tex->service_id(), level); |
| 392 |
| 393 glActiveTexture(GL_TEXTURE0); |
| 394 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
| 395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level); |
| 396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 397 GL_NEAREST_MIPMAP_NEAREST); |
| 398 |
| 399 glViewport(0, 0, width, height); |
| 400 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 401 width /= 2; |
| 402 height /= 2; |
| 403 } |
| 404 |
| 405 // Restore state |
| 406 decoder->RestoreAllAttributes(); |
| 407 decoder->RestoreTextureUnitBindings(0); |
| 408 decoder->RestoreActiveTexture(); |
| 409 decoder->RestoreProgramBindings(); |
| 410 decoder->RestoreBufferBindings(); |
| 411 decoder->RestoreFramebufferBindings(); |
| 412 decoder->RestoreGlobalState(); |
| 413 } |
| 414 |
325 } // namespace gles2. | 415 } // namespace gles2. |
326 } // namespace gpu | 416 } // namespace gpu |
OLD | NEW |