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

Unified Diff: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc

Issue 2318313004: emulate srgb format for generateMipmap (Closed)
Patch Set: addressed yunchao's feedback:update webgl2_conformance_expectation.py Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
index ffbaf3059e5384432e264139e5a5b321788246b6..5c0f210b25455bf0d86dafcc7b0770c8cb8e71ae 100644
--- a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
+++ b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
@@ -322,5 +322,89 @@ void SRGBConverter::Blit(
decoder->RestoreGlobalState();
}
+void SRGBConverter::SRGBGenerateMipmap(const gles2::GLES2Decoder* decoder,
+ Texture* tex,
+ GLenum target) {
Ken Russell (switch to Gerrit) 2016/09/21 01:00:14 Could you add some high-level comments for this fu
yizhou.jiang 2016/09/23 04:32:06 hi kbr, I'm not quite sure if I understand correct
+ DCHECK(srgb_converter_initialized_);
+
+ GLsizei width;
+ GLsizei height;
+ GLsizei depth;
+ GLenum type = 0;
+ GLenum internal_format = 0;
+ GLsizei base_level = tex->base_level();
+ tex->GetLevelSize(target, base_level, &width, &height, &depth);
+ tex->GetLevelType(target, 0, &type, &internal_format);
piman 2016/09/20 21:53:30 Should this be base_level instead of 0?
yizhou.jiang 2016/09/21 08:59:22 Done.
+ const GLint mipmap_level =
piman 2016/09/20 21:53:30 nit: maybe mipmap_levels, since it's a count, not
yizhou.jiang 2016/09/21 08:59:22 Done.
+ TextureManager::ComputeMipMapCount(target, width, height, depth);
+
+ // copy tex to srgb_decoder_textures_[0] with srgb format
+ glBindTexture(target, tex->service_id());
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER, srgb_decoder_fbo_);
+ glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex->service_id(), 0);
piman 2016/09/20 21:53:30 Should this be base_level instead of 0?
yizhou.jiang 2016/09/21 08:59:22 Done.
+
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]);
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, internal_format, 0, 0, width, height, 0);
piman 2016/09/20 21:53:30 Do we need to make that extra copy, could we use t
yizhou.jiang 2016/09/21 08:59:22 I removed copy tex to srgb_decoder_textures_[0]
+
+ // bind srgb_decoder_textures_[1] to draw framebuffer
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, nullptr);
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_);
+ glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, srgb_converter_textures_[1], 0);
+
+ // bind texture with srgb format and render with srgb_converter_program_
+ glUseProgram(srgb_converter_program_);
+ glViewport(0, 0, width, height);
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_STENCIL_TEST);
+ glDisable(GL_CULL_FACE);
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glDepthMask(GL_FALSE);
+ glDisable(GL_BLEND);
+ glDisable(GL_DITHER);
+
+ glBindVertexArrayOES(srgb_converter_vao_);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ // generateMipmap for tex and srgb_decoder_textures_[1]
+ glBindTexture(GL_TEXTURE_2D, tex->service_id());
+ glGenerateMipmapEXT(GL_TEXTURE_2D);
piman 2016/09/20 21:53:30 Why this one, is it to generate the image levels o
yizhou.jiang 2016/09/21 08:59:22 Done.
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
+ glGenerateMipmapEXT(GL_TEXTURE_2D);
+
+ // bind tex with rgba format and render with srgb_converter_program_
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_);
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST_MIPMAP_NEAREST);
+ width >>= 1;
+ height >>= 1;
+
+ for (GLint level = base_level + 1; level < mipmap_level; ++level) {
piman 2016/09/20 21:53:30 mipmap_level is computed as the number of levels i
yizhou.jiang 2016/09/21 08:59:22 Done.
+ glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex->service_id(), level);
+
+ glViewport(0, 0, width, height);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
Ken Russell (switch to Gerrit) 2016/09/21 01:00:14 What's the intent of this loop? Is it intended to
yizhou.jiang 2016/09/21 08:59:22 Yes. I try to sampling converter_textures_[1] to c
+ width >>= 1;
+ height >>= 1;
+ }
+
+ // Restore state
+ decoder->RestoreAllAttributes();
+ decoder->RestoreTextureUnitBindings(0);
+ decoder->RestoreActiveTexture();
+ decoder->RestoreProgramBindings();
+ decoder->RestoreBufferBindings();
+ decoder->RestoreFramebufferBindings();
+ decoder->RestoreGlobalState();
+}
+
} // namespace gles2.
} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698