| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 GLManager gl_; | 25 GLManager gl_; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 // Test that GL is at least minimally working. | 28 // Test that GL is at least minimally working. |
| 29 TEST_F(GLTest, Basic) { | 29 TEST_F(GLTest, Basic) { |
| 30 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | 30 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 31 glClear(GL_COLOR_BUFFER_BIT); | 31 glClear(GL_COLOR_BUFFER_BIT); |
| 32 uint8_t expected[] = { | 32 uint8_t expected[] = { |
| 33 0, 255, 0, 255, | 33 0, 255, 0, 255, |
| 34 }; | 34 }; |
| 35 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); | 35 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected, nullptr)); |
| 36 GLTestHelper::CheckGLError("no errors", __LINE__); | 36 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST_F(GLTest, BasicFBO) { | 39 TEST_F(GLTest, BasicFBO) { |
| 40 GLuint tex = 0; | 40 GLuint tex = 0; |
| 41 glGenTextures(1, &tex); | 41 glGenTextures(1, &tex); |
| 42 GLuint fbo = 0; | 42 GLuint fbo = 0; |
| 43 glGenFramebuffers(1, &fbo); | 43 glGenFramebuffers(1, &fbo); |
| 44 glBindTexture(GL_TEXTURE_2D, tex); | 44 glBindTexture(GL_TEXTURE_2D, tex); |
| 45 std::unique_ptr<uint8_t[]> pixels(new uint8_t[16 * 16 * 4]); | 45 std::unique_ptr<uint8_t[]> pixels(new uint8_t[16 * 16 * 4]); |
| 46 memset(pixels.get(), 0, 16*16*4); | 46 memset(pixels.get(), 0, 16*16*4); |
| 47 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 47 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 48 pixels.get()); | 48 pixels.get()); |
| 49 glGenerateMipmap(GL_TEXTURE_2D); | 49 glGenerateMipmap(GL_TEXTURE_2D); |
| 50 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 50 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 51 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 51 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 54 glBindFramebuffer(GL_FRAMEBUFFER, fbo); | 54 glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 55 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 55 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 56 tex, 0); | 56 tex, 0); |
| 57 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 57 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 58 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 58 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 59 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | 59 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 60 glClear(GL_COLOR_BUFFER_BIT); | 60 glClear(GL_COLOR_BUFFER_BIT); |
| 61 uint8_t expected[] = { | 61 uint8_t expected[] = { |
| 62 0, 255, 0, 255, | 62 0, 255, 0, 255, |
| 63 }; | 63 }; |
| 64 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 16, 16, 0, expected)); | 64 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 16, 16, 0, expected, nullptr)); |
| 65 glDeleteFramebuffers(1, &fbo); | 65 glDeleteFramebuffers(1, &fbo); |
| 66 glDeleteTextures(1, &tex); | 66 glDeleteTextures(1, &tex); |
| 67 GLTestHelper::CheckGLError("no errors", __LINE__); | 67 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(GLTest, SimpleShader) { | 70 TEST_F(GLTest, SimpleShader) { |
| 71 static const char* v_shader_str = | 71 static const char* v_shader_str = |
| 72 "attribute vec4 a_Position;\n" | 72 "attribute vec4 a_Position;\n" |
| 73 "void main()\n" | 73 "void main()\n" |
| 74 "{\n" | 74 "{\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 glUseProgram(program); | 85 glUseProgram(program); |
| 86 GLuint position_loc = glGetAttribLocation(program, "a_Position"); | 86 GLuint position_loc = glGetAttribLocation(program, "a_Position"); |
| 87 | 87 |
| 88 GLTestHelper::SetupUnitQuad(position_loc); | 88 GLTestHelper::SetupUnitQuad(position_loc); |
| 89 | 89 |
| 90 uint8_t expected_clear[] = { | 90 uint8_t expected_clear[] = { |
| 91 127, 0, 255, 0, | 91 127, 0, 255, 0, |
| 92 }; | 92 }; |
| 93 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); | 93 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); |
| 94 glClear(GL_COLOR_BUFFER_BIT); | 94 glClear(GL_COLOR_BUFFER_BIT); |
| 95 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear)); | 95 EXPECT_TRUE( |
| 96 GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear, nullptr)); |
| 96 uint8_t expected_draw[] = { | 97 uint8_t expected_draw[] = { |
| 97 0, 255, 0, 255, | 98 0, 255, 0, 255, |
| 98 }; | 99 }; |
| 99 glDrawArrays(GL_TRIANGLES, 0, 6); | 100 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 100 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw)); | 101 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw, nullptr)); |
| 101 } | 102 } |
| 102 | 103 |
| 103 TEST_F(GLTest, FeatureFlagsMatchCapabilities) { | 104 TEST_F(GLTest, FeatureFlagsMatchCapabilities) { |
| 104 scoped_refptr<gles2::FeatureInfo> features = | 105 scoped_refptr<gles2::FeatureInfo> features = |
| 105 new gles2::FeatureInfo(gl_.workarounds()); | 106 new gles2::FeatureInfo(gl_.workarounds()); |
| 106 EXPECT_TRUE(features->InitializeForTesting()); | 107 EXPECT_TRUE(features->InitializeForTesting()); |
| 107 const auto& caps = gl_.GetCapabilities(); | 108 const auto& caps = gl_.GetCapabilities(); |
| 108 const auto& flags = features->feature_flags(); | 109 const auto& flags = features->feature_flags(); |
| 109 EXPECT_EQ(caps.egl_image_external, flags.oes_egl_image_external); | 110 EXPECT_EQ(caps.egl_image_external, flags.oes_egl_image_external); |
| 110 EXPECT_EQ(caps.texture_format_bgra8888, flags.ext_texture_format_bgra8888); | 111 EXPECT_EQ(caps.texture_format_bgra8888, flags.ext_texture_format_bgra8888); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 135 EXPECT_STREQ( | 136 EXPECT_STREQ( |
| 136 "Chromium", | 137 "Chromium", |
| 137 reinterpret_cast<const char*>(glGetString(GL_RENDERER))); | 138 reinterpret_cast<const char*>(glGetString(GL_RENDERER))); |
| 138 EXPECT_STREQ( | 139 EXPECT_STREQ( |
| 139 "Chromium", | 140 "Chromium", |
| 140 reinterpret_cast<const char*>(glGetString(GL_VENDOR))); | 141 reinterpret_cast<const char*>(glGetString(GL_VENDOR))); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace gpu | 144 } // namespace gpu |
| 144 | 145 |
| OLD | NEW |