Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / test_hidden_depth_stencil.html
blob987af9e371e2769dd4f892809f54f6723e64185e
1 <!DOCTYPE HTML>
2 <title>WebGL test: Hidden depth/stencil passes without a depth/stencil buffer respectively</title>
3 <script src='/tests/SimpleTest/SimpleTest.js'></script>
4 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
5 <script src='webgl-util.js'></script>
6 <body>
7 <script id='vs' type='x-shader/x-vertex'>
8 void main(void) {
9 gl_PointSize = 1.0; // Note that this is undefined if we don't write to it!
10 gl_Position = vec4(vec3(0), 1);
12 </script>
14 <script id='fs' type='x-shader/x-fragment'>
15 precision mediump float;
17 void main(void) {
18 gl_FragColor = vec4(0, 1, 0, 1);
20 </script>
21 <script>
23 function ColorString(arr) {
24 return '[' + arr[0] + ', ' + arr[1] + ', ' + arr[2] + ', ' + arr[3] + ']';
27 function DrawAndCheck(gl, infoPrefix, refColorStr) {
28 gl.viewport(0, 0, 1, 1);
30 gl.clearColor(1, 0, 0, 1);
31 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
32 gl.drawArrays(gl.POINTS, 0, 1);
34 var pixel = new Uint8Array(4);
35 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
36 var pixelStr = ColorString(pixel);
38 ok(pixelStr == refColorStr, infoPrefix + pixelStr + ' should be ' + refColorStr);
41 function TestCurrent(gl, attribs, infoPrefix) {
42 infoPrefix = infoPrefix + JSON.stringify(attribs) + ': ';
44 var CLEAR_COLOR = ColorString([255, 0, 0, 255]);
45 var DRAW_COLOR = ColorString([0, 255, 0, 255]);
47 gl.disable(gl.DEPTH_TEST);
48 gl.disable(gl.STENCIL_TEST);
50 DrawAndCheck(gl, infoPrefix + 'initial: ', DRAW_COLOR);
52 if (!attribs.depth) {
53 gl.enable(gl.DEPTH_TEST);
54 gl.depthFunc(gl.NEVER);
56 gl.disable(gl.STENCIL_TEST);
58 // Depth test is enabled, and should pass NEVER.
59 // Since there is no depth buffer, the depth test is not run.
60 // Stencil test is disabled.
61 DrawAndCheck(gl, infoPrefix + 'no-depth: ', DRAW_COLOR);
64 if (!attribs.stencil) {
65 gl.disable(gl.DEPTH_TEST);
67 gl.enable(gl.STENCIL_TEST);
68 gl.stencilFunc(gl.NEVER, 0, 0);
70 // Depth test is disabled.
71 // Stencil test is enabled, and should pass NEVER.
72 // Since there is no stencil buffer, the stencil test is not run.
73 DrawAndCheck(gl, infoPrefix + 'no-stencil: ', DRAW_COLOR);
77 function TestBackbuffer(requestedAttribs) {
78 var canvas = document.createElement('canvas');
79 canvas.width = 1;
80 canvas.height = 1;
81 var gl = canvas.getContext('experimental-webgl', requestedAttribs);
82 if (!gl) {
83 ok(true, 'WebGL doesn\'t work, skipping test.');
84 return;
87 ok(gl.drawingBufferWidth == 1 && gl.drawingBufferHeight == 1,
88 'backbuffer should be 1x1');
90 var prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
91 gl.useProgram(prog);
93 var attribs = {
94 depth: gl.getContextAttributes().depth,
95 stencil: gl.getContextAttributes().stencil,
97 TestCurrent(gl, attribs, 'Backbuffer: ');
100 function TestUserFB() {
101 var canvas = document.createElement('canvas');
102 var gl = canvas.getContext('experimental-webgl');
103 if (!gl) {
104 ok(true, 'WebGL doesn\'t work, skipping test.');
105 return;
108 var prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
109 gl.useProgram(prog);
111 var rb = gl.createRenderbuffer();
112 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
113 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 1, 1);
115 var fb = gl.createFramebuffer();
116 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
117 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
119 var depthRB = gl.createRenderbuffer();
120 gl.bindRenderbuffer(gl.RENDERBUFFER, depthRB);
121 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1, 1);
123 var stencilRB = gl.createRenderbuffer();
124 gl.bindRenderbuffer(gl.RENDERBUFFER, stencilRB);
125 gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, 1, 1);
127 do {
128 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRB);
129 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);
130 var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
131 if (status != gl.FRAMEBUFFER_COMPLETE) {
132 ok(true, 'Depth-only user FB is incomplete. This is allowed.');
133 break;
136 TestCurrent(gl, {depth: true, stencil: false}, 'Depth-only user FB');
137 } while (false);
139 do {
140 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null);
141 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencilRB);
142 var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
143 if (status != gl.FRAMEBUFFER_COMPLETE) {
144 ok(true, 'Stencil-only user FB is incomplete. This is allowed.');
145 break;
148 TestCurrent(gl, {depth: false, stencil: true}, 'Stencil-only user FB');
149 } while (false);
152 (function(){
153 TestBackbuffer({depth: true, stencil: false});
154 TestBackbuffer({depth: false, stencil: true});
155 TestUserFB();
156 })();
158 </script>
159 </body>