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

Unified Diff: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc

Issue 2479513002: Reland of Extend CopyTextureCHROMIUM to more ES 3.0 texture formats. (Closed)
Patch Set: fix windows and mac bot Created 4 years, 1 month 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/tests/gl_copy_texture_CHROMIUM_unittest.cc
diff --git a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
index 44701c96b195fc0fedef0472d198686c8a72464e..a744c2adcd38802ac2985289ba592625d4f4515c 100644
--- a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
+++ b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
@@ -9,13 +9,16 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
+#include <GLES3/gl3.h>
#include <stddef.h>
#include <stdint.h>
+#include "base/command_line.h"
#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gl/gl_switches.h"
namespace gpu {
@@ -25,6 +28,28 @@ const CopyType kCopyTypes[] = {
TexImage,
TexSubImage,
};
+
+static const char* kSimpleVertexShaderES3 =
+ "#version 300 es\n"
+ "in vec2 a_position;\n"
+ "out vec2 v_texCoord;\n"
+ "void main() {\n"
+ " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
+ " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
+ "}\n";
+
+static const char* kIntTextureFragmentShaderES3 =
+ "#version 300 es\n"
+ "precision mediump float;\n"
+ "uniform mediump isampler2D u_texture;\n"
+ "in vec2 v_texCoord;\n"
+ "out vec4 fragData;\n"
+ "void main() {\n"
+ " ivec4 color = texture(u_texture, v_texCoord);\n"
+ " fragData = vec4(float(color[0])/255.0, float(color[1])/255.0,"
+ "float(color[2])/255.0, float(color[3])/255.0);\n"
+ "}\n";
+
}
// A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
@@ -51,7 +76,10 @@ class GLCopyTextureCHROMIUMTest
}
void SetUp() override {
- gl_.Initialize(GLManager::Options());
+ GLManager::Options options;
+ options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
+ options.size = gfx::Size(64, 64);
+ gl_.Initialize(options);
CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
}
@@ -132,6 +160,127 @@ TEST_P(GLCopyTextureCHROMIUMTest, Basic) {
EXPECT_TRUE(GL_NO_ERROR == glGetError());
}
+// Color-renderable to color-renderable
+TEST_P(GLCopyTextureCHROMIUMTest, R8ToR8) {
+ CopyType copy_type = GetParam();
+ uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u};
+
+ glBindTexture(GL_TEXTURE_2D, textures_[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE,
+ pixels);
+
+ if (copy_type == TexImage) {
+ glCopyTextureCHROMIUM(textures_[0], textures_[1], GL_R8,
+ GL_UNSIGNED_BYTE, false, false, false);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, textures_[1]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE,
+ nullptr);
+
+ glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0,
+ 0, 1, 1, false, false, false);
+ }
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+
+ // Check the FB is still bound.
+ GLint value = 0;
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
+ GLuint fb_id = value;
+ EXPECT_EQ(framebuffer_id_, fb_id);
+
+ // Check that FB is complete.
+ EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
+ glCheckFramebufferStatus(GL_FRAMEBUFFER));
+
+ GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
+ EXPECT_TRUE(GL_NO_ERROR == glGetError());
+}
+
+// Color-renderable to non-color-renderable
+TEST_P(GLCopyTextureCHROMIUMTest, RGBA8IToRGB8I) {
+ CopyType copy_type = GetParam();
+ const GLsizei kWidth = 8, kHeight = 8;
+ uint8_t pixels[8 * 8 * 4];
+ for (int i = 0; i < kWidth * kHeight * 4; i += 4) {
+ pixels[i + 0] = 0;
+ pixels[i + 1] = 1;
+ pixels[i + 2] = 2;
+ pixels[i + 3] = 3;
+ }
+
+ glBindTexture(GL_TEXTURE_2D, textures_[0]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, kWidth, kHeight, 0,
+ GL_RGBA_INTEGER, GL_BYTE, pixels);
+
+ if (copy_type == TexImage) {
+ glCopyTextureCHROMIUM(textures_[0], textures_[1], GL_RGB8I,
+ GL_BYTE, false, false, false);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, textures_[1]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, kWidth, kHeight, 0,
+ GL_RGB_INTEGER, GL_BYTE, nullptr);
+
+ glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0,
+ 0, kWidth, kHeight, false, false, false);
+ }
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+
+ // Check the FB is still bound.
+ GLint value = 0;
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value);
+ GLuint fb_id = value;
+ EXPECT_EQ(framebuffer_id_, fb_id);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ GLuint framebuffer = 0;
+ glGenFramebuffers(1, &framebuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
+ GLuint texture = 0;
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
+ glFramebufferTexture2D(
+ GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+
+ glViewport(0, 0, kWidth, kHeight);
+ EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
+ glCheckFramebufferStatus(GL_FRAMEBUFFER));
+
+ GLuint program = GLTestHelper::LoadProgram(
+ kSimpleVertexShaderES3, kIntTextureFragmentShaderES3);
+ EXPECT_NE(program, 0u);
+ GLint position_loc = glGetAttribLocation(program, "a_position");
+ GLint texture_loc = glGetUniformLocation(program, "u_texture");
+ ASSERT_NE(position_loc, -1);
+ ASSERT_NE(texture_loc, -1);
+ glUseProgram(program);
+
+ GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
+ ASSERT_NE(vbo, 0u);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textures_[1]);
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ // Destination texture does not contain alpha channel, sampling returns 1.
+ uint8_t expected_color[4] = {0, 1, 2, 1};
+ uint8_t result_pixels[kHeight][kWidth][4] = {{{1}}};
+ glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, result_pixels);
+ for (int x = 0; x < kWidth; ++x) {
+ for (int y = 0; y < kHeight; ++y) {
+ EXPECT_EQ(expected_color[0], result_pixels[y][x][0]);
+ EXPECT_EQ(expected_color[1], result_pixels[y][x][1]);
+ EXPECT_EQ(expected_color[2], result_pixels[y][x][2]);
+ }
+ }
+ EXPECT_TRUE(GL_NO_ERROR == glGetError());
+}
+
TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test...";
@@ -230,8 +379,8 @@ TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
EXPECT_TRUE(GL_NO_ERROR == glGetError());
// Check unsupported format reports error.
- GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE,
- GL_LUMINANCE_ALPHA};
+ // TODO(qiankun.miao@intel.com): find real unsupported formats.
+ GLint unsupported_dest_formats[] = {GL_RGBA8UI};
for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
dest_index++) {
if (copy_type == TexImage) {
@@ -241,7 +390,7 @@ TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
} else {
glBindTexture(GL_TEXTURE_2D, textures_[1]);
glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1,
- 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE,
+ 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE,
nullptr);
glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0,
0, 0, 1, 1, false, false, false);
@@ -567,6 +716,7 @@ TEST_P(GLCopyTextureCHROMIUMTest, ProgramStatePreservation) {
GLManager gl2;
GLManager::Options options;
+ options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
options.size = gfx::Size(16, 16);
options.share_group_manager = &gl_;
gl2.Initialize(options);

Powered by Google App Engine
This is Rietveld 408576698