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
3 // found in the LICENSE file.
6 #include <GLES2/gl2ext.h>
8 #include "gpu/command_buffer/service/feature_info.h"
9 #include "gpu/command_buffer/tests/gl_manager.h"
10 #include "gpu/command_buffer/tests/gl_test_utils.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 class GLTest
: public testing::Test
{
18 void SetUp() override
{ gl_
.Initialize(GLManager::Options()); }
20 void TearDown() override
{ gl_
.Destroy(); }
25 // Test that GL is at least minimally working.
26 TEST_F(GLTest
, Basic
) {
27 glClearColor(0.0f
, 1.0f
, 0.0f
, 1.0f
);
28 glClear(GL_COLOR_BUFFER_BIT
);
29 uint8 expected
[] = { 0, 255, 0, 255, };
30 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected
));
31 GLTestHelper::CheckGLError("no errors", __LINE__
);
34 TEST_F(GLTest
, BasicFBO
) {
36 glGenTextures(1, &tex
);
38 glGenFramebuffers(1, &fbo
);
39 glBindTexture(GL_TEXTURE_2D
, tex
);
40 scoped_ptr
<uint8
[]> pixels(new uint8
[16*16*4]);
41 memset(pixels
.get(), 0, 16*16*4);
42 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 16, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
44 glGenerateMipmap(GL_TEXTURE_2D
);
45 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
46 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
47 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
48 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
49 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
50 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
52 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_COMPLETE
),
53 glCheckFramebufferStatus(GL_FRAMEBUFFER
));
54 glClearColor(0.0f
, 1.0f
, 0.0f
, 1.0f
);
55 glClear(GL_COLOR_BUFFER_BIT
);
56 uint8 expected
[] = { 0, 255, 0, 255, };
57 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 16, 16, 0, expected
));
58 glDeleteFramebuffers(1, &fbo
);
59 glDeleteTextures(1, &tex
);
60 GLTestHelper::CheckGLError("no errors", __LINE__
);
63 TEST_F(GLTest
, SimpleShader
) {
64 static const char* v_shader_str
=
65 "attribute vec4 a_Position;\n"
68 " gl_Position = a_Position;\n"
70 static const char* f_shader_str
=
71 "precision mediump float;\n"
74 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
77 GLuint program
= GLTestHelper::LoadProgram(v_shader_str
, f_shader_str
);
78 glUseProgram(program
);
79 GLuint position_loc
= glGetAttribLocation(program
, "a_Position");
81 GLTestHelper::SetupUnitQuad(position_loc
);
83 uint8 expected_clear
[] = { 127, 0, 255, 0, };
84 glClearColor(0.5f
, 0.0f
, 1.0f
, 0.0f
);
85 glClear(GL_COLOR_BUFFER_BIT
);
86 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear
));
87 uint8 expected_draw
[] = { 0, 255, 0, 255, };
88 glDrawArrays(GL_TRIANGLES
, 0, 6);
89 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw
));
92 TEST_F(GLTest
, FeatureFlagsMatchCapabilities
) {
93 scoped_refptr
<gles2::FeatureInfo
> features
= new gles2::FeatureInfo
;
94 EXPECT_TRUE(features
->Initialize());
95 const auto& caps
= gl_
.GetCapabilities();
96 const auto& flags
= features
->feature_flags();
97 EXPECT_EQ(caps
.egl_image_external
, flags
.oes_egl_image_external
);
98 EXPECT_EQ(caps
.texture_format_bgra8888
, flags
.ext_texture_format_bgra8888
);
99 EXPECT_EQ(caps
.texture_format_etc1
, flags
.oes_compressed_etc1_rgb8_texture
);
100 EXPECT_EQ(caps
.texture_rectangle
, flags
.arb_texture_rectangle
);
101 EXPECT_EQ(caps
.texture_usage
, flags
.angle_texture_usage
);
102 EXPECT_EQ(caps
.texture_storage
, flags
.ext_texture_storage
);
103 EXPECT_EQ(caps
.discard_framebuffer
, flags
.ext_discard_framebuffer
);
104 EXPECT_EQ(caps
.sync_query
, flags
.chromium_sync_query
);
105 EXPECT_EQ(caps
.blend_equation_advanced
, flags
.blend_equation_advanced
);
106 EXPECT_EQ(caps
.blend_equation_advanced_coherent
,
107 flags
.blend_equation_advanced_coherent
);
108 EXPECT_EQ(caps
.texture_rg
, flags
.ext_texture_rg
);
109 EXPECT_EQ(caps
.render_buffer_format_bgra8888
,
110 flags
.ext_render_buffer_format_bgra8888
);
111 EXPECT_EQ(caps
.occlusion_query_boolean
, flags
.occlusion_query_boolean
);
114 TEST_F(GLTest
, GetString
) {
116 "OpenGL ES 2.0 Chromium",
117 reinterpret_cast<const char*>(glGetString(GL_VERSION
)));
119 "OpenGL ES GLSL ES 1.0 Chromium",
120 reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION
)));
123 reinterpret_cast<const char*>(glGetString(GL_RENDERER
)));
126 reinterpret_cast<const char*>(glGetString(GL_VENDOR
)));