2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL OVR_multiview2 Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
15 <script src=
"../../js/tests/ovr_multiview2_util.js"></script>
16 <script id=
"macroFragmentShader" type=
"x-shader/x-fragment">#version
300 es
17 precision highp float;
18 out vec4 my_FragColor;
20 #ifdef GL_OVR_multiview2
21 my_FragColor = vec4(
0.0,
1.0,
0.0,
1.0);
24 #error no GL_OVR_multiview2;
30 <div id=
"description"></div>
31 <div id=
"console"></div>
35 let wtu
= WebGLTestUtils
;
36 let gl
= wtu
.create3DContext(null, null, 2);
39 function runDepthRenderTest()
42 debug("Testing rendering with a depth texture array and depth test on");
47 let views
= gl
.getParameter(ext
.MAX_VIEWS_OVR
);
49 let multiviewShaders
= [
50 getMultiviewPassthroughVertexShader(views
),
51 getMultiviewColorFragmentShader()
53 let testProgram
= wtu
.setupProgram(gl
, multiviewShaders
, ['a_position'], [0], true);
55 testFailed("Compilation with extension enabled failed.");
59 let fb
= gl
.createFramebuffer();
60 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
61 let colorTex
= createTextureWithNearestFiltering(gl
.TEXTURE_2D_ARRAY
);
62 gl
.texStorage3D(gl
.TEXTURE_2D_ARRAY
, 1, gl
.RGBA8
, width
, height
, views
);
63 ext
.framebufferTextureMultiviewOVR(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, colorTex
, 0, 0, views
);
65 let depthTex
= createTextureWithNearestFiltering(gl
.TEXTURE_2D_ARRAY
);
66 gl
.texStorage3D(gl
.TEXTURE_2D_ARRAY
, 1, gl
.DEPTH32F_STENCIL8
, width
, height
, views
);
67 ext
.framebufferTextureMultiviewOVR(gl
.FRAMEBUFFER
, gl
.DEPTH_STENCIL_ATTACHMENT
, depthTex
, 0, 0, views
);
69 let expectedStatus
= gl
.FRAMEBUFFER_COMPLETE
;
70 let status
= gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
);
71 if (status
!= expectedStatus
) {
72 testFailed('Framebuffer status: ' + wtu
.glEnumToString(gl
, status
) + ' did not match with the expected value: ' + wtu
.glEnumToString(gl
, expectedStatus
));
74 testPassed('Framebuffer status: ' + wtu
.glEnumToString(gl
, status
) + ' matched with the expected value');
77 // Draw so that the depth test succeeds for all pixels.
78 gl
.viewport(0, 0, width
, height
);
79 gl
.enable(gl
.DEPTH_TEST
);
81 gl
.clear(gl
.DEPTH_BUFFER_BIT
);
84 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from draw when depth test succeeds");
86 let readFb
= gl
.createFramebuffer();
87 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, readFb
);
88 for (let viewIndex
= 0; viewIndex
< views
; ++viewIndex
) {
89 gl
.framebufferTextureLayer(gl
.READ_FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, colorTex
, 0, viewIndex
);
90 let expectedColor
= getExpectedColor(viewIndex
);
91 wtu
.checkCanvasRect(gl
, 0, 0, width
, height
, expectedColor
, 'view ' + viewIndex
+ ' should be colored ' + expectedColor
);
94 // Draw so that the depth test fails for all pixels.
96 gl
.clearColor(0.0, 0.0, 0.0, 0.0);
97 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
99 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors from draw when depth test fails");
101 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, readFb
);
102 for (let viewIndex
= 0; viewIndex
< views
; ++viewIndex
) {
103 gl
.framebufferTextureLayer(gl
.READ_FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, colorTex
, 0, viewIndex
);
104 let expectedColor
= [0, 0, 0, 0];
105 wtu
.checkCanvasRect(gl
, 0, 0, width
, height
, expectedColor
, 'view ' + viewIndex
+ ' should be colored ' + expectedColor
);
109 description("This test verifies drawing to depth buffers with the OVR_multiview2 extension, if it is available.");
114 testFailed("WebGL context does not exist");
116 testPassed("WebGL context exists");
120 if (!gl
.getExtension("OVR_multiview2")) {
121 testPassed("No OVR_multiview2 support -- this is legal");
123 testPassed("Successfully enabled OVR_multiview2 extension");
124 ext
= gl
.getExtension('OVR_multiview2');
126 wtu
.setupUnitQuad(gl
, 0, 1);
128 runDepthRenderTest();
133 var successfullyParsed
= true;
135 <script src=
"../../js/js-test-post.js"></script>