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

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

Issue 2318313004: emulate srgb format for generateMipmap (Closed)
Patch Set: addressed piman's feedback 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // This function generateMipmap for srgb texture.
329 // The steps are:
330 // 1) Copy the base level of the sRGB texture |tex| into a linear (non-sRGB)
yunchao 2016/09/23 15:09:20 There is no copy anymore. Maybe "Do sampling from
yizhou.jiang 2016/09/26 00:56:33 Done.
331 // texture
332 // 2) Perform the glGenerateMipmap call against the linear texture
333 // 3) Copy each mip level of the linear texture back into the sRGB texture
yunchao 2016/09/23 15:09:20 No copy too. Maybe "Iterate each mipmap level of t
yizhou.jiang 2016/09/26 00:56:33 Done.
334 // |tex|
335 DCHECK(srgb_converter_initialized_);
336
337 GLsizei width;
338 GLsizei height;
339 GLsizei depth;
340 GLenum type = 0;
341 GLenum internal_format = 0;
342 GLsizei base_level = tex->base_level();
343 tex->GetLevelSize(target, base_level, &width, &height, &depth);
344 tex->GetLevelType(target, base_level, &type, &internal_format);
345 const GLint mipmap_levels =
346 TextureManager::ComputeMipMapCount(target, width, height, depth);
347
348 // bind srgb_decoder_textures_[1] to draw framebuffer
349 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
350 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
351 GL_UNSIGNED_BYTE, nullptr);
352 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_);
353 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
354 GL_TEXTURE_2D, srgb_converter_textures_[1], 0);
355
356 // bind texture with srgb format and render with srgb_converter_program_
357 glUseProgram(srgb_converter_program_);
358 glViewport(0, 0, width, height);
359 glDisable(GL_SCISSOR_TEST);
360 glDisable(GL_DEPTH_TEST);
361 glDisable(GL_STENCIL_TEST);
362 glDisable(GL_CULL_FACE);
363 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
364 glDepthMask(GL_FALSE);
365 glDisable(GL_BLEND);
366 glDisable(GL_DITHER);
367
368 glBindVertexArrayOES(srgb_converter_vao_);
369 glActiveTexture(GL_TEXTURE0);
370 glBindTexture(GL_TEXTURE_2D, tex->service_id());
371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
372
373 glDrawArrays(GL_TRIANGLES, 0, 6);
374
375 // generateMipmap for srgb_decoder_textures_[1]
376 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
377 glGenerateMipmapEXT(GL_TEXTURE_2D);
378
379 // bind tex with rgba format and render with srgb_converter_program_
380 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_);
381 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
383 GL_NEAREST_MIPMAP_NEAREST);
384 width >>= 1;
385 height >>= 1;
386
387 for (GLint level = base_level + 1; level < base_level + mipmap_levels;
388 ++level) {
389 // copy mipmaps level by level from srgb_converter_textures_[1] to tex
390 // generate mipmap for tex manually
391 glBindTexture(GL_TEXTURE_2D, tex->service_id());
392 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0,
393 GL_SRGB, type, NULL);
394 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
395 GL_TEXTURE_2D, tex->service_id(), level);
396
397 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
398 glViewport(0, 0, width, height);
399 glDrawArrays(GL_TRIANGLES, 0, 6);
400 width >>= 1;
401 height >>= 1;
402 }
403
404 // Restore state
405 decoder->RestoreAllAttributes();
406 decoder->RestoreTextureUnitBindings(0);
407 decoder->RestoreActiveTexture();
408 decoder->RestoreProgramBindings();
409 decoder->RestoreBufferBindings();
410 decoder->RestoreFramebufferBindings();
411 decoder->RestoreGlobalState();
412 decoder->RestoreTextureState(tex->service_id());
413 }
414
325 } // namespace gles2. 415 } // namespace gles2.
326 } // namespace gpu 416 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698