b=612334; update in-tree webgl tests from svn; npotb

This commit is contained in:
Vladimir Vukicevic 2010-11-16 20:33:04 -08:00
parent 25fc7d07bd
commit 106644f6e1
28 changed files with 782 additions and 515 deletions

View File

@ -1,6 +1,6 @@
This is a local copy of the WebGL conformance suite.
SVN revision: 11955
SVN revision: 12905
The canonical location for this testsuite is:

View File

@ -7,7 +7,6 @@ buffer-data-array-buffer.html
canvas-test.html
constants.html
context-attributes-alpha-depth-stencil-antialias.html
context-attributes.html
context-type-test.html
copy-tex-image-and-sub-image-2d.html
draw-arrays-out-of-bounds.html
@ -17,11 +16,13 @@ framebuffer-object-attachment.html
framebuffer-test.html
get-active-test.html
gl-bind-attrib-location-test.html
gl-clear.html
gl-drawelements.html
gl-enable-enum-test.html
gl-enable-vertex-attrib.html
gl-enum-tests.html
gl-get-active-attribute.html
gl-get-active-uniform.html
gl-get-calls.html
gl-getstring.html
gl-object-get-calls.html
@ -45,10 +46,13 @@ index-validation-with-resized-buffer.html
index-validation.html
invalid-UTF-16.html
invalid-passed-params.html
is-object.html
methods.html
more-than-65536-points.html
null-object-behaviour.html
null-uniform-location.html
object-deletion-behaviour.html
origin-clean-conformance.html
point-size.html
program-test.html
read-pixels-pack-alignment.html
@ -72,7 +76,9 @@ texture-formats-test.html
texture-npot.html
texture-transparent-pixels-initialized.html
triangle.html
#uniform-location.html
type-conversion-test.html
uniform-location.html
uniform-samplers-test.html
uninitialized-test.html
viewport-unchanged-upon-resize.html
webgl-specific.html

View File

@ -1,82 +0,0 @@
array-buffer-crash.html
array-buffer-view-crash.html
array-unit-tests.html
bad-arguments-test.html
buffer-bind-test.html
buffer-data-array-buffer.html
canvas-test.html
constants.html
context-attributes-alpha-depth-stencil-antialias.html
context-attributes.html
context-type-test.html
copy-tex-image-and-sub-image-2d.html
draw-arrays-out-of-bounds.html
draw-elements-out-of-bounds.html
error-reporting.html
framebuffer-object-attachment.html
framebuffer-test.html
get-active-test.html
gl-bind-attrib-location-test.html
gl-clear.html
gl-drawelements.html
gl-enable-enum-test.html
gl-enable-vertex-attrib.html
gl-enum-tests.html
gl-get-active-attribute.html
gl-get-active-uniform.html
gl-get-calls.html
gl-getstring.html
gl-object-get-calls.html
gl-pixelstorei.html
gl-scissor-test.html
gl-shader-test.html
gl-teximage.html
gl-uniform-arrays.html
gl-uniform-bool.html
gl-uniformmatrix4fv.html
gl-unknown-uniform.html
gl-vertex-attrib.html
gl-vertexattribpointer.html
glsl-2types-of-textures-on-same-unit.html
glsl-conformance.html
incorrect-context-object-behaviour.html
index-validation-copies-indices.html
index-validation-crash-with-buffer-sub-data.html
index-validation-verifies-too-many-indices.html
index-validation-with-resized-buffer.html
index-validation.html
invalid-UTF-16.html
invalid-passed-params.html
methods.html
more-than-65536-points.html
null-object-behaviour.html
null-uniform-location.html
object-deletion-behaviour.html
origin-clean-conformance.html
point-size.html
program-test.html
read-pixels-pack-alignment.html
read-pixels-test.html
renderbuffer-initialization.html
resource-sharing-test.html
tex-image-and-sub-image-2d-with-array-buffer-view.html
tex-image-and-sub-image-2d-with-image-data.html
tex-image-and-sub-image-2d-with-image.html
tex-image-and-sub-image-2d-with-video.html
tex-image-and-uniform-binding-bugs.html
tex-image-with-format-and-type.html
tex-image-with-invalid-data.html
tex-input-validation.html
tex-sub-image-2d.html
texparameter-test.html
texture-active-bind-2.html
texture-active-bind.html
texture-complete.html
texture-formats-test.html
texture-npot.html
texture-transparent-pixels-initialized.html
triangle.html
uniform-location.html
uniform-samplers-test.html
uninitialized-test.html
viewport-unchanged-upon-resize.html

View File

