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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 949d2d081341379edc51159ca976cbb7df4dc3d4..5ffbb47de31545874f7b9c2a2b5ac981c4a40b7d 100644
--- a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
+++ b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
@@ -331,5 +331,99 @@ void SRGBConverter::Blit(
decoder->RestoreGlobalState();
}
+void SRGBConverter::GenerateMipmap(const gles2::GLES2Decoder* decoder,
+ Texture* tex,
+ GLenum target) {
+ // This function generateMipmap for srgb texture.
+ // The steps are:
+ // 1) Do sampling from the base level of the sRGB texture and draw into
+ // a linear texture. During sampling, the sRGB format is converted to
+ // Linear format
+ // 2) Perform the glGenerateMipmap call against the linear texture
+ // 3) Iterate each mipmap level of the linear texture and draw back into
+ // the sRGB texture's corresponding mipmap. During drawing, the linear
+ // format is converted to sRGB format
+ 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, base_level, &type, &internal_format);
+ const GLint mipmap_levels =
+ TextureManager::ComputeMipMapCount(target, width, height, depth);
+
+ // 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, tex->service_id());
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ // generateMipmap for srgb_decoder_textures_[1]
+ 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;
+
+ // TODO(yizhou): An optimization. Attach 1 level at a time, once for every
+ // iteration of the loop.
+ for (GLint level = base_level + 1; level < base_level + mipmap_levels;
+ ++level) {
+ // copy mipmaps level by level from srgb_converter_textures_[1] to tex
+ // generate mipmap for tex manually
+ glBindTexture(GL_TEXTURE_2D, tex->service_id());
+ glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0,
+ GL_SRGB, type, NULL);
+ glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex->service_id(), level);
+
+ glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
+ glViewport(0, 0, width, height);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ width >>= 1;
+ height >>= 1;
+ }
+
+ // Restore state
+ decoder->RestoreAllAttributes();
+ decoder->RestoreTextureUnitBindings(0);
+ decoder->RestoreActiveTexture();
+ decoder->RestoreProgramBindings();
+ decoder->RestoreBufferBindings();
+ decoder->RestoreFramebufferBindings();
+ decoder->RestoreGlobalState();
+ decoder->RestoreTextureState(tex->service_id());
+}
+
} // namespace gles2.
} // namespace gpu
« 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