Chromium Code Reviews| 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..1f963ebd92a1a7dd154bded17bd134786a1e37d3 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc |
| @@ -322,5 +322,98 @@ void SRGBConverter::Blit( |
| decoder->RestoreGlobalState(); |
| } |
| +void SRGBConverter::SRGBGenerateMipmap(const gles2::GLES2Decoder* decoder, |
| + Texture* tex, |
| + GLenum target) { |
| + // This function generateMipmap for srgb texture. |
| + // The steps are: |
| + // 1) Copy the base level of the sRGB texture |tex| into a linear (non-sRGB) |
| + // texture |
| + // 2) Perform the glGenerateMipmap call against the linear texture |
| + // 3) Copy each mip level of the linear texture back into the sRGB texture |
| + // |tex| |
| + 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, srgb_converter_textures_[0]); |
|
piman
2016/09/21 23:45:32
nit: remove commented code.
yizhou.jiang
2016/09/22 03:56:51
Done.
|
| + glBindTexture(GL_TEXTURE_2D, tex->service_id()); |
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
piman
2016/09/21 23:45:32
Because we modify the filters of the source textur
yizhou.jiang
2016/09/22 03:56:50
Done.
yizhou.jiang
2016/09/22 03:56:51
Done.
|
| + |
| + 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); |
| + glBindTexture(GL_TEXTURE_2D, tex->service_id()); |
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
piman
2016/09/21 23:45:32
Why is this needed? The following code doesn't sam
yizhou.jiang
2016/09/22 03:56:51
Done.
|
| + |
| + width >>= 1; |
| + height >>= 1; |
| + |
| + for (GLint level = base_level + 1; level < base_level + mipmap_levels; ++level) { |
|
piman
2016/09/21 23:45:32
nit: 80 columns limit. Maybe run 'git cl format'?
yizhou.jiang
2016/09/22 03:56:51
Done.
|
| + // 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(); |
| +} |
| + |
| } // namespace gles2. |
| } // namespace gpu |