@ -438,6 +438,15 @@ function testConstructionWithUnalignedOffset(type, name, elementSizeInBytes) {
}
}
function testConstructionWithUnalignedLength(type, name, elementSizeInBytes) {
if (elementSizeInBytes > 1) {
shouldThrowIndexSizeErr(function() {
var buffer = new ArrayBuffer(elementSizeInBytes + 1);
var array = new type(buffer, 0);
}, "Construction of " + name + " with unaligned length");
}
}
function testConstructionOfHugeArray(type, name, sz) {
if (sz == 1)
return;
@ -671,6 +680,7 @@ function runTests() {
testConstructionWithOutOfRangeValues(type, name);
testConstructionWithNegativeOutOfRangeValues(type, name);
testConstructionWithUnalignedOffset(type, name, testCase.elementSizeInBytes);
testConstructionWithUnalignedLength(type, name, testCase.elementSizeInBytes);
testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes);
testConstructionWithBothArrayBufferAndLength(type, name, testCase.elementSizeInBytes);
testSlicingWithOutOfRangeValues(type, name, testCase.elementSizeInBytes);

View File

@ -79,7 +79,6 @@ for (var i = 0; i < arguments.length; ++i) {
argument = arguments[i].value;
func("context.compileShader(argument)");
func("context.linkProgram(argument)");
func("context.attachShader(argument)");
func("context.attachShader(program, argument)");
func("context.attachShader(argument, shader)");
func("context.detachShader(program, argument)");

View File

@ -33,6 +33,10 @@ glErrorShouldBe(gl, gl.INVALID_OPERATION);
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
glErrorShouldBe(gl, gl.NO_ERROR);
// This should not crash, but the selection of the overload is ambiguous per Web IDL.
gl.bufferData(gl.ARRAY_BUFFER, null, gl.STATIC_DRAW);
gl.getError();
gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
glErrorShouldBe(gl, gl.NO_ERROR);
@ -41,6 +45,9 @@ array = new ArrayBuffer(64);
gl.bufferSubData(gl.ARRAY_BUFFER, 10, array);
glErrorShouldBe(gl, gl.NO_ERROR);
gl.bufferSubData(gl.ARRAY_BUFFER, 10, null);
glErrorShouldBe(gl, gl.NO_ERROR);
successfullyParsed = true;
</script>

View File

@ -375,10 +375,6 @@ VERTEX_ATTRIB_ARRAY_NORMALIZED : 0x886A,
VERTEX_ATTRIB_ARRAY_POINTER : 0x8645,
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
/* Read Format */
IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
/* Shader Source */
COMPILE_STATUS : 0x8B81,
INFO_LOG_LENGTH : 0x8B84,
@ -403,6 +399,7 @@ RGB565 : 0x8D62,
DEPTH_COMPONENT16 : 0x81A5,
STENCIL_INDEX : 0x1901,
STENCIL_INDEX8 : 0x8D48,
DEPTH_STENCIL : 0x84F9,
RENDERBUFFER_WIDTH : 0x8D42,
RENDERBUFFER_HEIGHT : 0x8D43,
@ -422,6 +419,7 @@ FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
COLOR_ATTACHMENT0 : 0x8CE0,
DEPTH_ATTACHMENT : 0x8D00,
STENCIL_ATTACHMENT : 0x8D20,
DEPTH_STENCIL_ATTACHMENT : 0x821A,
NONE : 0,
@ -435,7 +433,14 @@ FRAMEBUFFER_BINDING : 0x8CA6,
RENDERBUFFER_BINDING : 0x8CA7,
MAX_RENDERBUFFER_SIZE : 0x84E8,
INVALID_FRAMEBUFFER_OPERATION : 0x0506
INVALID_FRAMEBUFFER_OPERATION : 0x0506,
/* WebGL-specific enums */
UNPACK_FLIP_Y_WEBGL : 0x9240,
UNPACK_PREMULTIPLY_ALPHA_WEBGL : 0x9241,
CONTEXT_LOST_WEBGL : 0x9242,
UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
BROWSER_DEFAULT_WEBGL : 0x9244
};
function assertProperty(v, p) {

View File

@ -54,65 +54,14 @@ function init()
function getWebGL(canvasName, contextAttribs, clearColor, clearDepth, clearStencil)
{
var canvas = document.getElementById(canvasName);
var gl = canvas.getContext("experimental-webgl", contextAttribs);
if (!gl) {
alert("No WebGL context found");
return null;
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);
}
// Add a console
gl.console = ("console" in window) ? window.console : { log: function() { } };
// create our shaders
var vertexShader = loadShader(gl, "vshader");
var fragmentShader = loadShader(gl, "fshader");
if (!vertexShader || !fragmentShader)
return null;
// Create the program object
gl.program = gl.createProgram();
if (!gl.program)
return null;
// Attach our two shaders to the program
gl.attachShader(gl.program, vertexShader);
gl.attachShader(gl.program, fragmentShader);
// Bind attributes
var attribs = [ "pos", "colorIn" ];
for (var i in attribs)
gl.bindAttribLocation(gl.program, i, attribs[i]);
// Link the program
gl.linkProgram(gl.program);
// Check the link status
var linked = gl.getProgramParameter(gl.program, gl.LINK_STATUS);
if (!linked) {
// something went wrong with the link
var error = gl.getProgramInfoLog (gl.program);
gl.console.log("Error in program linking:"+error);
gl.deleteProgram(gl.program);
gl.deleteProgram(fragmentShader);
gl.deleteProgram(vertexShader);
return null;
}
gl.useProgram(gl.program);
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
gl.clearDepth(clearDepth);
gl.clearStencil(clearStencil);
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.STENCIL_TEST);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
return gl;
return context;
}
function drawAndReadPixel(gl, vertices, colors, x, y)
@ -146,25 +95,13 @@ function testAlpha(alpha)
shouldBeNonNull("webGL = getWebGL('alphaOff', { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
shouldBe("'depth' in contextAttribs", "true");
shouldBe("'stencil' in contextAttribs", "true");
shouldBe("'alpha' in contextAttribs", "true");
shouldBe("'antialias' in contextAttribs", "true");
shouldBe("'premultipliedAlpha' in contextAttribs", "true");
shouldBe("contextAttribs.alpha", (alpha ? "true" : "false"));
shouldBe("contextAttribs.depth", "false");
shouldBe("contextAttribs.stencil", "false");
shouldBe("contextAttribs.antialias", "false");
shouldBe("contextAttribs.premultipliedAlpha", "true");
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];
correctColor = (alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
correctColor = (contextAttribs.alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
shouldBe("pixel", "correctColor");
}
@ -176,11 +113,6 @@ function testDepth(depth)
else
shouldBeNonNull("webGL = getWebGL('depthOff', { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
shouldBe("contextAttribs.depth", (depth ? "true" : "false"));
shouldBe("contextAttribs.alpha", "true");
shouldBe("contextAttribs.stencil", "false");
shouldBe("contextAttribs.antialias", "false");
shouldBe("contextAttribs.premultipliedAlpha", "true");
webGL.depthFunc(webGL.NEVER);
@ -204,7 +136,7 @@ function testDepth(depth)
pixel[1] = buf[1];
pixel[2] = buf[2];
pixel[3] = buf[3];
correctColor = (depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
correctColor = (contextAttribs.depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
shouldBe("pixel", "correctColor");
}
@ -216,11 +148,6 @@ function testStencil(stencil)
else
shouldBeNonNull("webGL = getWebGL('stencilOff', { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
// If EXT_packed_depth_stencil is supported, both depth & stencil will be true; otherwise, both will be false.
shouldBe("contextAttribs.depth == contextAttribs.stencil", "true");
shouldBe("contextAttribs.alpha", "true");
shouldBe("contextAttribs.antialias", "false");
shouldBe("contextAttribs.premultipliedAlpha", "true");
webGL.depthFunc(webGL.ALWAYS);
@ -247,10 +174,7 @@ function testStencil(stencil)
pixel[1] = buf[1];
pixel[2] = buf[2];
pixel[3] = buf[3];
correctColor = (stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
// If stencil is requested but not supported, we fake the effect.
if (stencil && !contextAttribs.stencil)
pixel[0] = 0;
correctColor = (contextAttribs.stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
shouldBe("pixel", "correctColor");
}
@ -262,11 +186,6 @@ function testAntialias(antialias)
else
shouldBeNonNull("webGL = getWebGL('antialiasOff', { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
shouldBe("contextAttribs.depth", "false");
shouldBe("contextAttribs.stencil", "false");
shouldBe("contextAttribs.alpha", "false");
shouldBe("contextAttribs.antialias == true || contextAttribs.antialias == false", "true");
shouldBe("contextAttribs.premultipliedAlpha", "true");
var vertices = new Float32Array([
1.0, 1.0, 0.0,
@ -278,10 +197,7 @@ function testAntialias(antialias)
255, 0, 0, 255]);
var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
pixel[0] = buf[0];
// If antialias is requested but not supported, we fake the effect.
if (antialias && !contextAttribs.antialias)
pixel[0] = 127;
shouldBe("pixel[0] == 255 || pixel[0] == 0", (antialias ? "false" : "true"));
shouldBe("pixel[0] != 255 && pixel[0] != 0", "contextAttribs.antialias");
}
function runTest()

View File

@ -1,66 +0,0 @@
<!--
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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Test passing down and fetching of WebGLContextAttributes");
debug("Test default values");
var context;
var attribs;
shouldBeNonNull("context = create3DContext(null)");
shouldBeNonNull("attribs = context.getContextAttributes()");
shouldBe("attribs.depth", "true");
shouldBe("attribs.alpha", "true");
shouldBe("attribs.stencil", "false");
// Antialias is requested by default, but might or might not be supported.
shouldBe("attribs.antialias == true || attribs.antialias == false", "true");
shouldBe("attribs.premultipliedAlpha", "true");
debug ("Test customized values");
shouldBeNonNull("context = create3DContext(null, { stencil: false, antialias: false })");
shouldBeNonNull("attribs = context.getContextAttributes()");
shouldBe("attribs.depth", "true");
shouldBe("attribs.alpha", "true");
shouldBe("attribs.stencil", "false");
shouldBe("attribs.antialias", "false");
shouldBe("attribs.premultipliedAlpha", "true");
debug("Test customized values");
// (stencil == true && depth == false) is not supported.
// Default depth to true if EXT_packed_depth_stencil is supported.
// Otherwise, both depth and stencil should be false.
shouldBeNonNull("context = create3DContext(null, { depth: false, stencil: true, antialias: false })");
shouldBeNonNull("attribs = context.getContextAttributes()");
shouldBe("attribs.depth == attribs.stencil", "true");
shouldBe("attribs.alpha", "true");
shouldBe("attribs.antialias", "false");
shouldBe("attribs.premultipliedAlpha", "true");
debug("Test customized values");
// (premultipliedAlpha == false) is not supported by most implementations yet
shouldBeNonNull("context = create3DContext(null, { premultipliedAlpha: false, antialias: false })");
shouldBeNonNull("attribs = context.getContextAttributes()");
shouldBe("attribs.depth", "true");
shouldBe("attribs.alpha", "true");
shouldBe("attribs.stencil == true || attribs.stencil == false", "true");
shouldBe("attribs.antialias", "false");
shouldBe("attribs.premultipliedAlpha == true || attribs.premultipliedAlpha == false", "true");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>

View File

@ -88,7 +88,7 @@ function runTestIteration(antialias)
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, gl.FALSE, 0, texCoordOffset);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, texCoordOffset);
gl.colorMask(1, 1, 1, 0);
gl.disable(gl.BLEND);

View File

@ -50,10 +50,10 @@ shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 1, 0)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 1, 0)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 100, 0)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
@ -69,7 +69,7 @@ shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(co
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 100, 0)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");

