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

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

Issue 2318313004: emulate srgb format for generateMipmap (Closed)
Patch Set: rebase code Created 4 years, 2 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
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // Restore state 324 // Restore state
325 decoder->RestoreAllAttributes(); 325 decoder->RestoreAllAttributes();
326 decoder->RestoreTextureUnitBindings(0); 326 decoder->RestoreTextureUnitBindings(0);
327 decoder->RestoreActiveTexture(); 327 decoder->RestoreActiveTexture();
328 decoder->RestoreProgramBindings(); 328 decoder->RestoreProgramBindings();
329 decoder->RestoreBufferBindings(); 329 decoder->RestoreBufferBindings();
330 decoder->RestoreFramebufferBindings(); 330 decoder->RestoreFramebufferBindings();
331 decoder->RestoreGlobalState(); 331 decoder->RestoreGlobalState();
332 } 332 }
333 333
334 void SRGBConverter::GenerateMipmap(const gles2::GLES2Decoder* decoder,
335 Texture* tex,
336 GLenum target) {
337 // This function generateMipmap for srgb texture.
338 // The steps are:
339 // 1) Do sampling from the base level of the sRGB texture and draw into
340 // a linear texture. During sampling, the sRGB format is converted to
341 // Linear format
342 // 2) Perform the glGenerateMipmap call against the linear texture
343 // 3) Iterate each mipmap level of the linear texture and draw back into
344 // the sRGB texture's corresponding mipmap. During drawing, the linear
345 // format is converted to sRGB format
346 DCHECK(srgb_converter_initialized_);
347
348 GLsizei width;
349 GLsizei height;
350 GLsizei depth;
351 GLenum type = 0;
352 GLenum internal_format = 0;
353 GLsizei base_level = tex->base_level();
354 tex->GetLevelSize(target, base_level, &width, &height, &depth);
355 tex->GetLevelType(target, base_level, &type, &internal_format);
356 const GLint mipmap_levels =
357 TextureManager::ComputeMipMapCount(target, width, height, depth);
358
359 // bind srgb_decoder_textures_[1] to draw framebuffer
360 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
361 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
362 GL_UNSIGNED_BYTE, nullptr);
363 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_);
364 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
365 GL_TEXTURE_2D, srgb_converter_textures_[1], 0);
366
367 // bind texture with srgb format and render with srgb_converter_program_
368 glUseProgram(srgb_converter_program_);
369 glViewport(0, 0, width, height);
370 glDisable(GL_SCISSOR_TEST);
371 glDisable(GL_DEPTH_TEST);
372 glDisable(GL_STENCIL_TEST);
373 glDisable(GL_CULL_FACE);
374 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
375 glDepthMask(GL_FALSE);
376 glDisable(GL_BLEND);
377 glDisable(GL_DITHER);
378
379 glBindVertexArrayOES(srgb_converter_vao_);
380 glActiveTexture(GL_TEXTURE0);
381 glBindTexture(GL_TEXTURE_2D, tex->service_id());
382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
383
384 glDrawArrays(GL_TRIANGLES, 0, 6);
385
386 // generateMipmap for srgb_decoder_textures_[1]
387 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
388 glGenerateMipmapEXT(GL_TEXTURE_2D);
389
390 // bind tex with rgba format and render with srgb_converter_program_
391 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_);
392 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
394 GL_NEAREST_MIPMAP_NEAREST);
395 width >>= 1;
396 height >>= 1;
397
398 // TODO(yizhou): An optimization. Attach 1 level at a time, once for every
399 // iteration of the loop.
400 for (GLint level = base_level + 1; level < base_level + mipmap_levels;
401 ++level) {
402 // copy mipmaps level by level from srgb_converter_textures_[1] to tex
403 // generate mipmap for tex manually
404 glBindTexture(GL_TEXTURE_2D, tex->service_id());
405 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0,
406 GL_SRGB, type, NULL);
407 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
408 GL_TEXTURE_2D, tex->service_id(), level);
409
410 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
411 glViewport(0, 0, width, height);
412 glDrawArrays(GL_TRIANGLES, 0, 6);
413 width >>= 1;
414 height >>= 1;
415 }
416
417 // Restore state
418 decoder->RestoreAllAttributes();
419 decoder->RestoreTextureUnitBindings(0);
420 decoder->RestoreActiveTexture();
421 decoder->RestoreProgramBindings();
422 decoder->RestoreBufferBindings();
423 decoder->RestoreFramebufferBindings();
424 decoder->RestoreGlobalState();
425 decoder->RestoreTextureState(tex->service_id());
426 }
427
334 } // namespace gles2. 428 } // namespace gles2.
335 } // namespace gpu 429 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_srgb_converter.h ('k') | gpu/config/gpu_driver_bug_list_json.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698