blob: ebc0efce5e4a15b3df583d326cbf767535374a26 [file] [log] [blame]
Geoff Langc287ea62016-09-16 14:46:51 -04001//
2// Copyright 2015 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// WebGLCompatibilityTest.cpp : Tests of the GL_ANGLE_webgl_compatibility extension.
8
9#include "test_utils/ANGLETest.h"
10
11#include "test_utils/gl_raii.h"
12
13namespace angle
14{
15
16class WebGLCompatibilityTest : public ANGLETest
17{
18 protected:
19 WebGLCompatibilityTest()
20 {
21 setWindowWidth(128);
22 setWindowHeight(128);
23 setConfigRedBits(8);
24 setConfigGreenBits(8);
25 setConfigBlueBits(8);
26 setConfigAlphaBits(8);
27 setWebGLCompatibilityEnabled(true);
28 }
29
30 void SetUp() override
31 {
32 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050033 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
34 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040035 }
36
37 void TearDown() override { ANGLETest::TearDown(); }
38
Geoff Langc339c4e2016-11-29 10:37:36 -050039 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -040040};
41
42// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
43// the GL extension should always be present
44TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
45{
46 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
47}
48
49// Verify that all extension entry points are available
50TEST_P(WebGLCompatibilityTest, EntryPoints)
51{
Geoff Langc339c4e2016-11-29 10:37:36 -050052 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -040053 {
Geoff Langc339c4e2016-11-29 10:37:36 -050054 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040055 }
56}
57
58// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
59// even in ES2 contexts.
60TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
61{
62 GLRenderbuffer renderbuffer;
63 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
64 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
65
66 GLFramebuffer framebuffer;
67 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
68 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
69 renderbuffer.get());
70
71 EXPECT_GL_NO_ERROR();
72}
73
74// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
75TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
76{
Geoff Langc339c4e2016-11-29 10:37:36 -050077 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -040078 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
79}
80
81// Test enabling the GL_OES_element_index_uint extension
82TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
83{
84 if (getClientMajorVersion() != 2)
85 {
86 // This test only works on ES2 where uint indices are not available by default
87 return;
88 }
89
90 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
91
92 GLBuffer indexBuffer;
93 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
94
95 GLuint data[] = {0, 1, 2, 1, 3, 2};
96 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
97
98 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
99 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
100 glUseProgram(program.get());
101
102 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
103 EXPECT_GL_ERROR(GL_INVALID_ENUM);
104
Geoff Langc339c4e2016-11-29 10:37:36 -0500105 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400106 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500107 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400108 EXPECT_GL_NO_ERROR();
109 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
110
111 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
112 EXPECT_GL_NO_ERROR();
113 }
114}
115
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700116// Verify that shaders are of a compatible spec when the extension is enabled.
117TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
118{
119 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
120
121 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
122 const std::string &vert =
123 "struct Foo {\n"
124 " int _webgl_bar;\n"
125 "};\n"
126 "void main()\n"
127 "{\n"
128 " Foo foo = Foo(1);\n"
129 "}";
130
131 // Default fragement shader.
132 const std::string &frag =
133 "void main()\n"
134 "{\n"
135 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
136 "}";
137
138 GLuint program = CompileProgram(vert, frag);
139 EXPECT_EQ(0u, program);
140 glDeleteProgram(program);
141}
142
Geoff Langc287ea62016-09-16 14:46:51 -0400143// Use this to select which configurations (e.g. which renderer, which GLES major version) these
144// tests should be run against.
145ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
146 ES2_D3D9(),
147 ES2_D3D11(),
148 ES3_D3D11(),
149 ES2_D3D11_FL9_3(),
150 ES2_OPENGL(),
151 ES3_OPENGL(),
152 ES2_OPENGLES(),
153 ES3_OPENGLES());
154
155} // namespace