View File

@ -74,7 +74,7 @@ shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(cont
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4)");
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4)");
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0xffffffff, context.UNSIGNED_BYTE, 0)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0)");
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 0x7fffffff, context.UNSIGNED_BYTE, 0x7fffffff)");

View File

@ -28,25 +28,29 @@ function testAttachment(attachment, buffer, isConflicted)
{
shouldBeNonNull("fbo = gl.createFramebuffer()");
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, buffer);
glErrorShouldBe(gl, isConflicted ? gl.INVALID_OPERATION : gl.NO_ERROR);
glErrorShouldBe(gl, gl.NO_ERROR);
if (isConflicted) {
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UNSUPPORTED");
gl.clear(gl.COLOR_BUFFER_BIT);
glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(width * height * 4));
glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION);
}
}
function testAttachments(attachment0, buffer0, attachment1, buffer1, isConflicted)
{
shouldBeNonNull("fbo = gl.createFramebuffer()");
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment0, gl.RENDERBUFFER, buffer0);
glErrorShouldBe(gl, gl.NO_ERROR);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buffer1);
glErrorShouldBe(gl, isConflicted ? gl.INVALID_OPERATION : gl.NO_ERROR);
if (isConflicted) {
// Detach buffer0 first using a null object, then attaching buffer1 should succeed.
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment0, gl.RENDERBUFFER, null);
glErrorShouldBe(gl, gl.NO_ERROR);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buffer1);
glErrorShouldBe(gl, gl.NO_ERROR);
}
glErrorShouldBe(gl, gl.NO_ERROR);
if (isConflicted)
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UNSUPPORTED");
}
function testColorRenderbuffer(internalformat)
@ -58,10 +62,33 @@ function testColorRenderbuffer(internalformat)
testAttachment(gl.COLOR_ATTACHMENT0, colorBuffer, false);
}
function testDepthStencilRenderbuffer()
{
shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()");
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
glErrorShouldBe(gl, gl.NO_ERROR);
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)", "width");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)", "height");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)", "gl.DEPTH_STENCIL");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)", "0");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)", "0");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)", "0");
shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)", "0");
shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE) > 0");
shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_STENCIL_SIZE) > 0");
glErrorShouldBe(gl, gl.NO_ERROR);
testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, false);
}
description("Test framebuffer object attachment behaviors");
debug("Create renderbuffers");
shouldBeNonNull("gl = create3DContext()");
shouldBeNonNull("colorBuffer = gl.createRenderbuffer()");
gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height);
glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeNonNull("depthBuffer = gl.createRenderbuffer()");
gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
@ -116,6 +143,9 @@ testColorRenderbuffer(gl.RGB5_A1);
debug("Attach color renderbuffer with internalformat == RGB565");
testColorRenderbuffer(gl.RGB565);
debug("Create and attach depthStencil renderbuffer");
testDepthStencilRenderbuffer();
successfullyParsed = true;
</script>

View File

@ -64,7 +64,7 @@ var shaders = gl.getAttachedShaders(standardProgram);
shouldBe('shaders.length', '2');
shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag');
glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.getAttachedShaders(null)');
shouldBeNull('gl.getAttachedShaders(null)');
glErrorShouldBe(gl, gl.INVALID_VALUE);
shouldThrow('gl.getAttachedShaders(standardVert)');
glErrorShouldBe(gl, gl.NO_ERROR);
@ -174,9 +174,9 @@ gl.uniform3i(bval3Loc, 1, 0, 1);
gl.uniform4i(bval4Loc, 1, 0, 1, 0);
glErrorShouldBe(gl, gl.NO_ERROR);
shouldBe('gl.getUniform(boolProgram, bvalLoc)', 'true');
shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[1, 0]');
shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[1, 0, 1]');
shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[1, 0, 1, 0]');
shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[true, false]');
shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[true, false, true]');
shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[true, false, true, false]');
// Integer uniform variables
var intProgram = loadProgram(gl, "resources/intUniformShader.vert", "resources/noopUniformShader.frag");
shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true');

