Commit 0c614148 authored by junov's avatar junov Committed by Commit bot

Fix gpu mipmap support on ChromeOS

Fix gl version info check used to control texture internal
format substitutions so that it does the right thing on
ChromeOS.  Without this substitution we'd hit a Mesa bug
that prevents mipmapping from working when the internal
format is GL_BGRA

BUG=540761
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2164723003
Cr-Commit-Position: refs/heads/master@{#406924}
parent 7c430bb6
...@@ -152,6 +152,7 @@ test("gl_tests") { ...@@ -152,6 +152,7 @@ test("gl_tests") {
sources = [ sources = [
"command_buffer/tests/compressed_texture_test.cc", "command_buffer/tests/compressed_texture_test.cc",
"command_buffer/tests/es3_misc_functions_unittest.cc", "command_buffer/tests/es3_misc_functions_unittest.cc",
"command_buffer/tests/gl_bgra_mipmap_unittest.cc",
"command_buffer/tests/gl_bind_uniform_location_unittest.cc", "command_buffer/tests/gl_bind_uniform_location_unittest.cc",
"command_buffer/tests/gl_chromium_framebuffer_mixed_samples_unittest.cc", "command_buffer/tests/gl_chromium_framebuffer_mixed_samples_unittest.cc",
"command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc", "command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc",
......
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdint.h>
#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gpu {
// A collection of tests that exercise the GL_EXT_srgb extension.
class GLBGRAMipMapTest : public testing::Test {
protected:
void SetUp() override { gl_.Initialize(GLManager::Options()); }
void TearDown() override { gl_.Destroy(); }
GLManager gl_;
};
// Test to ensure that using GL_BGRA as a texture internal format does
// not hinder the use of mipmaps. Support for GL_BGRA as an internal format
// is required by ES 2.0 (internal format must be equal to external format),
// but some desktop GL implementations may not fully support the use of
// GL_BGRA. For example, Mesa+Intel does not support mipmapping on textures
// that use the GL_BGRA internal format. This test verifies a workaround.
TEST_F(GLBGRAMipMapTest, GenerateMipmapsSucceeds) {
static const int kWidth = 100;
static const int kHeight = 50;
uint8_t pixels[kWidth * kHeight * 4];
GLuint tex = 0;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
memset(pixels, 128, sizeof(pixels));
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, kWidth, kHeight, 0,
GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
// Without the workaround, the following call generates a
// GL_INVALID_OPERATION error on some desktop GL implementations
glGenerateMipmap(GL_TEXTURE_2D);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
} // namespace gpu
...@@ -430,6 +430,7 @@ ...@@ -430,6 +430,7 @@
# Note: sources list duplicated in GN build. # Note: sources list duplicated in GN build.
'command_buffer/tests/compressed_texture_test.cc', 'command_buffer/tests/compressed_texture_test.cc',
'command_buffer/tests/es3_misc_functions_unittest.cc', 'command_buffer/tests/es3_misc_functions_unittest.cc',
'command_buffer/tests/gl_bgra_mipmap_unittest.cc',
'command_buffer/tests/gl_bind_uniform_location_unittest.cc', 'command_buffer/tests/gl_bind_uniform_location_unittest.cc',
'command_buffer/tests/gl_chromium_framebuffer_mixed_samples_unittest.cc', 'command_buffer/tests/gl_chromium_framebuffer_mixed_samples_unittest.cc',
'command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc', 'command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc',
......
...@@ -36,10 +36,15 @@ static GLVersionInfo* g_version_info = NULL; ...@@ -36,10 +36,15 @@ static GLVersionInfo* g_version_info = NULL;
namespace { namespace {
static inline GLenum GetInternalFormat(GLenum internal_format) { static inline GLenum GetInternalFormat(GLenum internal_format) {
if (GetGLImplementation() != kGLImplementationEGLGLES2) { if (!g_version_info->is_es) {
if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT)
return GL_RGBA8; return GL_RGBA8;
} }
if (g_version_info->is_es3 && g_version_info->is_mesa) {
// Mesa bug workaround: Mipmapping does not work when using GL_BGRA_EXT
if (internal_format == GL_BGRA_EXT)
return GL_RGBA;
}
return internal_format; return internal_format;
} }
...@@ -47,10 +52,10 @@ static inline GLenum GetInternalFormat(GLenum internal_format) { ...@@ -47,10 +52,10 @@ static inline GLenum GetInternalFormat(GLenum internal_format) {
static inline GLenum GetTexInternalFormat(GLenum internal_format, static inline GLenum GetTexInternalFormat(GLenum internal_format,
GLenum format, GLenum format,
GLenum type) { GLenum type) {
DCHECK(g_version_info);
GLenum gl_internal_format = GetInternalFormat(internal_format); GLenum gl_internal_format = GetInternalFormat(internal_format);
// g_version_info must be initialized when this function is bound. // g_version_info must be initialized when this function is bound.
DCHECK(g_version_info);
if (g_version_info->is_es3) { if (g_version_info->is_es3) {
if (internal_format == GL_RED_EXT) { if (internal_format == GL_RED_EXT) {
// GL_EXT_texture_rg case in ES2. // GL_EXT_texture_rg case in ES2.
......
...@@ -45,6 +45,7 @@ GLVersionInfo::GLVersionInfo(const char* version_str, ...@@ -45,6 +45,7 @@ GLVersionInfo::GLVersionInfo(const char* version_str,
GLVersionInfo::GLVersionInfo() GLVersionInfo::GLVersionInfo()
: is_es(false), : is_es(false),
is_angle(false), is_angle(false),
is_mesa(false),
major_version(0), major_version(0),
minor_version(0), minor_version(0),
is_es2(false), is_es2(false),
...@@ -62,6 +63,8 @@ void GLVersionInfo::Initialize(const char* version_str, ...@@ -62,6 +63,8 @@ void GLVersionInfo::Initialize(const char* version_str,
if (renderer_str) { if (renderer_str) {
is_angle = base::StartsWith(renderer_str, "ANGLE", is_angle = base::StartsWith(renderer_str, "ANGLE",
base::CompareCase::SENSITIVE); base::CompareCase::SENSITIVE);
is_mesa = base::StartsWith(renderer_str, "Mesa",
base::CompareCase::SENSITIVE);
} }
is_desktop_core_profile = is_desktop_core_profile =
DesktopCoreCommonCheck(is_es, major_version, minor_version) && DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
......
...@@ -48,6 +48,7 @@ struct GL_EXPORT GLVersionInfo { ...@@ -48,6 +48,7 @@ struct GL_EXPORT GLVersionInfo {
bool is_es; bool is_es;
bool is_angle; bool is_angle;
bool is_mesa;
unsigned major_version; unsigned major_version;
unsigned minor_version; unsigned minor_version;
bool is_es2; bool is_es2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment