1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // ExplicitContextTest.cpp: Tests of the EGL_ANGLE_explicit_context extension
8
9 #include "test_utils/ANGLETest.h"
10
11 #include "test_utils/gl_raii.h"
12 #include "util/EGLWindow.h"
13
14 namespace angle
15 {
16
17 class ExplicitContextTest : public ANGLETest
18 {
19 protected:
ExplicitContextTest()20 ExplicitContextTest()
21 {
22 setWindowWidth(256);
23 setWindowHeight(256);
24 setConfigRedBits(8);
25 setConfigGreenBits(8);
26 setConfigBlueBits(8);
27 setConfigAlphaBits(8);
28 }
29 };
30
31 // Test to ensure that the basic functionality of the extension works.
TEST_P(ExplicitContextTest,BasicTest)32 TEST_P(ExplicitContextTest, BasicTest)
33 {
34 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_explicit_context") ||
35 !IsGLExtensionEnabled("GL_ANGLE_explicit_context_gles1"));
36
37 EGLContext context = getEGLWindow()->getContext();
38
39 // Clear to green
40 glClearColorContextANGLE(context, 0.0f, 1.0f, 0.0f, 1.0f);
41 glClearContextANGLE(context, GL_COLOR_BUFFER_BIT);
42
43 // Check for green
44 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
45 ASSERT_GL_NO_ERROR();
46 }
47
48 // Test to ensure that extension works with eglGetProcAddress
TEST_P(ExplicitContextTest,GetProcAddress)49 TEST_P(ExplicitContextTest, GetProcAddress)
50 {
51 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_explicit_context") ||
52 !IsGLExtensionEnabled("GL_ANGLE_explicit_context_gles1"));
53
54 EGLContext context = getEGLWindow()->getContext();
55
56 // Clear to green
57 glClearColorContextANGLE(context, 1.0f, 0, 0, 1.0f);
58 glClearContextANGLE(context, GL_COLOR_BUFFER_BIT);
59
60 // Check for green
61 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
62 EXPECT_GL_NO_ERROR();
63 }
64
65 // Test to ensure that a passed context of null results in a no-op
TEST_P(ExplicitContextTest,NullContext)66 TEST_P(ExplicitContextTest, NullContext)
67 {
68 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_explicit_context") ||
69 !IsGLExtensionEnabled("GL_ANGLE_explicit_context_gles1"));
70
71 EGLContext context = getEGLWindow()->getContext();
72
73 // Set clear color to red
74 glClearColorContextANGLE(context, 1.0f, 0, 0, 1.0f);
75 // Clear to red
76 glClearContextANGLE(context, GL_COLOR_BUFFER_BIT);
77
78 // Set clear color to green
79 glClearColorContextANGLE(context, 0.0f, 1.0f, 0.0f, 1.0f);
80 // Call clear with null context, which should perform a silent no-op
81 glClearContextANGLE(nullptr, GL_COLOR_BUFFER_BIT);
82
83 // Check that the color is red
84 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
85 EXPECT_GL_NO_ERROR();
86 }
87
88 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
89 // tests should be run against.
90 ANGLE_INSTANTIATE_TEST_ES2(ExplicitContextTest);
91
92 } // namespace angle
93