View File

@ -38,7 +38,8 @@ var imgURLs = [
'resources/gray-ramp.png',
'resources/zero-alpha.png',
'resources/3x3.png',
'resources/blue-1x1.jpg'];
'resources/blue-1x1.jpg',
'resources/green-2x2-16bit.png'];
wtu.loadImagesAsync(imgURLs, runTests);
@ -167,6 +168,7 @@ function runTests(imgs) {
debug("");
debug("Check that gamma settings don't effect 8bit pngs");
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
imgs['resources/gray-ramp-default-gamma.png']);
glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
@ -289,6 +291,19 @@ function runTests(imgs) {
glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
debug("");
debug("check uploading of 16-bit images");
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
imgs['resources/green-2x2-16bit.png']);
glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup");
wtu.drawQuad(gl);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
checkPixelRange(buf, middle, center, [ 15, 121, 0, 255], 10);
glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
debug("");
successfullyParsed = true;
shouldBeTrue("successfullyParsed");

View File

@ -19,7 +19,7 @@ found in the LICENSE file.
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This test ensures WebGL implementations vertexAttribPointer can not be set if no buffer is bound.");
description("This test checks vertexAttribPointer behaviors in WebGL.");
debug("");
debug("Canvas.getContext");
@ -36,6 +36,16 @@ if (!gl) {
gl.vertexAttribPointer(0, 3, gl.FLOAT, 0, 0, 12);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"vertexAttribPointer should fail if no buffer is bound");
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(512), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 1, gl.FLOAT, 0, 256, 0);
glErrorShouldBe(gl, gl.INVALID_VALUE,
"WebGL API supports vertex attribute data strides up to 255 bytes");
gl.vertexAttribPointer(0, 1, gl.FLOAT, 0, 255, 0);
glErrorShouldBe(gl, gl.NO_ERROR,
"vertexAttribPointer with stride <= 255 should succeed");
}
debug("");

View File

@ -60,6 +60,7 @@ function init()
gl = initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"],
[ 0, 0, 0, 1 ], 1);
gl = WebGLDebugUtils.makeDebugContext(gl);
gl.disable(gl.DEPTH_TEST);
gl.disable(gl.BLEND);
@ -124,7 +125,7 @@ function init()
var y = Math.floor(ii / 2);
gl.drawArrays(gl.TRIANGLES, 0, 6);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"drawing with 2 different targets on the same texture unit should generate error");
"drawing with 2 different targets on the same texture unit should generate INVALID_VALUE");
}
}

View File

@ -223,6 +223,37 @@ foo
<script id="vshaderWith__FILE__" type="text/something-not-javascript">
__FILE__
</script>
<script id="fshaderWithdFdx" type="text/something-not-javascript">
#extension GL_OES_standard_derivatives:enable
precision mediump float;
void main()
{
gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
}
</script>
<script id="fshaderWithdFdxNoExt" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
}
</script>
<script id="fshaderWith256CharacterIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 = 2.0;
void main()
{
gl_FragColor = vec4(a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345,0.0,0.0,1.0);
}
</script>
<script id="fshaderWith257CharacterIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 = 2.0;
void main()
{
gl_FragColor = vec4(a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456,0.0,0.0,1.0);
}
</script>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
@ -310,6 +341,20 @@ if (!gl) {
linkSuccess: false,
passMsg: 'fragment shader that uses gl_FragDepth should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithdFdx',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses dFdx should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithdFdxNoExt',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses dFdx without #extension should fail',
},
{ vShaderId: 'vshaderWithClipVertex',
vShaderSuccess: false,
fShaderId: 'fshader',
@ -415,7 +460,21 @@ if (!gl) {
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader uses #line directive should report correct line',
}
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWith256CharacterIdentifier',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'shared that uses 256 character identifier should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWith257CharacterIdentifier',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'shared that uses 257 character identifier should fail',
},
];
// Read in all the shader source.

View File

@ -0,0 +1,72 @@
<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 src="resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas">
<script>
var wtu;
var canvas;
var gl;
var shouldGenerateGLError;
var buffer;
var framebuffer;
var program;
var renderbuffer;
var shader;
var texture;
description("Tests 'is' calls against non-bound and deleted objects");
wtu = WebGLTestUtils;
canvas = document.getElementById("canvas");
gl = wtu.create3DContext(canvas);
shouldGenerateGLError = wtu.shouldGenerateGLError;
shouldGenerateGLError(gl, gl.NO_ERROR, "buffer = gl.createBuffer()");
shouldBeFalse("gl.isBuffer(buffer)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)");
shouldBeTrue("gl.isBuffer(buffer)");
debug("");
shouldGenerateGLError(gl, gl.NO_ERROR, "framebuffer = gl.createFramebuffer()");
shouldBeFalse("gl.isFramebuffer(framebuffer)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)");
shouldBeTrue("gl.isFramebuffer(framebuffer)");
debug("");
shouldGenerateGLError(gl, gl.NO_ERROR, "renderbuffer = gl.createRenderbuffer()");
shouldBeFalse("gl.isRenderbuffer(renderbuffer)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer)");
shouldBeTrue("gl.isRenderbuffer(renderbuffer)");
debug("");
shouldGenerateGLError(gl, gl.NO_ERROR, "texture = gl.createTexture()");
shouldBeFalse("gl.isTexture(texture)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_2D, texture)");
shouldBeTrue("gl.isTexture(texture)");
debug("");
shouldGenerateGLError(gl, gl.NO_ERROR, "program = gl.createProgram()");
shouldBeTrue("gl.isProgram(program)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteProgram(program)");
shouldBeFalse("gl.isProgram(program)");
debug("");
shouldGenerateGLError(gl, gl.NO_ERROR, "shader = gl.createShader(gl.VERTEX_SHADER)");
shouldBeTrue("gl.isShader(shader)");
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteShader(shader)");
shouldBeFalse("gl.isShader(shader)");
debug("");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>

View File

