2010-07-16 07:30:32 -07:00
|
|
|
<!--
|
|
|
|
Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style license that can be
|
|
|
|
found in the LICENSE file.
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
|
|
|
<script src="../resources/js-test-pre.js"></script>
|
|
|
|
<script src="resources/webgl-test.js"></script>
|
|
|
|
<script id="vshader" type="x-shader/x-vertex">
|
|
|
|
attribute vec3 pos;
|
|
|
|
attribute vec4 colorIn;
|
|
|
|
varying vec4 color;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
color = colorIn;
|
|
|
|
gl_Position = vec4(pos.xyz, 1.0);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script id="fshader" type="x-shader/x-fragment">
|
2010-08-25 16:09:26 -07:00
|
|
|
#ifdef GL_ES
|
|
|
|
precision highp float;
|
|
|
|
#endif
|
2010-07-16 07:30:32 -07:00
|
|
|
varying vec4 color;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_FragColor = color;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var successfullyParsed = false;
|
|
|
|
|
|
|
|
// These four declarations need to be global for "shouldBe" to see them
|
|
|
|
var webGL = null;
|
|
|
|
var contextAttribs = null;
|
|
|
|
var pixel = [0, 0, 0, 1];
|
|
|
|
var correctColor = null;
|
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
if (window.initNonKhronosFramework) {
|
|
|
|
window.initNonKhronosFramework(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
description('Verify WebGLContextAttributes are working as specified, including alpha, depth, stencil, antialias, but not premultipliedAlpha');
|
|
|
|
|
|
|
|
runTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWebGL(canvasName, contextAttribs, clearColor, clearDepth, clearStencil)
|
|
|
|
{
|
2010-11-16 20:33:04 -08:00
|
|
|
var context = initWebGL(canvasName, "vshader", "fshader", ["pos", "colorIn"], clearColor, clearDepth, contextAttribs);
|
|
|
|
if (context) {
|
|
|
|
context.clearStencil(clearStencil);
|
|
|
|
context.enable(context.STENCIL_TEST);
|
|
|
|
context.disable(context.BLEND);
|
|
|
|
context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT);
|
2010-07-16 07:30:32 -07:00
|
|
|
}
|
2010-11-16 20:33:04 -08:00
|
|
|
return context;
|
2010-07-16 07:30:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawAndReadPixel(gl, vertices, colors, x, y)
|
|
|
|
{
|
|
|
|
var colorOffset = vertices.byteLength;
|
|
|
|
|
|
|
|
var vbo = gl.createBuffer();
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DRAW);
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors);
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
|
|
|
gl.enableVertexAttribArray(0);
|
|
|
|
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset);
|
|
|
|
gl.enableVertexAttribArray(1);
|
|
|
|
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 3);
|
|
|
|
|
|
|
|
var buf = new Uint8Array(1 * 1 * 4);
|
|
|
|
gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAlpha(alpha)
|
|
|
|
{
|
|
|
|
debug("Testing alpha = " + alpha);
|
|
|
|
if (alpha)
|
|
|
|
shouldBeNonNull("webGL = getWebGL('alphaOn', { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
|
|
|
|
else
|
|
|
|
shouldBeNonNull("webGL = getWebGL('alphaOff', { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
|
|
|
|
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2010-07-16 07:30:32 -07:00
|
|
|
var buf = new Uint8Array(1 * 1 * 4);
|
|
|
|
webGL.readPixels(0, 0, 1, 1, webGL.RGBA, webGL.UNSIGNED_BYTE, buf);
|
|
|
|
pixel[0] = buf[0];
|
|
|
|
pixel[1] = buf[1];
|
|
|
|
pixel[2] = buf[2];
|
|
|
|
pixel[3] = buf[3];
|
2010-11-16 20:33:04 -08:00
|
|
|
correctColor = (contextAttribs.alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBe("pixel", "correctColor");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDepth(depth)
|
|
|
|
{
|
|
|
|
debug("Testing depth = " + depth);
|
|
|
|
if (depth)
|
|
|
|
shouldBeNonNull("webGL = getWebGL('depthOn', { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
else
|
|
|
|
shouldBeNonNull("webGL = getWebGL('depthOff', { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
|
|
|
|
|
|
|
|
webGL.depthFunc(webGL.NEVER);
|
|
|
|
|
2010-08-25 16:09:26 -07:00
|
|
|
var vertices = new Float32Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
1.0, 1.0, 0.0,
|
|
|
|
-1.0, 1.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0,
|
|
|
|
1.0, 1.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0,
|
|
|
|
1.0, -1.0, 0.0]);
|
2010-08-25 16:09:26 -07:00
|
|
|
var colors = new Uint8Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255]);
|
|
|
|
|
|
|
|
var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
|
|
|
|
pixel[0] = buf[0];
|
|
|
|
pixel[1] = buf[1];
|
|
|
|
pixel[2] = buf[2];
|
|
|
|
pixel[3] = buf[3];
|
2010-11-16 20:33:04 -08:00
|
|
|
correctColor = (contextAttribs.depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBe("pixel", "correctColor");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testStencil(stencil)
|
|
|
|
{
|
|
|
|
debug("Testing stencil = " + stencil);
|
|
|
|
if (stencil)
|
|
|
|
shouldBeNonNull("webGL = getWebGL('stencilOn', { depth: false, stencil: true, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
else
|
|
|
|
shouldBeNonNull("webGL = getWebGL('stencilOff', { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
|
|
|
|
|
|
|
|
webGL.depthFunc(webGL.ALWAYS);
|
|
|
|
|
|
|
|
webGL.stencilFunc(webGL.NEVER, 1, 1);
|
|
|
|
webGL.stencilOp(webGL.KEEP, webGL.KEEP, webGL.KEEP);
|
|
|
|
|
2010-08-25 16:09:26 -07:00
|
|
|
var vertices = new Float32Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
1.0, 1.0, 0.0,
|
|
|
|
-1.0, 1.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0,
|
|
|
|
1.0, 1.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0,
|
|
|
|
1.0, -1.0, 0.0]);
|
2010-08-25 16:09:26 -07:00
|
|
|
var colors = new Uint8Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255]);
|
|
|
|
|
|
|
|
var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
|
|
|
|
pixel[0] = buf[0];
|
|
|
|
pixel[1] = buf[1];
|
|
|
|
pixel[2] = buf[2];
|
|
|
|
pixel[3] = buf[3];
|
2010-11-16 20:33:04 -08:00
|
|
|
correctColor = (contextAttribs.stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBe("pixel", "correctColor");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAntialias(antialias)
|
|
|
|
{
|
|
|
|
debug("Testing antialias = " + antialias);
|
|
|
|
if (antialias)
|
|
|
|
shouldBeNonNull("webGL = getWebGL('antialiasOn', { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
else
|
|
|
|
shouldBeNonNull("webGL = getWebGL('antialiasOff', { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
|
|
|
|
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
|
|
|
|
|
2010-08-25 16:09:26 -07:00
|
|
|
var vertices = new Float32Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
1.0, 1.0, 0.0,
|
|
|
|
-1.0, 1.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0]);
|
2010-08-25 16:09:26 -07:00
|
|
|
var colors = new Uint8Array([
|
2010-07-16 07:30:32 -07:00
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255,
|
|
|
|
255, 0, 0, 255]);
|
|
|
|
var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
|
|
|
|
pixel[0] = buf[0];
|
2010-11-16 20:33:04 -08:00
|
|
|
shouldBe("pixel[0] != 255 && pixel[0] != 0", "contextAttribs.antialias");
|
2010-07-16 07:30:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
testAlpha(true);
|
|
|
|
testAlpha(false);
|
|
|
|
testDepth(true);
|
|
|
|
testDepth(false);
|
|
|
|
testStencil(true);
|
|
|
|
testStencil(false);
|
|
|
|
testAntialias(true);
|
|
|
|
testAntialias(false);
|
|
|
|
|
2011-03-03 08:02:36 -08:00
|
|
|
finishTest()
|
2010-07-16 07:30:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body onload="init()">
|
|
|
|
<canvas id="alphaOn" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="alphaOff" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="depthOn" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="depthOff" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="stencilOn" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="stencilOff" width="1px" height="1px"></canvas>
|
|
|
|
<canvas id="antialiasOn" width="2px" height="2px"></canvas>
|
|
|
|
<canvas id="antialiasOff" width="2px" height="2px"></canvas>
|
|
|
|
<div id="description"></div>
|
|
|
|
<div id="console"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|