@ -44,8 +44,6 @@ var gl = null;
var array = null;
var pixel = [ 0, 0, 0, 0 ];
var expectedColor = [ 0, 0, 0, 0 ];
var pixelFormat = 0;
var pixelType = 0;
function calculatePixelBytes(format, type)
{
@ -168,38 +166,26 @@ function runTestIteration(format, type, packAlignment, width, height)
var bytesPerPixel = calculatePixelBytes(format, type);
var padding = calculatePaddingBytes(bytesPerPixel, packAlignment, width);
var size = bytesPerPixel * width * height + padding * (height - 1);
var isShort = false;
switch (type) {
case gl.UNSIGNED_SHORT_5_6_5:
case gl.UNSIGNED_SHORT_4_4_4_4:
case gl.UNSIGNED_SHORT_5_5_5_1:
isShort = true;
if (type != gl.UNSIGNED_BYTE) {
throw "test error: only UNSIGNED_BYTE is valid to ReadPixels";
}
if (isShort)
size /= 2;
if (size < 0)
size = 0;
if (type == gl.UNSIGNED_BYTE)
array = new Uint8Array(size);
else
array = new Uint16Array(size);
array = new Uint8Array(size);
gl.readPixels(0, 0, width, height, format, type, array);
if (width < 0 || height < 0) {
glErrorShouldBe(gl, gl.INVALID_VALUE);
return;
} else {
glErrorShouldBe(gl, gl.NO_ERROR);
if (!array.length)
return;
}
glErrorShouldBe(gl, gl.NO_ERROR);
if (!array.length)
return;
// Check the last pixel of the last row.
var bytesPerRow = width * bytesPerPixel + padding;
var pos = bytesPerRow * (height - 1) + (width - 1) * bytesPerPixel;
var numComponents = bytesPerPixel;
if (isShort) {
pos /= 2;
numComponents /= 2;
}
for (var i = 0; i < numComponents; ++i)
pixel[i] = array[pos + i];
for (var i = numComponents; i < 4; ++i)
@ -209,75 +195,44 @@ function runTestIteration(format, type, packAlignment, width, height)
shouldBe("pixel", "expectedColor");
}
function checkSupportedPixelFormatAndType()
{
debug("Check supported pixel format/type besides RGBA/UNSIGNED_BYTE");
glErrorShouldBe(gl, gl.NO_ERROR);
pixelFormat = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT);
pixelType = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE);
glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeFalse("pixelFormat == gl.RGBA && pixelType == gl.UNSIGNED_BYTE");
}
description('Verify readPixels() works fine with various PACK_ALIGNMENT values.');
shouldBeNonNull("gl = initWebGL('example', 'vshader', 'fshader', [ 'pos', 'colorIn' ], [ 0, 0, 0, 1 ], 1)");
gl.disable(gl.BLEND);
checkSupportedPixelFormatAndType();
var formats = [ gl.RGBA ];
var formatNames = [ "RGBA" ];
debug("Testing format = RGBA and type = UNSIGNED_BYTE");
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 1, 1, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 2, 1, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 1, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 1, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 2, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 2, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 3, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 3, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 4, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 4, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 5, 1);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 5, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 5, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 6, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 7, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 8, 2);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 1, 0, 0);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 2, 0, 0);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 0, 0);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, 0, 0);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 1, -1, 1);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 2, 1, -1);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 4, 0, -1);
runTestIteration(gl.RGBA, gl.UNSIGNED_BYTE, 8, -1, -1);
debug("Testing the other supported format/type combination");
runTestIteration(pixelFormat, pixelType, 1, 1, 2);
runTestIteration(pixelFormat, pixelType, 2, 1, 2);
runTestIteration(pixelFormat, pixelType, 4, 1, 2);
runTestIteration(pixelFormat, pixelType, 8, 1, 2);
runTestIteration(pixelFormat, pixelType, 4, 2, 2);
runTestIteration(pixelFormat, pixelType, 8, 2, 2);
runTestIteration(pixelFormat, pixelType, 4, 3, 2);
runTestIteration(pixelFormat, pixelType, 8, 3, 2);
runTestIteration(pixelFormat, pixelType, 4, 4, 2);
runTestIteration(pixelFormat, pixelType, 8, 4, 2);
runTestIteration(pixelFormat, pixelType, 8, 5, 1);
runTestIteration(pixelFormat, pixelType, 4, 5, 2);
runTestIteration(pixelFormat, pixelType, 8, 5, 2);
runTestIteration(pixelFormat, pixelType, 8, 6, 2);
runTestIteration(pixelFormat, pixelType, 8, 7, 2);
runTestIteration(pixelFormat, pixelType, 8, 8, 2);
runTestIteration(pixelFormat, pixelType, 1, 0, 0);
runTestIteration(pixelFormat, pixelType, 2, 0, 0);
runTestIteration(pixelFormat, pixelType, 4, 0, 0);
runTestIteration(pixelFormat, pixelType, 8, 0, 0);
runTestIteration(pixelFormat, pixelType, 1, -1, 1);
runTestIteration(pixelFormat, pixelType, 2, 1, -1);
runTestIteration(pixelFormat, pixelType, 4, 0, -1);
runTestIteration(pixelFormat, pixelType, 8, -1, -1);
for (var i = 0; i < formats.length; ++i) {
var format = formats[i];
debug("Testing format = " + formatNames[i] + " and type = UNSIGNED_BYTE");
runTestIteration(format, gl.UNSIGNED_BYTE, 1, 1, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 2, 1, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 1, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 1, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 2, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 2, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 3, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 3, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 4, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 4, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 5, 1);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 5, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 5, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 6, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 7, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 8, 2);
runTestIteration(format, gl.UNSIGNED_BYTE, 1, 0, 0);
runTestIteration(format, gl.UNSIGNED_BYTE, 2, 0, 0);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 0, 0);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, 0, 0);
runTestIteration(format, gl.UNSIGNED_BYTE, 1, -1, 1);
runTestIteration(format, gl.UNSIGNED_BYTE, 2, 1, -1);
runTestIteration(format, gl.UNSIGNED_BYTE, 4, 0, -1);
runTestIteration(format, gl.UNSIGNED_BYTE, 8, -1, -1);
}
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>

View File

@ -11,6 +11,7 @@ found in the LICENSE file.
<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 src="resources/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="200" height="200"></canvas>
@ -19,6 +20,7 @@ found in the LICENSE file.
<script>
description("Checks that ReadPixels works as expected.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("example");
var gl = create3DContext(canvas);
@ -90,6 +92,56 @@ function checkBuffer(checkColor, x, y, oneColor, oneX, oneY) {
}
}
var badFormats = [
{
format: gl.RGB,
type: gl.UNSIGNED_BYTE,
dest: new Uint8Array(3)
},
{
format: gl.RGB,
type: gl.UNSIGNED_SHORT_5_6_5,
dest: new Uint8Array(3)
},
{
format: gl.RGBA,
type: gl.UNSIGNED_SHORT_5_5_5_1,
dest: new Uint16Array(1)
},
{
format: gl.RGBA,
type: gl.UNSIGNED_SHORT_4_4_4_4,
dest: new Uint16Array(1)
},
{
format: gl.ALPHA,
type: gl.UNSIGNED_BYTE,
dest: new Uint8Array(1)
},
{
format: gl.LUMINANCE,
type: gl.UNSIGNED_BYTE,
dest: new Uint8Array(1) },
{
format: gl.LUMINANCE_ALPHA,
type: gl.UNSIGNED_BYTE,
dest: new Uint8Array(2)
}
];
for (var tt = 0; tt < badFormats.length; ++ tt) {
var info = badFormats[tt]
var format = info.format;
var type = info.type;
var dest = info.dest;
gl.readPixels(0, 0, 1, 1, format, type, dest);
// note that the GL error is INVALID_OPERATION if both format and type are invalid, but
// INVALID_ENUM if only one is.
glErrorShouldBe(
gl, (format == gl.RGBA || type == gl.UNSIGNED_BYTE) ? gl.INVALID_ENUM : gl.INVALID_OPERATION,
"Should not be able to read as " + wtu.glEnumToString(gl, format) +
" / " + wtu.glEnumToString(gl, type));
}
debug("");
successfullyParsed = true;
</script>

View File

@ -12,7 +12,7 @@ found in the LICENSE file.
function runTest()
{
var canvas = document.getElementById("testbed");
var gl = canvas.getContext("experimental-webgl");
var gl = create3DContext(canvas);
if (!gl) {
testFailed('canvas.getContext() failed');
return false;

View File

@ -9,46 +9,18 @@ found in the LICENSE file.
<script src="../resources/js-test-pre.js"></script>
<script src="resources/webgl-test.js"></script>
<script src="resources/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="1px" height="2px"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
description('Verifies texImage2D and texSubImage2D code paths taking ArrayBufferView');
var wtu = WebGLTestUtils;
var gl = null;
var textureLoc = null;
var successfullyParsed = false;
var imageData = null;
function init()
{
if (window.initNonKhronosFramework) {
window.initNonKhronosFramework(true);
}
description('Verifies texImage2D and texSubImage2D code paths taking ArrayBufferView');
var canvas2d = document.getElementById("texcanvas");
var context2d = canvas2d.getContext("2d");
imageData = context2d.createImageData(1, 2);
var data = imageData.data;
data[0] = 255;
data[1] = 0;
data[2] = 0;
data[3] = 255;
data[4] = 0;
data[5] = 255;
data[6] = 0;
data[7] = 0;
var canvas = document.getElementById("example");
gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
gl.disable(gl.BLEND);
gl.clearColor(0,0,0,1);
gl.clearDepth(1);
textureLoc = gl.getUniformLocation(program, "tex");
runTest();
}
// These two declarations need to be global for "shouldBe" to see them
var buf = null;
@ -199,24 +171,21 @@ function runTest()
}
}
successfullyParsed = true;
var epilogue = document.createElement("script");
epilogue.onload = finish;
epilogue.src = "../resources/js-test-post.js";
document.body.appendChild(epilogue);
}
function finish() {
if (window.nonKhronosFrameworkNotifyDone) {
window.nonKhronosFrameworkNotifyDone();
}
}
var canvas = document.getElementById("example");
gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
gl.disable(gl.BLEND);
gl.clearColor(0,0,0,1);
gl.clearDepth(1);
textureLoc = gl.getUniformLocation(program, "tex");
runTest();
successfullyParsed = true;
</script>
</head>
<body onload="init()">
<canvas id="texcanvas" width="1px" height="2px"></canvas>
<canvas id="example" width="1px" height="2px"></canvas>
<div id="description"></div>
<div id="console"></div>
<script src="../resources/js-test-post.js"></script>
</body>
</html>

View File

@ -6,13 +6,12 @@
<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 src="resources/testrunner.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script><!--
<script type="text/javascript">
description("texImage2D and texSubImage2D tests with invalid data");
var canvas = document.getElementById("canvas");
@ -22,63 +21,79 @@ if (!gl)
else
testPassed("Context created.");
var tex;
/* object containing all tests in this testsuite */
var bug32619_tests = {
setup: function () {
bug32619_tests.tex = gl.createTexture();
function setup() {
tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, bug32619_tests.tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
},
teardown: function () {
gl.deleteTexture(bug32619_tests.tex);
},
"Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION" : function () {
this.setup = function () {
var tooSmall = new Uint8Array(64);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
};
this.expects = gl.INVALID_OPERATION;
},
"Passing texImage2D parameter data of Number type should throw a TypeError" : function () {
this.setup = function () {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
};
this.expects = "TypeError";
},
"Passing texImage2D parameter data of String type should throw a TypeError" : function () {
this.setup = function () {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
};
this.expects = "TypeError";
},
"Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION" : function () {
this.setup = function () {
var tooSmall = new Uint8Array(64);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
};
this.expects = gl.INVALID_OPERATION;
},
"Passing texSubImage2D parameter data of Number type should throw a TypeError" : function () {
this.setup = function () {
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
};
this.expects = "TypeError";
},
"Passing texSubImage2D parameter data of String type should throw a TypeError" : function () {
this.setup = function () {
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
};
this.expects = "TypeError";
},
}
runTestsuite(bug32619_tests);
function teardown() {
gl.deleteTexture(tex);
}
function test(desc, func, expected) {
debug(desc);
var exc = null;
try {
func();
} catch (x) {
exc = x;
}
if (expected == gl.INVALID_OPERATION) {
glErrorShouldBe(gl, expected);
} else if (expected == "exception") {
if (exc) {
testPassed("threw exception");
} else {
testFailed("did not throw exception");
}
}
}
test("Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
function () {
var tooSmall = new Uint8Array(64);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
},
gl.INVALID_OPERATION);
test("Passing texImage2D parameter data of Number type should throw an exception",
function () {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
},
"exception");
test("Passing texImage2D parameter data of String type should throw a TypeError",
function () {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
},
"exception");
test("Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
function () {
var tooSmall = new Uint8Array(64);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
},
gl.INVALID_OPERATION);
test("Passing texSubImage2D parameter data of Number type should throw a TypeError",
function () {
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
},
"exception");
test("Passing texSubImage2D parameter data of String type should throw a TypeError",
function () {
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
},
"exception");
debug("");
successfullyParsed = true;
--></script>
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>

View File

@ -51,7 +51,7 @@ function init()
var canvas = document.getElementById("example");
gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
gl.clearColor(0,0,0,1);
gl.clearColor(0.5,0.5,0.5,1);
gl.clearDepth(1);
textureLoc = gl.getUniformLocation(program, "tex");
@ -70,7 +70,7 @@ function init()
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, gl.FALSE, 0, 0);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
texture = wtu.loadTexture(gl, "resources/bug-32888-texture.png", runTest);
}
@ -82,16 +82,18 @@ var idx = 0;
function runTest()
{
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
// Bind the texture to texture unit 0
gl.bindTexture(gl.TEXTURE_2D, texture);
// Point the uniform sampler to texture unit 0
gl.uniform1i(textureLoc, 0);
// Draw the triangles
wtu.drawQuad(gl, [100, 100, 100, 255]);
wtu.drawQuad(gl, [0, 0, 0, 255]);
// Spot check a couple of 2x2 regions in the upper and lower left
// corners; they should be the rgb values in the texture.
color = [255, 255, 255]
color = [0, 0, 0];
debug("Checking lower left corner");
wtu.checkCanvasRect(gl, 1, gl.canvas.height - 3, 2, 2, color,
"shouldBe " + color);

View File

@ -0,0 +1,168 @@
<!--
Copyright (C) 2009 Apple Computer, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<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 src="resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
var wtu = WebGLTestUtils;
description("Tests calling WebGL APIs with various types");
var context = wtu.create3DContext();
var program = wtu.loadStandardProgram(context);
var shader = wtu.loadStandardVertexShader(context);
var shouldGenerateGLError = wtu.shouldGenerateGLError;
assertMsg(program != null, "Program Compiled");
assertMsg(shader != null, "Shader Compiled");
var loc = context.getUniformLocation(program, "u_modelViewProjMatrix");
assertMsg(loc != null, "getUniformLocation succeeded");
var buffer = context.createBuffer();
context.bindBuffer(context.ARRAY_BUFFER, buffer);
var texture = context.createTexture();
context.bindTexture(context.TEXTURE_2D, texture);
context.useProgram(program);
var args = [
{ type: "number", value: 0 },
{ type: "number", value: 2 },
{ type: "string that is NaN", value: "foo", },
{ type: "string that is number", value: "2", },
{ type: "null", value: null },
{ type: "Empty Array", value: [] },
{ type: "Object", value: {} },
{ type: "Array of Number", value: [2] },
{ type: "Array of String", value: ["foo"] },
{ type: "Array of String that is number", value: ["0"] },
{ type: "Array of String that is number", value: ["2"] },
{ type: "TypedArray", value: new Float32Array(1) }
];
var argument;
for (var i = 0; i < args.length; ++i) {
argument = args[i].value;
var func1 = shouldBeUndefined;
var func2 = shouldBeNonNull;
if (argument == 2) {
func2 = shouldBeNull;
}
func3 = shouldBeNull;
debug("");
debug("testing type of " + args[i].type + " : value = " + argument);
func1("context.bindAttribLocation(program, argument, 'foo')");
func1("context.blendColor(argument, argument, argument, argument)");
func1("context.bufferData(context.ARRAY_BUFFER, argument, context.STATIC_DRAW)");
func1("context.bufferData(context.ARRAY_BUFFER, new Float32Array(10), context.STATIC_DRAW)");
func1("context.bufferSubData(context.ARRAY_BUFFER, argument, new Float32Array(2))");
func1("context.clear(argument)")
func1("context.clearColor(argument, 0, 0, 0)");
func1("context.clearColor(0, argument, 0, 0)");
func1("context.clearColor(0, 0, argument, 0)");
func1("context.clearColor(0, 0, 0, argument)");
func1("context.clearDepth(argument)");
func1("context.clearStencil(argument)");
func1("context.copyTexImage2D(context.TEXTURE_2D, argument, context.RGBA, 0, 0, 1, 1, 0)");
func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, argument, 0, 1, 1, 0)");
func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, argument, 1, 1, 0)");
func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, argument, 1, 0)");
func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, 0, argument, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, argument, 0, 0, 0, 0, 0, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, argument, 0, 0, 0, 0, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, argument, 0, 0, 0, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, argument, 0, 0, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, argument, 0, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, argument, 0)");
func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, 0, argument)");
func1("context.depthMask(argument)");
func1("context.depthRange(argument, 1)");
func1("context.depthRange(0, argument)");
func1("context.drawArrays(context.POINTS, argument, 1)");
func1("context.drawArrays(context.POINTS, 0, argument)");
//func1("context.drawElements(...)");
func1("context.enableVertexAttribArray(argument)");
func1("context.disableVertexAttribArray(argument)");
func2("context.getActiveAttrib(program, argument)");
func2("context.getActiveUniform(program, argument)");
func3("context.getParameter(argument)");
func1("context.lineWidth(argument)");
func1("context.polygonOffset(argument, 0)");
func1("context.polygonOffset(0, argument)");
//func1("context.readPixels(...)");
//func1("context.renderbufferStorage(...)");
func1("context.sampleCoverage(argument, 0)");
func1("context.sampleCoverage(0, argument)");
func1("context.scissor(argument, 0, 10, 10)");
func1("context.scissor(0, argument, 10, 10)");
func1("context.scissor(0, 0, argument, 10)");
func1("context.scissor(0, 0, 10, argument)");
func1("context.shaderSource(shader, argument)");
func1("context.stencilFunc(context.NEVER, argument, 255)");
func1("context.stencilFunc(context.NEVER, 0, argument)");
//func1("context.stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)");
func1("context.stencilMask(argument)");
//func1("context.stencilMaskSeparate(context.FRONT, argument);
//func1("context.texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView pixels)");
//func1("context.texParameterf(GLenum target, GLenum pname, GLfloat param)");
//func1("context.texParameteri(GLenum target, GLenum pname, GLint param)");
//func1("context.texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,GLsizei width, GLsizei height,GLenum format, GLenum type, ArrayBufferView pixels)");
func1("context.uniform1i(loc, argument)");
func1("context.uniform2i(loc, argument, 0)");
func1("context.uniform2i(loc, 0, argument)");
func1("context.uniform3i(loc, argument, 0, 0)");
func1("context.uniform3i(loc, 0, argument, 0)");
func1("context.uniform3i(loc, 0, 0, argument)");
func1("context.uniform4i(loc, argument, 0, 0, 0)");
func1("context.uniform4i(loc, 0, argument, 0, 0)");
func1("context.uniform4i(loc, 0, 0, argument, 0)");
func1("context.uniform4i(loc, 0, 0, 0, argument)");
func1("context.uniform1f(loc, argument)");
func1("context.uniform2f(loc, argument, 0)");
func1("context.uniform2f(loc, 0, argument)");
func1("context.uniform3f(loc, argument, 0, 0)");
func1("context.uniform3f(loc, 0, argument, 0)");
func1("context.uniform3f(loc, 0, 0, argument)");
func1("context.uniform4f(loc, argument, 0, 0, 0)");
func1("context.uniform4f(loc, 0, argument, 0, 0)");
func1("context.uniform4f(loc, 0, 0, argument, 0)");
func1("context.uniform4f(loc, 0, 0, 0, argument)");
}
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>

View File

@ -6,13 +6,12 @@
<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 src="resources/testrunner.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script><!--
<script>
description("Tests to check user code cannot access uninitialized data from GL resources.");
var canvas = document.getElementById("canvas");
@ -23,66 +22,71 @@ else
testPassed("Context created.");
/* object containing all tests in this testsuite */
var uninitializedTests = {
"Reading an uninitialized texture should succeed with all bytes set to 0." : function () {
this._width = 512;
this._height = 512;
this._bpp = 4;
this._expectedDataLength = this._width*this._height*this._bpp;
debug("Reading an uninitialized texture should succeed with all bytes set to 0.");
this.setup = function () {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._width, this._height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var width = 512;
var height = 512;
var bpp = 4;
var expectedDataLength = width*height*bpp;
// this can be quite undeterministic so to improve odds of seeing uninitialized data write bits
// into tex then delete texture then re-create one with same characteristics (driver will likely reuse mem)
// with this trick on r59046 WebKit/OSX I get FAIL 100% of the time instead of ~15% of the time.
var badData = new Uint8Array(this._expectedDataLength);
for (var i = 0; i < badData.length; ++i) badData[i] = i % 255;
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this._width, this._height, gl.RGBA, gl.UNSIGNED_BYTE, badData);
gl.finish(); // make sure it has been uploaded
gl.deleteTexture(tex);
gl.finish(); // make sure it has been deleted
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._width, this._height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
// this can be quite undeterministic so to improve odds of seeing uninitialized data write bits
// into tex then delete texture then re-create one with same characteristics (driver will likely reuse mem)
// with this trick on r59046 WebKit/OSX I get FAIL 100% of the time instead of ~15% of the time.
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
var badData = new Uint8Array(expectedDataLength);
for (var i = 0; i < badData.length; ++i)
badData[i] = i % 255;
this.data = new Uint8Array(this._width * this._height * 4);
gl.readPixels(0, 0, this._width, this._height, gl.RGBA, gl.UNSIGNED_BYTE, this.data);
};
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, badData);
gl.finish(); // make sure it has been uploaded
this.expects = function () {
if (this.data.length !== this._expectedDataLength) {
debug("expected data length " + this._expectedDataLength + " but got " + this.data.length + " instead.");
return false;
}
for (var i = 0; i < this.data.length; ++i)
if (0 !== this.data[i]) {
debug("byte at offset " + i + " has value " + this.data[i]);
return false;
}
return true;
};
gl.deleteTexture(tex);
gl.finish(); // make sure it has been deleted
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
data = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
if (data.length != expectedDataLength) {
testFailed("expected data length " + expectedDataLength + " but got " + data.length + " instead.");
} else {
var k = 0;
for (var i = 0; i < data.length; ++i) {
if (data[i] != 0) {
k++;
}
//TODO: uninitialized vertex array buffer
//TODO: uninitialized vertex elements buffer
//TODO: uninitialized framebuffer? (implementations would need to do a GL clear at first binding?)
//TODO: uninitialized renderbuffer? (implementations would need to do a GL clear at first binding?)
//TODO: uninitialized uniform arrays?
}
if (k) {
testFailed("Found " + k + " non-zero bytes");
} else {
testPassed("All data initialized");
}
}
runTestsuite(uninitializedTests);
glErrorShouldBe(gl, gl.NO_ERROR);
//TODO: uninitialized vertex array buffer
//TODO: uninitialized vertex elements buffer
//TODO: uninitialized framebuffer? (implementations would need to do a GL clear at first binding?)
//TODO: uninitialized renderbuffer? (implementations would need to do a GL clear at first binding?)
//TODO: uninitialized uniform arrays?
debug("");
successfullyParsed = true;
--></script>
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>

View File

@ -0,0 +1,120 @@
<!--
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.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WebGL GLES2 difference test.</title>
<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 src="resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
var wtu = WebGLTestUtils;
description("Tests the a few differences between WebGL and GLES2");
var gl = wtu.create3DContext();
gl.blendFunc(gl.CONSTANT_COLOR, gl.CONSTANT_ALPHA);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.ONE_MINUS_CONSTANT_COLOR, gl.CONSTANT_ALPHA);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.CONSTANT_ALPHA, gl.CONSTANT_COLOR);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.ONE_MINUS_CONSTANT_ALPHA, gl.CONSTANT_COLOR);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFunc(gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.CONSTANT_COLOR, gl.CONSTANT_ALPHA, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_COLOR, gl.CONSTANT_ALPHA, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.CONSTANT_ALPHA, gl.CONSTANT_COLOR, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_ALPHA, gl.CONSTANT_COLOR, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE, gl.ZERO);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"constant color and constant alpha cannot be used together as source and destination factors in the blend function");
gl.depthRange(20, 10);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"depthRange should generate INVALID_OPERATION if zNear is greater than zFar");
gl.stencilMask(255);
glErrorShouldBe(gl, gl.NO_ERROR,
"stencilMask should generate no error");
gl.stencilMaskSeparate(gl.FRONT, 1);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different mask value for front and back facing is illegal");
gl.stencilMaskSeparate(gl.BACK, 1);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different mask value for front and back facing is illegal");
gl.stencilFunc(gl.ALWAYS, 0, 255);
glErrorShouldBe(gl, gl.NO_ERROR,
"stencilFunc should generate no error");
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 255);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different reference value for front and back facing is illegal");
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 1, 255);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different reference value for front and back facing is illegal");
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 0, 1);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different mask value for front and back facing is illegal");
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 0, 1);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"a different mask value for front and back facing is illegal");
shouldBeUndefined(gl.IMPLEMENTATION_COLOR_READ_FORMAT);
shouldBeUndefined(gl.IMPLEMENTATION_COLOR_READ_TYPE);
shouldBe("gl.getParameter(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL)", "gl.BROWSER_DEFAULT_WEBGL");
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
shouldBe("gl.getParameter(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL)", "gl.NONE");
glErrorShouldBe(gl, gl.NO_ERROR,
"set/get UNPACK_COLORSPACE_CONVERSION_WEBGL should generate no error");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>