b=578509; Update our copy of the WebGL conformance test suite to svn 11955; r=vladimir
@@ -1,6 +1,6 @@
|
|||||||
This is a local copy of the WebGL conformance suite.
|
This is a local copy of the WebGL conformance suite.
|
||||||
|
|
||||||
SVN revision: 11588
|
SVN revision: 11955
|
||||||
|
|
||||||
The canonical location for this testsuite is:
|
The canonical location for this testsuite is:
|
||||||
|
|
||||||
|
|||||||
0
content/canvas/test/webgl/conformance/00_readme.txt
Normal file → Executable file
38
content/canvas/test/webgl/conformance/00_test_list.txt
Normal file → Executable file
@@ -1,19 +1,20 @@
|
|||||||
|
array-buffer-crash.html
|
||||||
|
array-buffer-view-crash.html
|
||||||
array-unit-tests.html
|
array-unit-tests.html
|
||||||
buffer-bind-test.html
|
buffer-bind-test.html
|
||||||
bug-31889.html
|
|
||||||
bug-32364.html
|
|
||||||
bug-32456.html
|
|
||||||
bug-32692.html
|
|
||||||
bug-32888.html
|
|
||||||
canvas-test.html
|
canvas-test.html
|
||||||
constants.html
|
constants.html
|
||||||
|
context-attributes-alpha-depth-stencil-antialias.html
|
||||||
|
context-attributes.html
|
||||||
context-type-test.html
|
context-type-test.html
|
||||||
|
copy-tex-image-and-sub-image-2d.html
|
||||||
draw-arrays-out-of-bounds.html
|
draw-arrays-out-of-bounds.html
|
||||||
draw-elements-out-of-bounds.html
|
draw-elements-out-of-bounds.html
|
||||||
error-reporting.html
|
error-reporting.html
|
||||||
|
framebuffer-object-attachment.html
|
||||||
framebuffer-test.html
|
framebuffer-test.html
|
||||||
get-active-test.html
|
get-active-test.html
|
||||||
gl-bindattribLocation-test.html
|
gl-bind-attrib-location-test.html
|
||||||
gl-drawelements.html
|
gl-drawelements.html
|
||||||
gl-enable-enum-test.html
|
gl-enable-enum-test.html
|
||||||
gl-enable-vertex-attrib.html
|
gl-enable-vertex-attrib.html
|
||||||
@@ -23,31 +24,50 @@ gl-object-get-calls.html
|
|||||||
gl-pixelstorei.html
|
gl-pixelstorei.html
|
||||||
gl-scissor-test.html
|
gl-scissor-test.html
|
||||||
gl-shader-test.html
|
gl-shader-test.html
|
||||||
|
gl-teximage.html
|
||||||
gl-uniform-arrays.html
|
gl-uniform-arrays.html
|
||||||
gl-uniform-bool.html
|
gl-uniform-bool.html
|
||||||
gl-uniformmatrix4fv.html
|
gl-uniformmatrix4fv.html
|
||||||
gl-unknown-uniform.html
|
gl-unknown-uniform.html
|
||||||
gl-vertexattrib.html
|
gl-vertex-attrib.html
|
||||||
gl-vertexattribpointer.html
|
gl-vertexattribpointer.html
|
||||||
gl-getstring.html
|
gl-getstring.html
|
||||||
glsl-2types-of-textures-on-same-unit.html
|
glsl-2types-of-textures-on-same-unit.html
|
||||||
glsl-conformance.html
|
glsl-conformance.html
|
||||||
incorrect-context-object-behaviour.html
|
incorrect-context-object-behaviour.html
|
||||||
index-validation-copies-indices.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
|
index-validation.html
|
||||||
|
invalid-UTF-16.html
|
||||||
methods.html
|
methods.html
|
||||||
|
more-than-65536-points.html
|
||||||
null-object-behaviour.html
|
null-object-behaviour.html
|
||||||
|
null-uniform-location.html
|
||||||
origin-clean-conformance.html
|
origin-clean-conformance.html
|
||||||
|
point-size.html
|
||||||
program-test.html
|
program-test.html
|
||||||
readpixels-test.html
|
read-pixels-pack-alignment.html
|
||||||
|
read-pixels-test.html
|
||||||
|
renderbuffer-initialization.html
|
||||||
resource-sharing-test.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-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
|
||||||
texture-active-bind.html
|
texture-active-bind.html
|
||||||
texture-active-bind-2.html
|
texture-active-bind-2.html
|
||||||
texparameter-test.html
|
texparameter-test.html
|
||||||
texture-complete.html
|
texture-complete.html
|
||||||
texture-formats-test.html
|
texture-formats-test.html
|
||||||
texture-npot.html
|
texture-npot.html
|
||||||
|
texture-transparent-pixels-initialized.html
|
||||||
triangle.html
|
triangle.html
|
||||||
uniform-location.html
|
uniform-location.html
|
||||||
uniform-samplers-test.html
|
uniform-samplers-test.html
|
||||||
|
viewport-unchanged-upon-resize.html
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<!--
|
||||||
|
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 ArrayBuffer.byteLength');
|
||||||
|
|
||||||
|
<!-- The following used to cause a crash in Chrome -->
|
||||||
|
new ArrayBuffer().byteLength;
|
||||||
|
|
||||||
|
testPassed("new ArrayBuffer().byteLength did not crash");
|
||||||
|
successfullyParsed = true;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -39,12 +39,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
description('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=31889">https://bugs.webkit.org/show_bug.cgi?id=31889</a> : <code>[v8] WebCore::WebGLArrayBufferInternal::byteLengthAttrGetter NULL pointer</code>');
|
description('Verify that constructing a typed array view with no arguments and fetching its length does not crash');
|
||||||
|
|
||||||
<!-- The following used to cause a crash in Chrome -->
|
<!-- The following used to cause a crash in both Safari and Chrome -->
|
||||||
new WebGLArrayBuffer().byteLength;
|
new Uint32Array().length;
|
||||||
|
|
||||||
testPassed("new WebGLArrayBuffer().byteLength did not crash");
|
testPassed("new Uint32Array().length did not crash");
|
||||||
successfullyParsed = true;
|
successfullyParsed = true;
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
||||||
|
Copyright (C) 2009 Apple Computer, Inc. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -36,7 +37,699 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script type="text/javascript" src="resources/array-unit-tests.js"></script>
|
<script>
|
||||||
|
|
||||||
|
description("Verifies the functionality of the new array-like objects in the TypedArray spec");
|
||||||
|
|
||||||
|
var currentlyRunning = '';
|
||||||
|
var allPassed = true;
|
||||||
|
function running(str) {
|
||||||
|
currentlyRunning = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
function output(str) {
|
||||||
|
debug(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pass() {
|
||||||
|
testPassed(currentlyRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fail(str) {
|
||||||
|
allPassed = false;
|
||||||
|
var exc;
|
||||||
|
if (str)
|
||||||
|
exc = currentlyRunning + ': ' + str;
|
||||||
|
else
|
||||||
|
exc = currentlyRunning;
|
||||||
|
testFailed(exc);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertEq(prefix, expected, val) {
|
||||||
|
if (expected != val) {
|
||||||
|
var str = prefix + ': expected ' + expected + ', got ' + val;
|
||||||
|
throw str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert(prefix, expected) {
|
||||||
|
if (!expected) {
|
||||||
|
var str = prefix + ': expected value / true';
|
||||||
|
throw str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function printSummary() {
|
||||||
|
if (allPassed) {
|
||||||
|
debug("Test passed.");
|
||||||
|
} else {
|
||||||
|
debug("TEST FAILED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tests for unsigned array variants
|
||||||
|
//
|
||||||
|
|
||||||
|
function testSetAndGet10To1(type, name) {
|
||||||
|
running('test ' + name + ' SetAndGet10To1');
|
||||||
|
try {
|
||||||
|
var array = new type(10);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
array[i] = 10 - i;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructWithArrayOfUnsignedValues(type, name) {
|
||||||
|
running('test ' + name + ' ConstructWithArrayOfUnsignedValues');
|
||||||
|
try {
|
||||||
|
var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
|
||||||
|
assertEq('Array length', 10, array.length);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructWithTypedArrayOfUnsignedValues(type, name) {
|
||||||
|
running('test ' + name + ' ConstructWithTypedArrayOfUnsignedValues');
|
||||||
|
try {
|
||||||
|
var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
|
||||||
|
var array = new type(tmp);
|
||||||
|
assertEq('Array length', 10, array.length);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tests for signed array variants
|
||||||
|
//
|
||||||
|
|
||||||
|
function testSetAndGetPos10ToNeg10(type, name) {
|
||||||
|
running('test ' + name + ' SetAndGetPos10ToNeg10');
|
||||||
|
try {
|
||||||
|
var array = new type(21);
|
||||||
|
for (var i = 0; i < 21; i++) {
|
||||||
|
array[i] = 10 - i;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 21; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructWithArrayOfSignedValues(type, name) {
|
||||||
|
running('test ' + name + ' ConstructWithArrayOfSignedValues');
|
||||||
|
try {
|
||||||
|
var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]);
|
||||||
|
assertEq('Array length', 21, array.length);
|
||||||
|
for (var i = 0; i < 21; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructWithTypedArrayOfSignedValues(type, name) {
|
||||||
|
running('test ' + name + ' ConstructWithTypedArrayOfSignedValues');
|
||||||
|
try {
|
||||||
|
var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]);
|
||||||
|
var array = new type(tmp);
|
||||||
|
assertEq('Array length', 21, array.length);
|
||||||
|
for (var i = 0; i < 21; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test cases for both signed and unsigned types
|
||||||
|
//
|
||||||
|
|
||||||
|
function testGetWithOutOfRangeIndices(type, name) {
|
||||||
|
debug('Testing ' + name + ' GetWithOutOfRangeIndices');
|
||||||
|
// See below for declaration of this global variable
|
||||||
|
array = new type([2, 3]);
|
||||||
|
shouldBeUndefined("array[2]");
|
||||||
|
shouldBeUndefined("array[-1]");
|
||||||
|
shouldBeUndefined("array[0x20000000]");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testOffsetsAndSizes(type, name, elementSizeInBytes) {
|
||||||
|
running('test ' + name + ' OffsetsAndSizes');
|
||||||
|
try {
|
||||||
|
var len = 10;
|
||||||
|
assertEq('type.BYTES_PER_ELEMENT', elementSizeInBytes, type.BYTES_PER_ELEMENT);
|
||||||
|
var array = new type(len);
|
||||||
|
assert('array.buffer', array.buffer);
|
||||||
|
assertEq('array.byteOffset', 0, array.byteOffset);
|
||||||
|
assertEq('array.length', len, array.length);
|
||||||
|
assertEq('array.byteLength', len * elementSizeInBytes, array.byteLength);
|
||||||
|
array = new type(array.buffer, elementSizeInBytes, len - 1);
|
||||||
|
assert('array.buffer', array.buffer);
|
||||||
|
assertEq('array.byteOffset', elementSizeInBytes, array.byteOffset);
|
||||||
|
assertEq('array.length', len - 1, array.length);
|
||||||
|
assertEq('array.byteLength', (len - 1) * elementSizeInBytes, array.byteLength);
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSetFromTypedArray(type, name) {
|
||||||
|
running('test ' + name + ' SetFromTypedArray');
|
||||||
|
try {
|
||||||
|
var array = new type(10);
|
||||||
|
var array2 = new type(5);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
assertEq('Element ' + i, 0, array[i]);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array2.length; i++) {
|
||||||
|
array2[i] = i;
|
||||||
|
}
|
||||||
|
array.set(array2);
|
||||||
|
for (var i = 0; i < array2.length; i++) {
|
||||||
|
assertEq('Element ' + i, i, array[i]);
|
||||||
|
}
|
||||||
|
array.set(array2, 5);
|
||||||
|
for (var i = 0; i < array2.length; i++) {
|
||||||
|
assertEq('Element ' + i, i, array[5 + i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function negativeTestSetFromTypedArray(type, name) {
|
||||||
|
running('negativeTest ' + name + ' SetFromTypedArray');
|
||||||
|
try {
|
||||||
|
var array = new type(5);
|
||||||
|
var array2 = new type(6);
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
assertEq('Element ' + i, 0, array[i]);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array2.length; i++) {
|
||||||
|
array2[i] = i;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
array.set(array2);
|
||||||
|
fail('Expected exception from array.set(array2)');
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
array2.set(array, 2);
|
||||||
|
fail('Expected exception from array2.set(array, 2)');
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSetFromArray(type, name) {
|
||||||
|
running('test ' + name + ' SetFromArray');
|
||||||
|
try {
|
||||||
|
var array = new type(10);
|
||||||
|
var array2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
assertEq('Element ' + i, 0, array[i]);
|
||||||
|
}
|
||||||
|
array.set(array2, 0);
|
||||||
|
for (var i = 0; i < array2.length; i++) {
|
||||||
|
assertEq('Element ' + i, 10 - i, array[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function negativeTestSetFromArray(type, name) {
|
||||||
|
running('negativeTest ' + name + ' SetFromArray');
|
||||||
|
try {
|
||||||
|
var array = new type([2, 3]);
|
||||||
|
try {
|
||||||
|
array.set([4, 5], 1);
|
||||||
|
fail();
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
array.set([4, 5, 6]);
|
||||||
|
fail();
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSlice(type, name) {
|
||||||
|
running('test ' + name + ' Slice');
|
||||||
|
try {
|
||||||
|
var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||||
|
var slice = array.slice(0, 5);
|
||||||
|
assertEq('slice.length', 5, slice.length);
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
assertEq('Element ' + i, i, slice[i]);
|
||||||
|
}
|
||||||
|
slice = array.slice(4, 10);
|
||||||
|
assertEq('slice.length', 6, slice.length);
|
||||||
|
for (var i = 0; i < 6; i++) {
|
||||||
|
assertEq('Element ' + i, 4 + i, slice[i]);
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function negativeTestSlice(type, name) {
|
||||||
|
running('negativeTest ' + name + ' Slice');
|
||||||
|
try {
|
||||||
|
var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||||
|
slice = array.slice(5, 11);
|
||||||
|
if (slice.length != 5) {
|
||||||
|
fail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
slice = array.slice(10, 10);
|
||||||
|
if (slice.length != 0) {
|
||||||
|
fail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBoundaryConditions(type, name, lowValue, expectedLowValue, highValue, expectedHighValue) {
|
||||||
|
running('test ' + name + ' BoundaryConditions(' +
|
||||||
|
lowValue + ', ' + expectedLowValue + ', ' +
|
||||||
|
highValue + ', ' + expectedHighValue + ')');
|
||||||
|
try {
|
||||||
|
var array = new type(1);
|
||||||
|
assertEq('Array length', 1, array.length);
|
||||||
|
array[0] = lowValue;
|
||||||
|
assertEq('Element 0', expectedLowValue, array[0]);
|
||||||
|
array[0] = highValue;
|
||||||
|
assertEq('Element 0', expectedHighValue, array[0]);
|
||||||
|
pass();
|
||||||
|
} catch (e) {
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructionWithNullBuffer(type, name) {
|
||||||
|
var array;
|
||||||
|
try {
|
||||||
|
array = new type(null);
|
||||||
|
testFailed("Construction of " + name + " with null buffer should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of " + name + " with null buffer threw exception");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
array = new type(null, 0, 0);
|
||||||
|
testFailed("Construction of " + name + " with (null buffer, 0) should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of " + name + " with (null buffer, 0) threw exception");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
array = new type(null, 0, 0);
|
||||||
|
testFailed("Construction of " + name + " with (null buffer, 0, 0) should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of " + name + " with (null buffer, 0, 0) threw exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldThrowIndexSizeErr(func, text) {
|
||||||
|
var errorText = text + " should throw INDEX_SIZE_ERR exception";
|
||||||
|
try {
|
||||||
|
func();
|
||||||
|
testFailed(errorText);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code != DOMException.INDEX_SIZE_ERR) {
|
||||||
|
testFailed(errorText);
|
||||||
|
} else {
|
||||||
|
testPassed(text + " threw INDEX_SIZE_ERR exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructionWithOutOfRangeValues(type, name) {
|
||||||
|
shouldThrowIndexSizeErr(function() {
|
||||||
|
var buffer = new ArrayBuffer(4);
|
||||||
|
var array = new type(buffer, 4, 0x3FFFFFFF);
|
||||||
|
}, "Construction of " + name + " with out-of-range values");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructionWithNegativeOutOfRangeValues(type, name) {
|
||||||
|
try {
|
||||||
|
var buffer = new ArrayBuffer(-1);
|
||||||
|
testFailed("Construction of ArrayBuffer with negative size should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of ArrayBuffer with negative size threw exception");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var array = new type(-1);
|
||||||
|
testFailed("Construction of " + name + " with negative size should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of " + name + " with negative size threw exception");
|
||||||
|
}
|
||||||
|
shouldThrowIndexSizeErr(function() {
|
||||||
|
var buffer = new ArrayBuffer(4);
|
||||||
|
var array = new type(buffer, 4, -2147483648);
|
||||||
|
}, "Construction of " + name + " with negative out-of-range values");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructionWithUnalignedOffset(type, name, elementSizeInBytes) {
|
||||||
|
if (elementSizeInBytes > 1) {
|
||||||
|
shouldThrowIndexSizeErr(function() {
|
||||||
|
var buffer = new ArrayBuffer(32);
|
||||||
|
var array = new type(buffer, 1, elementSizeInBytes);
|
||||||
|
}, "Construction of " + name + " with unaligned offset");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConstructionOfHugeArray(type, name, sz) {
|
||||||
|
if (sz == 1)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
// Construction of huge arrays must fail because byteLength is
|
||||||
|
// an unsigned long
|
||||||
|
array = new type(3000000000);
|
||||||
|
testFailed("Construction of huge " + name + " should throw exception");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Construction of huge " + name + " threw exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// These need to be global for shouldBe to see them
|
||||||
|
var array;
|
||||||
|
var typeSize;
|
||||||
|
|
||||||
|
function testSlicingWithOutOfRangeValues(type, name, sz) {
|
||||||
|
debug("Testing slicing of " + name);
|
||||||
|
try {
|
||||||
|
var buffer = new ArrayBuffer(32);
|
||||||
|
array = new type(buffer);
|
||||||
|
typeSize = sz;
|
||||||
|
shouldBe("array.length", "32 / typeSize");
|
||||||
|
try {
|
||||||
|
shouldBe("array.slice(4, 0x3FFFFFFF).length", "(32 / typeSize) - 4");
|
||||||
|
shouldBe("array.slice(4, -2147483648).length", "0");
|
||||||
|
// Test slice() against overflows.
|
||||||
|
array = array.slice(2);
|
||||||
|
if (sz > 1) {
|
||||||
|
// Full byte offset is +1 larger than the maximum unsigned long int.
|
||||||
|
// Make sure slice() still handles it correctly. Otherwise overflow would happen and
|
||||||
|
// offset would be 0, and array.length array.length would incorrectly be 1.
|
||||||
|
var start = 4294967296 / sz - 2;
|
||||||
|
array = array.slice(start, start + 1);
|
||||||
|
shouldBe("array.length", "0");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
testFailed("Slicing of " + name + " threw exception");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
testFailed("Exception: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSlicingWithDefaultValues(type, name, sz) {
|
||||||
|
debug("Testing slicing with default inputs of " + name);
|
||||||
|
try {
|
||||||
|
var buffer = new ArrayBuffer(32);
|
||||||
|
array = new type(buffer);
|
||||||
|
typeSize = sz;
|
||||||
|
shouldBe("array.length", "32 / typeSize");
|
||||||
|
try {
|
||||||
|
shouldBe("array.slice().length", "(32 / typeSize)");
|
||||||
|
shouldBe("array.slice(2).length", "(32 / typeSize) - 2");
|
||||||
|
shouldBe("array.slice(-2).length", "2");
|
||||||
|
shouldBe("array.slice(-2147483648).length", "(32 / typeSize)");
|
||||||
|
} catch (e) {
|
||||||
|
testFailed("Slicing of " + name + " threw exception");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
testFailed("Exception: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSettingFromArrayWithOutOfRangeOffset(type, name) {
|
||||||
|
var webglArray = new type(32);
|
||||||
|
var array = [];
|
||||||
|
for (var i = 0; i < 16; i++) {
|
||||||
|
array.push(i);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
webglArray.set(array, 0x7FFFFFF8);
|
||||||
|
testFailed("Setting " + name + " from array with out-of-range offset was not caught");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Setting " + name + " from array with out-of-range offset was caught");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSettingFromFakeArrayWithOutOfRangeLength(type, name) {
|
||||||
|
var webglArray = new type(32);
|
||||||
|
var array = {};
|
||||||
|
array.length = 0x80000000;
|
||||||
|
try {
|
||||||
|
webglArray.set(array, 8);
|
||||||
|
testFailed("Setting " + name + " from fake array with invalid length was not caught");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Setting " + name + " from fake array with invalid length was caught");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSettingFromTypedArrayWithOutOfRangeOffset(type, name) {
|
||||||
|
var webglArray = new type(32);
|
||||||
|
var srcArray = new type(16);
|
||||||
|
for (var i = 0; i < 16; i++) {
|
||||||
|
srcArray[i] = i;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
webglArray.set(srcArray, 0x7FFFFFF8);
|
||||||
|
testFailed("Setting " + name + " from " + name + " with out-of-range offset was not caught");
|
||||||
|
} catch (e) {
|
||||||
|
testPassed("Setting " + name + " from " + name + " with out-of-range offset was caught");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function negativeTestGetAndSetMethods(type, name) {
|
||||||
|
array = new type([2, 3]);
|
||||||
|
shouldBeUndefined("array.get");
|
||||||
|
var exceptionThrown = false;
|
||||||
|
// We deliberately check for an exception here rather than using
|
||||||
|
// shouldThrow here because the precise contents of the syntax
|
||||||
|
// error are not specified.
|
||||||
|
try {
|
||||||
|
webGLArray.set(0, 1);
|
||||||
|
} catch (e) {
|
||||||
|
exceptionThrown = true;
|
||||||
|
}
|
||||||
|
var output = "array.set(0, 1) ";
|
||||||
|
if (exceptionThrown) {
|
||||||
|
testPassed(output + "threw exception.");
|
||||||
|
} else {
|
||||||
|
testFailed(output + "did not throw exception.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test driver
|
||||||
|
//
|
||||||
|
|
||||||
|
function runTests() {
|
||||||
|
allPassed = true;
|
||||||
|
|
||||||
|
// The "name" attribute is a concession to browsers which don't
|
||||||
|
// implement the "name" property on function objects
|
||||||
|
var testCases =
|
||||||
|
[ {name: "Float32Array",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: -500.5,
|
||||||
|
expectedLow: -500.5,
|
||||||
|
high: 500.5,
|
||||||
|
expectedHigh: 500.5},
|
||||||
|
{name: "Int8Array",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 1,
|
||||||
|
low: -128,
|
||||||
|
expectedLow: -128,
|
||||||
|
high: 127,
|
||||||
|
expectedHigh: 127},
|
||||||
|
{name: "Int16Array",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 2,
|
||||||
|
low: -32768,
|
||||||
|
expectedLow: -32768,
|
||||||
|
high: 32767,
|
||||||
|
expectedHigh: 32767},
|
||||||
|
{name: "Int32Array",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: -2147483648,
|
||||||
|
expectedLow: -2147483648,
|
||||||
|
high: 2147483647,
|
||||||
|
expectedHigh: 2147483647},
|
||||||
|
{name: "Uint8Array",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 1,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 255,
|
||||||
|
expectedHigh: 255},
|
||||||
|
{name: "Uint16Array",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 2,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 65535,
|
||||||
|
expectedHigh: 65535},
|
||||||
|
{name: "Uint32Array",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 4294967295,
|
||||||
|
expectedHigh: 4294967295},
|
||||||
|
|
||||||
|
// Legacy names of these types. Left here only to catch breakage
|
||||||
|
// until the WebGLArray aliases are removed completely. (FIXME)
|
||||||
|
{name: "WebGLByteArray",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 1,
|
||||||
|
low: -128,
|
||||||
|
expectedLow: -128,
|
||||||
|
high: 127,
|
||||||
|
expectedHigh: 127},
|
||||||
|
{name: "WebGLFloatArray",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: -500.5,
|
||||||
|
expectedLow: -500.5,
|
||||||
|
high: 500.5,
|
||||||
|
expectedHigh: 500.5},
|
||||||
|
{name: "WebGLIntArray",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: -2147483648,
|
||||||
|
expectedLow: -2147483648,
|
||||||
|
high: 2147483647,
|
||||||
|
expectedHigh: 2147483647},
|
||||||
|
{name: "WebGLShortArray",
|
||||||
|
unsigned: false,
|
||||||
|
elementSizeInBytes: 2,
|
||||||
|
low: -32768,
|
||||||
|
expectedLow: -32768,
|
||||||
|
high: 32767,
|
||||||
|
expectedHigh: 32767},
|
||||||
|
{name: "WebGLUnsignedByteArray",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 1,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 255,
|
||||||
|
expectedHigh: 255},
|
||||||
|
{name: "WebGLUnsignedIntArray",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 4,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 4294967295,
|
||||||
|
expectedHigh: 4294967295},
|
||||||
|
{name: "WebGLUnsignedShortArray",
|
||||||
|
unsigned: true,
|
||||||
|
elementSizeInBytes: 2,
|
||||||
|
low: 0,
|
||||||
|
expectedLow: 0,
|
||||||
|
high: 65535,
|
||||||
|
expectedHigh: 65535} ];
|
||||||
|
|
||||||
|
for (var i = 0; i < testCases.length; i++) {
|
||||||
|
var testCase = testCases[i];
|
||||||
|
running(testCase.name);
|
||||||
|
if (!(testCase.name in window)) {
|
||||||
|
fail("does not exist");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var type = window[testCase.name];
|
||||||
|
var name = testCase.name;
|
||||||
|
if (testCase.unsigned) {
|
||||||
|
testSetAndGet10To1(type, name);
|
||||||
|
testConstructWithArrayOfUnsignedValues(type, name);
|
||||||
|
testConstructWithTypedArrayOfUnsignedValues(type, name);
|
||||||
|
} else {
|
||||||
|
testSetAndGetPos10ToNeg10(type, name);
|
||||||
|
testConstructWithArrayOfSignedValues(type, name);
|
||||||
|
testConstructWithTypedArrayOfSignedValues(type, name);
|
||||||
|
}
|
||||||
|
testGetWithOutOfRangeIndices(type, name);
|
||||||
|
testOffsetsAndSizes(type, name, testCase.elementSizeInBytes);
|
||||||
|
testSetFromTypedArray(type, name);
|
||||||
|
negativeTestSetFromTypedArray(type, name);
|
||||||
|
testSetFromArray(type, name);
|
||||||
|
negativeTestSetFromArray(type, name);
|
||||||
|
testSlice(type, name);
|
||||||
|
negativeTestSlice(type, name);
|
||||||
|
testBoundaryConditions(type,
|
||||||
|
name,
|
||||||
|
testCase.low,
|
||||||
|
testCase.expectedLow,
|
||||||
|
testCase.high,
|
||||||
|
testCase.expectedHigh);
|
||||||
|
testConstructionWithNullBuffer(type, name);
|
||||||
|
testConstructionWithOutOfRangeValues(type, name);
|
||||||
|
testConstructionWithNegativeOutOfRangeValues(type, name);
|
||||||
|
testConstructionWithUnalignedOffset(type, name, testCase.elementSizeInBytes);
|
||||||
|
testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes);
|
||||||
|
testSlicingWithOutOfRangeValues(type, name, testCase.elementSizeInBytes);
|
||||||
|
testSlicingWithDefaultValues(type, name, testCase.elementSizeInBytes);
|
||||||
|
testSettingFromArrayWithOutOfRangeOffset(type, name);
|
||||||
|
testSettingFromFakeArrayWithOutOfRangeLength(type, name);
|
||||||
|
testSettingFromTypedArrayWithOutOfRangeOffset(type, name);
|
||||||
|
negativeTestGetAndSetMethods(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
printSummary();
|
||||||
|
}
|
||||||
|
|
||||||
|
runTests();
|
||||||
|
successfullyParsed = true;
|
||||||
|
|
||||||
|
</script>
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* 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.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"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 THE COPYRIGHT
|
|
||||||
OWNER 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>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="description"></div>
|
|
||||||
<div id="console"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
description('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=32456">https://bugs.webkit.org/show_bug.cgi?id=32456</a> : <code>Errors in WebGL[T]Array set() and get() methods</code>');
|
|
||||||
|
|
||||||
debug("Testing WebGLFloatArray get / set");
|
|
||||||
var array = new WebGLFloatArray([1.5]);
|
|
||||||
shouldBe("array.get(0)", "1.5");
|
|
||||||
shouldBe("array[0]", "1.5");
|
|
||||||
shouldBeUndefined("array.set(0, 2.5)");
|
|
||||||
shouldBe("array.get(0)", "2.5");
|
|
||||||
shouldBe("array[0]", "2.5");
|
|
||||||
|
|
||||||
debug("Testing WebGLByteArray get / set");
|
|
||||||
array = new WebGLByteArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, 127)");
|
|
||||||
shouldBe("array.get(0)", "127");
|
|
||||||
shouldBe("array[0]", "127");
|
|
||||||
shouldBeUndefined("array.set(0, -128)");
|
|
||||||
shouldBe("array.get(0)", "-128");
|
|
||||||
shouldBe("array[0]", "-128");
|
|
||||||
|
|
||||||
debug("Testing WebGLUnsignedByteArray get / set");
|
|
||||||
array = new WebGLUnsignedByteArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, 255)");
|
|
||||||
shouldBe("array.get(0)", "255");
|
|
||||||
shouldBe("array[0]", "255");
|
|
||||||
|
|
||||||
debug("Testing WebGLShortArray get / set");
|
|
||||||
array = new WebGLShortArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, 32767)");
|
|
||||||
shouldBe("array.get(0)", "32767");
|
|
||||||
shouldBe("array[0]", "32767");
|
|
||||||
shouldBeUndefined("array.set(0, -32768)");
|
|
||||||
shouldBe("array.get(0)", "-32768");
|
|
||||||
shouldBe("array[0]", "-32768");
|
|
||||||
|
|
||||||
debug("Testing WebGLUnsignedShortArray get / set");
|
|
||||||
array = new WebGLUnsignedShortArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, 65535)");
|
|
||||||
shouldBe("array.get(0)", "65535");
|
|
||||||
shouldBe("array[0]", "65535");
|
|
||||||
|
|
||||||
debug("Testing WebGLIntArray get / set");
|
|
||||||
array = new WebGLIntArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, -2147483648)");
|
|
||||||
shouldBe("array.get(0)", "-2147483648");
|
|
||||||
shouldBe("array[0]", "-2147483648");
|
|
||||||
shouldBeUndefined("array.set(0, 2147483647)");
|
|
||||||
shouldBe("array.get(0)", "2147483647");
|
|
||||||
shouldBe("array[0]", "2147483647");
|
|
||||||
|
|
||||||
debug("Testing WebGLUnsignedIntArray get / set");
|
|
||||||
array = new WebGLUnsignedIntArray(1);
|
|
||||||
shouldBeUndefined("array.set(0, 4294967295)");
|
|
||||||
shouldBe("array.get(0)", "4294967295");
|
|
||||||
shouldBe("array[0]", "4294967295");
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
||||||
<title>WebKit Bug #32619 regression 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/testrunner.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="description"></div>
|
|
||||||
<div id="console"></div>
|
|
||||||
<canvas id="canvas" width="2" height="2"> </canvas>
|
|
||||||
<script><!--
|
|
||||||
description("WebKit Bug #32619 regression test.");
|
|
||||||
|
|
||||||
var canvas = document.getElementById("canvas");
|
|
||||||
var gl = create3DContext(canvas);
|
|
||||||
if (!gl)
|
|
||||||
testFailed("Context created.");
|
|
||||||
else
|
|
||||||
testPassed("Context created.");
|
|
||||||
|
|
||||||
|
|
||||||
/* object containing all tests in this testsuite */
|
|
||||||
var bug32619_tests = {
|
|
||||||
setup: function () {
|
|
||||||
bug32619_tests.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 WebGLUnsignedByteArray(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 WebGLUnsignedByteArray(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);
|
|
||||||
|
|
||||||
debug("");
|
|
||||||
successfullyParsed = true;
|
|
||||||
--></script>
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
|
||||||
<script>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* 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.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"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 THE COPYRIGHT
|
|
||||||
OWNER 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>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="description"></div>
|
|
||||||
<div id="console"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
description('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=32692">https://bugs.webkit.org/show_bug.cgi?id=32692</a> : <code>Index validation for drawElements examines too many indices</code>');
|
|
||||||
|
|
||||||
var context = create3DContext();
|
|
||||||
var program = loadStandardProgram(context);
|
|
||||||
|
|
||||||
context.useProgram(program);
|
|
||||||
var vertexObject = context.createBuffer();
|
|
||||||
context.enableVertexAttribArray(0);
|
|
||||||
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
|
||||||
// 4 vertices -> 2 triangles
|
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW);
|
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
|
||||||
|
|
||||||
var indexObject = context.createBuffer();
|
|
||||||
|
|
||||||
debug("Test out of range indices")
|
|
||||||
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
|
||||||
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray([ 10000, 0, 1, 2, 3, 10000 ]), context.STATIC_DRAW);
|
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)");
|
|
||||||
|
|
||||||
debug("")
|
|
||||||
successfullyParsed = true;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
2
content/canvas/test/webgl/conformance/canvas-test.html
Normal file → Executable file
@@ -37,7 +37,7 @@ if (!gl) {
|
|||||||
debug("");
|
debug("");
|
||||||
debug("Checking canvas and WebGL interaction");
|
debug("Checking canvas and WebGL interaction");
|
||||||
|
|
||||||
// Check that a canvas with no width or height is 300x300 pixels
|
// Check that a canvas with no width or height is 300x150 pixels
|
||||||
shouldBe('canvas.width', '300');
|
shouldBe('canvas.width', '300');
|
||||||
shouldBe('canvas.height', '150');
|
shouldBe('canvas.height', '150');
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,316 @@
|
|||||||
|
<!--
|
||||||
|
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">
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
var canvas = document.getElementById(canvasName);
|
||||||
|
var gl = canvas.getContext("experimental-webgl", contextAttribs);
|
||||||
|
if (!gl) {
|
||||||
|
alert("No WebGL context found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var actualContextAttribs = gl.getContextAttributes();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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()");
|
||||||
|
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]);
|
||||||
|
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()");
|
||||||
|
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);
|
||||||
|
|
||||||
|
var vertices = new WebGLFloatArray([
|
||||||
|
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]);
|
||||||
|
var colors = new WebGLUnsignedByteArray([
|
||||||
|
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];
|
||||||
|
correctColor = (depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
|
||||||
|
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()");
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
webGL.stencilFunc(webGL.NEVER, 1, 1);
|
||||||
|
webGL.stencilOp(webGL.KEEP, webGL.KEEP, webGL.KEEP);
|
||||||
|
|
||||||
|
var vertices = new WebGLFloatArray([
|
||||||
|
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]);
|
||||||
|
var colors = new WebGLUnsignedByteArray([
|
||||||
|
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];
|
||||||
|
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;
|
||||||
|
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()");
|
||||||
|
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 WebGLFloatArray([
|
||||||
|
1.0, 1.0, 0.0,
|
||||||
|
-1.0, 1.0, 0.0,
|
||||||
|
-1.0, -1.0, 0.0]);
|
||||||
|
var colors = new WebGLUnsignedByteArray([
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
testAlpha(true);
|
||||||
|
testAlpha(false);
|
||||||
|
testDepth(true);
|
||||||
|
testDepth(false);
|
||||||
|
testStencil(true);
|
||||||
|
testStencil(false);
|
||||||
|
testAntialias(true);
|
||||||
|
testAntialias(false);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
<!--
|
||||||
|
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 g_Position;
|
||||||
|
attribute vec2 g_TexCoord0;
|
||||||
|
|
||||||
|
varying vec2 texCoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);
|
||||||
|
texCoord = g_TexCoord0;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="fshader" type="x-shader/x-fragment">
|
||||||
|
uniform sampler2D tex;
|
||||||
|
// Workaround for non-compliant WebGL implementations (FIXME)
|
||||||
|
#if defined(GL_ES)
|
||||||
|
varying mediump vec2 texCoord;
|
||||||
|
#else
|
||||||
|
varying vec2 texCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = texture2D(tex, texCoord);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var successfullyParsed = false;
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
if (window.initNonKhronosFramework) {
|
||||||
|
window.initNonKhronosFramework(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
description('Verify copyTexImage2D and copyTexSubImage2D');
|
||||||
|
|
||||||
|
runTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// These two declarations need to be global for "shouldBe" to see them
|
||||||
|
var pixel = [0, 0, 0];
|
||||||
|
var correctColor = null;
|
||||||
|
var gl = null;
|
||||||
|
|
||||||
|
function runTestIteration(antialias)
|
||||||
|
{
|
||||||
|
if (antialias)
|
||||||
|
gl = initWebGL("antialiasOn", "vshader", "fshader", [ "g_Position", "g_TexCoord0" ], [ 0, 0, 0, 1 ], 1);
|
||||||
|
else
|
||||||
|
gl = initWebGL("antialiasOff", "vshader", "fshader", [ "g_Position", "g_TexCoord0" ], [ 0, 0, 0, 1 ], 1, { antialias: false });
|
||||||
|
|
||||||
|
var textureLoc = gl.getUniformLocation(gl.program, "tex");
|
||||||
|
|
||||||
|
var vertices = new WebGLFloatArray([
|
||||||
|
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]);
|
||||||
|
var texCoords = new WebGLFloatArray([
|
||||||
|
1.0, 1.0,
|
||||||
|
0.0, 1.0,
|
||||||
|
0.0, 0.0,
|
||||||
|
1.0, 1.0,
|
||||||
|
0.0, 0.0,
|
||||||
|
1.0, 0.0]);
|
||||||
|
var texCoordOffset = vertices.byteLength;
|
||||||
|
|
||||||
|
var vbo = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER,
|
||||||
|
texCoordOffset + texCoords.byteLength,
|
||||||
|
gl.STATIC_DRAW);
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, texCoordOffset, texCoords);
|
||||||
|
|
||||||
|
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.colorMask(1, 1, 1, 0);
|
||||||
|
gl.disable(gl.BLEND);
|
||||||
|
debug('Testing copyTexImage2D');
|
||||||
|
|
||||||
|
// Red canvas
|
||||||
|
gl.clearColor(1, 0, 0, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
var texture = gl.createTexture();
|
||||||
|
// Bind the texture to texture unit 0
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
|
// Set up texture
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||||
|
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 2, 2, 0);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
|
||||||
|
// Green canvas
|
||||||
|
gl.clearColor(0, 1, 0, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Point the uniform sampler to texture unit 0
|
||||||
|
gl.uniform1i(textureLoc, 0);
|
||||||
|
// Draw the triangles
|
||||||
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
// Read back the rendering results, should be red
|
||||||
|
var buf = new Uint8Array(2 * 2 * 4);
|
||||||
|
gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
var idx = 0;
|
||||||
|
correctColor = [255, 0, 0];
|
||||||
|
for (var y = 0; y < 2; y++) {
|
||||||
|
for (var x = 0; x < 2; x++) {
|
||||||
|
idx = (y * 2 + x) * 4;
|
||||||
|
pixel[0] = buf[idx];
|
||||||
|
pixel[1] = buf[idx + 1];
|
||||||
|
pixel[2] = buf[idx + 2];
|
||||||
|
shouldBe("pixel", "correctColor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug('Testing copyTexSubImage2D');
|
||||||
|
|
||||||
|
// Green canvas
|
||||||
|
gl.clearColor(0, 1, 0, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
|
||||||
|
// Blue canvas
|
||||||
|
gl.clearColor(0, 0, 1, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Draw the triangles
|
||||||
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
// Read back the rendering results, should be green
|
||||||
|
gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
correctColor = [0, 255, 0];
|
||||||
|
for (var y = 0; y < 2; y++) {
|
||||||
|
for (var x = 0; x < 2; x++) {
|
||||||
|
idx = (y * 2 + x) * 4;
|
||||||
|
pixel[0] = buf[idx];
|
||||||
|
pixel[1] = buf[idx + 1];
|
||||||
|
pixel[2] = buf[idx + 2];
|
||||||
|
shouldBe("pixel", "correctColor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest(antialias)
|
||||||
|
{
|
||||||
|
debug("Testing with antialias on");
|
||||||
|
runTestIteration(true);
|
||||||
|
debug("Testing with antialias off");
|
||||||
|
runTestIteration(false);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<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>
|
||||||
@@ -44,27 +44,32 @@ context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
|||||||
context.enableVertexAttribArray(0);
|
context.enableVertexAttribArray(0);
|
||||||
|
|
||||||
debug("Test empty buffer")
|
debug("Test empty buffer")
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ ]), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array([ ]), context.STATIC_DRAW);
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 1)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 1)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
|
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_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 1, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 1, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "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.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
|
||||||
|
|
||||||
debug("")
|
debug("")
|
||||||
debug("Test buffer with 3 float vectors")
|
debug("Test buffer with 3 float vectors")
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 3)");
|
shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 3)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawArrays(0x0009, 0, 3)"); // GL_POLYGON
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 3, 2)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 3, 2)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
|
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_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
|
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.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.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 1, -1)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 1)");
|
||||||
|
|
||||||
@@ -86,7 +91,7 @@ context.useProgram(program2);
|
|||||||
var vbo = context.createBuffer();
|
var vbo = context.createBuffer();
|
||||||
context.bindBuffer(context.ARRAY_BUFFER, vbo);
|
context.bindBuffer(context.ARRAY_BUFFER, vbo);
|
||||||
// enough for 9 vertices, so 3 triangles
|
// enough for 9 vertices, so 3 triangles
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray(9*5), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_DRAW);
|
||||||
|
|
||||||
// bind first 3 elements, with a stride of 5 float elements
|
// bind first 3 elements, with a stride of 5 float elements
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0);
|
||||||
|
|||||||
@@ -42,33 +42,42 @@ context.useProgram(program);
|
|||||||
var vertexObject = context.createBuffer();
|
var vertexObject = context.createBuffer();
|
||||||
context.enableVertexAttribArray(0);
|
context.enableVertexAttribArray(0);
|
||||||
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
var indexObject = context.createBuffer();
|
var indexObject = context.createBuffer();
|
||||||
|
|
||||||
debug("Test empty index buffer")
|
debug("Test empty index buffer")
|
||||||
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
||||||
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ ]), context.STATIC_DRAW);
|
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint8Array([ ]), context.STATIC_DRAW);
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)");
|
||||||
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_VALUE, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
|
||||||
|
|
||||||
debug("")
|
debug("")
|
||||||
debug("Test buffer with 3 byte indexes")
|
debug("Test buffer with 3 byte indexes")
|
||||||
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
||||||
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ 0, 1, 2 ]), context.STATIC_DRAW);
|
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint8Array([ 0, 1, 2 ]), context.STATIC_DRAW);
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_INT, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(0x0009, 3, context.UNSIGNED_BYTE, 0)"); // GL_POLYGON
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
|
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_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.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)");
|
||||||
|
|
||||||
debug("")
|
debug("")
|
||||||
debug("Test buffer with interleaved (3+2) float vectors")
|
debug("Test buffer with interleaved (3+2) float vectors")
|
||||||
@@ -88,7 +97,7 @@ context.useProgram(program2);
|
|||||||
var vbo = context.createBuffer();
|
var vbo = context.createBuffer();
|
||||||
context.bindBuffer(context.ARRAY_BUFFER, vbo);
|
context.bindBuffer(context.ARRAY_BUFFER, vbo);
|
||||||
// enough for 9 vertices, so 3 triangles
|
// enough for 9 vertices, so 3 triangles
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray(9*5), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array(9*5), context.STATIC_DRAW);
|
||||||
|
|
||||||
// bind first 3 elements, with a stride of 5 float elements
|
// bind first 3 elements, with a stride of 5 float elements
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 5*4, 0);
|
||||||
@@ -100,7 +109,7 @@ context.enableVertexAttribArray(1);
|
|||||||
|
|
||||||
var ebo = context.createBuffer();
|
var ebo = context.createBuffer();
|
||||||
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, ebo);
|
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, ebo);
|
||||||
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray([ 0, 1, 2,
|
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 0, 1, 2,
|
||||||
1, 2, 0,
|
1, 2, 0,
|
||||||
2, 0, 1,
|
2, 0, 1,
|
||||||
200, 200, 200,
|
200, 200, 200,
|
||||||
|
|||||||
@@ -37,7 +37,61 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/error-reporting.js"></script>
|
<script>
|
||||||
|
description("Tests generation of synthetic and real GL errors");
|
||||||
|
|
||||||
|
var context = create3DContext();
|
||||||
|
var program = loadStandardProgram(context);
|
||||||
|
|
||||||
|
// Other tests in this directory like getActiveTest and
|
||||||
|
// incorrect-context-object-behaviour already test the raising of many
|
||||||
|
// synthetic GL errors. This test verifies the raising of certain
|
||||||
|
// known real GL errors, and contains a few regression tests for bugs
|
||||||
|
// discovered in the synthetic error generation and in the WebGL
|
||||||
|
// implementation itself.
|
||||||
|
|
||||||
|
shouldBe("context.getError()", "0");
|
||||||
|
|
||||||
|
debug("Testing getActiveAttrib");
|
||||||
|
// Synthetic OpenGL error
|
||||||
|
shouldBeNull("context.getActiveAttrib(null, 2)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
// Real OpenGL error
|
||||||
|
shouldBeNull("context.getActiveAttrib(program, 2)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
|
||||||
|
debug("Testing getActiveUniform");
|
||||||
|
// Synthetic OpenGL error
|
||||||
|
shouldBeNull("context.getActiveUniform(null, 0)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
// Real OpenGL error
|
||||||
|
shouldBeNull("context.getActiveUniform(program, 50)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
|
||||||
|
debug("Testing attempts to manipulate the default framebuffer");
|
||||||
|
shouldBeUndefined("context.bindFramebuffer(context.FRAMEBUFFER, 0)");
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
shouldBeUndefined("context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, 0)");
|
||||||
|
// Synthetic OpenGL error
|
||||||
|
glErrorShouldBe(context, context.INVALID_OPERATION);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
shouldBeUndefined("context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, 0, 0)");
|
||||||
|
// Synthetic OpenGL error
|
||||||
|
glErrorShouldBe(context, context.INVALID_OPERATION);
|
||||||
|
// Error state should be clear by this point
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
|
||||||
|
var gl;
|
||||||
|
var fbo;
|
||||||
|
var depthBuffer;
|
||||||
|
var stencilBuffer;
|
||||||
|
var depthStencilBuffer;
|
||||||
|
var colorBuffer;
|
||||||
|
var width = 2;
|
||||||
|
var height = 2;
|
||||||
|
|
||||||
|
function testAttachment(attachment, buffer, isConflicted)
|
||||||
|
{
|
||||||
|
shouldBeNonNull("fbo = gl.createFramebuffer()");
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, buffer);
|
||||||
|
shouldBe("gl.getError()", isConflicted ? "gl.INVALID_OPERATION" : "gl.NO_ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAttachments(attachment0, buffer0, attachment1, buffer1, isConflicted)
|
||||||
|
{
|
||||||
|
shouldBeNonNull("fbo = gl.createFramebuffer()");
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment0, gl.RENDERBUFFER, buffer0);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buffer1);
|
||||||
|
shouldBe("gl.getError()", 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);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buffer1);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testColorRenderbuffer(internalformat)
|
||||||
|
{
|
||||||
|
shouldBeNonNull("colorBuffer = gl.createRenderbuffer()");
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalformat, width, height);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
testAttachment(gl.COLOR_ATTACHMENT0, colorBuffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
description("Test framebuffer object attachment behaviors");
|
||||||
|
|
||||||
|
debug("Create renderbuffers");
|
||||||
|
shouldBeNonNull("gl = create3DContext()");
|
||||||
|
shouldBeNonNull("depthBuffer = gl.createRenderbuffer()");
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
shouldBeNonNull("stencilBuffer = gl.createRenderbuffer()");
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, stencilBuffer);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()");
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
|
||||||
|
debug("Attach depth using DEPTH_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_ATTACHMENT, depthBuffer, false);
|
||||||
|
debug("Attach depth using STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.STENCIL_ATTACHMENT, depthBuffer, true);
|
||||||
|
debug("Attach depth using DEPTH_STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthBuffer, true);
|
||||||
|
debug("Attach stencil using STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.STENCIL_ATTACHMENT, stencilBuffer, false);
|
||||||
|
debug("Attach stencil using DEPTH_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_ATTACHMENT, stencilBuffer, true);
|
||||||
|
debug("Attach stencil using DEPTH_STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, stencilBuffer, true);
|
||||||
|
debug("Attach depthStencil using DEPTH_STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, false);
|
||||||
|
debug("Attach depthStencil using DEPTH_ATTACHMENT");
|
||||||
|
testAttachment(gl.DEPTH_ATTACHMENT, depthStencilBuffer, true);
|
||||||
|
debug("Attach depthStencil using STENCIL_ATTACHMENT");
|
||||||
|
testAttachment(gl.STENCIL_ATTACHMENT, depthStencilBuffer, true);
|
||||||
|
|
||||||
|
debug("Attach depth, then stencil, causing conflict");
|
||||||
|
testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.STENCIL_ATTACHMENT, stencilBuffer, true);
|
||||||
|
debug("Attach stencil, then depth, causing conflict");
|
||||||
|
testAttachments(gl.STENCIL_ATTACHMENT, stencilBuffer, gl.DEPTH_ATTACHMENT, depthBuffer, true);
|
||||||
|
debug("Attach depth, then depthStencil, causing conflict");
|
||||||
|
testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, true);
|
||||||
|
debug("Attach depthStencil, then depth, causing conflict");
|
||||||
|
testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.DEPTH_ATTACHMENT, depthBuffer, true);
|
||||||
|
debug("Attach stencil, then depthStencil, causing conflict");
|
||||||
|
testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, true);
|
||||||
|
debug("Attach depthStencil, then stencil, causing conflict");
|
||||||
|
testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.STENCIL_ATTACHMENT, stencilBuffer, true);
|
||||||
|
|
||||||
|
debug("Attach color renderbuffer with internalformat == RGBA4");
|
||||||
|
testColorRenderbuffer(gl.RGBA4);
|
||||||
|
|
||||||
|
debug("Attach color renderbuffer with internalformat == RGB5_A1");
|
||||||
|
testColorRenderbuffer(gl.RGB5_A1);
|
||||||
|
|
||||||
|
debug("Attach color renderbuffer with internalformat == RGB565");
|
||||||
|
testColorRenderbuffer(gl.RGB565);
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -41,6 +41,9 @@ if (!gl) {
|
|||||||
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
||||||
"calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
|
"calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
|
||||||
|
|
||||||
|
assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE,
|
||||||
|
"calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE.");
|
||||||
|
|
||||||
var tex = gl.createTexture();
|
var tex = gl.createTexture();
|
||||||
gl.bindTexture(gl.TEXTURE_2D, tex);
|
gl.bindTexture(gl.TEXTURE_2D, tex);
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||||
@@ -96,6 +99,46 @@ if (!gl) {
|
|||||||
assertMsg(gl.getError() == gl.NO_ERROR,
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
||||||
"binding a newly created framebuffer should succeed.");
|
"binding a newly created framebuffer should succeed.");
|
||||||
|
|
||||||
|
var target = 0x8CA8; // GL_READ_FRAMEBUFFER
|
||||||
|
gl.getFramebufferAttachmentParameter(
|
||||||
|
target,
|
||||||
|
gl.COLOR_ATTACHMENT0,
|
||||||
|
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
assertMsg(gl.checkFramebufferStatus(target) == 0,
|
||||||
|
"calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0.");
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
gl.bindFramebuffer(target, gl.createFramebuffer());
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING),
|
||||||
|
"calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING.");
|
||||||
|
gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
|
||||||
|
|
||||||
|
var attachment = 0x8CE1; // GL_COLOR_ATTACHMENT1
|
||||||
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
|
||||||
|
|
||||||
|
gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER,
|
||||||
|
gl.COLOR_ATTACHMENT0,
|
||||||
|
0x8210); // GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
|
"calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM.");
|
||||||
|
|
||||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
|
||||||
assertMsg(gl.getError() == gl.NO_ERROR,
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
||||||
"attaching a texture to a framebuffer should succeed.");
|
"attaching a texture to a framebuffer should succeed.");
|
||||||
|
|||||||
@@ -33,7 +33,101 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/get-active-test.js"></script>
|
<script>
|
||||||
|
description("Test of getActiveAttrib and getActiveUniform");
|
||||||
|
|
||||||
|
var context = create3DContext();
|
||||||
|
var context2 = create3DContext();
|
||||||
|
var program = loadStandardProgram(context);
|
||||||
|
var program2 = loadProgram(context2,
|
||||||
|
"resources/intArrayUniformShader.vert",
|
||||||
|
"resources/noopUniformShader.frag");
|
||||||
|
|
||||||
|
glErrorShouldBe(context, context.NO_ERROR);
|
||||||
|
shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'");
|
||||||
|
shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4");
|
||||||
|
shouldBe("context.getActiveUniform(program, 0).size", "1");
|
||||||
|
shouldBeNull("context.getActiveUniform(program, 1)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
shouldBeNull("context.getActiveUniform(program, -1)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
shouldBeNull("context.getActiveUniform(null, 0)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
|
||||||
|
// we don't know the order the attribs will appear.
|
||||||
|
var info = [
|
||||||
|
context.getActiveAttrib(program, 0),
|
||||||
|
context.getActiveAttrib(program, 1)
|
||||||
|
];
|
||||||
|
for (var ii = 0; ii < info.length; ++ii)
|
||||||
|
shouldBeNonNull("info[ii]");
|
||||||
|
|
||||||
|
var expected = [
|
||||||
|
{ name: 'a_normal', type: context.FLOAT_VEC3, size: 1 },
|
||||||
|
{ name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 }
|
||||||
|
];
|
||||||
|
|
||||||
|
if (info[0].name != expected[0].name) {
|
||||||
|
t = info[0];
|
||||||
|
info[0] = info[1];
|
||||||
|
info[1] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var ii = 0; ii < info.length; ++ii) {
|
||||||
|
shouldBe("info[ii].name", "expected[ii].name");
|
||||||
|
shouldBe("info[ii].type", "expected[ii].type");
|
||||||
|
shouldBe("info[ii].size", "expected[ii].size");
|
||||||
|
}
|
||||||
|
|
||||||
|
// we don't know the order the uniforms will appear.
|
||||||
|
var info2 = [
|
||||||
|
context2.getActiveUniform(program2, 0),
|
||||||
|
context2.getActiveUniform(program2, 1)
|
||||||
|
];
|
||||||
|
for (var ii = 0; ii < info2.length; ++ii)
|
||||||
|
shouldBeNonNull("info2[ii]");
|
||||||
|
|
||||||
|
var expected2 = [
|
||||||
|
{ name: 'ival', type: context2.INT, size: 1 },
|
||||||
|
{ name: 'ival2[0]', type: context2.INT, size: 2 }
|
||||||
|
];
|
||||||
|
|
||||||
|
if (info2[0].name != expected2[0].name) {
|
||||||
|
t = info2[0];
|
||||||
|
info2[0] = info2[1];
|
||||||
|
info2[1] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var ii = 0; ii < info2.length; ++ii) {
|
||||||
|
shouldBe("info2[ii].name", "expected2[ii].name");
|
||||||
|
shouldBe("info2[ii].type", "expected2[ii].type");
|
||||||
|
shouldBe("info2[ii].size", "expected2[ii].size");
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldBeNull("context.getActiveAttrib(program, 2)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
shouldBeNull("context.getActiveAttrib(program, -1)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
shouldBeNull("context.getActiveAttrib(null, 0)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
|
||||||
|
glErrorShouldBe(context2, context.NO_ERROR);
|
||||||
|
|
||||||
|
debug("Check trying to get attribs from different context");
|
||||||
|
shouldBeNull("context2.getActiveAttrib(program, 0)");
|
||||||
|
glErrorShouldBe(context2, context2.INVALID_OPERATION);
|
||||||
|
shouldBeNull("context2.getActiveUniform(program, 0)");
|
||||||
|
glErrorShouldBe(context2, context2.INVALID_OPERATION);
|
||||||
|
|
||||||
|
debug("Check trying to get attribs from deleted program");
|
||||||
|
context.deleteProgram(program);
|
||||||
|
shouldBeNull("context.getActiveUniform(program, 0)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
shouldBeNull("context.getActiveAttrib(program, 0)");
|
||||||
|
glErrorShouldBe(context, context.INVALID_VALUE);
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
204
content/canvas/test/webgl/conformance/gl-bind-attrib-location-test.html
Executable file
@@ -0,0 +1,204 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2009 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>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>WebGL BindAttribLocation Conformance Tests</title>
|
||||||
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
||||||
|
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
||||||
|
<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>
|
||||||
|
<canvas style="border: 1px solid black;" id="canvas" width="50" height="50">
|
||||||
|
</canvas><script id="vshader" type="text/something-not-javascript">
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
attribute vec4 vColor;
|
||||||
|
varying vec4 color;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vPosition;
|
||||||
|
color = vColor;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="fshader" type="text/something-not-javascript">
|
||||||
|
varying vec4 color;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("Canvas.getContext");
|
||||||
|
|
||||||
|
var gl = create3DContext(document.getElementById("canvas"));
|
||||||
|
shouldBeNonNull(gl);
|
||||||
|
|
||||||
|
function fail(x,y, buf, shouldBe)
|
||||||
|
{
|
||||||
|
var i = (y*50+x) * 4;
|
||||||
|
var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
|
||||||
|
testFailed(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pass()
|
||||||
|
{
|
||||||
|
testPassed("drawing is correct");
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadShader(shaderType, shaderId) {
|
||||||
|
// Get the shader source.
|
||||||
|
var shaderSource = document.getElementById(shaderId).text;
|
||||||
|
|
||||||
|
// Create the shader object
|
||||||
|
var shader = gl.createShader(shaderType);
|
||||||
|
if (shader == null) {
|
||||||
|
debug("*** Error: unable to create shader '"+shaderId+"'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the shader source
|
||||||
|
gl.shaderSource(shader, shaderSource);
|
||||||
|
|
||||||
|
// Compile the shader
|
||||||
|
gl.compileShader(shader);
|
||||||
|
|
||||||
|
// Check the compile status
|
||||||
|
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
||||||
|
if (!compiled) {
|
||||||
|
// Something went wrong during compilation; get the error
|
||||||
|
var error = gl.getShaderInfoLog(shader);
|
||||||
|
debug("*** Error compiling shader '"+shader+"':"+error);
|
||||||
|
gl.deleteShader(shader);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("Checking gl.bindAttribLocation.");
|
||||||
|
|
||||||
|
var program = gl.createProgram();
|
||||||
|
gl.bindAttribLocation(program, 0, "gl_foo");
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
||||||
|
"bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
|
||||||
|
gl.bindAttribLocation(program, 0, "gl_TexCoord0");
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
||||||
|
"bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
|
||||||
|
|
||||||
|
var vs = loadShader(gl.VERTEX_SHADER, "vshader");
|
||||||
|
var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
|
||||||
|
gl.attachShader(program, vs);
|
||||||
|
gl.attachShader(program, fs);
|
||||||
|
|
||||||
|
var positions = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, positions);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
var colors = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, colors);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
||||||
|
0,1,0,1,
|
||||||
|
0,1,0,1,
|
||||||
|
0,1,0,1]), gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
function setBindLocations(colorLocation, positionLocation) {
|
||||||
|
gl.bindAttribLocation(program, positionLocation, "vPosition");
|
||||||
|
gl.bindAttribLocation(program, colorLocation, "vColor");
|
||||||
|
gl.linkProgram(program);
|
||||||
|
gl.useProgram(program);
|
||||||
|
var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
|
||||||
|
assertMsg(linked, "program linked successfully");
|
||||||
|
|
||||||
|
debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
|
||||||
|
debug("vColor :" + gl.getAttribLocation(program, "vColor"))
|
||||||
|
assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
|
||||||
|
"location of vPositon should be " + positionLocation);
|
||||||
|
assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
|
||||||
|
"location of vColor should be " + colorLocation);
|
||||||
|
|
||||||
|
var ploc = gl.getAttribLocation(program, "vPosition");
|
||||||
|
var cloc = gl.getAttribLocation(program, "vColor");
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, positions);
|
||||||
|
gl.enableVertexAttribArray(positionLocation);
|
||||||
|
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, colors);
|
||||||
|
gl.enableVertexAttribArray(colorLocation);
|
||||||
|
gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkDraw(colorLocation, positionLocation, r, g, b, a) {
|
||||||
|
gl.clearColor(0, 0, 0, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||||
|
|
||||||
|
var width = 50;
|
||||||
|
var height = 50;
|
||||||
|
var buf = new Uint8Array(width * height * 4);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
|
||||||
|
function checkPixel(x, y, r, g, b, a) {
|
||||||
|
var offset = (y * width + x) * 4;
|
||||||
|
if (buf[offset + 0] != r ||
|
||||||
|
buf[offset + 1] != g ||
|
||||||
|
buf[offset + 2] != b ||
|
||||||
|
buf[offset + 3] != a) {
|
||||||
|
fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test several locations
|
||||||
|
// First line should be all black
|
||||||
|
var success = true;
|
||||||
|
for (var i = 0; i < 50; ++i)
|
||||||
|
success = success && checkPixel(i, 0, 0, 0, 0, 255);
|
||||||
|
|
||||||
|
// Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
|
||||||
|
var offset = (15 * 50 + 20) * 4;
|
||||||
|
for (var i = 0; i < 10; ++i)
|
||||||
|
success = success && checkPixel(20 + i, 15, r, g, b, a);
|
||||||
|
|
||||||
|
// Last line should be all black
|
||||||
|
for (var i = 0; i < 50; ++i)
|
||||||
|
success = success && checkPixel(i, 49, 0, 0, 0, 255);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
pass();
|
||||||
|
|
||||||
|
gl.disableVertexAttribArray(positionLocation);
|
||||||
|
gl.disableVertexAttribArray(colorLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
setBindLocations(2, 3);
|
||||||
|
checkDraw(2, 3, 0, 255, 0, 255);
|
||||||
|
|
||||||
|
setBindLocations(0, 3);
|
||||||
|
gl.disableVertexAttribArray(0);
|
||||||
|
gl.vertexAttrib4f(0, 1, 0, 0, 1);
|
||||||
|
checkDraw(0, 3, 255, 0, 0, 255);
|
||||||
|
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
successfullyParsed = true;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright (c) 2009 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>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
||||||
<title>WebGL BindAttribLocation Conformance Tests</title>
|
|
||||||
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
|
||||||
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
|
||||||
<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>
|
|
||||||
<canvas style="border: 1px solid black;" id="canvas" width="50" height="50">
|
|
||||||
</canvas><script id="vshader" type="text/something-not-javascript">
|
|
||||||
attribute vec4 vPosition;
|
|
||||||
attribute vec4 vColor;
|
|
||||||
varying vec4 color;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vPosition;
|
|
||||||
color = vColor;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<script id="fshader" type="text/something-not-javascript">
|
|
||||||
precision mediump float;
|
|
||||||
varying vec4 color;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_FragColor = color;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
|
|
||||||
|
|
||||||
debug("");
|
|
||||||
debug("Canvas.getContext");
|
|
||||||
|
|
||||||
var gl = create3DContext(document.getElementById("canvas"));
|
|
||||||
if (!gl) {
|
|
||||||
testFailed("context does not exist");
|
|
||||||
} else {
|
|
||||||
testPassed("context exists");
|
|
||||||
|
|
||||||
function fail(x,y, buf, shouldBe)
|
|
||||||
{
|
|
||||||
var i = (y*50+x) * 4;
|
|
||||||
var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
|
|
||||||
testFailed(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pass()
|
|
||||||
{
|
|
||||||
testPassed("drawing is correct");
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadShader(shaderType, shaderId) {
|
|
||||||
// Get the shader source.
|
|
||||||
var shaderSource = document.getElementById(shaderId).text;
|
|
||||||
|
|
||||||
// Create the shader object
|
|
||||||
var shader = gl.createShader(shaderType);
|
|
||||||
if (shader == null) {
|
|
||||||
debug("*** Error: unable to create shader '"+shaderId+"'");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the shader source
|
|
||||||
gl.shaderSource(shader, shaderSource);
|
|
||||||
|
|
||||||
// Compile the shader
|
|
||||||
gl.compileShader(shader);
|
|
||||||
|
|
||||||
// Check the compile status
|
|
||||||
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
|
||||||
if (!compiled) {
|
|
||||||
// Something went wrong during compilation; get the error
|
|
||||||
var error = gl.getShaderInfoLog(shader);
|
|
||||||
log("*** Error compiling shader '"+shader+"':"+error);
|
|
||||||
gl.deleteShader(shader);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("");
|
|
||||||
debug("Checking gl.bindAttribLocation.");
|
|
||||||
|
|
||||||
var program = gl.createProgram();
|
|
||||||
gl.bindAttribLocation(program, 0, "gl_foo");
|
|
||||||
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
|
||||||
"bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
|
|
||||||
gl.bindAttribLocation(program, 0, "gl_TexCoord0");
|
|
||||||
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
|
||||||
"bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
|
|
||||||
|
|
||||||
var vs = loadShader(gl.VERTEX_SHADER, "vshader");
|
|
||||||
var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
|
|
||||||
gl.attachShader(program, vs);
|
|
||||||
gl.attachShader(program, fs);
|
|
||||||
|
|
||||||
var positions = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, positions);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
|
||||||
|
|
||||||
var colors = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, colors);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([
|
|
||||||
0,1,0,1,
|
|
||||||
0,1,0,1,
|
|
||||||
0,1,0,1]), gl.STATIC_DRAW);
|
|
||||||
|
|
||||||
function setBindLocations(colorLocation, positionLocation) {
|
|
||||||
gl.bindAttribLocation(program, positionLocation, "vPosition");
|
|
||||||
gl.bindAttribLocation(program, colorLocation, "vColor");
|
|
||||||
gl.linkProgram(program);
|
|
||||||
gl.useProgram(program);
|
|
||||||
var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
|
|
||||||
assertMsg(linked, "program linked successfully");
|
|
||||||
|
|
||||||
debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
|
|
||||||
debug("vColor :" + gl.getAttribLocation(program, "vColor"))
|
|
||||||
assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
|
|
||||||
"location of vPositon should be " + positionLocation);
|
|
||||||
assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
|
|
||||||
"location of vColor should be " + colorLocation);
|
|
||||||
|
|
||||||
var ploc = gl.getAttribLocation(program, "vPosition");
|
|
||||||
var cloc = gl.getAttribLocation(program, "vColor");
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, positions);
|
|
||||||
gl.enableVertexAttribArray(positionLocation);
|
|
||||||
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, colors);
|
|
||||||
gl.enableVertexAttribArray(colorLocation);
|
|
||||||
gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkDraw(colorLocation, positionLocation, r, g, b, a) {
|
|
||||||
gl.clearColor(0, 0, 0, 1);
|
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
||||||
|
|
||||||
var buf = gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE);
|
|
||||||
|
|
||||||
function checkPixel(x, y, r, g, b, a) {
|
|
||||||
var offset = (y * 50 + x) * 4;
|
|
||||||
if (buf[offset + 0] != r ||
|
|
||||||
buf[offset + 1] != g ||
|
|
||||||
buf[offset + 2] != b ||
|
|
||||||
buf[offset + 3] != a) {
|
|
||||||
fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test several locations
|
|
||||||
// First line should be all black
|
|
||||||
var success = true;
|
|
||||||
for (var i = 0; i < 50; ++i) {
|
|
||||||
success = success && checkPixel(i, 0, 0, 0, 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
|
|
||||||
var offset = (15 * 50 + 20) * 4;
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
success = success && checkPixel(20 + i, 15, r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last line should be all black
|
|
||||||
for (var i = 0; i < 50; ++i) {
|
|
||||||
success = success && checkPixel(i, 49, 0, 0, 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
pass();
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.disableVertexAttribArray(positionLocation);
|
|
||||||
gl.disableVertexAttribArray(colorLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
setBindLocations(2, 3);
|
|
||||||
checkDraw(2, 3, 0, 255, 0, 255);
|
|
||||||
setBindLocations(0, 3);
|
|
||||||
|
|
||||||
gl.disableVertexAttribArray(0);
|
|
||||||
gl.vertexAttrib4f(0, 1, 0, 0, 1);
|
|
||||||
checkDraw(0, 3, 255, 0, 0, 255);
|
|
||||||
|
|
||||||
shouldBe("gl.getError()", "gl.NO_ERROR");
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("");
|
|
||||||
successfullyParsed = true;
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
13
content/canvas/test/webgl/conformance/gl-drawelements.html
Normal file → Executable file
@@ -35,9 +35,8 @@ found in the LICENSE file.
|
|||||||
<script>
|
<script>
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
if (window.layoutTestController) {
|
if (window.initNonKhronosFramework) {
|
||||||
layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
|
window.initNonKhronosFramework(false);
|
||||||
layoutTestController.dumpAsText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDrawElements(mode, count, type, expect, msg) {
|
function checkDrawElements(mode, count, type, expect, msg) {
|
||||||
@@ -50,20 +49,20 @@ found in the LICENSE file.
|
|||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray([ 0, 1, 2]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 0, 1, 2]), gl.STATIC_DRAW);
|
||||||
|
|
||||||
checkDrawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT,
|
checkDrawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT,
|
||||||
gl.NO_ERROR, "can call gl.DrawElements with UNSIGNED_SHORT");
|
gl.NO_ERROR, "can call gl.DrawElements with UNSIGNED_SHORT");
|
||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ 0, 1, 2, 0]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([ 0, 1, 2, 0]), gl.STATIC_DRAW);
|
||||||
|
|
||||||
checkDrawElements(
|
checkDrawElements(
|
||||||
gl.TRIANGLES, 3, gl.UNSIGNED_BYTE,
|
gl.TRIANGLES, 3, gl.UNSIGNED_BYTE,
|
||||||
@@ -80,7 +79,7 @@ found in the LICENSE file.
|
|||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedIntArray([ 0, 1, 2]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array([ 0, 1, 2]), gl.STATIC_DRAW);
|
||||||
|
|
||||||
checkDrawElements(
|
checkDrawElements(
|
||||||
gl.TRIANGLES, 3, gl.UNSIGNED_INT,
|
gl.TRIANGLES, 3, gl.UNSIGNED_INT,
|
||||||
|
|||||||
0
content/canvas/test/webgl/conformance/gl-enable-enum-test.html
Normal file → Executable file
@@ -37,7 +37,7 @@ gl.viewport(0, 0, 50, 50);
|
|||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
|||||||
10
content/canvas/test/webgl/conformance/gl-enum-tests.html
Normal file → Executable file
@@ -19,7 +19,7 @@ found in the LICENSE file.
|
|||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
<canvas id="canvas" width="2" height="2"> </canvas>
|
<canvas id="canvas" width="2" height="2"> </canvas>
|
||||||
<script>
|
<script>
|
||||||
description("This test ensures WebGL various functions fail when passed non OpenGL ES 2.0 enums.");
|
description("This test ensures various WebGL functions fail when passed non OpenGL ES 2.0 enums.");
|
||||||
|
|
||||||
debug("");
|
debug("");
|
||||||
debug("Canvas.getContext");
|
debug("Canvas.getContext");
|
||||||
@@ -33,6 +33,8 @@ if (!gl) {
|
|||||||
debug("");
|
debug("");
|
||||||
debug("Checking gl enums.");
|
debug("Checking gl enums.");
|
||||||
|
|
||||||
|
var buffer = new ArrayBuffer(1);
|
||||||
|
var buf = new Uint16Array(buffer);
|
||||||
var tex = gl.createTexture();
|
var tex = gl.createTexture();
|
||||||
var tests = [
|
var tests = [
|
||||||
"gl.bindTexture(desktopGL['TEXTURE_3D'], tex)",
|
"gl.bindTexture(desktopGL['TEXTURE_3D'], tex)",
|
||||||
@@ -52,14 +54,14 @@ if (!gl) {
|
|||||||
"gl.isEnabled(desktopGL['CLIP_PLANE0'])",
|
"gl.isEnabled(desktopGL['CLIP_PLANE0'])",
|
||||||
"gl.isEnabled(desktopGL['POINT_SPRITE'])",
|
"gl.isEnabled(desktopGL['POINT_SPRITE'])",
|
||||||
"gl.pixelStorei(desktopGL['PACK_SWAP_BYTES'], 1)",
|
"gl.pixelStorei(desktopGL['PACK_SWAP_BYTES'], 1)",
|
||||||
"gl.readPixels(0, 0, 1, 1, gl.ALPHA, gl.SHORT)",
|
"gl.readPixels(0, 0, 1, 1, gl.ALPHA, gl.SHORT, buf)",
|
||||||
"gl.texParameteri(desktopGL['TEXTURE_3D'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
|
"gl.texParameteri(desktopGL['TEXTURE_3D'], gl.TEXTURE_MAG_FILTER, gl.NEAREST)",
|
||||||
"gl.texParameteri(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'], 1)"
|
"gl.texParameteri(gl.TEXTURE_2D, desktopGL['GENERATE_MIPMAP'], 1)"
|
||||||
];
|
];
|
||||||
for (var ii = 0; ii < tests.length; ++ii) {
|
for (var ii = 0; ii < tests.length; ++ii) {
|
||||||
eval(tests[ii]);
|
eval(tests[ii]);
|
||||||
assertMsg(gl.getError() != gl.NO_ERROR,
|
assertMsg(gl.getError() == gl.INVALID_ENUM,
|
||||||
tests[ii] + " should fail.");
|
tests[ii] + " should return INVALID_ENUM.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ else {
|
|||||||
shouldBe('context.getParameter(context.BLEND_SRC_ALPHA)', '1');
|
shouldBe('context.getParameter(context.BLEND_SRC_ALPHA)', '1');
|
||||||
shouldBe('context.getParameter(context.BLEND_SRC_RGB)', '1');
|
shouldBe('context.getParameter(context.BLEND_SRC_RGB)', '1');
|
||||||
shouldBe('context.getParameter(context.COLOR_CLEAR_VALUE)', '[0, 0, 0, 0]');
|
shouldBe('context.getParameter(context.COLOR_CLEAR_VALUE)', '[0, 0, 0, 0]');
|
||||||
shouldBe('context.getParameter(context.COLOR_WRITEMASK)', '[1, 1, 1, 1]');
|
shouldBe('context.getParameter(context.COLOR_WRITEMASK)', '[true, true, true, true]');
|
||||||
shouldBe('context.getParameter(context.CULL_FACE)', 'false');
|
shouldBe('context.getParameter(context.CULL_FACE)', 'false');
|
||||||
shouldBe('context.getParameter(context.CULL_FACE_MODE)', 'context.BACK');
|
shouldBe('context.getParameter(context.CULL_FACE_MODE)', 'context.BACK');
|
||||||
shouldBe('context.getParameter(context.CURRENT_PROGRAM)', 'null');
|
shouldBe('context.getParameter(context.CURRENT_PROGRAM)', 'null');
|
||||||
@@ -98,9 +98,12 @@ else {
|
|||||||
shouldBe('context.getParameter(context.STENCIL_BACK_PASS_DEPTH_FAIL)', 'context.KEEP');
|
shouldBe('context.getParameter(context.STENCIL_BACK_PASS_DEPTH_FAIL)', 'context.KEEP');
|
||||||
shouldBe('context.getParameter(context.STENCIL_BACK_PASS_DEPTH_PASS)', 'context.KEEP');
|
shouldBe('context.getParameter(context.STENCIL_BACK_PASS_DEPTH_PASS)', 'context.KEEP');
|
||||||
shouldBe('context.getParameter(context.STENCIL_BACK_REF)', '0');
|
shouldBe('context.getParameter(context.STENCIL_BACK_REF)', '0');
|
||||||
|
|
||||||
shouldBe('context.getParameter(context.STENCIL_BACK_VALUE_MASK)', '0xFFFFFFFF');
|
shouldBe('context.getParameter(context.STENCIL_BACK_VALUE_MASK)', '0xFFFFFFFF');
|
||||||
shouldBe('context.getParameter(context.STENCIL_BACK_WRITEMASK)', '0xFFFFFFFF');
|
shouldBe('context.getParameter(context.STENCIL_BACK_WRITEMASK)', '0xFFFFFFFF');
|
||||||
shouldBe('context.getParameter(context.STENCIL_BITS)', '0');
|
|
||||||
|
// If EXT_packed_depth_stencil is supported, STENCIL_BITS > 0; otherwise, STENCIL_BITS == 0.
|
||||||
|
shouldBe('context.getParameter(context.STENCIL_BITS) >= 0', 'true');
|
||||||
shouldBe('context.getParameter(context.STENCIL_CLEAR_VALUE)', '0');
|
shouldBe('context.getParameter(context.STENCIL_CLEAR_VALUE)', '0');
|
||||||
shouldBe('context.getParameter(context.STENCIL_FAIL)', 'context.KEEP');
|
shouldBe('context.getParameter(context.STENCIL_FAIL)', 'context.KEEP');
|
||||||
shouldBe('context.getParameter(context.STENCIL_FUNC)', 'context.ALWAYS');
|
shouldBe('context.getParameter(context.STENCIL_FUNC)', 'context.ALWAYS');
|
||||||
@@ -108,19 +111,21 @@ else {
|
|||||||
shouldBe('context.getParameter(context.STENCIL_PASS_DEPTH_PASS)', 'context.KEEP');
|
shouldBe('context.getParameter(context.STENCIL_PASS_DEPTH_PASS)', 'context.KEEP');
|
||||||
shouldBe('context.getParameter(context.STENCIL_REF)', '0');
|
shouldBe('context.getParameter(context.STENCIL_REF)', '0');
|
||||||
shouldBe('context.getParameter(context.STENCIL_TEST)', 'false');
|
shouldBe('context.getParameter(context.STENCIL_TEST)', 'false');
|
||||||
|
|
||||||
shouldBe('context.getParameter(context.STENCIL_VALUE_MASK)', '0xFFFFFFFF');
|
shouldBe('context.getParameter(context.STENCIL_VALUE_MASK)', '0xFFFFFFFF');
|
||||||
shouldBe('context.getParameter(context.STENCIL_WRITEMASK)', '0xFFFFFFFF');
|
shouldBe('context.getParameter(context.STENCIL_WRITEMASK)', '0xFFFFFFFF');
|
||||||
|
|
||||||
shouldBe('context.getParameter(context.TEXTURE_BINDING_2D)', 'null');
|
shouldBe('context.getParameter(context.TEXTURE_BINDING_2D)', 'null');
|
||||||
shouldBe('context.getParameter(context.TEXTURE_BINDING_CUBE_MAP)', 'null');
|
shouldBe('context.getParameter(context.TEXTURE_BINDING_CUBE_MAP)', 'null');
|
||||||
|
shouldBe('context.getParameter(context.UNPACK_ALIGNMENT)', '4');
|
||||||
|
shouldBe('context.getParameter(context.UNPACK_FLIP_Y_WEBGL)', 'false');
|
||||||
|
shouldBe('context.getParameter(context.UNPACK_PREMULTIPLY_ALPHA_WEBGL)', 'false');
|
||||||
shouldBe('context.getParameter(context.VIEWPORT)', '[0, 0, 2, 2]');
|
shouldBe('context.getParameter(context.VIEWPORT)', '[0, 0, 2, 2]');
|
||||||
shouldBeTrue('context.getParameter(context.MAX_FRAGMENT_UNIFORM_VECTORS) >= 16');
|
shouldBeTrue('context.getParameter(context.MAX_FRAGMENT_UNIFORM_VECTORS) >= 16');
|
||||||
shouldBeTrue('context.getParameter(context.MAX_VERTEX_UNIFORM_VECTORS) >= 128');
|
shouldBeTrue('context.getParameter(context.MAX_VERTEX_UNIFORM_VECTORS) >= 128');
|
||||||
shouldBeTrue('context.getParameter(context.MAX_VARYING_VECTORS) >= 8');
|
shouldBeTrue('context.getParameter(context.MAX_VARYING_VECTORS) >= 8');
|
||||||
shouldBe('context.getParameter(context.NUM_COMPRESSED_TEXTURE_FORMATS)', '0');
|
shouldBe('context.getParameter(context.NUM_COMPRESSED_TEXTURE_FORMATS)', '0');
|
||||||
shouldBe('context.getParameter(context.SHADER_COMPILER)', 'true');
|
shouldBe('context.getParameter(context.SHADER_COMPILER)', 'true');
|
||||||
shouldBe('context.getParameter(context.IMPLEMENTATION_COLOR_READ_FORMAT)', 'context.RGBA');
|
|
||||||
shouldBe('context.getParameter(context.IMPLEMENTATION_COLOR_READ_TYPE)', 'context.UNSIGNED_BYTE');
|
|
||||||
shouldBe('context.getParameter(context.COMPRESSED_TEXTURE_FORMATS)', '[]');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("");
|
debug("");
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ if (!gl) {
|
|||||||
|
|
||||||
function checkPrefix(expected, enum) {
|
function checkPrefix(expected, enum) {
|
||||||
var s = gl.getParameter(gl[enum]);
|
var s = gl.getParameter(gl[enum]);
|
||||||
if (s.length >= expected.length &&
|
if (s != null &&
|
||||||
|
s.length >= expected.length &&
|
||||||
s.substring(0, expected.length) == expected) {
|
s.substring(0, expected.length) == expected) {
|
||||||
testPassed("getParameter(gl." + enum + ") correctly started with " + expected);
|
testPassed("getParameter(gl." + enum + ") correctly started with " + expected);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,7 +33,210 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/gl-object-get-calls.js"></script>
|
<script>
|
||||||
|
description("Test of get calls against GL objects like getBufferParameter, etc.");
|
||||||
|
|
||||||
|
var gl = create3DContext();
|
||||||
|
|
||||||
|
var standardVert = loadStandardVertexShader(gl);
|
||||||
|
var standardFrag = loadStandardFragmentShader(gl);
|
||||||
|
var standardProgram = gl.createProgram();
|
||||||
|
gl.attachShader(standardProgram, standardVert);
|
||||||
|
gl.attachShader(standardProgram, standardFrag);
|
||||||
|
gl.linkProgram(standardProgram);
|
||||||
|
var shaders = gl.getAttachedShaders(standardProgram);
|
||||||
|
shouldBe('shaders.length', '2');
|
||||||
|
shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag');
|
||||||
|
shouldBe('gl.getError()', 'gl.NO_ERROR');
|
||||||
|
shouldBeUndefined('gl.getAttachedShaders(null)');
|
||||||
|
shouldBe('gl.getError()', 'gl.INVALID_VALUE');
|
||||||
|
shouldBeUndefined('gl.getAttachedShaders(standardVert)');
|
||||||
|
shouldBe('gl.getError()', 'gl.INVALID_VALUE');
|
||||||
|
|
||||||
|
// Test getBufferParameter
|
||||||
|
var buffer = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, 16, gl.DYNAMIC_DRAW);
|
||||||
|
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16');
|
||||||
|
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_DRAW');
|
||||||
|
|
||||||
|
// Test getFramebufferAttachmentParameter
|
||||||
|
var texture = gl.createTexture();
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
||||||
|
new Uint8Array([
|
||||||
|
0, 0, 0, 255,
|
||||||
|
255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255,
|
||||||
|
0, 0, 0, 255]));
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||||
|
var framebuffer = gl.createFramebuffer();
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||||
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
||||||
|
var renderbuffer = gl.createRenderbuffer();
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 2, 2);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
|
||||||
|
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
|
||||||
|
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE');
|
||||||
|
shouldBeNonNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
||||||
|
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0');
|
||||||
|
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0');
|
||||||
|
|
||||||
|
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER');
|
||||||
|
shouldBeNonNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
||||||
|
|
||||||
|
// Test getProgramParameter
|
||||||
|
shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false');
|
||||||
|
shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true');
|
||||||
|
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"');
|
||||||
|
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.INFO_LOG_LENGTH)', '"number"');
|
||||||
|
shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2');
|
||||||
|
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2');
|
||||||
|
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTE_MAX_LENGTH)');
|
||||||
|
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1');
|
||||||
|
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORM_MAX_LENGTH)');
|
||||||
|
|
||||||
|
// Test getRenderbufferParameter
|
||||||
|
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)', '2');
|
||||||
|
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)', '2');
|
||||||
|
// Note: we can't test the actual value of the internal format since
|
||||||
|
// the implementation is allowed to change it.
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)');
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE)');
|
||||||
|
var colorbuffer = gl.createRenderbuffer();
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 2, 2);
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)');
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)');
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)');
|
||||||
|
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)');
|
||||||
|
|
||||||
|
// Test getShaderParameter
|
||||||
|
shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADER');
|
||||||
|
shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false');
|
||||||
|
shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true');
|
||||||
|
shouldBe('typeof gl.getShaderParameter(standardVert, gl.INFO_LOG_LENGTH)', '"number"');
|
||||||
|
shouldBeNonZero('gl.getShaderParameter(standardVert, gl.SHADER_SOURCE_LENGTH)');
|
||||||
|
|
||||||
|
// Test getTexParameter
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||||
|
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST');
|
||||||
|
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST');
|
||||||
|
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_EDGE');
|
||||||
|
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_EDGE');
|
||||||
|
|
||||||
|
// Test getUniform with all variants of data types
|
||||||
|
// Boolean uniform variables
|
||||||
|
var boolProgram = loadProgram(gl, "resources/boolUniformShader.vert", "resources/noopUniformShader.frag");
|
||||||
|
shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true');
|
||||||
|
var bvalLoc = gl.getUniformLocation(boolProgram, "bval");
|
||||||
|
var bval2Loc = gl.getUniformLocation(boolProgram, "bval2");
|
||||||
|
var bval3Loc = gl.getUniformLocation(boolProgram, "bval3");
|
||||||
|
var bval4Loc = gl.getUniformLocation(boolProgram, "bval4");
|
||||||
|
gl.useProgram(boolProgram);
|
||||||
|
gl.uniform1i(bvalLoc, 1);
|
||||||
|
gl.uniform2i(bval2Loc, 1, 0);
|
||||||
|
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]');
|
||||||
|
// Integer uniform variables
|
||||||
|
var intProgram = loadProgram(gl, "resources/intUniformShader.vert", "resources/noopUniformShader.frag");
|
||||||
|
shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true');
|
||||||
|
var ivalLoc = gl.getUniformLocation(intProgram, "ival");
|
||||||
|
var ival2Loc = gl.getUniformLocation(intProgram, "ival2");
|
||||||
|
var ival3Loc = gl.getUniformLocation(intProgram, "ival3");
|
||||||
|
var ival4Loc = gl.getUniformLocation(intProgram, "ival4");
|
||||||
|
gl.useProgram(intProgram);
|
||||||
|
gl.uniform1i(ivalLoc, 1);
|
||||||
|
gl.uniform2i(ival2Loc, 2, 3);
|
||||||
|
gl.uniform3i(ival3Loc, 4, 5, 6);
|
||||||
|
gl.uniform4i(ival4Loc, 7, 8, 9, 10);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
shouldBe('gl.getUniform(intProgram, ivalLoc)', '1');
|
||||||
|
shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]');
|
||||||
|
shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]');
|
||||||
|
shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]');
|
||||||
|
// Float uniform variables
|
||||||
|
var floatProgram = loadProgram(gl, "resources/floatUniformShader.vert", "resources/noopUniformShader.frag");
|
||||||
|
shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true');
|
||||||
|
var fvalLoc = gl.getUniformLocation(floatProgram, "fval");
|
||||||
|
var fval2Loc = gl.getUniformLocation(floatProgram, "fval2");
|
||||||
|
var fval3Loc = gl.getUniformLocation(floatProgram, "fval3");
|
||||||
|
var fval4Loc = gl.getUniformLocation(floatProgram, "fval4");
|
||||||
|
gl.useProgram(floatProgram);
|
||||||
|
gl.uniform1f(fvalLoc, 11);
|
||||||
|
gl.uniform2f(fval2Loc, 12, 13);
|
||||||
|
gl.uniform3f(fval3Loc, 14, 15, 16);
|
||||||
|
gl.uniform4f(fval4Loc, 17, 18, 19, 20);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11');
|
||||||
|
shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]');
|
||||||
|
shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]');
|
||||||
|
shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]');
|
||||||
|
// Matrix uniform variables
|
||||||
|
var matProgram = loadProgram(gl, "resources/matUniformShader.vert", "resources/noopUniformShader.frag");
|
||||||
|
shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true');
|
||||||
|
var mval2Loc = gl.getUniformLocation(matProgram, "mval2");
|
||||||
|
var mval3Loc = gl.getUniformLocation(matProgram, "mval3");
|
||||||
|
var mval4Loc = gl.getUniformLocation(matProgram, "mval4");
|
||||||
|
gl.useProgram(matProgram);
|
||||||
|
gl.uniformMatrix2fv(mval2Loc, false, [1, 2, 3, 4]);
|
||||||
|
gl.uniformMatrix3fv(mval3Loc, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
||||||
|
gl.uniformMatrix4fv(mval4Loc, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]');
|
||||||
|
shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]');
|
||||||
|
shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]');
|
||||||
|
|
||||||
|
// Test getVertexAttrib
|
||||||
|
var array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW);
|
||||||
|
// Vertex attribute 0 is special in that it has no current state, so
|
||||||
|
// fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute
|
||||||
|
// 1 for these tests instead.
|
||||||
|
gl.enableVertexAttribArray(1);
|
||||||
|
gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0);
|
||||||
|
shouldBeNonNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)');
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true');
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4');
|
||||||
|
shouldBe('(gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 0) || (gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 4 * gl.sizeInBytes(gl.FLOAT))', 'true');
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT');
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false');
|
||||||
|
gl.disableVertexAttribArray(1);
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false');
|
||||||
|
gl.vertexAttrib4f(1, 5, 6, 7, 8);
|
||||||
|
shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]');
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
|
||||||
|
// Test cases where name == 0
|
||||||
|
gl.deleteTexture(texture);
|
||||||
|
shouldBeNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
||||||
|
gl.deleteRenderbuffer(renderbuffer);
|
||||||
|
shouldBeNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
||||||
|
gl.deleteBuffer(buffer);
|
||||||
|
shouldBeNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)');
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
81
content/canvas/test/webgl/conformance/gl-pixelstorei.html
Normal file → Executable file
@@ -6,12 +6,12 @@ found in the LICENSE file.
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
"http://www.w3.org/TR/html4/loose.dtd">
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>WebGL pixelStorei Test</title>
|
<title>WebGL pixelStorei Test</title>
|
||||||
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
||||||
<script src="../resources/js-test-pre.js"></script>
|
<script src="../resources/js-test-pre.js"></script>
|
||||||
<script src="resources/webgl-test.js"> </script>
|
<script src="resources/webgl-test.js"> </script>
|
||||||
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="example" width="50" height="50"></canvas>
|
<canvas id="example" width="50" height="50"></canvas>
|
||||||
@@ -21,41 +21,31 @@ found in the LICENSE file.
|
|||||||
<canvas id="2d03" width="50" height="50"></canvas>
|
<canvas id="2d03" width="50" height="50"></canvas>
|
||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
<script id="vshader" type="x-shader/x-vertex">
|
<script id="vshader" type="x-shader/x-vertex">
|
||||||
attribute vec4 vPosition;
|
attribute vec4 vPosition;
|
||||||
void main()
|
void main() {
|
||||||
{
|
|
||||||
gl_Position = vPosition;
|
gl_Position = vPosition;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="fshader" type="x-shader/x-fragment">
|
<script id="fshader" type="x-shader/x-fragment">
|
||||||
void main()
|
void main() {
|
||||||
{
|
|
||||||
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
|
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function fail(x,y, name, buf, shouldBe)
|
function fail(x,y, name, buf, shouldBe) {
|
||||||
{
|
|
||||||
var i = (y*50+x) * 4;
|
var i = (y*50+x) * 4;
|
||||||
var reason = "pixel in "+name+" at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
|
var reason = "pixel in "+name+" at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
|
||||||
testFailed(reason);
|
testFailed(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pass(name)
|
function pass(name) {
|
||||||
{
|
|
||||||
testPassed("drawing is correct in " + name);
|
testPassed("drawing is correct in " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init()
|
|
||||||
{
|
|
||||||
if (window.layoutTestController) {
|
|
||||||
layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
|
|
||||||
layoutTestController.dumpAsText();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function init() {
|
||||||
debug("There should be 5 red triangles on 5 black squares above");
|
debug("There should be 5 red triangles on 5 black squares above");
|
||||||
debug("");
|
debug("");
|
||||||
|
|
||||||
@@ -67,7 +57,7 @@ found in the LICENSE file.
|
|||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
@@ -78,32 +68,37 @@ found in the LICENSE file.
|
|||||||
function checkData(buf, name) {
|
function checkData(buf, name) {
|
||||||
// Test several locations
|
// Test several locations
|
||||||
// First line should be all black
|
// First line should be all black
|
||||||
for (var i = 0; i < 50; ++i)
|
for (var i = 0; i < 50; ++i) {
|
||||||
if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) {
|
if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) {
|
||||||
fail(i, 0, name, buf, "(0,0,0,255)");
|
fail(i, 0, name, buf, "(0,0,0,255)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Line 15 should be red for at least 10 red pixels starting 20 pixels in
|
// Line 25 should be red for at least 6 red pixels starting 22 pixels in
|
||||||
var offset = (15*50+20) * 4;
|
var offset = (25*50+22) * 4;
|
||||||
for (var i = 0; i < 10; ++i)
|
for (var i = 0; i < 6; ++i) {
|
||||||
if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
|
if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
|
||||||
fail(20 + i, 15, name, buf, "(255,0,0,255)");
|
fail(22 + i, 25, name, buf, "(255,0,0,255)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Last line should be all black
|
// Last line should be all black
|
||||||
offset = (49*50) * 4;
|
offset = (49*50) * 4;
|
||||||
for (var i = 0; i < 50; ++i)
|
for (var i = 0; i < 50; ++i) {
|
||||||
if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
|
if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
|
||||||
fail(i, 49, name, buf, "(0,0,0,255)");
|
fail(i, 49, name, buf, "(0,0,0,255)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pass(name);
|
pass(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkColors() {
|
function checkColors() {
|
||||||
var buf = gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE);
|
var buf = new Uint8Array(50 * 50 * 4);
|
||||||
|
gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
checkData(buf, "3d context");
|
checkData(buf, "3d context");
|
||||||
var imgData = ctx2d.getImageData(0, 0, 50, 50);
|
var imgData = ctx2d.getImageData(0, 0, 50, 50);
|
||||||
checkData(imgData.data, "2d context");
|
checkData(imgData.data, "2d context");
|
||||||
@@ -119,11 +114,11 @@ found in the LICENSE file.
|
|||||||
assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii],
|
assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii],
|
||||||
"PACK_ALIGNMENT is " + table[ii]);
|
"PACK_ALIGNMENT is " + table[ii]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
successfullyParsed = true;
|
successfullyParsed = true;
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ found in the LICENSE file.
|
|||||||
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
||||||
<script src="../../debug/webgl-debug.js"></script>
|
<script src="../../debug/webgl-debug.js"></script>
|
||||||
<script src="../resources/js-test-pre.js"></script>
|
<script src="../resources/js-test-pre.js"></script>
|
||||||
<script src="../fast/resources/webgl-test.js"></script>
|
<script src="resources/webgl-test-utils.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
@@ -25,7 +25,8 @@ description("Check if glScissor setting works.");
|
|||||||
debug("");
|
debug("");
|
||||||
debug("Canvas.getContext");
|
debug("Canvas.getContext");
|
||||||
|
|
||||||
var gl = create3DContext(document.getElementById("canvas"));
|
var wtu = WebGLTestUtils;
|
||||||
|
var gl = wtu.create3DContext(document.getElementById("canvas"));
|
||||||
if (!gl) {
|
if (!gl) {
|
||||||
testFailed("context does not exist");
|
testFailed("context does not exist");
|
||||||
} else {
|
} else {
|
||||||
@@ -33,13 +34,17 @@ if (!gl) {
|
|||||||
|
|
||||||
debug("");
|
debug("");
|
||||||
|
|
||||||
|
gl.clearColor(0,0,0,0);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// clear a portion of our FBO
|
// clear a portion of our FBO
|
||||||
gl.enable(gl.SCISSOR_TEST);
|
gl.enable(gl.SCISSOR_TEST);
|
||||||
gl.scissor(0, 0, 1, 1);
|
gl.scissor(0, 0, 1, 1);
|
||||||
gl.clearColor(0,1,0,1);
|
gl.clearColor(0,1,0,1);
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
var b = gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE);
|
var b = new Uint8Array(2 * 2 * 4);
|
||||||
|
gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, b);
|
||||||
checkPixel(b, 0, 0, [0, 1, 0, 1]);
|
checkPixel(b, 0, 0, [0, 1, 0, 1]);
|
||||||
checkPixel(b, 1, 0, [0, 0, 0, 0]);
|
checkPixel(b, 1, 0, [0, 0, 0, 0]);
|
||||||
checkPixel(b, 0, 1, [0, 0, 0, 0]);
|
checkPixel(b, 0, 1, [0, 0, 0, 0]);
|
||||||
|
|||||||
265
content/canvas/test/webgl/conformance/gl-teximage.html
Executable file
@@ -0,0 +1,265 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2009 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 texImage2D conformance test.</title>
|
||||||
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
||||||
|
<script src="../resources/js-test-pre.js"></script>
|
||||||
|
<script src="resources/webgl-test-utils.js"> </script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="example" width="256" height="16" style="width: 256px; height: 48px;"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script>
|
||||||
|
description("Test texImage2D conversions.");
|
||||||
|
var wtu = WebGLTestUtils;
|
||||||
|
var canvas = document.getElementById("example");
|
||||||
|
var gl = wtu.create3DContext(canvas);
|
||||||
|
var program = wtu.setupTexturedQuad(gl);
|
||||||
|
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
|
||||||
|
|
||||||
|
var imgURLs = [
|
||||||
|
'resources/gray-ramp-256-with-128-alpha.png',
|
||||||
|
'resources/gray-ramp-256.png',
|
||||||
|
'resources/gray-ramp-default-gamma.png',
|
||||||
|
'resources/gray-ramp-gamma0.1.png',
|
||||||
|
'resources/gray-ramp-gamma1.0.png',
|
||||||
|
'resources/gray-ramp-gamma2.0.png',
|
||||||
|
'resources/gray-ramp-gamma4.0.png',
|
||||||
|
'resources/gray-ramp-gamma9.0.png',
|
||||||
|
'resources/gray-ramp.png',
|
||||||
|
'resources/zero-alpha.png',
|
||||||
|
'resources/3x3.png'];
|
||||||
|
|
||||||
|
wtu.loadImagesAsync(imgURLs, runTests);
|
||||||
|
|
||||||
|
function runTests(imgs) {
|
||||||
|
var loc = gl.getUniformLocation(program, "tex");
|
||||||
|
gl.uniform1i(loc, 0);
|
||||||
|
|
||||||
|
gl.disable(gl.BLEND);
|
||||||
|
gl.disable(gl.DEPTH_TEST);
|
||||||
|
|
||||||
|
var width = canvas.width;
|
||||||
|
var height = canvas.height;
|
||||||
|
|
||||||
|
function checkPixel(buf, x, y, color) {
|
||||||
|
var off = (y * width + x) * 4;
|
||||||
|
var msg = "pixel " + x + ", " + y + " should be " +
|
||||||
|
color[0] + ", " +
|
||||||
|
color[1] + ", " +
|
||||||
|
color[2] + ", " +
|
||||||
|
color[3] + " was " +
|
||||||
|
buf[off + 0] + ", " +
|
||||||
|
buf[off + 1] + ", " +
|
||||||
|
buf[off + 2] + ", " +
|
||||||
|
buf[off + 3];
|
||||||
|
|
||||||
|
for (var ii = 0; ii < 4; ++ii) {
|
||||||
|
if (buf[off + ii] != color[ii]) {
|
||||||
|
testFailed(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testPassed(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tex = gl.createTexture();
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, tex);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||||
|
|
||||||
|
var buf = new Uint8Array(width * height * 4);
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("check pixels are NOT pre-multiplied");
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
|
||||||
|
imgs['resources/zero-alpha.png']);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
|
||||||
|
var left = 0;
|
||||||
|
var middle = Math.floor(width / 2);
|
||||||
|
var right = width - 1;
|
||||||
|
var top = 0;
|
||||||
|
var center = Math.floor(height / 2);
|
||||||
|
var bottom = height - 1;
|
||||||
|
checkPixel(buf, left, top, [ 0, 0, 0, 255]);
|
||||||
|
checkPixel(buf, middle, top, [255, 0, 255, 255]);
|
||||||
|
checkPixel(buf, right, top, [ 0, 0, 255, 255]);
|
||||||
|
checkPixel(buf, left, center, [128, 128, 128, 255]);
|
||||||
|
checkPixel(buf, middle, center, [255, 255, 255, 255]);
|
||||||
|
checkPixel(buf, right, center, [ 0, 255, 255, 255]);
|
||||||
|
checkPixel(buf, left, bottom, [255, 0, 0, 255]);
|
||||||
|
checkPixel(buf, middle, bottom, [255, 255, 0, 255]);
|
||||||
|
checkPixel(buf, right, bottom, [ 0, 255, 0, 255]);
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("check quantization");
|
||||||
|
var quantInfo = [
|
||||||
|
{format: gl.RGBA, type: gl.UNSIGNED_BYTE, counts: [256, 256, 256, 256]},
|
||||||
|
{format: gl.RGBA, type: gl.UNSIGNED_SHORT_4_4_4_4, counts: [ 16, 16, 16, 16]},
|
||||||
|
{format: gl.RGB, type: gl.UNSIGNED_SHORT_5_6_5, counts: [ 32, 64, 32, 1]},
|
||||||
|
{format: gl.RGBA, type: gl.UNSIGNED_SHORT_5_5_5_1, counts: [ 32, 32, 32, 2]}];
|
||||||
|
for (var qq = 0; qq < quantInfo.length; ++qq) {
|
||||||
|
var info = quantInfo[qq];
|
||||||
|
gl.texImage2D(
|
||||||
|
gl.TEXTURE_2D, 0, info.format, info.format, info.type,
|
||||||
|
imgs['resources/gray-ramp-256.png']);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
var counts = [{ }, { }, { }, { }];
|
||||||
|
var numUniqueValues = [0, 0, 0, 0];
|
||||||
|
// Count the number of unique values in each channel.
|
||||||
|
for (var ii = 0; ii < width * height * 4; ii += 4) {
|
||||||
|
for (var jj = 0; jj < 4; ++jj) {
|
||||||
|
var v = buf[ii + jj];
|
||||||
|
if (!counts[jj][v]) {
|
||||||
|
counts[jj][v] = 1;
|
||||||
|
++numUniqueValues[jj];
|
||||||
|
} else {
|
||||||
|
++counts[jj][v];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var ii = 0; ii < 4; ++ii) {
|
||||||
|
assertMsg(numUniqueValues[ii] == info.counts[ii],
|
||||||
|
"There should be " + info.counts[ii] +
|
||||||
|
" unique values in channel " + ii + ". Found " +
|
||||||
|
numUniqueValues[ii]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("Check that gamma settings don't effect 8bit pngs");
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
|
||||||
|
imgs['resources/gray-ramp-default-gamma.png']);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
var ref = new Uint8Array(width * height * 4);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, ref);
|
||||||
|
|
||||||
|
var gammaImages = [
|
||||||
|
'resources/gray-ramp-gamma0.1.png',
|
||||||
|
'resources/gray-ramp-gamma1.0.png',
|
||||||
|
'resources/gray-ramp-gamma2.0.png',
|
||||||
|
'resources/gray-ramp-gamma4.0.png',
|
||||||
|
'resources/gray-ramp-gamma9.0.png'];
|
||||||
|
for (var ii = 0; ii < gammaImages.length; ++ii) {
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
|
||||||
|
imgs[gammaImages[ii]]);
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
var same = true;
|
||||||
|
for (var jj = 0; jj < width * height * 4; ++jj) {
|
||||||
|
if (buf[jj] != ref[jj]) {
|
||||||
|
same = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertMsg(same, "pixels should be same regardless of gamma settings.");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("check pixels are UN pre-multiplied");
|
||||||
|
var canvas2d = document.createElement("canvas");
|
||||||
|
canvas2d.width = 256;
|
||||||
|
canvas2d.height = 1;
|
||||||
|
//canvas2d.style.height = "40px";
|
||||||
|
//var description = document.getElementById("description");
|
||||||
|
//description.appendChild(canvas2d);
|
||||||
|
var ctx = canvas2d.getContext("2d");
|
||||||
|
ctx.fillRect(0, 0, 256, 1);
|
||||||
|
ctx.drawImage(imgs['resources/gray-ramp-256-with-128-alpha.png'], 0, 0);
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, canvas2d);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
var ref = new Uint8Array(width * height * 4);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, ref);
|
||||||
|
var lt128Count = [0, 0, 0];
|
||||||
|
var ge128Count = [0, 0, 0];
|
||||||
|
for (var jj = 0; jj < width; ++jj) {
|
||||||
|
var off = jj * 4;
|
||||||
|
for (var cc = 0; cc < 3; ++cc) {
|
||||||
|
if (buf[off + cc] < 128) {
|
||||||
|
++lt128Count[cc];
|
||||||
|
} else {
|
||||||
|
++ge128Count[cc];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Not sure the exact count here because gamma does effect drawing into the
|
||||||
|
// canvas but it should be close to 50% so I'll pass 45%
|
||||||
|
for (var jj = 0; jj < 3; ++jj) {
|
||||||
|
assertMsg(ge128Count[jj] > 256 * 0.45,
|
||||||
|
"Half the pixels in channel " + jj +
|
||||||
|
" should be >= 128,128,128. found " +
|
||||||
|
((ge128Count[jj] / 256) * 100).toFixed() + "%");
|
||||||
|
assertMsg(lt128Count[jj] > 256 * 0.45,
|
||||||
|
"Half the pixels in channel " + jj +
|
||||||
|
" should be < 128,128,128. found " +
|
||||||
|
((lt128Count[jj] / 256) * 100).toFixed() + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("check pixels are pre-multiplied");
|
||||||
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
||||||
|
// TODO(gman): use different texture that won't pass on failure
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
|
||||||
|
imgs['resources/zero-alpha.png']);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
|
||||||
|
var same = true;
|
||||||
|
for (var jj = 0; jj < width * height * 4; ++jj) {
|
||||||
|
if (buf[jj] != 0) {
|
||||||
|
same = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertMsg(same, "pixels should all be 0.");
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
debug("check pixels are flipped");
|
||||||
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
||||||
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE,
|
||||||
|
imgs['resources/3x3.png']);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup");
|
||||||
|
wtu.drawQuad(gl);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
|
||||||
|
checkPixel(buf, left, top, [255, 0, 0, 255]);
|
||||||
|
checkPixel(buf, middle, top, [255, 255, 0, 255]);
|
||||||
|
checkPixel(buf, right, top, [255, 0, 0, 255]);
|
||||||
|
checkPixel(buf, left, center, [255, 0, 255, 255]);
|
||||||
|
checkPixel(buf, middle, center, [255, 0, 0, 255]);
|
||||||
|
checkPixel(buf, right, center, [ 0, 255, 0, 255]);
|
||||||
|
checkPixel(buf, left, bottom, [ 0, 0, 0, 255]);
|
||||||
|
checkPixel(buf, middle, bottom, [ 0, 0, 255, 255]);
|
||||||
|
checkPixel(buf, right, bottom, [255, 0, 0, 255]);
|
||||||
|
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors");
|
||||||
|
|
||||||
|
debug("");
|
||||||
|
successfullyParsed = true;
|
||||||
|
shouldBeTrue("successfullyParsed");
|
||||||
|
debug('<br /><span class="pass">TEST COMPLETE</span>');
|
||||||
|
notifyFinishedToHarness();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@@ -27,7 +27,12 @@ found in the LICENSE file.
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="fshader" type="x-shader/x-fragment">
|
<script id="fshader" type="x-shader/x-fragment">
|
||||||
|
// Workaround for non-compliant WebGL implementations (FIXME)
|
||||||
|
#if defined(GL_ES)
|
||||||
|
uniform mediump $type color[3];
|
||||||
|
#else
|
||||||
uniform $type color[3];
|
uniform $type color[3];
|
||||||
|
#endif
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = vec4(color[0]$elem, color[1]$elem, color[2]$elem, 1);
|
gl_FragColor = vec4(color[0]$elem, color[1]$elem, color[2]$elem, 1);
|
||||||
@@ -96,7 +101,7 @@ var typeInfos = [
|
|||||||
setter: 'uniform1fv',
|
setter: 'uniform1fv',
|
||||||
elem: '',
|
elem: '',
|
||||||
numSrcValues: 3,
|
numSrcValues: 3,
|
||||||
badSet: function(loc) {
|
invalidSet: function(loc) {
|
||||||
gl.uniform2fv(loc, [1, 2]);
|
gl.uniform2fv(loc, [1, 2]);
|
||||||
},
|
},
|
||||||
srcValueAsString: function(index, srcValues) {
|
srcValueAsString: function(index, srcValues) {
|
||||||
@@ -111,16 +116,20 @@ var typeInfos = [
|
|||||||
checkValue: function(typeInfo, index, value) {
|
checkValue: function(typeInfo, index, value) {
|
||||||
return typeInfo.srcValues[index] == value;
|
return typeInfo.srcValues[index] == value;
|
||||||
},
|
},
|
||||||
srcValues: [16, 15, 14]
|
srcValues: [16, 15, 14],
|
||||||
|
srcValuesBad: [],
|
||||||
},
|
},
|
||||||
{ type: 'vec2',
|
{ type: 'vec2',
|
||||||
jsTypeOf: 'WebGLFloatArray',
|
jsTypeOf: 'Float32Array',
|
||||||
setter: 'uniform2fv',
|
setter: 'uniform2fv',
|
||||||
elem: '[1]',
|
elem: '[1]',
|
||||||
numSrcValues: 3,
|
numSrcValues: 3,
|
||||||
badSet: function(loc) {
|
invalidSet: function(loc) {
|
||||||
gl.uniform1fv(loc, [2]);
|
gl.uniform1fv(loc, [2]);
|
||||||
},
|
},
|
||||||
|
illegalSet: function(loc) {
|
||||||
|
gl.uniform1fv(loc, 2);
|
||||||
|
},
|
||||||
srcValueAsString: function(index, srcValues) {
|
srcValueAsString: function(index, srcValues) {
|
||||||
return "[" + srcValues[index * 2 + 0].toString() + ", " +
|
return "[" + srcValues[index * 2 + 0].toString() + ", " +
|
||||||
srcValues[index * 2 + 1].toString() + "]";
|
srcValues[index * 2 + 1].toString() + "]";
|
||||||
@@ -138,15 +147,19 @@ var typeInfos = [
|
|||||||
typeInfo.srcValues[index * 2 + 1] == value[1];
|
typeInfo.srcValues[index * 2 + 1] == value[1];
|
||||||
},
|
},
|
||||||
srcValues: [16, 15, 14, 13, 12, 11],
|
srcValues: [16, 15, 14, 13, 12, 11],
|
||||||
|
srcValuesBad: [16],
|
||||||
},
|
},
|
||||||
{ type: 'vec3',
|
{ type: 'vec3',
|
||||||
jsTypeOf: 'WebGLFloatArray',
|
jsTypeOf: 'Float32Array',
|
||||||
setter: 'uniform3fv',
|
setter: 'uniform3fv',
|
||||||
elem: '[2]',
|
elem: '[2]',
|
||||||
numSrcValues: 3,
|
numSrcValues: 3,
|
||||||
badSet: function(loc) {
|
invalidSet: function(loc) {
|
||||||
gl.uniform1fv(loc, [2]);
|
gl.uniform1fv(loc, [2]);
|
||||||
},
|
},
|
||||||
|
illegalSet: function(loc) {
|
||||||
|
gl.uniform1fv(loc, 2);
|
||||||
|
},
|
||||||
srcValueAsString: function(index, srcValues) {
|
srcValueAsString: function(index, srcValues) {
|
||||||
return "[" + srcValues[index * 3 + 0].toString() + ", " +
|
return "[" + srcValues[index * 3 + 0].toString() + ", " +
|
||||||
srcValues[index * 3 + 1].toString() + ", " +
|
srcValues[index * 3 + 1].toString() + ", " +
|
||||||
@@ -166,16 +179,20 @@ var typeInfos = [
|
|||||||
typeInfo.srcValues[index * 3 + 1] == value[1] &&
|
typeInfo.srcValues[index * 3 + 1] == value[1] &&
|
||||||
typeInfo.srcValues[index * 3 + 2] == value[2];
|
typeInfo.srcValues[index * 3 + 2] == value[2];
|
||||||
},
|
},
|
||||||
srcValues: [16, 15, 14, 13, 12, 11, 10, 11, 9],
|
srcValues: [16, 15, 14, 13, 12, 11, 10, 9, 8],
|
||||||
|
srcValuesBad: [16, 15],
|
||||||
},
|
},
|
||||||
{ type: 'vec4',
|
{ type: 'vec4',
|
||||||
jsTypeOf: 'WebGLFloatArray',
|
jsTypeOf: 'Float32Array',
|
||||||
setter: 'uniform4fv',
|
setter: 'uniform4fv',
|
||||||
elem: '[3]',
|
elem: '[3]',
|
||||||
numSrcValues: 3,
|
numSrcValues: 3,
|
||||||
badSet: function(loc) {
|
invalidSet: function(loc) {
|
||||||
gl.uniform1fv(loc, [2]);
|
gl.uniform1fv(loc, [2]);
|
||||||
},
|
},
|
||||||
|
illegalSet: function(loc) {
|
||||||
|
gl.uniform1fv(loc, 2);
|
||||||
|
},
|
||||||
srcValueAsString: function(index, srcValues) {
|
srcValueAsString: function(index, srcValues) {
|
||||||
return "[" + srcValues[index * 4 + 0].toString() + ", " +
|
return "[" + srcValues[index * 4 + 0].toString() + ", " +
|
||||||
srcValues[index * 4 + 1].toString() + ", " +
|
srcValues[index * 4 + 1].toString() + ", " +
|
||||||
@@ -198,7 +215,8 @@ var typeInfos = [
|
|||||||
typeInfo.srcValues[index * 4 + 2] == value[2] &&
|
typeInfo.srcValues[index * 4 + 2] == value[2] &&
|
||||||
typeInfo.srcValues[index * 4 + 3] == value[3];
|
typeInfo.srcValues[index * 4 + 3] == value[3];
|
||||||
},
|
},
|
||||||
srcValues: [16, 15, 14, 13, 12, 11, 10, 11, 9, 8, 7, 6, 5],
|
srcValues: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5],
|
||||||
|
srcValuesBad: [16, 15, 14],
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -218,6 +236,7 @@ for (var tt = 0; tt < typeInfos.length; ++tt) {
|
|||||||
"uniform name is 'color[0]' not 'color' as per OpenGL ES 2.0.24 section 2.10");
|
"uniform name is 'color[0]' not 'color' as per OpenGL ES 2.0.24 section 2.10");
|
||||||
var loc = gl.getUniformLocation(program, "color");
|
var loc = gl.getUniformLocation(program, "color");
|
||||||
var srcValues = typeInfo.srcValues;
|
var srcValues = typeInfo.srcValues;
|
||||||
|
var srcValuesBad = typeInfo.srcValuesBad;
|
||||||
|
|
||||||
// Try setting the value before using the program
|
// Try setting the value before using the program
|
||||||
gl[typeInfo.setter](loc, srcValues);
|
gl[typeInfo.setter](loc, srcValues);
|
||||||
@@ -225,6 +244,9 @@ for (var tt = 0; tt < typeInfos.length; ++tt) {
|
|||||||
"should fail if there is no current program");
|
"should fail if there is no current program");
|
||||||
|
|
||||||
gl.useProgram(program);
|
gl.useProgram(program);
|
||||||
|
gl[typeInfo.setter](loc, srcValuesBad);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_VALUE,
|
||||||
|
"should fail with insufficient array size with gl." + typeInfo.setter);
|
||||||
gl[typeInfo.setter](loc, srcValues);
|
gl[typeInfo.setter](loc, srcValues);
|
||||||
assertMsg(gl.getError() == gl.NO_ERROR,
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
||||||
"can set an array of uniforms with gl." + typeInfo.setter);
|
"can set an array of uniforms with gl." + typeInfo.setter);
|
||||||
@@ -246,11 +268,22 @@ for (var tt = 0; tt < typeInfos.length; ++tt) {
|
|||||||
") matches value pulled out (" +
|
") matches value pulled out (" +
|
||||||
typeInfo.returnValueAsString(value) + ")");
|
typeInfo.returnValueAsString(value) + ")");
|
||||||
}
|
}
|
||||||
typeInfo.badSet(loc);
|
typeInfo.invalidSet(loc);
|
||||||
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
||||||
"using the wrong size of gl.Uniform fails");
|
"using the wrong size of gl.Uniform fails");
|
||||||
|
var exceptionCaught = false;
|
||||||
|
if (typeInfo.illegalSet) {
|
||||||
|
try {
|
||||||
|
typeInfo.illegalSet(loc);
|
||||||
|
} catch (e) {
|
||||||
|
exceptionCaught = true;
|
||||||
|
}
|
||||||
|
assertMsg(exceptionCaught, "passing non-array to glUniform*fv should throw TypeError");
|
||||||
|
}
|
||||||
|
|
||||||
gl.useProgram(null);
|
gl.useProgram(null);
|
||||||
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
||||||
|
"can call gl.useProgram(null)");
|
||||||
}
|
}
|
||||||
debug("");
|
debug("");
|
||||||
successfullyParsed = true;
|
successfullyParsed = true;
|
||||||
|
|||||||
40
content/canvas/test/webgl/conformance/gl-uniformmatrix4fv.html
Normal file → Executable file
@@ -18,23 +18,25 @@ found in the LICENSE file.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
<canvas id="example" width="2" height="2"> </canvas>
|
<canvas id="example" width="2" height="2"> </canvas>
|
||||||
<script id="vshader" type="x-shader/x-vertex">
|
|
||||||
attribute vec4 vPosition;
|
|
||||||
uniform mat4 world4;
|
|
||||||
uniform mat3 world3;
|
|
||||||
uniform mat2 world2;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(vPosition.xyz, world3[0].x + world2[0].x) * world4;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script id="fshader" type="x-shader/x-fragment">
|
<script id="vshader" type="x-shader/x-vertex">
|
||||||
void main()
|
attribute vec4 vPosition;
|
||||||
{
|
uniform mat4 world4;
|
||||||
|
uniform mat3 world3;
|
||||||
|
uniform mat2 world2;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(vPosition.xyz, world3[0].x + world2[0].x) * world4;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="fshader" type="x-shader/x-fragment">
|
||||||
|
void main()
|
||||||
|
{
|
||||||
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
|
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
description("This test ensures WebGL implementations handle uniformMatrix in a OpenGL ES 2.0 spec compliant way");
|
description("This test ensures WebGL implementations handle uniformMatrix in a OpenGL ES 2.0 spec compliant way");
|
||||||
|
|
||||||
@@ -47,11 +49,16 @@ for (var ii = 2; ii <= 4; ++ii) {
|
|||||||
var mat = [];
|
var mat = [];
|
||||||
for (var jj = 0; jj < ii; ++jj) {
|
for (var jj = 0; jj < ii; ++jj) {
|
||||||
for (var ll = 0; ll < ii; ++ll) {
|
for (var ll = 0; ll < ii; ++ll) {
|
||||||
|
if (jj == ii - 1 && ll == ii - 1)
|
||||||
|
continue;
|
||||||
mat[jj * ii + ll] = (jj == ll) ? 1 : 0;
|
mat[jj * ii + ll] = (jj == ll) ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name = "uniformMatrix" + ii + "fv";
|
name = "uniformMatrix" + ii + "fv";
|
||||||
gl[name](loc, false, mat);
|
gl[name](loc, false, mat);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_VALUE, "should fail with insufficient array size for " + name);
|
||||||
|
mat[ii * ii - 1] = 1;
|
||||||
|
gl[name](loc, false, mat);
|
||||||
assertMsg(gl.getError() == gl.NO_ERROR, "can call " + name + "with transpose = false");
|
assertMsg(gl.getError() == gl.NO_ERROR, "can call " + name + "with transpose = false");
|
||||||
gl[name](loc, true, mat);
|
gl[name](loc, true, mat);
|
||||||
assertMsg(gl.getError() == gl.INVALID_VALUE, name + " should return INVALID_VALUE with transpose = true");
|
assertMsg(gl.getError() == gl.INVALID_VALUE, name + " should return INVALID_VALUE with transpose = true");
|
||||||
@@ -63,8 +70,5 @@ successfullyParsed = true;
|
|||||||
</script>
|
</script>
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
<script>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ description("Tests that unknown uniforms don't cause errors.");
|
|||||||
debug("");
|
debug("");
|
||||||
debug("Canvas.getContext");
|
debug("Canvas.getContext");
|
||||||
|
|
||||||
gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
|
var gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
|
||||||
var gl = create3DContext(document.getElementById("canvas"));
|
|
||||||
if (!gl) {
|
if (!gl) {
|
||||||
testFailed("context does not exist");
|
testFailed("context does not exist");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ if (!gl) {
|
|||||||
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[1]', '2');
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[1]', '2');
|
||||||
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[2]', '3');
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[2]', '3');
|
||||||
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[3]', '4');
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[3]', '4');
|
||||||
|
|
||||||
|
gl.vertexAttrib1f(0, 5);
|
||||||
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[0]', '5');
|
||||||
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[1]', '0');
|
||||||
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[2]', '0');
|
||||||
|
shouldBe('gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB)[3]', '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("");
|
debug("");
|
||||||
0
content/canvas/test/webgl/conformance/gl-vertexattribpointer.html
Normal file → Executable file
@@ -43,9 +43,8 @@ void main()
|
|||||||
<script>
|
<script>
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
if (window.layoutTestController) {
|
if (window.initNonKhronosFramework) {
|
||||||
layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
|
window.initNonKhronosFramework(false);
|
||||||
layoutTestController.dumpAsText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Tests that using 2 types of textures on the same texture unit");
|
debug("Tests that using 2 types of textures on the same texture unit");
|
||||||
@@ -67,7 +66,8 @@ function init()
|
|||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(
|
gl.bufferData(
|
||||||
gl.ARRAY_BUFFER,
|
gl.ARRAY_BUFFER,
|
||||||
new WebGLFloatArray([-1, 1,0, 1,1,0, -1,-1,0,
|
new Float32Array([
|
||||||
|
-1, 1,0, 1,1,0, -1,-1,0,
|
||||||
-1,-1,0, 1,1,0, 1,-1,0]),
|
-1,-1,0, 1,1,0, 1,-1,0]),
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
@@ -77,7 +77,8 @@ function init()
|
|||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(
|
gl.bufferData(
|
||||||
gl.ARRAY_BUFFER,
|
gl.ARRAY_BUFFER,
|
||||||
new WebGLFloatArray([ 0,0, 1,0, 0,1,
|
new Float32Array([
|
||||||
|
0,0, 1,0, 0,1,
|
||||||
0,1, 1,0, 1,1]),
|
0,1, 1,0, 1,1]),
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(1);
|
gl.enableVertexAttribArray(1);
|
||||||
@@ -91,9 +92,7 @@ function init()
|
|||||||
gl.bindTexture(gl.TEXTURE_2D, tex2d);
|
gl.bindTexture(gl.TEXTURE_2D, tex2d);
|
||||||
ctx2d.fillStyle = "rgba(0, 0, 255, 255)";
|
ctx2d.fillStyle = "rgba(0, 0, 255, 255)";
|
||||||
ctx2d.fillRect(0, 0, 1, 1);
|
ctx2d.fillRect(0, 0, 1, 1);
|
||||||
gl.texImage2D(gl.TEXTURE_2D,
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
|
||||||
0, // level
|
|
||||||
canvas2d); // internalFormat
|
|
||||||
|
|
||||||
// make a cube texture
|
// make a cube texture
|
||||||
var texCube = gl.createTexture();
|
var texCube = gl.createTexture();
|
||||||
@@ -107,9 +106,7 @@ function init()
|
|||||||
gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||||
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];
|
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];
|
||||||
for (var ii = 0; ii < targets.length; ++ii) {
|
for (var ii = 0; ii < targets.length; ++ii) {
|
||||||
gl.texImage2D(targets[ii],
|
gl.texImage2D(targets[ii], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
|
||||||
0, // level
|
|
||||||
canvas2d); // internalFormat
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tex2dLoc = gl.getUniformLocation(gl.program, "tex2d");
|
var tex2dLoc = gl.getUniformLocation(gl.program, "tex2d");
|
||||||
|
|||||||
164
content/canvas/test/webgl/conformance/glsl-conformance.html
Normal file → Executable file
@@ -12,7 +12,7 @@ found in the LICENSE file.
|
|||||||
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
||||||
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
||||||
<script src="../resources/js-test-pre.js"></script>
|
<script src="../resources/js-test-pre.js"></script>
|
||||||
<script src="resources/webgl-test.js"></script>
|
<script src="resources/webgl-test-utils.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
@@ -64,7 +64,7 @@ void main()
|
|||||||
precision mediump float;
|
precision mediump float;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = vec4(0.0,0.0,1.0);
|
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foo
|
foo
|
||||||
@@ -157,6 +157,45 @@ void main()
|
|||||||
gl_Position = _webgl_vPosition;
|
gl_Position = _webgl_vPosition;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<script id="vshaderWithImplicitVec3Cast" type="text/something-not-javascript">
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
highp vec3 k = vec3(1, 2, 3);
|
||||||
|
gl_Position = k;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="vshaderWithExplicitIntCast" type="text/something-not-javascript">
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
int k = 123;
|
||||||
|
gl_Position = vec4(vPosition.x, vPosition.y, vPosition.z, float(k));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="vshaderWithVersion130" type="text/something-not-javascript">
|
||||||
|
#version 130
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vPosition;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="vshaderWithVersion100" type="text/something-not-javascript">
|
||||||
|
#version 100
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vPosition;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="vshaderWithLineDirective" type="text/something-not-javascript">
|
||||||
|
#line 123
|
||||||
|
foo
|
||||||
|
</script>
|
||||||
|
<script id="vshaderWith__FILE__" type="text/something-not-javascript">
|
||||||
|
__FILE__
|
||||||
|
</script>
|
||||||
<canvas id="canvas" width="2" height="2"> </canvas>
|
<canvas id="canvas" width="2" height="2"> </canvas>
|
||||||
<script>
|
<script>
|
||||||
description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
|
description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
|
||||||
@@ -164,7 +203,8 @@ description("This test ensures WebGL implementations allow proper GLES2 shaders
|
|||||||
debug("");
|
debug("");
|
||||||
debug("Canvas.getContext");
|
debug("Canvas.getContext");
|
||||||
|
|
||||||
var gl = create3DContext(document.getElementById("canvas"));
|
var wtu = WebGLTestUtils;
|
||||||
|
var gl = wtu.create3DContext(document.getElementById("canvas"));
|
||||||
if (!gl) {
|
if (!gl) {
|
||||||
testFailed("context does not exist");
|
testFailed("context does not exist");
|
||||||
} else {
|
} else {
|
||||||
@@ -179,35 +219,6 @@ if (!gl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadShader(shaderType, shaderId) {
|
|
||||||
// Get the shader source.
|
|
||||||
var shaderSource = document.getElementById(shaderId).text;
|
|
||||||
|
|
||||||
// Create the shader object
|
|
||||||
var shader = gl.createShader(shaderType);
|
|
||||||
if (shader == null) {
|
|
||||||
debug("*** Error: unable to create shader '"+shaderId+"'");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the shader source
|
|
||||||
gl.shaderSource(shader, shaderSource);
|
|
||||||
|
|
||||||
// Compile the shader
|
|
||||||
gl.compileShader(shader);
|
|
||||||
|
|
||||||
// Check the compile status
|
|
||||||
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
|
||||||
if (!compiled) {
|
|
||||||
// Something went wrong during compilation; get the error
|
|
||||||
var error = gl.getShaderInfoLog(shader);
|
|
||||||
log("*** Error compiling shader '"+shader+"':"+error);
|
|
||||||
gl.deleteShader(shader);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
var shaderInfo = [
|
var shaderInfo = [
|
||||||
{ vShaderId: 'vshader',
|
{ vShaderId: 'vshader',
|
||||||
vShaderSuccess: true,
|
vShaderSuccess: true,
|
||||||
@@ -255,7 +266,7 @@ if (!gl) {
|
|||||||
vShaderSuccess: true,
|
vShaderSuccess: true,
|
||||||
fShaderId: 'fshaderWithFragDepth',
|
fShaderId: 'fshaderWithFragDepth',
|
||||||
fShaderSuccess: false,
|
fShaderSuccess: false,
|
||||||
linkSuccess: true,
|
linkSuccess: false,
|
||||||
passMsg: 'fragment shader that uses gl_FragDepth should fail',
|
passMsg: 'fragment shader that uses gl_FragDepth should fail',
|
||||||
},
|
},
|
||||||
{ vShaderId: 'vshaderWithClipVertex',
|
{ vShaderId: 'vshaderWithClipVertex',
|
||||||
@@ -320,22 +331,91 @@ if (!gl) {
|
|||||||
fShaderSuccess: true,
|
fShaderSuccess: true,
|
||||||
linkSuccess: false,
|
linkSuccess: false,
|
||||||
passMsg: 'vertex shader that uses _webgl_ identifier should fail',
|
passMsg: 'vertex shader that uses _webgl_ identifier should fail',
|
||||||
|
},
|
||||||
|
{ vShaderId: 'vshaderWithExplicitIntCast',
|
||||||
|
vShaderSuccess: true,
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: true,
|
||||||
|
passMsg: 'vertex shader that explicit int to float cast should succeed',
|
||||||
|
},
|
||||||
|
{ vShaderId: 'vshaderWithImplicitVec3Cast',
|
||||||
|
vShaderSuccess: false,
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: false,
|
||||||
|
passMsg: 'vertex shader that implicit vec3 to vec4 cast should fail',
|
||||||
|
},
|
||||||
|
{ vShaderId: 'vshaderWithVersion130',
|
||||||
|
vShaderSuccess: false,
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: false,
|
||||||
|
passMsg: 'vertex shader uses the #version not 100 directive should fail',
|
||||||
|
},
|
||||||
|
{ vShaderId: 'vshaderWithVersion100',
|
||||||
|
vShaderSuccess: true,
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: true,
|
||||||
|
passMsg: 'vertex shader uses the #version 100 directive should succeed',
|
||||||
|
},
|
||||||
|
{ vShaderId: 'vshaderWithLineDirective',
|
||||||
|
vShaderSuccess: false,
|
||||||
|
vShaderTest: (function() { return wtu.getLastError().indexOf("124") >= 0; }),
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: false,
|
||||||
|
passMsg: 'vertex shader uses #line directive should report correct line',
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Read in all the shader source.
|
||||||
|
for (var ii = 0; ii < shaderInfo.length; ++ii) {
|
||||||
|
var si = shaderInfo[ii];
|
||||||
|
si.vShaderSource = document.getElementById(si.vShaderId).text;
|
||||||
|
si.fShaderSource = document.getElementById(si.fShaderId).text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add more tests from external file
|
||||||
|
var fShader = document.getElementById('fshader').text;
|
||||||
|
var files = wtu.readFileList("shaders/implicit/00_shaders.txt");
|
||||||
|
for (var ii = 0; ii < files.length; ++ii) {
|
||||||
|
var file = files[ii];
|
||||||
|
var vShader = wtu.readFile(file);
|
||||||
|
shaderInfo.push({
|
||||||
|
vShaderId: file,
|
||||||
|
vShaderSource: vShader,
|
||||||
|
vShaderSuccess: false,
|
||||||
|
fShaderId: 'fshader',
|
||||||
|
fShaderSource: fShader,
|
||||||
|
fShaderSuccess: true,
|
||||||
|
linkSuccess: false,
|
||||||
|
passMsg: 'shader with implicit cast should fail',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
for (var ii = 0; ii < shaderInfo.length; ++ii) {
|
for (var ii = 0; ii < shaderInfo.length; ++ii) {
|
||||||
var info = shaderInfo[ii];
|
var info = shaderInfo[ii];
|
||||||
log("vs = " + info.vShaderId + ", fs = " + info.fShaderId);
|
var passMsg = '[' + info.vShaderId + '/' + info.fShaderId + ']: ' +
|
||||||
|
info.passMsg
|
||||||
|
log(passMsg);
|
||||||
//debug(info.fShaderId);
|
//debug(info.fShaderId);
|
||||||
var vShader = loadShader(gl.VERTEX_SHADER, info.vShaderId);
|
var vShader = wtu.loadShader(gl, info.vShaderSource, gl.VERTEX_SHADER);
|
||||||
if ((vShader != null) != info.vShaderSuccess) {
|
if (info.vShaderTest) {
|
||||||
testFailed(info.passMsg);
|
if (!info.vShaderTest(vShader)) {
|
||||||
|
testFailed(passMsg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var fShader = loadShader(gl.FRAGMENT_SHADER, info.fShaderId);
|
}
|
||||||
|
if ((vShader != null) != info.vShaderSuccess) {
|
||||||
|
testFailed(passMsg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var fShader = wtu.loadShader(gl, info.fShaderSource, gl.FRAGMENT_SHADER);
|
||||||
//debug(fShader == null ? "fail" : "succeed");
|
//debug(fShader == null ? "fail" : "succeed");
|
||||||
if ((fShader != null) != info.fShaderSuccess) {
|
if ((fShader != null) != info.fShaderSuccess) {
|
||||||
testFailed(info.passMsg);
|
testFailed(passMsg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,16 +430,16 @@ if (!gl) {
|
|||||||
log("*** Error linking program '"+program+"':"+error);
|
log("*** Error linking program '"+program+"':"+error);
|
||||||
}
|
}
|
||||||
if (linked != info.linkSuccess) {
|
if (linked != info.linkSuccess) {
|
||||||
testFailed(info.passMsg);
|
testFailed(passMsg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (info.linkSuccess) {
|
if (info.linkSuccess) {
|
||||||
testFailed(info.passMsg);
|
testFailed(passMsg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testPassed(info.passMsg);
|
testPassed(passMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,49 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/incorrect-context-object-behaviour.js"></script>
|
<script>
|
||||||
|
description("Tests calling WebGL APIs with objects from other contexts");
|
||||||
|
|
||||||
|
var contextA = create3DContext();
|
||||||
|
var contextB = create3DContext();
|
||||||
|
var programA = loadStandardProgram(contextA);
|
||||||
|
var programB = loadStandardProgram(contextB);
|
||||||
|
var shaderA = loadStandardVertexShader(contextA);
|
||||||
|
var shaderB = loadStandardVertexShader(contextB);
|
||||||
|
var textureA = contextA.createTexture();
|
||||||
|
var textureB = contextB.createTexture();
|
||||||
|
var frameBufferA = contextA.createFramebuffer();
|
||||||
|
var frameBufferB = contextB.createFramebuffer();
|
||||||
|
var renderBufferA = contextA.createRenderbuffer();
|
||||||
|
var renderBufferB = contextB.createRenderbuffer();
|
||||||
|
var locationA = contextA.getUniformLocation(programA, 'u_modelViewProjMatrix');
|
||||||
|
var locationB = contextB.getUniformLocation(programB, 'u_modelViewProjMatrix');
|
||||||
|
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.compileShader(shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.linkProgram(programB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programA, shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderA)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programA, shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderA)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.shaderSource(shaderB, 'foo')");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindAttribLocation(programB, 0, 'foo')");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindFramebuffer(contextA.FRAMEBUFFER, frameBufferB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindRenderbuffer(contextA.RENDERBUFFER, renderBufferB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindTexture(contextA.TEXTURE_2D, textureB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferRenderbuffer(contextA.FRAMEBUFFER, contextA.DEPTH_ATTACHMENT, contextA.RENDERBUFFER, renderBufferB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferTexture2D(contextA.FRAMEBUFFER, contextA.COLOR_ATTACHMENT0, contextA.TEXTURE_2D, textureB, 0)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramParameter(programB, 0)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramInfoLog(programB, 0)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderParameter(shaderB, 0)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderInfoLog(shaderB, 0)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderSource(shaderB)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniform(programB, locationA)");
|
||||||
|
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniformLocation(programB, 'u_modelViewProjMatrix')");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<script>
|
<script>
|
||||||
description('Test that client data is always copied during bufferData and bufferSubData calls, because otherwise the data the GL uses to draw may differ from that checked by the index validation code.')
|
description('Test that client data is always copied during bufferData and bufferSubData calls, because otherwise the data the GL uses to draw may differ from that checked by the index validation code.')
|
||||||
|
|
||||||
debug('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=32748">https://bugs.webkit.org/show_bug.cgi?id=32748</a> : <code>Index validation code must always copy client data</code>');
|
debug('');
|
||||||
|
|
||||||
var context = create3DContext();
|
var context = create3DContext();
|
||||||
var program = loadStandardProgram(context);
|
var program = loadStandardProgram(context);
|
||||||
@@ -50,13 +50,13 @@ var vertexObject = context.createBuffer();
|
|||||||
context.enableVertexAttribArray(0);
|
context.enableVertexAttribArray(0);
|
||||||
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
||||||
// 4 vertices -> 2 triangles
|
// 4 vertices -> 2 triangles
|
||||||
context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW);
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW);
|
||||||
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
var indexObject = context.createBuffer();
|
var indexObject = context.createBuffer();
|
||||||
|
|
||||||
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
||||||
var indices = new WebGLUnsignedShortArray([ 10000, 0, 1, 2, 3, 10000 ]);
|
var indices = new Uint16Array([ 10000, 0, 1, 2, 3, 10000 ]);
|
||||||
context.bufferData(context.ELEMENT_ARRAY_BUFFER, indices, context.STATIC_DRAW);
|
context.bufferData(context.ELEMENT_ARRAY_BUFFER, indices, context.STATIC_DRAW);
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
|
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<!--
|
||||||
|
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('Verifies that the index validation code which is within bufferSubData does not crash.')
|
||||||
|
|
||||||
|
debug('');
|
||||||
|
|
||||||
|
var gl = create3DContext();
|
||||||
|
|
||||||
|
var elementBuffer = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 256, gl.STATIC_DRAW);
|
||||||
|
var data = new Uint8Array(127);
|
||||||
|
gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 63, data);
|
||||||
|
testPassed("bufferSubData, when buffer object was initialized with null, did not crash");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<!--
|
||||||
|
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('Index validation for drawElements does not examine too many indices');
|
||||||
|
|
||||||
|
var context = create3DContext();
|
||||||
|
var program = loadStandardProgram(context);
|
||||||
|
|
||||||
|
context.useProgram(program);
|
||||||
|
var vertexObject = context.createBuffer();
|
||||||
|
context.enableVertexAttribArray(0);
|
||||||
|
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
|
||||||
|
// 4 vertices -> 2 triangles
|
||||||
|
context.bufferData(context.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), context.STATIC_DRAW);
|
||||||
|
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
var indexObject = context.createBuffer();
|
||||||
|
|
||||||
|
debug("Test out of range indices")
|
||||||
|
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
|
||||||
|
context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 10000, 0, 1, 2, 3, 10000 ]), context.STATIC_DRAW);
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)");
|
||||||
|
|
||||||
|
debug("")
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
<canvas id="example" width="1px" height="1px"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
|
||||||
|
<script id="vs" type="x-shader/x-vertex">
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
attribute vec4 vColor;
|
||||||
|
varying vec4 color;
|
||||||
|
void main() {
|
||||||
|
gl_Position = vPosition;
|
||||||
|
color = vColor;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="fs" type="x-shader/x-fragment">
|
||||||
|
#if defined(GL_ES)
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
varying vec4 color;
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
|
||||||
|
|
||||||
|
debug('');
|
||||||
|
|
||||||
|
var gl = initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1], 1);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after initialization");
|
||||||
|
|
||||||
|
gl.useProgram(gl.program);
|
||||||
|
var vertexObject = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
|
||||||
|
[-1,1,0, 1,1,0, -1,-1,0,
|
||||||
|
-1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW);
|
||||||
|
gl.enableVertexAttribArray(0);
|
||||||
|
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup");
|
||||||
|
|
||||||
|
var texCoordObject = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
|
||||||
|
[0,0, 1,0, 0,1,
|
||||||
|
0,1, 1,0, 1,1]), gl.STATIC_DRAW);
|
||||||
|
gl.enableVertexAttribArray(1);
|
||||||
|
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup");
|
||||||
|
|
||||||
|
// Now resize these buffers because we want to change what we're drawing.
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
||||||
|
-1,1,0, 1,1,0, -1,-1,0, 1,-1,0,
|
||||||
|
-1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition");
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255]), gl.STATIC_DRAW);
|
||||||
|
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition");
|
||||||
|
|
||||||
|
var numQuads = 2;
|
||||||
|
var indices = new Uint8Array(numQuads * 6);
|
||||||
|
for (var ii = 0; ii < numQuads; ++ii) {
|
||||||
|
var offset = ii * 6;
|
||||||
|
var quad = (ii == (numQuads - 1)) ? 4 : 0;
|
||||||
|
indices[offset + 0] = quad + 0;
|
||||||
|
indices[offset + 1] = quad + 1;
|
||||||
|
indices[offset + 2] = quad + 2;
|
||||||
|
indices[offset + 3] = quad + 2;
|
||||||
|
indices[offset + 4] = quad + 1;
|
||||||
|
indices[offset + 5] = quad + 3;
|
||||||
|
}
|
||||||
|
var indexObject = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");
|
||||||
|
gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0);
|
||||||
|
glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
|
||||||
|
|
||||||
|
debug("")
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -37,7 +37,82 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/index-validation.js"></script>
|
<script>
|
||||||
|
description("Tests that index validation verifies the correct number of indices");
|
||||||
|
|
||||||
|
var gl = create3DContext();
|
||||||
|
var program = loadStandardProgram(gl);
|
||||||
|
|
||||||
|
// 3 vertices => 1 triangle, interleaved data
|
||||||
|
var dataComplete = new Float32Array([0, 0, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
1, 0, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
1, 1, 1, 1,
|
||||||
|
0, 0, 1]);
|
||||||
|
var dataIncomplete = new Float32Array([0, 0, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
1, 0, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
1, 1, 1, 1]);
|
||||||
|
var indices = new Uint16Array([0, 1, 2]);
|
||||||
|
|
||||||
|
debug("Testing with valid indices");
|
||||||
|
|
||||||
|
var bufferComplete = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
|
||||||
|
var elements = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
||||||
|
gl.useProgram(program);
|
||||||
|
var vertexLoc = gl.getAttribLocation(program, "a_vertex");
|
||||||
|
var normalLoc = gl.getAttribLocation(program, "a_normal");
|
||||||
|
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
|
||||||
|
gl.enableVertexAttribArray(vertexLoc);
|
||||||
|
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
|
||||||
|
gl.enableVertexAttribArray(normalLoc);
|
||||||
|
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
|
||||||
|
debug("Testing with out-of-range indices");
|
||||||
|
|
||||||
|
var bufferIncomplete = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
|
||||||
|
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
|
||||||
|
gl.enableVertexAttribArray(vertexLoc);
|
||||||
|
gl.disableVertexAttribArray(normalLoc);
|
||||||
|
debug("Enable vertices, valid");
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
debug("Enable normals, out-of-range");
|
||||||
|
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
|
||||||
|
gl.enableVertexAttribArray(normalLoc);
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
||||||
|
shouldBe('gl.getError()', 'gl.INVALID_OPERATION');
|
||||||
|
|
||||||
|
debug("Test with enabled attribute that does not belong to current program");
|
||||||
|
|
||||||
|
gl.disableVertexAttribArray(normalLoc);
|
||||||
|
var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
|
||||||
|
gl.enableVertexAttribArray(extraLoc);
|
||||||
|
debug("Enable an extra attribute with null");
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
||||||
|
shouldBe('gl.getError()', 'gl.INVALID_OPERATION');
|
||||||
|
debug("Enable an extra attribute with insufficient data buffer");
|
||||||
|
gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
||||||
|
shouldBe('gl.getError()', '0');
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
48
content/canvas/test/webgl/conformance/invalid-UTF-16.html
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
<p id="description"></p>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script>
|
||||||
|
if (window.initNonKhronosFramework) {
|
||||||
|
window.initNonKhronosFramework(false);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
description('This test verifies that the internal conversion from UTF16 to UTF8 is robust to invalid inputs. Any DOM entry point which converts an incoming string to UTF8 could be used for this test.');
|
||||||
|
|
||||||
|
var array = [];
|
||||||
|
array.push(String.fromCharCode(0x48)); // H
|
||||||
|
array.push(String.fromCharCode(0x69)); // i
|
||||||
|
array.push(String.fromCharCode(0xd87e)); // Bogus
|
||||||
|
var string = array.join('');
|
||||||
|
|
||||||
|
// In order to make this test not depend on WebGL, the following were
|
||||||
|
// attempted:
|
||||||
|
// - Send a string to console.log
|
||||||
|
// - Submit a mailto: form containing a text input with the bogus
|
||||||
|
// string
|
||||||
|
// The first code path does not perform a utf8 conversion of the
|
||||||
|
// incoming string unless Console::shouldPrintExceptions() returns
|
||||||
|
// true. The second seems to sanitize the form's input before
|
||||||
|
// converting it to a UTF8 string.
|
||||||
|
|
||||||
|
var gl = create3DContext(null);
|
||||||
|
var program = gl.createProgram();
|
||||||
|
gl.bindAttribLocation(program, 0, string);
|
||||||
|
testPassed("bindAttribLocation with invalid UTF-16 did not crash");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2009 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 More than 65536 points.</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>
|
||||||
|
<canvas id="example" width="40" height="40" style="width: 40px; height: 40px;"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script id="vs" type="text/something-not-javascript">
|
||||||
|
attribute vec4 vPosition;
|
||||||
|
attribute vec4 vColor;
|
||||||
|
varying vec4 color;
|
||||||
|
void main() {
|
||||||
|
gl_Position = vPosition;
|
||||||
|
color = vColor;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script id="fs" type="text/something-not-javascript">
|
||||||
|
#if defined(GL_ES)
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
varying vec4 color;
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
var wtu = WebGLTestUtils;
|
||||||
|
var gl = initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1], 1);
|
||||||
|
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initWebGL");
|
||||||
|
var bufferObjects = wtu.setupUnitQuad(gl, 0, 1);
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0]);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
||||||
|
-1,1,0, 1,1,0, -1,-1,0, 1,-1,0,
|
||||||
|
-1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW);
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[1]);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
255, 0, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255,
|
||||||
|
0, 255, 0, 255]), gl.STATIC_DRAW);
|
||||||
|
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0);
|
||||||
|
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after program setup");
|
||||||
|
gl.enable(gl.BLEND);
|
||||||
|
gl.disable(gl.DEPTH_TEST);
|
||||||
|
|
||||||
|
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture");
|
||||||
|
var numQuads = Math.floor(65536 / 6) + 2;
|
||||||
|
debug("numQuads: " + numQuads);
|
||||||
|
debug("numPoints: " + numQuads * 6);
|
||||||
|
var indexBuf = new ArrayBuffer(numQuads * 6);
|
||||||
|
var indices = new Uint8Array(indexBuf);
|
||||||
|
for (var ii = 0; ii < numQuads; ++ii) {
|
||||||
|
var offset = ii * 6;
|
||||||
|
var quad = (ii == (numQuads - 1)) ? 4 : 0;
|
||||||
|
indices[offset + 0] = quad + 0;
|
||||||
|
indices[offset + 1] = quad + 1;
|
||||||
|
indices[offset + 2] = quad + 2;
|
||||||
|
indices[offset + 3] = quad + 2;
|
||||||
|
indices[offset + 4] = quad + 1;
|
||||||
|
indices[offset + 5] = quad + 3;
|
||||||
|
}
|
||||||
|
var indexBuffer = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
||||||
|
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");
|
||||||
|
gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0);
|
||||||
|
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
|
||||||
|
wtu.checkCanvas(gl, [0, 255, 0, 255], "Should be green.");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
@@ -26,13 +26,49 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
||||||
<script src="../resources/js-test-pre.js"></script>
|
<script src="../resources/js-test-pre.js"></script>
|
||||||
<script src="resources/webgl-test.js"></script>
|
<script src="resources/webgl-test-utils.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="description"></div>
|
<div id="description"></div>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
|
||||||
<script src="resources/null-object-behaviour.js"></script>
|
<script>
|
||||||
|
var wtu = WebGLTestUtils;
|
||||||
|
description("Tests calling WebGL APIs without providing the necessary objects");
|
||||||
|
|
||||||
|
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");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.compileShader()");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.linkProgram()");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader()");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(program, undefined)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(undefined, shader)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(program, undefined)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(undefined, shader)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource()");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource(undefined, 'foo')");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.bindAttribLocation(undefined, 0, 'foo')");
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, 0)");
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, 0)");
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, 0)");
|
||||||
|
shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, 0, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramParameter(undefined, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramInfoLog(undefined, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderParameter(undefined, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderInfoLog(undefined, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderSource(undefined)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniform(undefined, 0)");
|
||||||
|
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniformLocation(undefined, 'foo')");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../resources/js-test-post.js"></script>
|
<script src="../resources/js-test-post.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<!--
|
||||||
|
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("Tests calling the various uniform[Matrix]* APIs with a null uniform location");
|
||||||
|
|
||||||
|
var gl = create3DContext();
|
||||||
|
var program = loadStandardProgram(gl);
|
||||||
|
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
shouldBeUndefined("gl.useProgram(program)");
|
||||||
|
var floatArray = new WebGLFloatArray([1, 2, 3, 4]);
|
||||||
|
var intArray = new WebGLIntArray([1, 2, 3, 4]);
|
||||||
|
|
||||||
|
function callUniformFunction(name) {
|
||||||
|
var isArrayVariant = (name.charAt(name.length - 1) == 'v');
|
||||||
|
var isMatrix = (name.indexOf("Matrix") != -1);
|
||||||
|
var isFloat =
|
||||||
|
(name.charAt(name.length - 1) == 'f' ||
|
||||||
|
name.charAt(name.length - 2) == 'f');
|
||||||
|
var sizeIndex = (isArrayVariant ? name.length - 3 : name.length - 2);
|
||||||
|
var size = parseInt(name.substring(sizeIndex, sizeIndex + 1));
|
||||||
|
// Initialize argument list with null uniform location
|
||||||
|
var args = [ null ];
|
||||||
|
if (isArrayVariant) {
|
||||||
|
// Call variant which takes values as array
|
||||||
|
if (isMatrix) {
|
||||||
|
size = size * size;
|
||||||
|
args.push(false);
|
||||||
|
}
|
||||||
|
var array = (isFloat ? new WebGLFloatArray(size) : new WebGLIntArray(size));
|
||||||
|
for (var i = 0; i < size; i++) {
|
||||||
|
array[i] = i;
|
||||||
|
}
|
||||||
|
args.push(array);
|
||||||
|
} else {
|
||||||
|
// Call variant which takes values as parameters
|
||||||
|
for (var i = 0; i < size; i++) {
|
||||||
|
args.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var func = gl[name];
|
||||||
|
return func.apply(gl, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
var funcs = [ "uniform1f", "uniform1fv", "uniform1i", "uniform1iv",
|
||||||
|
"uniform2f", "uniform2fv", "uniform2i", "uniform2iv",
|
||||||
|
"uniform3f", "uniform3fv", "uniform3i", "uniform3iv",
|
||||||
|
"uniform4f", "uniform4fv", "uniform4i", "uniform4iv",
|
||||||
|
"uniformMatrix2fv", "uniformMatrix3fv", "uniformMatrix4fv" ];
|
||||||
|
for (var i = 0; i < funcs.length; i++) {
|
||||||
|
callString = "callUniformFunction('" + funcs[i] + "')";
|
||||||
|
shouldBeUndefined(callString);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -52,7 +52,8 @@ window.onload = function() {
|
|||||||
|
|
||||||
function makeReadPixels(gl) {
|
function makeReadPixels(gl) {
|
||||||
return function() {
|
return function() {
|
||||||
var buf = gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE);
|
var buf = new Uint8Array(4);
|
||||||
|
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ window.onload = function() {
|
|||||||
|
|
||||||
var tex = gl1.createTexture();
|
var tex = gl1.createTexture();
|
||||||
gl1.bindTexture(gl1.TEXTURE_2D, tex);
|
gl1.bindTexture(gl1.TEXTURE_2D, tex);
|
||||||
gl1.texImage2D(gl1.TEXTURE_2D, 0, img);
|
gl1.texImage2D(gl1.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
||||||
|
|
||||||
assertMsg(causedException(makeReadPixels(gl1)),
|
assertMsg(causedException(makeReadPixels(gl1)),
|
||||||
"should throw exception by readPixels for NON origin clean canvas.");
|
"should throw exception by readPixels for NON origin clean canvas.");
|
||||||
@@ -92,7 +93,7 @@ window.onload = function() {
|
|||||||
|
|
||||||
var tex = gl2.createTexture();
|
var tex = gl2.createTexture();
|
||||||
gl1.bindTexture(gl2.TEXTURE_2D, tex);
|
gl1.bindTexture(gl2.TEXTURE_2D, tex);
|
||||||
gl1.texImage2D(gl2.TEXTURE_2D, 0, canvas1);
|
gl1.texImage2D(gl2.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas1);
|
||||||
|
|
||||||
assertMsg(causedException(makeReadPixels(gl2)),
|
assertMsg(causedException(makeReadPixels(gl2)),
|
||||||
"should throw exception by readPixels for NON origin clean canvas.");
|
"should throw exception by readPixels for NON origin clean canvas.");
|
||||||
|
|||||||
132
content/canvas/test/webgl/conformance/point-size.html
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<!--
|
||||||
|
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;
|
||||||
|
uniform float pointSize;
|
||||||
|
varying vec4 color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_PointSize = pointSize;
|
||||||
|
color = colorIn;
|
||||||
|
gl_Position = vec4(pos.xyz, 3.0);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="fshader" type="x-shader/x-fragment">
|
||||||
|
varying vec4 color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function runTest()
|
||||||
|
{
|
||||||
|
var gl = initWebGL('testbed', 'vshader', 'fshader', ['pos', 'colorIn'], [0, 0, 0, 1], 1, { antialias: false });
|
||||||
|
if (!gl) {
|
||||||
|
testFailed('initWebGL(..) failed');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
gl.disable(gl.BLEND);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// The choice of (0.4, 0.4) ensures that the centers of the surrounding
|
||||||
|
// pixels are not contained within the point when it is of size 1, but
|
||||||
|
// that they definitely are when it is of size 2.
|
||||||
|
var vertices = new WebGLFloatArray([
|
||||||
|
0.4, 0.4, 0.0]);
|
||||||
|
var colors = new WebGLUnsignedByteArray([
|
||||||
|
255, 0, 0, 255]);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
var locPointSize = gl.getUniformLocation(gl.program, 'pointSize');
|
||||||
|
|
||||||
|
debug('Draw a point of size 1 and verify it does not touch any other pixels.');
|
||||||
|
|
||||||
|
gl.uniform1f(locPointSize, 1.0);
|
||||||
|
gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
|
||||||
|
var buf = new Uint8Array(2 * 2 * 4);
|
||||||
|
gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
var index = 0;
|
||||||
|
for (var y = 0; y < 2; ++y) {
|
||||||
|
for (var x = 0; x < 2; ++x) {
|
||||||
|
var correctColor = [0, 0, 0];
|
||||||
|
if (x == 1 && y == 1)
|
||||||
|
correctColor[0] = 255;
|
||||||
|
if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[1] || buf[index + 2] != correctColor[2]) {
|
||||||
|
testFailed('Drawing a point of size 1 touched pixels that should not be touched');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
index += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
debug('Draw a point of size 2 and verify it fills the appropriate region.');
|
||||||
|
|
||||||
|
var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
|
||||||
|
if (pointSizeRange < 2.0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
gl.uniform1f(locPointSize, 2.0);
|
||||||
|
gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
|
||||||
|
gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
index = 0;
|
||||||
|
for (var y = 0; y < 2; ++y) {
|
||||||
|
for (var x = 0; x < 2; ++x) {
|
||||||
|
var correctColor = [255, 0, 0];
|
||||||
|
if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[1] || buf[index + 2] != correctColor[2]) {
|
||||||
|
testFailed('Drawing a point of size 2 failed to fill the appropriate region');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
index += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="testbed" width="2px" height="2px"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script>
|
||||||
|
description('Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled in WebGL');
|
||||||
|
|
||||||
|
debug('');
|
||||||
|
|
||||||
|
if (runTest())
|
||||||
|
testPassed("");
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -140,11 +140,11 @@ function go() {
|
|||||||
checkGetAttachedShaders([fs], [], [fs], "attaching a single shader should give the expected list");
|
checkGetAttachedShaders([fs], [], [fs], "attaching a single shader should give the expected list");
|
||||||
checkGetAttachedShaders([fs, vs, fs2, vs2], [], [fs, vs, fs2, vs2],
|
checkGetAttachedShaders([fs, vs, fs2, vs2], [], [fs, vs, fs2, vs2],
|
||||||
"attaching some shaders should give the expected list");
|
"attaching some shaders should give the expected list");
|
||||||
checkGetAttachedShaders([fs], [fs], [], "attaching a shader and detaching it should leave an empty list");
|
checkGetAttachedShaders([fs], [fs], [], "attaching a shader and detaching it shoud leave an empty list");
|
||||||
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs, fs2, vs2], [],
|
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs, fs2, vs2], [],
|
||||||
"attaching some shaders and detaching them in same order should leave an empty list");
|
"attaching some shaders and detaching them in same order shoud leave an empty list");
|
||||||
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs2, vs, fs2], [],
|
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs2, vs, fs2], [],
|
||||||
"attaching some shaders and detaching them in random order should leave an empty list");
|
"attaching some shaders and detaching them in random order shoud leave an empty list");
|
||||||
checkGetAttachedShaders([fs, vs, fs2, vs2], [vs], [fs, fs2, vs2],
|
checkGetAttachedShaders([fs, vs, fs2, vs2], [vs], [fs, fs2, vs2],
|
||||||
"attaching and detaching some shaders should leave the difference list");
|
"attaching and detaching some shaders should leave the difference list");
|
||||||
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs2], [vs, fs2],
|
checkGetAttachedShaders([fs, vs, fs2, vs2], [fs, vs2], [vs, fs2],
|
||||||
@@ -163,43 +163,28 @@ function go() {
|
|||||||
gl.bindAttribLocation(prog, 0, "aVertex");
|
gl.bindAttribLocation(prog, 0, "aVertex");
|
||||||
gl.bindAttribLocation(prog, 1, "aColor");
|
gl.bindAttribLocation(prog, 1, "aColor");
|
||||||
gl.linkProgram(prog);
|
gl.linkProgram(prog);
|
||||||
if(gl.getError() != gl.NO_ERROR)
|
if (gl.getError() != gl.NO_ERROR)
|
||||||
assertMsg(false, "unexpected error in linkProgram()");
|
assertMsg(false, "unexpected error in linkProgram()");
|
||||||
assertMsg(gl.getProgramParameter(prog, gl.LINK_STATUS) == expected_status,
|
assertMsg(gl.getProgramParameter(prog, gl.LINK_STATUS) == expected_status, errmsg);
|
||||||
errmsg);
|
|
||||||
if (expected_status == true && gl.getProgramParameter(prog, gl.LINK_STATUS) == false)
|
if (expected_status == true && gl.getProgramParameter(prog, gl.LINK_STATUS) == false)
|
||||||
debug(gl.getProgramInfoLog(prog));
|
debug(gl.getProgramInfoLog(prog));
|
||||||
if(gl.getError() != gl.NO_ERROR)
|
if (gl.getError() != gl.NO_ERROR)
|
||||||
assertMsg(false, "unexpected error in getProgramParameter()");
|
assertMsg(false, "unexpected error in getProgramParameter()");
|
||||||
gl.useProgram(prog);
|
gl.useProgram(prog);
|
||||||
if(expected_status == true)
|
if (expected_status == true)
|
||||||
assertMsg(gl.getError() == gl.NO_ERROR, "using a valid program should succeed");
|
assertMsg(gl.getError() == gl.NO_ERROR, "using a valid program should succeed");
|
||||||
if(expected_status == false)
|
if (expected_status == false)
|
||||||
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
assertMsg(gl.getError() == gl.INVALID_OPERATION, "using an invalid program should generate INVALID_OPERATION");
|
||||||
"using an invalid program should generate INVALID_OPERATION");
|
|
||||||
return prog;
|
return prog;
|
||||||
}
|
}
|
||||||
|
|
||||||
var progGood1 = checkLinkAndUse([vs, fs], true,
|
var progGood1 = checkLinkAndUse([vs, fs], true, "valid program should link");
|
||||||
"valid program should link");
|
var progGood2 = checkLinkAndUse([vs, fs2], true, "valid program #2 should link");
|
||||||
|
var progBad1 = checkLinkAndUse([vs], false, "program with no fragment shader should fail to link");
|
||||||
var progGood2 = checkLinkAndUse([vs, fs2], true,
|
var progBad2 = checkLinkAndUse([fs], false, "program with no vertex shader should fail to link");
|
||||||
"valid program #2 should link");
|
var progBad3 = checkLinkAndUse([vsBad, fs], false, "program with bad vertex shader should fail to link");
|
||||||
|
var progBad4 = checkLinkAndUse([vs, fsBad], false, "program with bad fragment shader should fail to link");
|
||||||
var progBad1 = checkLinkAndUse([vs], false,
|
var progBad5 = checkLinkAndUse([vsBad, fsBad], false, "program with bad shaders should fail to link");
|
||||||
"program with no fragment shader should fail to link");
|
|
||||||
|
|
||||||
var progBad2 = checkLinkAndUse([fs], false,
|
|
||||||
"program with no vertex shader should fail to link");
|
|
||||||
|
|
||||||
var progBad3 = checkLinkAndUse([vsBad, fs], false,
|
|
||||||
"program with bad vertex shader should fail to link");
|
|
||||||
|
|
||||||
var progBad4 = checkLinkAndUse([vs, fsBad], false,
|
|
||||||
"program with bad fragment shader should fail to link");
|
|
||||||
|
|
||||||
var progBad5 = checkLinkAndUse([vsBad, fsBad], false,
|
|
||||||
"program with bad shaders should fail to link");
|
|
||||||
|
|
||||||
gl.useProgram(progGood1);
|
gl.useProgram(progGood1);
|
||||||
assertMsg(gl.getError() == gl.NO_ERROR,
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
||||||
@@ -207,10 +192,13 @@ function go() {
|
|||||||
|
|
||||||
var vbuf = gl.createBuffer();
|
var vbuf = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([0.0, 0.0, 0.0, 1.0,
|
gl.bufferData(gl.ARRAY_BUFFER,
|
||||||
|
new Float32Array([
|
||||||
|
0.0, 0.0, 0.0, 1.0,
|
||||||
1.0, 0.0, 0.0, 1.0,
|
1.0, 0.0, 0.0, 1.0,
|
||||||
1.0, 1.0, 0.0, 1.0,
|
1.0, 1.0, 0.0, 1.0,
|
||||||
0.0, 1.0, 0.0, 1.0]), gl.STATIC_DRAW);
|
0.0, 1.0, 0.0, 1.0]),
|
||||||
|
gl.STATIC_DRAW);
|
||||||
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
gl.vertexAttrib3f(1, 1.0, 0.0, 0.0);
|
gl.vertexAttrib3f(1, 1.0, 0.0, 0.0);
|
||||||
@@ -224,6 +212,8 @@ function go() {
|
|||||||
"drawing with a valid program shouldn't generate a GL error");
|
"drawing with a valid program shouldn't generate a GL error");
|
||||||
|
|
||||||
gl.useProgram(progBad1);
|
gl.useProgram(progBad1);
|
||||||
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
||||||
|
"using an invalid program should generate INVALID_OPERATION");
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||||
assertMsg(gl.getError() != gl.NO_ERROR,
|
assertMsg(gl.getError() != gl.NO_ERROR,
|
||||||
"drawing with an invalid program should generate some GL error XXX");
|
"drawing with an invalid program should generate some GL error XXX");
|
||||||
|
|||||||
@@ -0,0 +1,282 @@
|
|||||||
|
<!--
|
||||||
|
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">
|
||||||
|
varying vec4 color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="example" width="32px" height="32px"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script>
|
||||||
|
var successfullyParsed = false;
|
||||||
|
|
||||||
|
// The below declarations need to be global for "shouldBe" to see them
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
var size = 0;
|
||||||
|
switch (format) {
|
||||||
|
case gl.ALPHA:
|
||||||
|
size = 1;
|
||||||
|
break;
|
||||||
|
case gl.RGB:
|
||||||
|
size = 3;
|
||||||
|
break;
|
||||||
|
case gl.RGBA:
|
||||||
|
size = 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
|
case gl.UNSIGNED_BYTE:
|
||||||
|
break;
|
||||||
|
case gl.UNSIGNED_SHORT_5_6_5:
|
||||||
|
if (format != gl.RGB)
|
||||||
|
return -1;
|
||||||
|
size = 2;
|
||||||
|
break;
|
||||||
|
case gl.UNSIGNED_SHORT_4_4_4_4:
|
||||||
|
case gl.UNSIGNED_SHORT_5_5_5_1:
|
||||||
|
if (format != gl.RGBA)
|
||||||
|
return -1;
|
||||||
|
size = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculatePaddingBytes(bytesPerPixel, packAlignment, width)
|
||||||
|
{
|
||||||
|
var padding = 0;
|
||||||
|
switch (packAlignment) {
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
case 8:
|
||||||
|
padding = (bytesPerPixel * width) % packAlignment;
|
||||||
|
if (padding > 0)
|
||||||
|
padding = packAlignment - padding;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
function packColor(format, type, r, g, b, a)
|
||||||
|
{
|
||||||
|
// FIXME: not sure if the color packing is correct for UNSIGNED_SHORT_*.
|
||||||
|
var color = [ 0, 0, 0, 0 ];
|
||||||
|
switch (type) {
|
||||||
|
case gl.UNSIGNED_BYTE:
|
||||||
|
switch (format) {
|
||||||
|
case gl.ALPHA:
|
||||||
|
color[0] = a;
|
||||||
|
break;
|
||||||
|
case gl.RGB:
|
||||||
|
color[0] = r;
|
||||||
|
color[1] = g;
|
||||||
|
color[2] = b;
|
||||||
|
break;
|
||||||
|
case gl.RGBA:
|
||||||
|
color[0] = r;
|
||||||
|
color[1] = g;
|
||||||
|
color[2] = b;
|
||||||
|
color[3] = a;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case gl.UNSIGNED_SHORT_5_6_5:
|
||||||
|
if (format != gl.RGB)
|
||||||
|
return null;
|
||||||
|
r >>= 3;
|
||||||
|
g >>= 2;
|
||||||
|
b >>= 3;
|
||||||
|
color[0] = (r << 11) + (g << 5) + b;
|
||||||
|
break;
|
||||||
|
case gl.UNSIGNED_SHORT_4_4_4_4:
|
||||||
|
if (format != gl.RGBA)
|
||||||
|
return null;
|
||||||
|
r >>= 4;
|
||||||
|
g >>= 4;
|
||||||
|
b >>= 4;
|
||||||
|
a >>= 4;
|
||||||
|
color[0] = (r << 12) + (g << 8) + (b << 4) + a;
|
||||||
|
break;
|
||||||
|
case gl.UNSIGNED_SHORT_5_5_5_1:
|
||||||
|
if (format != gl.RGBA)
|
||||||
|
return null;
|
||||||
|
r >>= 3;
|
||||||
|
g >>= 3;
|
||||||
|
b >>= 3;
|
||||||
|
a >>= 7;
|
||||||
|
color[0] = (r << 11) + (g << 6) + (b << 1) + a;
|
||||||
|
break;
|
||||||
|
Default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTestIteration(format, type, packAlignment, width, height)
|
||||||
|
{
|
||||||
|
debug("Testing PACK_ALIGNMENT = " + packAlignment + ", width = " + width + ", height = " + height);
|
||||||
|
gl.clearColor(1, 0.4, 0, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
gl.pixelStorei(gl.PACK_ALIGNMENT, packAlignment);
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
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 (isShort)
|
||||||
|
size /= 2;
|
||||||
|
if (size < 0)
|
||||||
|
size = 0;
|
||||||
|
if (type == gl.UNSIGNED_BYTE)
|
||||||
|
array = new Uint8Array(size);
|
||||||
|
else
|
||||||
|
array = new Uint16Array(size);
|
||||||
|
gl.readPixels(0, 0, width, height, format, type, array);
|
||||||
|
if (width < 0 || height < 0) {
|
||||||
|
shouldBe("gl.getError()", "gl.INVALID_VALUE");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
shouldBe("gl.getError()", "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)
|
||||||
|
pixel[i] = 0;
|
||||||
|
expectedColor = packColor(format, type, 255, 102, 0, 255);
|
||||||
|
shouldBeNonNull(expectedColor);
|
||||||
|
shouldBe("pixel", "expectedColor");
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSupportedPixelFormatAndType()
|
||||||
|
{
|
||||||
|
debug("Check supported pixel format/type besides RGBA/UNSIGNED_BYTE");
|
||||||
|
shouldBe("gl.getError()", "gl.NO_ERROR");
|
||||||
|
pixelFormat = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT);
|
||||||
|
pixelType = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE);
|
||||||
|
shouldBe("gl.getError()", "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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -22,9 +22,8 @@ description("Checks that ReadPixels works as expected.");
|
|||||||
var canvas = document.getElementById("example");
|
var canvas = document.getElementById("example");
|
||||||
var gl = create3DContext(canvas);
|
var gl = create3DContext(canvas);
|
||||||
|
|
||||||
if (window.layoutTestController) {
|
if (window.initNonKhronosFramework) {
|
||||||
layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
|
window.initNonKhronosFramework(false);
|
||||||
layoutTestController.dumpAsText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var width = 2;
|
var width = 2;
|
||||||
@@ -73,7 +72,8 @@ assertMsg(gl.getError() == gl.NO_ERROR,
|
|||||||
"there should be no GL errors");
|
"there should be no GL errors");
|
||||||
|
|
||||||
function checkBuffer(checkColor, x, y, oneColor, oneX, oneY) {
|
function checkBuffer(checkColor, x, y, oneColor, oneX, oneY) {
|
||||||
var buf = gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE);
|
var buf = new Uint8Array(width * height * 4);
|
||||||
|
gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
for (var yy = 0; yy < height; ++yy) {
|
for (var yy = 0; yy < height; ++yy) {
|
||||||
for (var xx = 0; xx < width; ++xx) {
|
for (var xx = 0; xx < width; ++xx) {
|
||||||
var offset = (yy * width + xx) * 4;
|
var offset = (yy * width + xx) * 4;
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
function runTest()
|
||||||
|
{
|
||||||
|
var canvas = document.getElementById("testbed");
|
||||||
|
var gl = canvas.getContext("experimental-webgl");
|
||||||
|
if (!gl) {
|
||||||
|
testFailed('canvas.getContext() failed');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug('Test whether the WebGL internal buffers have been initialized to 0.');
|
||||||
|
var buf = new Uint8Array(500 * 500 * 4);
|
||||||
|
gl.readPixels(0, 0, 500, 500, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
if (gl.getError() != gl.NO_ERROR) {
|
||||||
|
testFailed('GL error detected after readPixels().');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var totalBytes = 500 * 500 * 4;
|
||||||
|
for (var i = 0; i < totalBytes; ++i) {
|
||||||
|
if (buf[i] != 0) {
|
||||||
|
testFailed('WebGL internal buffers are dirty.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testPassed('Buffers have been initialized to 0.');
|
||||||
|
|
||||||
|
debug('Test whether user created buffers have been initialized to 0.');
|
||||||
|
var fbo = gl.createFramebuffer();
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
||||||
|
var colorbuffer = gl.createRenderbuffer();
|
||||||
|
gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
|
||||||
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 500, 500);
|
||||||
|
if (gl.getError() != gl.NO_ERROR) {
|
||||||
|
testFailed('GL error detected after renderbufferStorage(internalformat = RGBA4).');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer);
|
||||||
|
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
|
||||||
|
testFailed('Framebuffer incomplete.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
gl.readPixels(0, 0, 500, 500, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
|
if (gl.getError() != gl.NO_ERROR) {
|
||||||
|
testFailed('GL error detected after readPixels().');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < totalBytes; ++i) {
|
||||||
|
if (buf[i] != 0) {
|
||||||
|
testFailed('User created buffers are dirty.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testPassed('Buffers have been initialized to 0.');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="testbed" width="500px" height="500px"></canvas>
|
||||||
|
<div id="description"></div>
|
||||||
|
<div id="console"></div>
|
||||||
|
<script>
|
||||||
|
var successfullyParsed = false;
|
||||||
|
|
||||||
|
description('Verify renderbuffers are initialized to 0 before being read in WebGL');
|
||||||
|
|
||||||
|
debug('');
|
||||||
|
|
||||||
|
runTest();
|
||||||
|
|
||||||
|
successfullyParsed = true;
|
||||||
|
</script>
|
||||||
|
<script src="../resources/js-test-post.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
0
content/canvas/test/webgl/conformance/resource-sharing-test.html
Normal file → Executable file
BIN
content/canvas/test/webgl/conformance/resources/3x3.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
@@ -1,461 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
* 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:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * 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.
|
|
||||||
* * Neither the name of Google Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "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 THE COPYRIGHT
|
|
||||||
* OWNER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Verifies the functionality of the new array-like objects in the WebGL spec");
|
|
||||||
|
|
||||||
var currentlyRunning = '';
|
|
||||||
var allPassed = true;
|
|
||||||
function running(str) {
|
|
||||||
currentlyRunning = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function output(str) {
|
|
||||||
debug(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pass() {
|
|
||||||
testPassed(currentlyRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
function fail(str) {
|
|
||||||
allPassed = false;
|
|
||||||
var exc;
|
|
||||||
if (str)
|
|
||||||
exc = currentlyRunning + ': ' + str;
|
|
||||||
else
|
|
||||||
exc = str;
|
|
||||||
testFailed(exc);
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertEq(prefix, expected, val) {
|
|
||||||
if (expected != val) {
|
|
||||||
var str = prefix + ': expected ' + expected + ', got ' + val;
|
|
||||||
throw str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function assert(prefix, expected) {
|
|
||||||
if (!expected) {
|
|
||||||
var str = prefix + ': expected value / true';
|
|
||||||
throw str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function printSummary() {
|
|
||||||
if (allPassed) {
|
|
||||||
debug("Test passed.");
|
|
||||||
} else {
|
|
||||||
debug("TEST FAILED");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tests for unsigned array variants
|
|
||||||
//
|
|
||||||
|
|
||||||
function testSetAndGet10To1(type, name) {
|
|
||||||
running('test ' + name + ' SetAndGet10To1');
|
|
||||||
try {
|
|
||||||
var array = new type(10);
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
array[i] = 10 - i;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetAndGetMethods10To1(type, name) {
|
|
||||||
running('test ' + name + ' SetAndGetMethods10To1');
|
|
||||||
try {
|
|
||||||
var array = new type(10);
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
array.set(i, 10 - i);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array.get(i));
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConstructWithArrayOfUnsignedValues(type, name) {
|
|
||||||
running('test ' + name + ' ConstructWithArrayOfUnsignedValues');
|
|
||||||
try {
|
|
||||||
var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
|
|
||||||
assertEq('Array length', 10, array.length);
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConstructWithWebGLArrayOfUnsignedValues(type, name) {
|
|
||||||
running('test ' + name + ' ConstructWithWebGLArrayOfUnsignedValues');
|
|
||||||
try {
|
|
||||||
var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
|
|
||||||
var array = new type(tmp);
|
|
||||||
assertEq('Array length', 10, array.length);
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tests for signed array variants
|
|
||||||
//
|
|
||||||
|
|
||||||
function testSetAndGetPos10ToNeg10(type, name) {
|
|
||||||
running('test ' + name + ' SetAndGetPos10ToNeg10');
|
|
||||||
try {
|
|
||||||
var array = new type(21);
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
array[i] = 10 - i;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetAndGetMethodsPos10ToNeg10(type, name) {
|
|
||||||
running('test ' + name + ' SetAndGetMethodsPos10ToNeg10');
|
|
||||||
try {
|
|
||||||
var array = new type(21);
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
array.set(i, 10 - i);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array.get(i));
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConstructWithArrayOfSignedValues(type, name) {
|
|
||||||
running('test ' + name + ' ConstructWithArrayOfSignedValues');
|
|
||||||
try {
|
|
||||||
var array = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]);
|
|
||||||
assertEq('Array length', 21, array.length);
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConstructWithWebGLArrayOfSignedValues(type, name) {
|
|
||||||
running('test ' + name + ' ConstructWithWebGLArrayOfSignedValues');
|
|
||||||
try {
|
|
||||||
var tmp = new type([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]);
|
|
||||||
var array = new type(tmp);
|
|
||||||
assertEq('Array length', 21, array.length);
|
|
||||||
for (var i = 0; i < 21; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Test cases for both signed and unsigned types
|
|
||||||
//
|
|
||||||
|
|
||||||
function testOffsetsAndSizes(type, name, elementSizeInBytes) {
|
|
||||||
running('test ' + name + ' OffsetsAndSizes');
|
|
||||||
try {
|
|
||||||
var len = 10;
|
|
||||||
var array = new type(len);
|
|
||||||
assert('array.buffer', array.buffer);
|
|
||||||
assertEq('array.byteOffset', array.byteOffset, 0);
|
|
||||||
assertEq('array.length', array.length, len);
|
|
||||||
assertEq('array.byteLength', array.byteLength, len * elementSizeInBytes);
|
|
||||||
array = new type(array.buffer, elementSizeInBytes, len - 1);
|
|
||||||
assert('array.buffer', array.buffer);
|
|
||||||
assertEq('array.byteOffset', array.byteOffset, elementSizeInBytes);
|
|
||||||
assertEq('array.length', array.length, len - 1);
|
|
||||||
assertEq('array.byteLength', array.byteLength, (len - 1) * elementSizeInBytes);
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetFromWebGLArray(type, name) {
|
|
||||||
running('test ' + name + ' SetFromWebGLArray');
|
|
||||||
try {
|
|
||||||
var array = new type(10);
|
|
||||||
var array2 = new type(5);
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 0, array[i]);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < array2.length; i++) {
|
|
||||||
array2[i] = i;
|
|
||||||
}
|
|
||||||
array.set(array2);
|
|
||||||
for (var i = 0; i < array2.length; i++) {
|
|
||||||
assertEq('Element ' + i, i, array[i]);
|
|
||||||
}
|
|
||||||
array.set(array2, 5);
|
|
||||||
for (var i = 0; i < array2.length; i++) {
|
|
||||||
assertEq('Element ' + i, i, array[5 + i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function negativeTestSetFromWebGLArray(type, name) {
|
|
||||||
running('negativeTest ' + name + ' SetFromWebGLArray');
|
|
||||||
try {
|
|
||||||
var array = new type(5);
|
|
||||||
var array2 = new type(6);
|
|
||||||
for (var i = 0; i < 5; i++) {
|
|
||||||
assertEq('Element ' + i, 0, array[i]);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < array2.length; i++) {
|
|
||||||
array2[i] = i;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
array.set(array2);
|
|
||||||
fail('Expected exception from array.set(array2)');
|
|
||||||
return;
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
array2.set(array, 2);
|
|
||||||
fail('Expected exception from array2.set(array, 2)');
|
|
||||||
return;
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetFromArray(type, name) {
|
|
||||||
running('test ' + name + ' SetFromArray');
|
|
||||||
try {
|
|
||||||
var array = new type(10);
|
|
||||||
var array2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
assertEq('Element ' + i, 0, array[i]);
|
|
||||||
}
|
|
||||||
array.set(array2, 0);
|
|
||||||
for (var i = 0; i < array2.length; i++) {
|
|
||||||
assertEq('Element ' + i, 10 - i, array[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSlice(type, name) {
|
|
||||||
running('test ' + name + ' Slice');
|
|
||||||
try {
|
|
||||||
var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
||||||
var slice = array.slice(0, 5);
|
|
||||||
assertEq('slice.length', 5, slice.length);
|
|
||||||
for (var i = 0; i < 5; i++) {
|
|
||||||
assertEq('Element ' + i, i, slice[i]);
|
|
||||||
}
|
|
||||||
slice = array.slice(4, 6);
|
|
||||||
assertEq('slice.length', 6, slice.length);
|
|
||||||
for (var i = 0; i < 6; i++) {
|
|
||||||
assertEq('Element ' + i, 4 + i, slice[i]);
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function negativeTestSlice(type, name) {
|
|
||||||
running('negativeTest ' + name + ' Slice');
|
|
||||||
try {
|
|
||||||
var array = new type([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
||||||
slice = array.slice(5, 6);
|
|
||||||
if (slice) {
|
|
||||||
fail();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
slice = array.slice(10, 0);
|
|
||||||
if (slice) {
|
|
||||||
fail();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
pass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBoundaryConditions(type, name, lowValue, expectedLowValue, highValue, expectedHighValue) {
|
|
||||||
running('test ' + name + ' BoundaryConditions(' +
|
|
||||||
lowValue + ', ' + expectedLowValue + ', ' +
|
|
||||||
highValue + ', ' + expectedHighValue + ')');
|
|
||||||
try {
|
|
||||||
var array = new type(1);
|
|
||||||
assertEq('Array length', 1, array.length);
|
|
||||||
array[0] = lowValue;
|
|
||||||
assertEq('Element 0', expectedLowValue, array[0]);
|
|
||||||
array[0] = highValue;
|
|
||||||
assertEq('Element 0', expectedHighValue, array[0]);
|
|
||||||
pass();
|
|
||||||
} catch (e) {
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Test driver
|
|
||||||
//
|
|
||||||
|
|
||||||
function runTests() {
|
|
||||||
allPassed = true;
|
|
||||||
|
|
||||||
// The "name" attribute is a concession to browsers which don't
|
|
||||||
// implement the "name" property on function objects
|
|
||||||
var testCases =
|
|
||||||
[ {name: "WebGLByteArray",
|
|
||||||
unsigned: false,
|
|
||||||
elementSizeInBytes: 1,
|
|
||||||
low: -128,
|
|
||||||
expectedLow: -128,
|
|
||||||
high: 127,
|
|
||||||
expectedHigh: 127},
|
|
||||||
{name: "WebGLFloatArray",
|
|
||||||
unsigned: false,
|
|
||||||
elementSizeInBytes: 4,
|
|
||||||
low: -500,
|
|
||||||
expectedLow: -500,
|
|
||||||
high: 500,
|
|
||||||
expectedHigh: 500},
|
|
||||||
{name: "WebGLIntArray",
|
|
||||||
unsigned: false,
|
|
||||||
elementSizeInBytes: 4,
|
|
||||||
low: -2147483648,
|
|
||||||
expectedLow: -2147483648,
|
|
||||||
high: 2147483647,
|
|
||||||
expectedHigh: 2147483647},
|
|
||||||
{name: "WebGLShortArray",
|
|
||||||
unsigned: false,
|
|
||||||
elementSizeInBytes: 2,
|
|
||||||
low: -32768,
|
|
||||||
expectedLow: -32768,
|
|
||||||
high: 32767,
|
|
||||||
expectedHigh: 32767},
|
|
||||||
{name: "WebGLUnsignedByteArray",
|
|
||||||
unsigned: true,
|
|
||||||
elementSizeInBytes: 1,
|
|
||||||
low: 0,
|
|
||||||
expectedLow: 0,
|
|
||||||
high: 255,
|
|
||||||
expectedHigh: 255},
|
|
||||||
{name: "WebGLUnsignedIntArray",
|
|
||||||
unsigned: true,
|
|
||||||
elementSizeInBytes: 4,
|
|
||||||
low: 0,
|
|
||||||
expectedLow: 0,
|
|
||||||
high: 4294967295,
|
|
||||||
expectedHigh: 4294967295},
|
|
||||||
{name: "WebGLUnsignedShortArray",
|
|
||||||
unsigned: true,
|
|
||||||
elementSizeInBytes: 2,
|
|
||||||
low: 0,
|
|
||||||
expectedLow: 0,
|
|
||||||
high: 65535,
|
|
||||||
expectedHigh: 65535} ];
|
|
||||||
|
|
||||||
for (var i = 0; i < testCases.length; i++) {
|
|
||||||
var testCase = testCases[i];
|
|
||||||
running(testCase.name);
|
|
||||||
if (!(testCase.name in window)) {
|
|
||||||
fail("does not exist");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var type = window[testCase.name];
|
|
||||||
var name = testCase.name;
|
|
||||||
if (testCase.unsigned) {
|
|
||||||
testSetAndGet10To1(type, name);
|
|
||||||
testSetAndGetMethods10To1(type, name);
|
|
||||||
testConstructWithArrayOfUnsignedValues(type, name);
|
|
||||||
testConstructWithWebGLArrayOfUnsignedValues(type, name);
|
|
||||||
} else {
|
|
||||||
testSetAndGetPos10ToNeg10(type, name);
|
|
||||||
testSetAndGetMethodsPos10ToNeg10(type, name);
|
|
||||||
testConstructWithArrayOfSignedValues(type, name);
|
|
||||||
testConstructWithWebGLArrayOfSignedValues(type, name);
|
|
||||||
}
|
|
||||||
testOffsetsAndSizes(type, name, testCase.elementSizeInBytes);
|
|
||||||
testSetFromWebGLArray(type, name);
|
|
||||||
negativeTestSetFromWebGLArray(type, name);
|
|
||||||
testSetFromArray(type, name);
|
|
||||||
testSlice(type, name);
|
|
||||||
negativeTestSlice(type, name);
|
|
||||||
testBoundaryConditions(type,
|
|
||||||
name,
|
|
||||||
testCase.low,
|
|
||||||
testCase.expectedLow,
|
|
||||||
testCase.high,
|
|
||||||
testCase.expectedHigh);
|
|
||||||
}
|
|
||||||
|
|
||||||
printSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
runTests();
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * 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.
|
|
||||||
* * Neither the name of Google Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "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 THE COPYRIGHT
|
|
||||||
* OWNER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Tests generation of synthetic and real GL errors");
|
|
||||||
|
|
||||||
var context = create3DContext();
|
|
||||||
var program = loadStandardProgram(context);
|
|
||||||
|
|
||||||
// Other tests in this directory like getActiveTest and
|
|
||||||
// incorrect-context-object-behaviour already test the raising of many
|
|
||||||
// synthetic GL errors. This test verifies the raising of certain
|
|
||||||
// known real GL errors, and contains a few regression tests for bugs
|
|
||||||
// discovered in the synthetic error generation and in the WebGL
|
|
||||||
// implementation itself.
|
|
||||||
|
|
||||||
shouldBe("context.getError()", "0");
|
|
||||||
|
|
||||||
debug("Testing getActiveAttrib");
|
|
||||||
// Synthetic OpenGL error
|
|
||||||
shouldBeNull("context.getActiveAttrib(null, 2)");
|
|
||||||
glErrorShouldBe(context, context.INVALID_OPERATION);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
// Real OpenGL error
|
|
||||||
shouldBeNull("context.getActiveAttrib(program, 2)");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
|
|
||||||
debug("Testing getActiveUniform");
|
|
||||||
// Synthetic OpenGL error
|
|
||||||
shouldBeNull("context.getActiveUniform(null, 0)");
|
|
||||||
glErrorShouldBe(context, context.INVALID_OPERATION);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
// Real OpenGL error
|
|
||||||
shouldBeNull("context.getActiveUniform(program, 50)");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
|
|
||||||
debug("Testing attempts to manipulate the default framebuffer");
|
|
||||||
shouldBeUndefined("context.bindFramebuffer(context.FRAMEBUFFER, 0)");
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
shouldBeUndefined("context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, 0)");
|
|
||||||
// Synthetic OpenGL error
|
|
||||||
glErrorShouldBe(context, context.INVALID_OPERATION);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
shouldBeUndefined("context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, 0, 0)");
|
|
||||||
// Synthetic OpenGL error
|
|
||||||
glErrorShouldBe(context, context.INVALID_OPERATION);
|
|
||||||
// Error state should be clear by this point
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -23,7 +23,12 @@ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Workaround for non-compliant WebGL implementations (FIXME)
|
||||||
|
#if defined(GL_ES)
|
||||||
|
varying mediump vec3 v_normal;
|
||||||
|
#else
|
||||||
varying vec3 v_normal;
|
varying vec3 v_normal;
|
||||||
|
#endif
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Test of getActiveAttrib and getActiveUniform");
|
|
||||||
|
|
||||||
var context = create3DContext();
|
|
||||||
var context2 = create3DContext();
|
|
||||||
var program = loadStandardProgram(context);
|
|
||||||
var program2 = loadStandardProgram(context2);
|
|
||||||
|
|
||||||
glErrorShouldBe(context, context.NO_ERROR);
|
|
||||||
shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'");
|
|
||||||
shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4");
|
|
||||||
shouldBe("context.getActiveUniform(program, 0).size", "1");
|
|
||||||
shouldBe("context.getActiveUniform(program, 1)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
shouldBe("context.getActiveUniform(program, -1)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
shouldBe("context.getActiveUniform(null, 0)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
|
|
||||||
// we don't know the order the attribs will appear.
|
|
||||||
var info = [
|
|
||||||
context.getActiveAttrib(program, 0),
|
|
||||||
context.getActiveAttrib(program, 1)
|
|
||||||
];
|
|
||||||
|
|
||||||
var expected = [
|
|
||||||
{ name: 'a_normal', type: context.FLOAT_VEC3, size: 1 },
|
|
||||||
{ name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 }
|
|
||||||
];
|
|
||||||
|
|
||||||
if (info[0].name != expected[0].name) {
|
|
||||||
t = info[0];
|
|
||||||
info[0] = info[1];
|
|
||||||
info[1] = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var ii = 0; ii < info.length; ++ii) {
|
|
||||||
shouldBe("info[ii].name", "expected[ii].name");
|
|
||||||
shouldBe("info[ii].type", "expected[ii].type");
|
|
||||||
shouldBe("info[ii].size", "expected[ii].size");
|
|
||||||
}
|
|
||||||
shouldBe("context.getActiveAttrib(program, 2)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
shouldBe("context.getActiveAttrib(program, -1)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
shouldBe("context.getActiveAttrib(null, 0)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
|
|
||||||
debug("Check trying to get attribs from different context");
|
|
||||||
shouldBe("context2.getActiveAttrib(program, 0)", "null");
|
|
||||||
glErrorShouldBe(context2, context2.INVALID_OPERATION);
|
|
||||||
shouldBe("context2.getActiveUniform(program, 0)", "null");
|
|
||||||
glErrorShouldBe(context2, context2.INVALID_OPERATION);
|
|
||||||
|
|
||||||
debug("Check trying to get attribs from deleted program");
|
|
||||||
context.deleteProgram(program);
|
|
||||||
shouldBe("context.getActiveUniform(program, 0)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
shouldBe("context.getActiveAttrib(program, 0)", "null");
|
|
||||||
glErrorShouldBe(context, context.INVALID_VALUE);
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
* 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:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * 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.
|
|
||||||
* * Neither the name of Google Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "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 THE COPYRIGHT
|
|
||||||
* OWNER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Test of get calls against GL objects like getBufferParameter, etc.");
|
|
||||||
|
|
||||||
var gl = create3DContext();
|
|
||||||
|
|
||||||
var standardVert = loadStandardVertexShader(gl);
|
|
||||||
var standardFrag = loadStandardFragmentShader(gl);
|
|
||||||
var standardProgram = gl.createProgram();
|
|
||||||
gl.attachShader(standardProgram, standardVert);
|
|
||||||
gl.attachShader(standardProgram, standardFrag);
|
|
||||||
gl.linkProgram(standardProgram);
|
|
||||||
|
|
||||||
// Test getBufferParameter
|
|
||||||
var buffer = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, 16, gl.DYNAMIC_DRAW);
|
|
||||||
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16');
|
|
||||||
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_DRAW');
|
|
||||||
|
|
||||||
// Test getFramebufferAttachmentParameter
|
|
||||||
var texture = gl.createTexture();
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
|
||||||
new WebGLUnsignedByteArray([0, 0, 0, 255,
|
|
||||||
255, 255, 255, 255,
|
|
||||||
255, 255, 255, 255,
|
|
||||||
0, 0, 0, 255]));
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
||||||
var framebuffer = gl.createFramebuffer();
|
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
||||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
||||||
var renderbuffer = gl.createRenderbuffer();
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT, 2, 2);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
|
|
||||||
// FIXME: on some machines (in particular the WebKit commit bots) the
|
|
||||||
// framebuffer status is FRAMEBUFFER_UNSUPPORTED; more investigation
|
|
||||||
// is needed why this is the case, because the FBO allocated
|
|
||||||
// internally by the WebKit implementation has almost identical
|
|
||||||
// parameters to this one. See https://bugs.webkit.org/show_bug.cgi?id=31843.
|
|
||||||
//shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
|
|
||||||
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE');
|
|
||||||
shouldBeNonNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
|
||||||
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0');
|
|
||||||
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0');
|
|
||||||
|
|
||||||
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER');
|
|
||||||
shouldBeNonNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
|
|
||||||
|
|
||||||
// Test getProgramParameter
|
|
||||||
shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false');
|
|
||||||
shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true');
|
|
||||||
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"');
|
|
||||||
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.INFO_LOG_LENGTH)', '"number"');
|
|
||||||
shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2');
|
|
||||||
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2');
|
|
||||||
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTE_MAX_LENGTH)');
|
|
||||||
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1');
|
|
||||||
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORM_MAX_LENGTH)');
|
|
||||||
|
|
||||||
// Test getRenderbufferParameter
|
|
||||||
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)', '2');
|
|
||||||
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)', '2');
|
|
||||||
// Note: we can't test the actual value of the internal format since
|
|
||||||
// the implementation is allowed to change it.
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)');
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE)');
|
|
||||||
var colorbuffer = gl.createRenderbuffer();
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 2, 2);
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)');
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)');
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)');
|
|
||||||
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)');
|
|
||||||
|
|
||||||
// Test getShaderParameter
|
|
||||||
shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADER');
|
|
||||||
shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false');
|
|
||||||
shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true');
|
|
||||||
shouldBe('typeof gl.getShaderParameter(standardVert, gl.INFO_LOG_LENGTH)', '"number"');
|
|
||||||
shouldBeNonZero('gl.getShaderParameter(standardVert, gl.SHADER_SOURCE_LENGTH)');
|
|
||||||
|
|
||||||
// Test getTexParameter
|
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
||||||
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST');
|
|
||||||
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST');
|
|
||||||
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_EDGE');
|
|
||||||
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_EDGE');
|
|
||||||
|
|
||||||
// Test getUniform with all variants of data types
|
|
||||||
// Boolean uniform variables
|
|
||||||
var boolProgram = loadProgram(gl, "resources/boolUniformShader.vert", "resources/noopUniformShader.frag");
|
|
||||||
shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true');
|
|
||||||
var bvalLoc = gl.getUniformLocation(boolProgram, "bval");
|
|
||||||
var bval2Loc = gl.getUniformLocation(boolProgram, "bval2");
|
|
||||||
var bval3Loc = gl.getUniformLocation(boolProgram, "bval3");
|
|
||||||
var bval4Loc = gl.getUniformLocation(boolProgram, "bval4");
|
|
||||||
gl.useProgram(boolProgram);
|
|
||||||
gl.uniform1i(bvalLoc, 1);
|
|
||||||
gl.uniform2i(bval2Loc, 1, 0);
|
|
||||||
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]');
|
|
||||||
// Integer uniform variables
|
|
||||||
var intProgram = loadProgram(gl, "resources/intUniformShader.vert", "resources/noopUniformShader.frag");
|
|
||||||
shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true');
|
|
||||||
var ivalLoc = gl.getUniformLocation(intProgram, "ival");
|
|
||||||
var ival2Loc = gl.getUniformLocation(intProgram, "ival2");
|
|
||||||
var ival3Loc = gl.getUniformLocation(intProgram, "ival3");
|
|
||||||
var ival4Loc = gl.getUniformLocation(intProgram, "ival4");
|
|
||||||
gl.useProgram(intProgram);
|
|
||||||
gl.uniform1i(ivalLoc, 1);
|
|
||||||
gl.uniform2i(ival2Loc, 2, 3);
|
|
||||||
gl.uniform3i(ival3Loc, 4, 5, 6);
|
|
||||||
gl.uniform4i(ival4Loc, 7, 8, 9, 10);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
shouldBe('gl.getUniform(intProgram, ivalLoc)', '1');
|
|
||||||
shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]');
|
|
||||||
shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]');
|
|
||||||
shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]');
|
|
||||||
// Float uniform variables
|
|
||||||
var floatProgram = loadProgram(gl, "resources/floatUniformShader.vert", "resources/noopUniformShader.frag");
|
|
||||||
shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true');
|
|
||||||
var fvalLoc = gl.getUniformLocation(floatProgram, "fval");
|
|
||||||
var fval2Loc = gl.getUniformLocation(floatProgram, "fval2");
|
|
||||||
var fval3Loc = gl.getUniformLocation(floatProgram, "fval3");
|
|
||||||
var fval4Loc = gl.getUniformLocation(floatProgram, "fval4");
|
|
||||||
gl.useProgram(floatProgram);
|
|
||||||
gl.uniform1f(fvalLoc, 11);
|
|
||||||
gl.uniform2f(fval2Loc, 12, 13);
|
|
||||||
gl.uniform3f(fval3Loc, 14, 15, 16);
|
|
||||||
gl.uniform4f(fval4Loc, 17, 18, 19, 20);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11');
|
|
||||||
shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]');
|
|
||||||
shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]');
|
|
||||||
shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]');
|
|
||||||
// Matrix uniform variables
|
|
||||||
var matProgram = loadProgram(gl, "resources/matUniformShader.vert", "resources/noopUniformShader.frag");
|
|
||||||
shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true');
|
|
||||||
var mval2Loc = gl.getUniformLocation(matProgram, "mval2");
|
|
||||||
var mval3Loc = gl.getUniformLocation(matProgram, "mval3");
|
|
||||||
var mval4Loc = gl.getUniformLocation(matProgram, "mval4");
|
|
||||||
gl.useProgram(matProgram);
|
|
||||||
gl.uniformMatrix2fv(mval2Loc, false, [1, 2, 3, 4]);
|
|
||||||
gl.uniformMatrix3fv(mval3Loc, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
|
||||||
gl.uniformMatrix4fv(mval4Loc, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]');
|
|
||||||
shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]');
|
|
||||||
shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]');
|
|
||||||
|
|
||||||
// Test getVertexAttrib
|
|
||||||
var array = new WebGLFloatArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW);
|
|
||||||
// Vertex attribute 0 is special in that it has no current state, so
|
|
||||||
// fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute
|
|
||||||
// 1 for these tests instead.
|
|
||||||
gl.enableVertexAttribArray(1);
|
|
||||||
gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0);
|
|
||||||
shouldBeNonNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)');
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true');
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4');
|
|
||||||
shouldBe('(gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 0) || (gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 4 * gl.sizeInBytes(gl.FLOAT))', 'true');
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT');
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false');
|
|
||||||
gl.disableVertexAttribArray(1);
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false');
|
|
||||||
gl.vertexAttrib4f(1, 5, 6, 7, 8);
|
|
||||||
shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]');
|
|
||||||
glErrorShouldBe(gl, gl.NO_ERROR);
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
|
After Width: | Height: | Size: 81 B |
|
After Width: | Height: | Size: 78 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-default-gamma.png
Executable file
|
After Width: | Height: | Size: 123 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-gamma0.1.png
Executable file
|
After Width: | Height: | Size: 133 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-gamma1.0.png
Executable file
|
After Width: | Height: | Size: 133 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-gamma2.0.png
Executable file
|
After Width: | Height: | Size: 133 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-gamma4.0.png
Executable file
|
After Width: | Height: | Size: 133 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp-gamma9.0.png
Executable file
|
After Width: | Height: | Size: 133 B |
BIN
content/canvas/test/webgl/conformance/resources/gray-ramp.png
Executable file
|
After Width: | Height: | Size: 123 B |
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Tests calling WebGL APIs with objects from other contexts");
|
|
||||||
|
|
||||||
var contextA = create3DContext();
|
|
||||||
var contextB = create3DContext();
|
|
||||||
var programA = loadStandardProgram(contextA);
|
|
||||||
var programB = loadStandardProgram(contextB);
|
|
||||||
var shaderA = loadStandardVertexShader(contextA);
|
|
||||||
var shaderB = loadStandardVertexShader(contextB);
|
|
||||||
var textureA = contextA.createTexture();
|
|
||||||
var textureB = contextB.createTexture();
|
|
||||||
var frameBufferA = contextA.createFramebuffer();
|
|
||||||
var frameBufferB = contextB.createFramebuffer();
|
|
||||||
var renderBufferA = contextA.createRenderbuffer();
|
|
||||||
var renderBufferB = contextB.createRenderbuffer();
|
|
||||||
var locationA = contextA.getUniformLocation(programA, 'u_modelViewProjMatrix');
|
|
||||||
var locationB = contextB.getUniformLocation(programB, 'u_modelViewProjMatrix');
|
|
||||||
|
|
||||||
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.compileShader(shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.linkProgram(programB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programA, shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderA)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programA, shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderA)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.shaderSource(shaderB, 'foo')");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindAttribLocation(programB, 0, 'foo')");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindFramebuffer(contextA.FRAMEBUFFER, frameBufferB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindRenderbuffer(contextA.RENDERBUFFER, renderBufferB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindTexture(contextA.TEXTURE_2D, textureB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferRenderbuffer(contextA.FRAMEBUFFER, contextA.DEPTH_ATTACHMENT, contextA.RENDERBUFFER, renderBufferB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferTexture2D(contextA.FRAMEBUFFER, contextA.COLOR_ATTACHMENT0, contextA.TEXTURE_2D, textureB, 0)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramParameter(programB, 0)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramInfoLog(programB, 0)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderParameter(shaderB, 0)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderInfoLog(shaderB, 0)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderSource(shaderB)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniform(programB, locationA)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniformLocation(programB, 'u_modelViewProjMatrix')");
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * 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.
|
|
||||||
* * Neither the name of Google Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "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 THE COPYRIGHT
|
|
||||||
* OWNER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Tests that index validation verifies the correct number of indices");
|
|
||||||
|
|
||||||
var gl = create3DContext();
|
|
||||||
var program = loadStandardProgram(gl);
|
|
||||||
|
|
||||||
// 3 vertices => 1 triangle, interleaved data
|
|
||||||
var data = new WebGLFloatArray([0, 0, 0, 1,
|
|
||||||
0, 0, 1,
|
|
||||||
1, 0, 0, 1,
|
|
||||||
0, 0, 1,
|
|
||||||
1, 1, 1, 1,
|
|
||||||
0, 0, 1]);
|
|
||||||
var indices = new WebGLUnsignedShortArray([0, 1, 2]);
|
|
||||||
|
|
||||||
var buffer = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
||||||
var elements = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
|
|
||||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
|
||||||
gl.useProgram(program);
|
|
||||||
var vertexLoc = gl.getAttribLocation(program, "a_vertex");
|
|
||||||
var normalLoc = gl.getAttribLocation(program, "a_normal");
|
|
||||||
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
|
|
||||||
gl.enableVertexAttribArray(vertexLoc);
|
|
||||||
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 3 * gl.sizeInBytes(gl.FLOAT));
|
|
||||||
gl.enableVertexAttribArray(normalLoc);
|
|
||||||
shouldBe('gl.getError()', '0');
|
|
||||||
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
|
||||||
shouldBe('gl.getError()', '0');
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
uniform int ival;
|
||||||
|
uniform int ival2[2];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
int sum = ival + ival2[0] + ival2[1];
|
||||||
|
gl_Position = vec4(sum, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Tests calling WebGL APIs without providing the necessary objects");
|
|
||||||
|
|
||||||
var context = create3DContext();
|
|
||||||
var program = loadStandardProgram(context);
|
|
||||||
var shader = loadStandardVertexShader(context);
|
|
||||||
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.compileShader()");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.linkProgram()");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader()");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(program, undefined)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(undefined, shader)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(program, undefined)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(undefined, shader)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource()");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource(undefined, 'foo')");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.bindAttribLocation(undefined, 0, 'foo')");
|
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, 0)");
|
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, 0)");
|
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, 0)");
|
|
||||||
shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, 0, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramParameter(undefined, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramInfoLog(undefined, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderParameter(undefined, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderInfoLog(undefined, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderSource(undefined)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniform(undefined, 0)");
|
|
||||||
shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniformLocation(undefined, 'foo')");
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
207
content/canvas/test/webgl/conformance/resources/pnglib.js
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
/**
|
||||||
|
* A handy class to calculate color values.
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
* @author Robert Eisele <robert@xarg.org>
|
||||||
|
* @copyright Copyright (c) 2010, Robert Eisele
|
||||||
|
* @link http://www.xarg.org/2010/03/generate-client-side-png-files-using-javascript/
|
||||||
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
// helper functions for that ctx
|
||||||
|
function write(buffer, offs) {
|
||||||
|
for (var i = 2; i < arguments.length; i++) {
|
||||||
|
for (var j = 0; j < arguments[i].length; j++) {
|
||||||
|
buffer[offs++] = arguments[i].charAt(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte2(w) {
|
||||||
|
return String.fromCharCode((w >> 8) & 255, w & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte4(w) {
|
||||||
|
return String.fromCharCode((w >> 24) & 255, (w >> 16) & 255, (w >> 8) & 255, w & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte2lsb(w) {
|
||||||
|
return String.fromCharCode(w & 255, (w >> 8) & 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.PNGlib = function(width,height,depth) {
|
||||||
|
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.depth = depth;
|
||||||
|
|
||||||
|
// pixel data and row filter identifier size
|
||||||
|
this.pix_size = height * (width + 1);
|
||||||
|
|
||||||
|
// deflate header, pix_size, block headers, adler32 checksum
|
||||||
|
this.data_size = 2 + this.pix_size + 5 * Math.floor((0xfffe + this.pix_size) / 0xffff) + 4;
|
||||||
|
|
||||||
|
// offsets and sizes of Png chunks
|
||||||
|
this.ihdr_offs = 0; // IHDR offset and size
|
||||||
|
this.ihdr_size = 4 + 4 + 13 + 4;
|
||||||
|
this.plte_offs = this.ihdr_offs + this.ihdr_size; // PLTE offset and size
|
||||||
|
this.plte_size = 4 + 4 + 3 * depth + 4;
|
||||||
|
this.trns_offs = this.plte_offs + this.plte_size; // tRNS offset and size
|
||||||
|
this.trns_size = 4 + 4 + depth + 4;
|
||||||
|
this.idat_offs = this.trns_offs + this.trns_size; // IDAT offset and size
|
||||||
|
this.idat_size = 4 + 4 + this.data_size + 4;
|
||||||
|
this.iend_offs = this.idat_offs + this.idat_size; // IEND offset and size
|
||||||
|
this.iend_size = 4 + 4 + 4;
|
||||||
|
this.buffer_size = this.iend_offs + this.iend_size; // total PNG size
|
||||||
|
|
||||||
|
this.buffer = new Array();
|
||||||
|
this.palette = new Object();
|
||||||
|
this.pindex = 0;
|
||||||
|
|
||||||
|
var _crc32 = new Array();
|
||||||
|
|
||||||
|
// initialize buffer with zero bytes
|
||||||
|
for (var i = 0; i < this.buffer_size; i++) {
|
||||||
|
this.buffer[i] = "\x00";
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize non-zero elements
|
||||||
|
write(this.buffer, this.ihdr_offs, byte4(this.ihdr_size - 12), 'IHDR', byte4(width), byte4(height), "\x08\x03");
|
||||||
|
write(this.buffer, this.plte_offs, byte4(this.plte_size - 12), 'PLTE');
|
||||||
|
write(this.buffer, this.trns_offs, byte4(this.trns_size - 12), 'tRNS');
|
||||||
|
write(this.buffer, this.idat_offs, byte4(this.idat_size - 12), 'IDAT');
|
||||||
|
write(this.buffer, this.iend_offs, byte4(this.iend_size - 12), 'IEND');
|
||||||
|
|
||||||
|
// initialize deflate header
|
||||||
|
var header = ((8 + (7 << 4)) << 8) | (3 << 6);
|
||||||
|
header+= 31 - (header % 31);
|
||||||
|
|
||||||
|
write(this.buffer, this.idat_offs + 8, byte2(header));
|
||||||
|
|
||||||
|
// initialize deflate block headers
|
||||||
|
for (var i = 0; (i << 16) - 1 < this.pix_size; i++) {
|
||||||
|
var size, bits;
|
||||||
|
if (i + 0xffff < this.pix_size) {
|
||||||
|
size = 0xffff;
|
||||||
|
bits = "\x00";
|
||||||
|
} else {
|
||||||
|
size = this.pix_size - (i << 16) - i;
|
||||||
|
bits = "\x01";
|
||||||
|
}
|
||||||
|
write(this.buffer, this.idat_offs + 8 + 2 + (i << 16) + (i << 2), bits, byte2lsb(size), byte2lsb(~size));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create crc32 lookup table */
|
||||||
|
for (var i = 0; i < 256; i++) {
|
||||||
|
var c = i;
|
||||||
|
for (var j = 0; j < 8; j++) {
|
||||||
|
if (c & 1) {
|
||||||
|
c = -306674912 ^ ((c >> 1) & 0x7fffffff);
|
||||||
|
} else {
|
||||||
|
c = (c >> 1) & 0x7fffffff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_crc32[i] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute the index into a png for a given pixel
|
||||||
|
this.index = function(x,y) {
|
||||||
|
var i = y * (this.width + 1) + x + 1;
|
||||||
|
var j = this.idat_offs + 8 + 2 + 5 * Math.floor((i / 0xffff) + 1) + i;
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert a color and build up the palette
|
||||||
|
this.color = function(red, green, blue, alpha) {
|
||||||
|
|
||||||
|
alpha = alpha >= 0 ? alpha : 255;
|
||||||
|
var color = (((((alpha << 8) | red) << 8) | green) << 8) | blue;
|
||||||
|
|
||||||
|
if (typeof this.palette[color] == "undefined") {
|
||||||
|
if (this.pindex == this.depth) return "\x00";
|
||||||
|
|
||||||
|
var ndx = this.plte_offs + 8 + 3 * this.pindex;
|
||||||
|
|
||||||
|
this.buffer[ndx + 0] = String.fromCharCode(red);
|
||||||
|
this.buffer[ndx + 1] = String.fromCharCode(green);
|
||||||
|
this.buffer[ndx + 2] = String.fromCharCode(blue);
|
||||||
|
this.buffer[this.trns_offs+8+this.pindex] = String.fromCharCode(alpha);
|
||||||
|
|
||||||
|
this.palette[color] = String.fromCharCode(this.pindex++);
|
||||||
|
}
|
||||||
|
return this.palette[color];
|
||||||
|
}
|
||||||
|
|
||||||
|
// output a PNG string, Base64 encoded
|
||||||
|
this.getBase64 = function() {
|
||||||
|
|
||||||
|
var s = this.getDump();
|
||||||
|
|
||||||
|
var ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
|
var c1, c2, c3, e1, e2, e3, e4;
|
||||||
|
var l = s.length;
|
||||||
|
var i = 0;
|
||||||
|
var r = "";
|
||||||
|
|
||||||
|
do {
|
||||||
|
c1 = s.charCodeAt(i);
|
||||||
|
e1 = c1 >> 2;
|
||||||
|
c2 = s.charCodeAt(i+1);
|
||||||
|
e2 = ((c1 & 3) << 4) | (c2 >> 4);
|
||||||
|
c3 = s.charCodeAt(i+2);
|
||||||
|
if (l < i+2) { e3 = 64; } else { e3 = ((c2 & 0xf) << 2) | (c3 >> 6); }
|
||||||
|
if (l < i+3) { e4 = 64; } else { e4 = c3 & 0x3f; }
|
||||||
|
r+= ch.charAt(e1) + ch.charAt(e2) + ch.charAt(e3) + ch.charAt(e4);
|
||||||
|
} while ((i+= 3) < l);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// output a PNG string
|
||||||
|
this.getDump = function() {
|
||||||
|
|
||||||
|
// compute adler32 of output pixels + row filter bytes
|
||||||
|
var BASE = 65521; /* largest prime smaller than 65536 */
|
||||||
|
var NMAX = 5552; /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||||
|
var s1 = 1;
|
||||||
|
var s2 = 0;
|
||||||
|
var n = NMAX;
|
||||||
|
|
||||||
|
for (var y = 0; y < this.height; y++) {
|
||||||
|
for (var x = -1; x < this.width; x++) {
|
||||||
|
s1+= this.buffer[this.index(x, y)].charCodeAt(0);
|
||||||
|
s2+= s1;
|
||||||
|
if ((n-= 1) == 0) {
|
||||||
|
s1%= BASE;
|
||||||
|
s2%= BASE;
|
||||||
|
n = NMAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s1%= BASE;
|
||||||
|
s2%= BASE;
|
||||||
|
write(this.buffer, this.idat_offs + this.idat_size - 8, byte4((s2 << 16) | s1));
|
||||||
|
|
||||||
|
// compute crc32 of the PNG chunks
|
||||||
|
function crc32(png, offs, size) {
|
||||||
|
var crc = -1;
|
||||||
|
for (var i = 4; i < size-4; i += 1) {
|
||||||
|
crc = _crc32[(crc ^ png[offs+i].charCodeAt(0)) & 0xff] ^ ((crc >> 8) & 0x00ffffff);
|
||||||
|
}
|
||||||
|
write(png, offs+size-4, byte4(crc ^ -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
crc32(this.buffer, this.ihdr_offs, this.ihdr_size);
|
||||||
|
crc32(this.buffer, this.plte_offs, this.plte_size);
|
||||||
|
crc32(this.buffer, this.trns_offs, this.trns_size);
|
||||||
|
crc32(this.buffer, this.idat_offs, this.idat_size);
|
||||||
|
crc32(this.buffer, this.iend_offs, this.iend_size);
|
||||||
|
|
||||||
|
// convert PNG to string
|
||||||
|
return "\211PNG\r\n\032\n"+this.buffer.join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
BIN
content/canvas/test/webgl/conformance/resources/red-green.png
Normal file
|
After Width: | Height: | Size: 144 B |
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * 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.
|
|
||||||
* * Neither the name of Google Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "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 THE COPYRIGHT
|
|
||||||
* OWNER 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
description("Tests the WebGLUniformLocation API");
|
|
||||||
|
|
||||||
var contextA = create3DContext();
|
|
||||||
var contextB = create3DContext();
|
|
||||||
var programA1 = loadStandardProgram(contextA);
|
|
||||||
var programA2 = loadStandardProgram(contextA);
|
|
||||||
var programB = loadStandardProgram(contextB);
|
|
||||||
var programS = loadProgram(contextA, "resources/structUniformShader.vert", "resources/fragmentShader.frag");
|
|
||||||
var programV = loadProgram(contextA, "resources/floatUniformShader.vert", "resources/noopUniformShader.frag");
|
|
||||||
var locationA = contextA.getUniformLocation(programA1, 'u_modelViewProjMatrix');
|
|
||||||
var locationB = contextB.getUniformLocation(programB, 'u_modelViewProjMatrix');
|
|
||||||
var locationSx = contextA.getUniformLocation(programS, "u_struct.x");
|
|
||||||
var locationArray0 = contextA.getUniformLocation(programS, "u_array[0]");
|
|
||||||
var locationVec4 = contextA.getUniformLocation(programV, "fval4");
|
|
||||||
|
|
||||||
var vec = [1, 2, 3, 4];
|
|
||||||
var mat = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
|
||||||
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.useProgram(programA2)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.uniformMatrix4fv(locationA, false, mat)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.useProgram(programA1)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.uniformMatrix4fv(locationA, false, mat)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_VALUE, "contextA.uniformMatrix4fv(0, false, mat)");
|
|
||||||
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.useProgram(programS)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.uniform1i(locationSx, 3)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.uniform1f(locationArray0, 4.0)");
|
|
||||||
|
|
||||||
shouldBe("contextA.getUniform(programS, locationSx)", "3");
|
|
||||||
shouldBe("contextA.getUniform(programS, locationArray0)", "4.0");
|
|
||||||
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.useProgram(programV)");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.uniform4fv(locationVec4, vec)");
|
|
||||||
shouldBe("contextA.getUniform(programV, locationVec4)", "vec");
|
|
||||||
|
|
||||||
shouldBeNull("contextA.getUniformLocation(programV, \"IDontExist\")");
|
|
||||||
shouldGenerateGLError(contextA, contextA.NO_ERROR, "contextA.linkProgram(programA1)");
|
|
||||||
// After linking all boxes are bad.
|
|
||||||
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.uniformMatrix4fv(locationA, false, mat)");
|
|
||||||
|
|
||||||
|
|
||||||
successfullyParsed = true;
|
|
||||||
@@ -1,592 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
|
||||||
// initWebGL
|
|
||||||
//
|
|
||||||
// Initialize the Canvas element with the passed name as a WebGL object and return the
|
|
||||||
// WebGLRenderingContext.
|
|
||||||
//
|
|
||||||
// Load shaders with the passed names and create a program with them. Return this program
|
|
||||||
// in the 'program' property of the returned context.
|
|
||||||
//
|
|
||||||
// For each string in the passed attribs array, bind an attrib with that name at that index.
|
|
||||||
// Once the attribs are bound, link the program and then use it.
|
|
||||||
//
|
|
||||||
// Set the clear color to the passed array (4 values) and set the clear depth to the passed value.
|
|
||||||
// Enable depth testing and blending with a blend func of (SRC_ALPHA, ONE_MINUS_SRC_ALPHA)
|
|
||||||
//
|
|
||||||
function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth)
|
|
||||||
{
|
|
||||||
var canvas = document.getElementById(canvasName);
|
|
||||||
var gl = create3DContext(canvas);
|
|
||||||
if (!gl) {
|
|
||||||
alert("No WebGL context found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create our shaders
|
|
||||||
var vertexShader = loadShaderFromScript(gl, vshader);
|
|
||||||
var fragmentShader = loadShaderFromScript(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
|
|
||||||
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);
|
|
||||||
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.enable(gl.DEPTH_TEST);
|
|
||||||
gl.enable(gl.BLEND);
|
|
||||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
return gl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// getShaderSource
|
|
||||||
//
|
|
||||||
// Load the source from the passed shader file.
|
|
||||||
//
|
|
||||||
function getShaderSource(file)
|
|
||||||
{
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", file, false);
|
|
||||||
xhr.send();
|
|
||||||
return xhr.responseText;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// loadShader
|
|
||||||
//
|
|
||||||
// 'shader' is either the id of a <script> element containing the shader source string
|
|
||||||
// or the URL of a file containing the shader source. Load this shader and return the
|
|
||||||
// WebGLShader object corresponding to it.
|
|
||||||
//
|
|
||||||
function loadShader(ctx, shaderId, shaderType, isFile)
|
|
||||||
{
|
|
||||||
var shaderSource = "";
|
|
||||||
|
|
||||||
if (isFile)
|
|
||||||
shaderSource = getShaderSource(shaderId);
|
|
||||||
else {
|
|
||||||
var shaderScript = document.getElementById(shaderId);
|
|
||||||
if (!shaderScript) {
|
|
||||||
console.log("*** Error: shader script '"+shaderId+"' not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this overrides the passed in shader type
|
|
||||||
if (shaderScript.type == "x-shader/x-vertex")
|
|
||||||
shaderType = ctx.VERTEX_SHADER;
|
|
||||||
else if (shaderScript.type == "x-shader/x-fragment")
|
|
||||||
shaderType = ctx.FRAGMENT_SHADER;
|
|
||||||
else if (shaderType != ctx.VERTEX_SHADER && shaderType != ctx.FRAGMENT_SHADER) {
|
|
||||||
console.log("*** Error: unknown shader type");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
shaderSource = shaderScript.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the shader object
|
|
||||||
var shader = ctx.createShader(shaderType);
|
|
||||||
if (shader == null) {
|
|
||||||
console.log("*** Error: unable to create shader '"+shaderId+"'");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the shader source
|
|
||||||
ctx.shaderSource(shader, shaderSource);
|
|
||||||
|
|
||||||
// Compile the shader
|
|
||||||
ctx.compileShader(shader);
|
|
||||||
|
|
||||||
// Check the compile status
|
|
||||||
var compiled = ctx.getShaderParameter(shader, ctx.COMPILE_STATUS);
|
|
||||||
if (!compiled) {
|
|
||||||
// Something went wrong during compilation; get the error
|
|
||||||
var error = ctx.getShaderInfoLog(shader);
|
|
||||||
console.log("*** Error compiling shader '"+shader+"':"+error);
|
|
||||||
ctx.deleteShader(shader);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadShaderFromFile(ctx, file, type)
|
|
||||||
{
|
|
||||||
return loadShader(ctx, file, type, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadShaderFromScript(ctx, script)
|
|
||||||
{
|
|
||||||
return loadShader(ctx, script, 0, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// makeBox
|
|
||||||
//
|
|
||||||
// Create a box with vertices, normals and texCoords. Create VBOs for each as well as the index array.
|
|
||||||
// Return an object with the following properties:
|
|
||||||
//
|
|
||||||
// normalObject WebGLBuffer object for normals
|
|
||||||
// texCoordObject WebGLBuffer object for texCoords
|
|
||||||
// vertexObject WebGLBuffer object for vertices
|
|
||||||
// indexObject WebGLBuffer object for indices
|
|
||||||
// numIndices The number of indices in the indexObject
|
|
||||||
//
|
|
||||||
function makeBox(ctx)
|
|
||||||
{
|
|
||||||
// box
|
|
||||||
// v6----- v5
|
|
||||||
// /| /|
|
|
||||||
// v1------v0|
|
|
||||||
// | | | |
|
|
||||||
// | |v7---|-|v4
|
|
||||||
// |/ |/
|
|
||||||
// v2------v3
|
|
||||||
//
|
|
||||||
// vertex coords array
|
|
||||||
var vertices = new WebGLFloatArray(
|
|
||||||
[ 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 front
|
|
||||||
1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v5 right
|
|
||||||
1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v1 top
|
|
||||||
-1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1-v6-v7-v2 left
|
|
||||||
-1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7-v4-v3-v2 bottom
|
|
||||||
1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 ] // v4-v7-v6-v5 back
|
|
||||||
);
|
|
||||||
|
|
||||||
// normal array
|
|
||||||
var normals = new WebGLFloatArray(
|
|
||||||
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
|
|
||||||
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
|
|
||||||
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
|
|
||||||
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left
|
|
||||||
0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7-v4-v3-v2 bottom
|
|
||||||
0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 ] // v4-v7-v6-v5 back
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// texCoord array
|
|
||||||
var texCoords = new WebGLFloatArray(
|
|
||||||
[ 1, 1, 0, 1, 0, 0, 1, 0, // v0-v1-v2-v3 front
|
|
||||||
0, 1, 0, 0, 1, 0, 1, 1, // v0-v3-v4-v5 right
|
|
||||||
1, 0, 1, 1, 0, 1, 0, 0, // v0-v5-v6-v1 top
|
|
||||||
1, 1, 0, 1, 0, 0, 1, 0, // v1-v6-v7-v2 left
|
|
||||||
0, 0, 1, 0, 1, 1, 0, 1, // v7-v4-v3-v2 bottom
|
|
||||||
0, 0, 1, 0, 1, 1, 0, 1 ] // v4-v7-v6-v5 back
|
|
||||||
);
|
|
||||||
|
|
||||||
// index array
|
|
||||||
var indices = new WebGLUnsignedByteArray(
|
|
||||||
[ 0, 1, 2, 0, 2, 3, // front
|
|
||||||
4, 5, 6, 4, 6, 7, // right
|
|
||||||
8, 9,10, 8,10,11, // top
|
|
||||||
12,13,14, 12,14,15, // left
|
|
||||||
16,17,18, 16,18,19, // bottom
|
|
||||||
20,21,22, 20,22,23 ] // back
|
|
||||||
);
|
|
||||||
|
|
||||||
var retval = { };
|
|
||||||
|
|
||||||
retval.normalObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, normals, ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
retval.texCoordObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, texCoords, ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
retval.vertexObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, vertices, ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
retval.indexObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject);
|
|
||||||
ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, indices, ctx.STATIC_DRAW);
|
|
||||||
ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
retval.numIndices = indices.length;
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// makeSphere
|
|
||||||
//
|
|
||||||
// Create a sphere with the passed number of latitude and longitude bands and the passed radius.
|
|
||||||
// Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array.
|
|
||||||
// Return an object with the following properties:
|
|
||||||
//
|
|
||||||
// normalObject WebGLBuffer object for normals
|
|
||||||
// texCoordObject WebGLBuffer object for texCoords
|
|
||||||
// vertexObject WebGLBuffer object for vertices
|
|
||||||
// indexObject WebGLBuffer object for indices
|
|
||||||
// numIndices The number of indices in the indexObject
|
|
||||||
//
|
|
||||||
function makeSphere(ctx, radius, lats, longs)
|
|
||||||
{
|
|
||||||
var geometryData = [ ];
|
|
||||||
var normalData = [ ];
|
|
||||||
var texCoordData = [ ];
|
|
||||||
var indexData = [ ];
|
|
||||||
|
|
||||||
for (var latNumber = 0; latNumber <= lats; ++latNumber) {
|
|
||||||
for (var longNumber = 0; longNumber <= longs; ++longNumber) {
|
|
||||||
var theta = latNumber * Math.PI / lats;
|
|
||||||
var phi = longNumber * 2 * Math.PI / longs;
|
|
||||||
var sinTheta = Math.sin(theta);
|
|
||||||
var sinPhi = Math.sin(phi);
|
|
||||||
var cosTheta = Math.cos(theta);
|
|
||||||
var cosPhi = Math.cos(phi);
|
|
||||||
|
|
||||||
var x = cosPhi * sinTheta;
|
|
||||||
var y = cosTheta;
|
|
||||||
var z = sinPhi * sinTheta;
|
|
||||||
var u = 1-(longNumber/longs);
|
|
||||||
var v = latNumber/lats;
|
|
||||||
|
|
||||||
normalData.push(x);
|
|
||||||
normalData.push(y);
|
|
||||||
normalData.push(z);
|
|
||||||
texCoordData.push(u);
|
|
||||||
texCoordData.push(v);
|
|
||||||
geometryData.push(radius * x);
|
|
||||||
geometryData.push(radius * y);
|
|
||||||
geometryData.push(radius * z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
longs += 1;
|
|
||||||
for (var latNumber = 0; latNumber < lats; ++latNumber) {
|
|
||||||
for (var longNumber = 0; longNumber < longs; ++longNumber) {
|
|
||||||
var first = (latNumber * longs) + (longNumber % longs);
|
|
||||||
var second = first + longs;
|
|
||||||
indexData.push(first);
|
|
||||||
indexData.push(second);
|
|
||||||
indexData.push(first+1);
|
|
||||||
|
|
||||||
indexData.push(second);
|
|
||||||
indexData.push(second+1);
|
|
||||||
indexData.push(first+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var retval = { };
|
|
||||||
|
|
||||||
retval.normalObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(normalData), ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
retval.texCoordObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(texCoordData), ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
retval.vertexObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject);
|
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(geometryData), ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
retval.numIndices = indexData.length;
|
|
||||||
retval.indexObject = ctx.createBuffer();
|
|
||||||
ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject);
|
|
||||||
ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray(indexData), ctx.STREAM_DRAW);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// loadObj
|
|
||||||
//
|
|
||||||
// Load a .obj file from the passed URL. Return an object with a 'loaded' property set to false.
|
|
||||||
// When the object load is complete, the 'loaded' property becomes true and the following
|
|
||||||
// properties are set:
|
|
||||||
//
|
|
||||||
// normalObject WebGLBuffer object for normals
|
|
||||||
// texCoordObject WebGLBuffer object for texCoords
|
|
||||||
// vertexObject WebGLBuffer object for vertices
|
|
||||||
// indexObject WebGLBuffer object for indices
|
|
||||||
// numIndices The number of indices in the indexObject
|
|
||||||
//
|
|
||||||
function loadObj(ctx, url)
|
|
||||||
{
|
|
||||||
var obj = { loaded : false };
|
|
||||||
obj.ctx = ctx;
|
|
||||||
var req = new XMLHttpRequest();
|
|
||||||
req.obj = obj;
|
|
||||||
req.onreadystatechange = function () { processLoadObj(req) };
|
|
||||||
req.open("GET", url, true);
|
|
||||||
req.send(null);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processLoadObj(req)
|
|
||||||
{
|
|
||||||
console.log("req="+req)
|
|
||||||
// only if req shows "complete"
|
|
||||||
if (req.readyState == 4) {
|
|
||||||
doLoadObj(req.obj, req.responseText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function doLoadObj(obj, text)
|
|
||||||
{
|
|
||||||
vertexArray = [ ];
|
|
||||||
normalArray = [ ];
|
|
||||||
textureArray = [ ];
|
|
||||||
indexArray = [ ];
|
|
||||||
|
|
||||||
var vertex = [ ];
|
|
||||||
var normal = [ ];
|
|
||||||
var texture = [ ];
|
|
||||||
var facemap = { };
|
|
||||||
var index = 0;
|
|
||||||
|
|
||||||
var lines = text.split("\n");
|
|
||||||
for (var lineIndex in lines) {
|
|
||||||
var line = lines[lineIndex].replace(/[ \t]+/g, " ").replace(/\s\s*$/, "");
|
|
||||||
|
|
||||||
// ignore comments
|
|
||||||
if (line[0] == "#")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var array = line.split(" ");
|
|
||||||
if (array[0] == "v") {
|
|
||||||
// vertex
|
|
||||||
vertex.push(parseFloat(array[1]));
|
|
||||||
vertex.push(parseFloat(array[2]));
|
|
||||||
vertex.push(parseFloat(array[3]));
|
|
||||||
}
|
|
||||||
else if (array[0] == "vt") {
|
|
||||||
// normal
|
|
||||||
texture.push(parseFloat(array[1]));
|
|
||||||
texture.push(parseFloat(array[2]));
|
|
||||||
}
|
|
||||||
else if (array[0] == "vn") {
|
|
||||||
// normal
|
|
||||||
normal.push(parseFloat(array[1]));
|
|
||||||
normal.push(parseFloat(array[2]));
|
|
||||||
normal.push(parseFloat(array[3]));
|
|
||||||
}
|
|
||||||
else if (array[0] == "f") {
|
|
||||||
// face
|
|
||||||
if (array.length != 4) {
|
|
||||||
console.log("*** Error: face '"+line+"' not handled");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 1; i < 4; ++i) {
|
|
||||||
if (!(array[i] in facemap)) {
|
|
||||||
// add a new entry to the map and arrays
|
|
||||||
var f = array[i].split("/");
|
|
||||||
var vtx, nor, tex;
|
|
||||||
|
|
||||||
if (f.length == 1) {
|
|
||||||
vtx = parseInt(f[0]) - 1;
|
|
||||||
nor = vtx;
|
|
||||||
tex = vtx;
|
|
||||||
}
|
|
||||||
else if (f.length = 3) {
|
|
||||||
vtx = parseInt(f[0]) - 1;
|
|
||||||
tex = parseInt(f[1]) - 1;
|
|
||||||
nor = parseInt(f[2]) - 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log("*** Error: did not understand face '"+array[i]+"'");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the vertices
|
|
||||||
var x = 0;
|
|
||||||
var y = 0;
|
|
||||||
var z = 0;
|
|
||||||
if (vtx * 3 + 2 < vertex.length) {
|
|
||||||
x = vertex[vtx*3];
|
|
||||||
y = vertex[vtx*3+1];
|
|
||||||
z = vertex[vtx*3+2];
|
|
||||||
}
|
|
||||||
vertexArray.push(x);
|
|
||||||
vertexArray.push(y);
|
|
||||||
vertexArray.push(z);
|
|
||||||
|
|
||||||
// do the textures
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
if (tex * 2 + 1 < texture.length) {
|
|
||||||
x = texture[tex*2];
|
|
||||||
y = texture[tex*2+1];
|
|
||||||
}
|
|
||||||
textureArray.push(x);
|
|
||||||
textureArray.push(y);
|
|
||||||
|
|
||||||
// do the normals
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
z = 1;
|
|
||||||
if (nor * 3 + 2 < normal.length) {
|
|
||||||
x = normal[nor*3];
|
|
||||||
y = normal[nor*3+1];
|
|
||||||
z = normal[nor*3+2];
|
|
||||||
}
|
|
||||||
normalArray.push(x);
|
|
||||||
normalArray.push(y);
|
|
||||||
normalArray.push(z);
|
|
||||||
|
|
||||||
facemap[array[i]] = index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
indexArray.push(facemap[array[i]]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the VBOs
|
|
||||||
obj.normalObject = obj.ctx.createBuffer();
|
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.normalObject);
|
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(normalArray), obj.ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
obj.texCoordObject = obj.ctx.createBuffer();
|
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.texCoordObject);
|
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(textureArray), obj.ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
obj.vertexObject = obj.ctx.createBuffer();
|
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.vertexObject);
|
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(vertexArray), obj.ctx.STATIC_DRAW);
|
|
||||||
|
|
||||||
obj.numIndices = indexArray.length;
|
|
||||||
obj.indexObject = obj.ctx.createBuffer();
|
|
||||||
obj.ctx.bindBuffer(obj.ctx.ELEMENT_ARRAY_BUFFER, obj.indexObject);
|
|
||||||
obj.ctx.bufferData(obj.ctx.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray(indexArray), obj.ctx.STREAM_DRAW);
|
|
||||||
|
|
||||||
obj.loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// loadImageTexture
|
|
||||||
//
|
|
||||||
// Load the image at the passed url, place it in a new WebGLTexture object and return the WebGLTexture.
|
|
||||||
//
|
|
||||||
function loadImageTexture(ctx, url)
|
|
||||||
{
|
|
||||||
var texture = ctx.createTexture();
|
|
||||||
texture.image = new Image();
|
|
||||||
texture.image.onload = function() { doLoadImageTexture(ctx, texture.image, texture) }
|
|
||||||
texture.image.src = url;
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
function doLoadImageTexture(ctx, image, texture)
|
|
||||||
{
|
|
||||||
ctx.enable(ctx.TEXTURE_2D);
|
|
||||||
ctx.bindTexture(ctx.TEXTURE_2D, texture);
|
|
||||||
ctx.texImage2D(ctx.TEXTURE_2D, 0, image);
|
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MAG_FILTER, ctx.LINEAR);
|
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MIN_FILTER, ctx.LINEAR_MIPMAP_LINEAR);
|
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.CLAMP_TO_EDGE);
|
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_T, ctx.CLAMP_TO_EDGE);
|
|
||||||
ctx.generateMipmap(ctx.TEXTURE_2D)
|
|
||||||
ctx.bindTexture(ctx.TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Framerate object
|
|
||||||
//
|
|
||||||
// This object keeps track of framerate and displays it as the innerHTML text of the
|
|
||||||
// HTML element with the passed id. Once created you call snapshot at the end
|
|
||||||
// of every rendering cycle. Every 500ms the framerate is updated in the HTML element.
|
|
||||||
//
|
|
||||||
Framerate = function(id)
|
|
||||||
{
|
|
||||||
this.numFramerates = 10;
|
|
||||||
this.framerateUpdateInterval = 500;
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
this.renderTime = -1;
|
|
||||||
this.framerates = [ ];
|
|
||||||
self = this;
|
|
||||||
var fr = function() { self.updateFramerate() }
|
|
||||||
setInterval(fr, this.framerateUpdateInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
Framerate.prototype.updateFramerate = function()
|
|
||||||
{
|
|
||||||
var tot = 0;
|
|
||||||
for (var i = 0; i < this.framerates.length; ++i)
|
|
||||||
tot += this.framerates[i];
|
|
||||||
|
|
||||||
var framerate = tot / this.framerates.length;
|
|
||||||
framerate = Math.round(framerate);
|
|
||||||
document.getElementById(this.id).innerHTML = "Framerate:"+framerate+"fps";
|
|
||||||
}
|
|
||||||
|
|
||||||
Framerate.prototype.snapshot = function()
|
|
||||||
{
|
|
||||||
if (this.renderTime < 0)
|
|
||||||
this.renderTime = new Date().getTime();
|
|
||||||
else {
|
|
||||||
var newTime = new Date().getTime();
|
|
||||||
var t = newTime - this.renderTime;
|
|
||||||
var framerate = 1000/t;
|
|
||||||
this.framerates.push(framerate);
|
|
||||||
while (this.framerates.length > this.numFramerates)
|
|
||||||
this.framerates.shift();
|
|
||||||
this.renderTime = newTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
attribute vec4 a_vertex;
|
attribute vec4 a_vertex;
|
||||||
attribute vec3 a_normal;
|
attribute vec3 a_normal;
|
||||||
|
|
||||||
|
// Workaround for non-compliant WebGL implementations (FIXME)
|
||||||
|
#if defined(GL_ES)
|
||||||
|
uniform mediump mat4 u_modelViewProjMatrix;
|
||||||
|
#else
|
||||||
uniform mat4 u_modelViewProjMatrix;
|
uniform mat4 u_modelViewProjMatrix;
|
||||||
|
#endif
|
||||||
|
|
||||||
varying vec3 v_normal;
|
varying vec3 v_normal;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ var log = function(msg) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var lastError = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last compiler/linker error.
|
||||||
|
* @return {string} The last compiler/linker error.
|
||||||
|
*/
|
||||||
|
var getLastError = function() {
|
||||||
|
return lastError;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A vertex shader for a single texture.
|
* A vertex shader for a single texture.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
@@ -32,6 +42,9 @@ var simpleTextureVertexShader = '' +
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
var simpleTextureFragmentShader = '' +
|
var simpleTextureFragmentShader = '' +
|
||||||
|
'#ifdef GL_ES\n' +
|
||||||
|
'precision mediump float;\n' +
|
||||||
|
'#endif\n' +
|
||||||
'uniform sampler2D tex;\n' +
|
'uniform sampler2D tex;\n' +
|
||||||
'varying vec2 texCoord;\n' +
|
'varying vec2 texCoord;\n' +
|
||||||
'void main() {\n' +
|
'void main() {\n' +
|
||||||
@@ -44,7 +57,7 @@ var simpleTextureFragmentShader = '' +
|
|||||||
* @return {!WebGLShader}
|
* @return {!WebGLShader}
|
||||||
*/
|
*/
|
||||||
var setupSimpleTextureVertexShader = function(gl) {
|
var setupSimpleTextureVertexShader = function(gl) {
|
||||||
return loadShader(gl, simpleTextureVertexShader, gl.VERTEX_SHADER, false);
|
return loadShader(gl, simpleTextureVertexShader, gl.VERTEX_SHADER);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +67,42 @@ var setupSimpleTextureVertexShader = function(gl) {
|
|||||||
*/
|
*/
|
||||||
var setupSimpleTextureFragmentShader = function(gl) {
|
var setupSimpleTextureFragmentShader = function(gl) {
|
||||||
return loadShader(
|
return loadShader(
|
||||||
gl, simpleTextureFragmentShader, gl.FRAGMENT_SHADER, false);
|
gl, simpleTextureFragmentShader, gl.FRAGMENT_SHADER);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a program, attaches shaders, binds attrib locations, links the
|
||||||
|
* program and calls useProgram.
|
||||||
|
* @param {!Array.<!WebGLShader>} shaders The shaders to attach .
|
||||||
|
* @param {!Array.<string>} attribs The attribs names.
|
||||||
|
* @param {!Array.<number>} opt_locations The locations for the attribs.
|
||||||
|
*/
|
||||||
|
var setupProgram = function(gl, shaders, attribs, opt_locations) {
|
||||||
|
var program = gl.createProgram();
|
||||||
|
for (var ii = 0; ii < shaders.length; ++ii) {
|
||||||
|
gl.attachShader(program, shaders[ii]);
|
||||||
|
}
|
||||||
|
for (var ii = 0; ii < attribs.length; ++ii) {
|
||||||
|
gl.bindAttribLocation(
|
||||||
|
program,
|
||||||
|
opt_locations ? opt_locations[ii] : ii,
|
||||||
|
attribs[ii]);
|
||||||
|
}
|
||||||
|
gl.linkProgram(program);
|
||||||
|
|
||||||
|
// Check the link status
|
||||||
|
var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
|
||||||
|
if (!linked) {
|
||||||
|
// something went wrong with the link
|
||||||
|
lastError = gl.getProgramInfoLog (program);
|
||||||
|
log("Error in program linking:" + lastError);
|
||||||
|
|
||||||
|
gl.deleteProgram(program);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.useProgram(program);
|
||||||
|
return program;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,28 +121,15 @@ var setupSimpleTextureProgram = function(
|
|||||||
if (!vs || !fs) {
|
if (!vs || !fs) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var program = gl.createProgram();
|
var program = setupProgram(
|
||||||
gl.attachShader(program, vs);
|
gl,
|
||||||
gl.attachShader(program, fs);
|
[vs, fs],
|
||||||
gl.bindAttribLocation(program, opt_positionLocation, 'vPosition');
|
['vPosition', 'texCoord0'],
|
||||||
gl.bindAttribLocation(program, opt_texcoordLocation, 'texCoord0');
|
[opt_positionLocation, opt_texcoordLocation]);
|
||||||
gl.linkProgram(program);
|
if (!program) {
|
||||||
|
gl.deleteShader(fs);
|
||||||
// Check the link status
|
gl.deleteShader(vs);
|
||||||
var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
|
|
||||||
if (!linked) {
|
|
||||||
// something went wrong with the link
|
|
||||||
var error = gl.getProgramInfoLog (program);
|
|
||||||
log("Error in program linking:"+error);
|
|
||||||
|
|
||||||
gl.deleteProgram(program);
|
|
||||||
gl.deleteProgram(fs);
|
|
||||||
gl.deleteProgram(vs);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.useProgram(program);
|
|
||||||
return program;
|
return program;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,26 +138,32 @@ var setupSimpleTextureProgram = function(
|
|||||||
* @param {!WebGLContext} gl The WebGLContext to use.
|
* @param {!WebGLContext} gl The WebGLContext to use.
|
||||||
* @param {number} opt_positionLocation The attrib location for position.
|
* @param {number} opt_positionLocation The attrib location for position.
|
||||||
* @param {number} opt_texcoordLocation The attrib location for texture coords.
|
* @param {number} opt_texcoordLocation The attrib location for texture coords.
|
||||||
|
* @return {!Array.<WebGLBuffer>} The buffer objects that were
|
||||||
|
* created.
|
||||||
*/
|
*/
|
||||||
var setupUnitQuad = function(gl, opt_positionLocation, opt_texcoordLocation) {
|
var setupUnitQuad = function(gl, opt_positionLocation, opt_texcoordLocation) {
|
||||||
opt_positionLocation = opt_positionLocation || 0;
|
opt_positionLocation = opt_positionLocation || 0;
|
||||||
opt_texcoordLocation = opt_texcoordLocation || 1;
|
opt_texcoordLocation = opt_texcoordLocation || 1;
|
||||||
|
var objects = [];
|
||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray(
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
|
||||||
[-1,1,0, 1,1,0, -1,-1,0,
|
[-1,1,0, 1,1,0, -1,-1,0,
|
||||||
-1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW);
|
-1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(opt_positionLocation);
|
gl.enableVertexAttribArray(opt_positionLocation);
|
||||||
gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0);
|
||||||
|
objects.push(vertexObject);
|
||||||
|
|
||||||
var vertexObject = gl.createBuffer();
|
var vertexObject = gl.createBuffer();
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray(
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
|
||||||
[0,0, 1,0, 0,1,
|
[0,0, 1,0, 0,1,
|
||||||
0,1, 1,0, 1,1]), gl.STATIC_DRAW);
|
0,1, 1,0, 1,1]), gl.STATIC_DRAW);
|
||||||
gl.enableVertexAttribArray(opt_texcoordLocation);
|
gl.enableVertexAttribArray(opt_texcoordLocation);
|
||||||
gl.vertexAttribPointer(opt_texcoordLocation, 2, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(opt_texcoordLocation, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
objects.push(vertexObject);
|
||||||
|
return objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +200,8 @@ var fillTexture = function(gl, tex, width, height, color, opt_level) {
|
|||||||
ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")";
|
ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")";
|
||||||
ctx2d.fillRect(0, 0, width, height);
|
ctx2d.fillRect(0, 0, width, height);
|
||||||
gl.bindTexture(gl.TEXTURE_2D, tex);
|
gl.bindTexture(gl.TEXTURE_2D, tex);
|
||||||
gl.texImage2D(gl.TEXTURE_2D, opt_level, canvas);
|
gl.texImage2D(
|
||||||
|
gl.TEXTURE_2D, opt_level, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,7 +247,8 @@ var drawQuad = function(gl, opt_color) {
|
|||||||
var checkCanvas = function(gl, color, msg) {
|
var checkCanvas = function(gl, color, msg) {
|
||||||
var width = gl.canvas.width;
|
var width = gl.canvas.width;
|
||||||
var height = gl.canvas.height;
|
var height = gl.canvas.height;
|
||||||
var buf = gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE);
|
var buf = new Uint8Array(width * height * 4);
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
|
||||||
for (var i = 0; i < width * height; ++i) {
|
for (var i = 0; i < width * height; ++i) {
|
||||||
var offset = i * 4;
|
var offset = i * 4;
|
||||||
if (buf[offset + 0] != color[0] ||
|
if (buf[offset + 0] != color[0] ||
|
||||||
@@ -346,13 +389,17 @@ var shouldGenerateGLError = function(gl, glError, evalStr) {
|
|||||||
* Tests that the first error GL returns is the specified error.
|
* Tests that the first error GL returns is the specified error.
|
||||||
* @param {!WebGLContext} gl The WebGLContext to use.
|
* @param {!WebGLContext} gl The WebGLContext to use.
|
||||||
* @param {number} glError The expected gl error.
|
* @param {number} glError The expected gl error.
|
||||||
|
* @param {string} opt_msg
|
||||||
*/
|
*/
|
||||||
var glErrorShouldBe = function(gl, glError) {
|
var glErrorShouldBe = function(gl, glError, opt_msg) {
|
||||||
|
opt_msg = opt_msg || "";
|
||||||
var err = gl.getError();
|
var err = gl.getError();
|
||||||
if (err != glError) {
|
if (err != glError) {
|
||||||
testFailed("getError expected: " + getGLErrorAsString(gl, glError) + ". Was " + getGLErrorAsString(gl, err) + ".");
|
testFailed("getError expected: " + getGLErrorAsString(gl, glError) +
|
||||||
|
". Was " + getGLErrorAsString(gl, err) + " : " + opt_msg);
|
||||||
} else {
|
} else {
|
||||||
testPassed("getError was expected value: " + getGLErrorAsString(gl, glError) + ".");
|
testPassed("getError was expected value: " +
|
||||||
|
getGLErrorAsString(gl, glError) + " : " + opt_msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -436,17 +483,46 @@ var setupWebGLWithShaders = function(
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets shader source from a file/URL
|
* Gets a file from a file/URL
|
||||||
* @param {string} file the URL of the file to get.
|
* @param {string} file the URL of the file to get.
|
||||||
* @return {string} The contents of the file.
|
* @return {string} The contents of the file.
|
||||||
*/
|
*/
|
||||||
var getShaderSource = function(file) {
|
var readFile = function(file) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", file, false);
|
xhr.open("GET", file, false);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
return xhr.responseText;
|
return xhr.responseText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a file from a URL and parses it for filenames. IF a file name ends
|
||||||
|
* in .txt recursively reads that file and adds it to the list.
|
||||||
|
*/
|
||||||
|
var readFileList = function(url) {
|
||||||
|
var files = [];
|
||||||
|
if (url.substr(url.length - 4) == '.txt') {
|
||||||
|
var lines = readFile(url).split('\n');
|
||||||
|
var prefix = '';
|
||||||
|
var lastSlash = url.lastIndexOf('/');
|
||||||
|
if (lastSlash >= 0) {
|
||||||
|
prefix = url.substr(0, lastSlash + 1);
|
||||||
|
}
|
||||||
|
for (var ii = 0; ii < lines.length; ++ii) {
|
||||||
|
var str = lines[ii].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||||
|
if (str.length > 4 &&
|
||||||
|
str[0] != '#' &&
|
||||||
|
str[0] != ";" &&
|
||||||
|
str.substr(0, 2) != "//") {
|
||||||
|
new_url = prefix + str;
|
||||||
|
files = files.concat(readFileList(new_url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
files.push(url);
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a shader.
|
* Loads a shader.
|
||||||
* @param {!WebGLContext} gl The WebGLContext to use.
|
* @param {!WebGLContext} gl The WebGLContext to use.
|
||||||
@@ -472,8 +548,8 @@ var loadShader = function(gl, shaderSource, shaderType) {
|
|||||||
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
||||||
if (!compiled) {
|
if (!compiled) {
|
||||||
// Something went wrong during compilation; get the error
|
// Something went wrong during compilation; get the error
|
||||||
var error = gl.getShaderInfoLog(shader);
|
lastError = gl.getShaderInfoLog(shader);
|
||||||
log("*** Error compiling shader '"+shader+"':"+error);
|
log("*** Error compiling shader '" + shader + "':" + lastError);
|
||||||
gl.deleteShader(shader);
|
gl.deleteShader(shader);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -489,7 +565,7 @@ var loadShader = function(gl, shaderSource, shaderType) {
|
|||||||
* @return {!WebGLShader} The created shader.
|
* @return {!WebGLShader} The created shader.
|
||||||
*/
|
*/
|
||||||
var loadShaderFromFile = function(gl, file, type) {
|
var loadShaderFromFile = function(gl, file, type) {
|
||||||
var shaderSource = getShaderSource(file);
|
var shaderSource = readFile(file);
|
||||||
return loadShader(gl, shaderSource, type);
|
return loadShader(gl, shaderSource, type);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -503,21 +579,22 @@ var loadShaderFromFile = function(gl, file, type) {
|
|||||||
*/
|
*/
|
||||||
var loadShaderFromScript = function(gl, scriptId, opt_shaderType) {
|
var loadShaderFromScript = function(gl, scriptId, opt_shaderType) {
|
||||||
var shaderSource = "";
|
var shaderSource = "";
|
||||||
|
var shaderType;
|
||||||
var shaderScript = document.getElementById(scriptId);
|
var shaderScript = document.getElementById(scriptId);
|
||||||
if (!shaderScript) {
|
if (!shaderScript) {
|
||||||
throw("*** Error: unknown script element" + scriptId);
|
throw("*** Error: unknown script element" + scriptId);
|
||||||
} else if (!opt_shaderType) {
|
}
|
||||||
|
shaderSource = shaderScript.text;
|
||||||
|
|
||||||
|
if (!opt_shaderType) {
|
||||||
if (shaderScript.type == "x-shader/x-vertex") {
|
if (shaderScript.type == "x-shader/x-vertex") {
|
||||||
opt_shaderType = gl.VERTEX_SHADER;
|
shaderType = gl.VERTEX_SHADER;
|
||||||
} else if (shaderScript.type == "x-shader/x-fragment") {
|
} else if (shaderScript.type == "x-shader/x-fragment") {
|
||||||
opt_shaderType = gl.FRAGMENT_SHADER;
|
shaderType = gl.FRAGMENT_SHADER;
|
||||||
} else if (shaderType != gl.VERTEX_SHADER && shaderType != gl.FRAGMENT_SHADER) {
|
} else if (shaderType != gl.VERTEX_SHADER && shaderType != gl.FRAGMENT_SHADER) {
|
||||||
throw("*** Error: unknown shader type");
|
throw("*** Error: unknown shader type");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderSource = shaderScript.text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadShader(
|
return loadShader(
|
||||||
@@ -580,10 +657,52 @@ var loadStandardVertexShader = function(gl) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var loadStandardFragmentShader = function(gl) {
|
var loadStandardFragmentShader = function(gl) {
|
||||||
return loadShaderFromfile(
|
return loadShaderFromFile(
|
||||||
gl, "resources/fragmentShader.frag", gl.FRAGMENT_SHADER);
|
gl, "resources/fragmentShader.frag", gl.FRAGMENT_SHADER);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an image asynchronously.
|
||||||
|
* @param {string} url URL of image to load.
|
||||||
|
* @param {!function(!Element): void} callback Function to call
|
||||||
|
* with loaded image.
|
||||||
|
*/
|
||||||
|
var loadImageAsync = function(url, callback) {
|
||||||
|
var img = document.createElement('img');
|
||||||
|
img.onload = function() {
|
||||||
|
callback(img);
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an array of images.
|
||||||
|
* @param {!Array.<string>} urls URLs of images to load.
|
||||||
|
* @param {!function(!{string, img}): void} callback. Callback
|
||||||
|
* that gets passed map of urls to img tags.
|
||||||
|
*/
|
||||||
|
var loadImagesAsync = function(urls, callback) {
|
||||||
|
var count = 1;
|
||||||
|
var images = { };
|
||||||
|
function countDown() {
|
||||||
|
--count;
|
||||||
|
if (count == 0) {
|
||||||
|
callback(images);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function imageLoaded(url) {
|
||||||
|
return function(img) {
|
||||||
|
images[url] = img;
|
||||||
|
countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var ii = 0; ii < urls.length; ++ii) {
|
||||||
|
++count;
|
||||||
|
loadImageAsync(urls[ii], imageLoaded(urls[ii]));
|
||||||
|
}
|
||||||
|
countDown();
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create3DContext: create3DContext,
|
create3DContext: create3DContext,
|
||||||
create3DContextWithWrapperThatThrowsOnGLError:
|
create3DContextWithWrapperThatThrowsOnGLError:
|
||||||
@@ -591,8 +710,11 @@ return {
|
|||||||
checkCanvas: checkCanvas,
|
checkCanvas: checkCanvas,
|
||||||
createColoredTexture: createColoredTexture,
|
createColoredTexture: createColoredTexture,
|
||||||
drawQuad: drawQuad,
|
drawQuad: drawQuad,
|
||||||
|
getLastError: getLastError,
|
||||||
glErrorShouldBe: glErrorShouldBe,
|
glErrorShouldBe: glErrorShouldBe,
|
||||||
fillTexture: fillTexture,
|
fillTexture: fillTexture,
|
||||||
|
loadImageAsync: loadImageAsync,
|
||||||
|
loadImagesAsync: loadImagesAsync,
|
||||||
loadProgramFromFile: loadProgramFromFile,
|
loadProgramFromFile: loadProgramFromFile,
|
||||||
loadProgramFromScript: loadProgramFromScript,
|
loadProgramFromScript: loadProgramFromScript,
|
||||||
loadShader: loadShader,
|
loadShader: loadShader,
|
||||||
@@ -601,12 +723,15 @@ return {
|
|||||||
loadStandardProgram: loadStandardProgram,
|
loadStandardProgram: loadStandardProgram,
|
||||||
loadStandardVertexShader: loadStandardVertexShader,
|
loadStandardVertexShader: loadStandardVertexShader,
|
||||||
loadStandardFragmentShader: loadStandardFragmentShader,
|
loadStandardFragmentShader: loadStandardFragmentShader,
|
||||||
|
setupProgram: setupProgram,
|
||||||
setupSimpleTextureFragmentShader: setupSimpleTextureFragmentShader,
|
setupSimpleTextureFragmentShader: setupSimpleTextureFragmentShader,
|
||||||
setupSimpleTextureProgram: setupSimpleTextureProgram,
|
setupSimpleTextureProgram: setupSimpleTextureProgram,
|
||||||
setupSimpleTextureVertexShader: setupSimpleTextureVertexShader,
|
setupSimpleTextureVertexShader: setupSimpleTextureVertexShader,
|
||||||
setupTexturedQuad: setupTexturedQuad,
|
setupTexturedQuad: setupTexturedQuad,
|
||||||
setupUnitQuad: setupUnitQuad,
|
setupUnitQuad: setupUnitQuad,
|
||||||
shouldGenerateGLError: shouldGenerateGLError,
|
shouldGenerateGLError: shouldGenerateGLError,
|
||||||
|
readFile: readFile,
|
||||||
|
readFileList: readFileList,
|
||||||
|
|
||||||
none: false
|
none: false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,24 +36,24 @@ function webglTestLog(msg) {
|
|||||||
//
|
//
|
||||||
// create3DContext
|
// create3DContext
|
||||||
//
|
//
|
||||||
// Return the WebGLRenderingContext for any known implementation
|
// Returns the WebGLRenderingContext for any known implementation.
|
||||||
//
|
//
|
||||||
function create3DContext(canvas)
|
function create3DContext(canvas, attributes)
|
||||||
{
|
{
|
||||||
if (!canvas)
|
if (!canvas)
|
||||||
canvas = document.createElement("canvas");
|
canvas = document.createElement("canvas");
|
||||||
var context = null;
|
var context = null;
|
||||||
try {
|
try {
|
||||||
context = canvas.getContext("experimental-webgl");
|
context = canvas.getContext("experimental-webgl", attributes);
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
if (!context) {
|
if (!context) {
|
||||||
try {
|
try {
|
||||||
context = canvas.getContext("webkit-3d");
|
context = canvas.getContext("webkit-3d", attributes);
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
if (!context) {
|
if (!context) {
|
||||||
try {
|
try {
|
||||||
context = canvas.getContext("moz-webgl");
|
context = canvas.getContext("moz-webgl", attributes);
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
if (!context) {
|
if (!context) {
|
||||||
@@ -72,8 +72,8 @@ function createGLErrorWrapper(context, fname) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function create3DContextWithWrapperThatThrowsOnGLError(canvas) {
|
function create3DContextWithWrapperThatThrowsOnGLError(canvas, attributes) {
|
||||||
var context = create3DContext(canvas);
|
var context = create3DContext(canvas, attributes);
|
||||||
// Thanks to Ilmari Heikkinen for the idea on how to implement this so elegantly.
|
// Thanks to Ilmari Heikkinen for the idea on how to implement this so elegantly.
|
||||||
var wrap = {};
|
var wrap = {};
|
||||||
for (var i in context) {
|
for (var i in context) {
|
||||||
@@ -98,7 +98,6 @@ function getGLErrorAsString(ctx, err) {
|
|||||||
return "NO_ERROR";
|
return "NO_ERROR";
|
||||||
}
|
}
|
||||||
for (var name in ctx) {
|
for (var name in ctx) {
|
||||||
if (name == "canvas") continue;
|
|
||||||
if (ctx[name] === err) {
|
if (ctx[name] === err) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -120,19 +119,28 @@ function shouldGenerateGLError(ctx, glError, evalStr) {
|
|||||||
if (err != glError) {
|
if (err != glError) {
|
||||||
testFailed(evalStr + " expected: " + getGLErrorAsString(ctx, glError) + ". Was " + getGLErrorAsString(ctx, err) + ".");
|
testFailed(evalStr + " expected: " + getGLErrorAsString(ctx, glError) + ". Was " + getGLErrorAsString(ctx, err) + ".");
|
||||||
} else {
|
} else {
|
||||||
testPassed(evalStr + " was expected value: " + getGLErrorAsString(ctx, glError) + ".");
|
testPassed(evalStr + " generated expected GL error: " + getGLErrorAsString(ctx, glError) + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function glErrorShouldBe(ctx, glError) {
|
/**
|
||||||
var err = ctx.getError();
|
* Tests that the first error GL returns is the specified error.
|
||||||
|
* @param {!WebGLContext} gl The WebGLContext to use.
|
||||||
|
* @param {number} glError The expected gl error.
|
||||||
|
* @param {string} opt_msg Optional additional message.
|
||||||
|
*/
|
||||||
|
function glErrorShouldBe(gl, glError, opt_msg) {
|
||||||
|
opt_msg = opt_msg || "";
|
||||||
|
var err = gl.getError();
|
||||||
if (err != glError) {
|
if (err != glError) {
|
||||||
testFailed("getError expected: " + getGLErrorAsString(ctx, glError) + ". Was " + getGLErrorAsString(ctx, err) + ".");
|
testFailed("getError expected: " + getGLErrorAsString(gl, glError) +
|
||||||
|
". Was " + getGLErrorAsString(gl, err) + " : " + opt_msg);
|
||||||
} else {
|
} else {
|
||||||
testPassed("getError was expected value: " + getGLErrorAsString(ctx, glError) + ".");
|
testPassed("getError was expected value: " +
|
||||||
|
getGLErrorAsString(gl, glError) + " : " + opt_msg);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// createProgram
|
// createProgram
|
||||||
@@ -209,10 +217,10 @@ function createProgram(gl, vshaders, fshaders, attribs)
|
|||||||
// Set the clear color to the passed array (4 values) and set the clear depth to the passed value.
|
// Set the clear color to the passed array (4 values) and set the clear depth to the passed value.
|
||||||
// Enable depth testing and blending with a blend func of (SRC_ALPHA, ONE_MINUS_SRC_ALPHA)
|
// Enable depth testing and blending with a blend func of (SRC_ALPHA, ONE_MINUS_SRC_ALPHA)
|
||||||
//
|
//
|
||||||
function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth)
|
function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth, contextAttribs)
|
||||||
{
|
{
|
||||||
var canvas = document.getElementById(canvasName);
|
var canvas = document.getElementById(canvasName);
|
||||||
var gl = create3DContext(canvas);
|
var gl = create3DContext(canvas, contextAttribs);
|
||||||
if (!gl) {
|
if (!gl) {
|
||||||
alert("No WebGL context found");
|
alert("No WebGL context found");
|
||||||
return null;
|
return null;
|
||||||
@@ -366,7 +374,7 @@ function makeBox(ctx)
|
|||||||
// v2------v3
|
// v2------v3
|
||||||
//
|
//
|
||||||
// vertex coords array
|
// vertex coords array
|
||||||
var vertices = new WebGLFloatArray(
|
var vertices = new Float32Array(
|
||||||
[ 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 front
|
[ 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 front
|
||||||
1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v5 right
|
1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v5 right
|
||||||
1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v1 top
|
1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v1 top
|
||||||
@@ -376,7 +384,7 @@ function makeBox(ctx)
|
|||||||
);
|
);
|
||||||
|
|
||||||
// normal array
|
// normal array
|
||||||
var normals = new WebGLFloatArray(
|
var normals = new Float32Array(
|
||||||
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
|
[ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
|
||||||
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
|
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
|
||||||
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
|
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
|
||||||
@@ -387,7 +395,7 @@ function makeBox(ctx)
|
|||||||
|
|
||||||
|
|
||||||
// texCoord array
|
// texCoord array
|
||||||
var texCoords = new WebGLFloatArray(
|
var texCoords = new Float32Array(
|
||||||
[ 1, 1, 0, 1, 0, 0, 1, 0, // v0-v1-v2-v3 front
|
[ 1, 1, 0, 1, 0, 0, 1, 0, // v0-v1-v2-v3 front
|
||||||
0, 1, 0, 0, 1, 0, 1, 1, // v0-v3-v4-v5 right
|
0, 1, 0, 0, 1, 0, 1, 1, // v0-v3-v4-v5 right
|
||||||
1, 0, 1, 1, 0, 1, 0, 0, // v0-v5-v6-v1 top
|
1, 0, 1, 1, 0, 1, 0, 0, // v0-v5-v6-v1 top
|
||||||
@@ -397,7 +405,7 @@ function makeBox(ctx)
|
|||||||
);
|
);
|
||||||
|
|
||||||
// index array
|
// index array
|
||||||
var indices = new WebGLUnsignedByteArray(
|
var indices = new Uint8Array(
|
||||||
[ 0, 1, 2, 0, 2, 3, // front
|
[ 0, 1, 2, 0, 2, 3, // front
|
||||||
4, 5, 6, 4, 6, 7, // right
|
4, 5, 6, 4, 6, 7, // right
|
||||||
8, 9,10, 8,10,11, // top
|
8, 9,10, 8,10,11, // top
|
||||||
@@ -497,20 +505,20 @@ function makeSphere(ctx, radius, lats, longs)
|
|||||||
|
|
||||||
retval.normalObject = ctx.createBuffer();
|
retval.normalObject = ctx.createBuffer();
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject);
|
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject);
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(normalData), ctx.STATIC_DRAW);
|
ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(normalData), ctx.STATIC_DRAW);
|
||||||
|
|
||||||
retval.texCoordObject = ctx.createBuffer();
|
retval.texCoordObject = ctx.createBuffer();
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject);
|
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject);
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(texCoordData), ctx.STATIC_DRAW);
|
ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(texCoordData), ctx.STATIC_DRAW);
|
||||||
|
|
||||||
retval.vertexObject = ctx.createBuffer();
|
retval.vertexObject = ctx.createBuffer();
|
||||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject);
|
ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject);
|
||||||
ctx.bufferData(ctx.ARRAY_BUFFER, new WebGLFloatArray(geometryData), ctx.STATIC_DRAW);
|
ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(geometryData), ctx.STATIC_DRAW);
|
||||||
|
|
||||||
retval.numIndices = indexData.length;
|
retval.numIndices = indexData.length;
|
||||||
retval.indexObject = ctx.createBuffer();
|
retval.indexObject = ctx.createBuffer();
|
||||||
ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject);
|
ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject);
|
||||||
ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray(indexData), ctx.STREAM_DRAW);
|
ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), ctx.STREAM_DRAW);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -663,20 +671,20 @@ function doLoadObj(obj, text)
|
|||||||
// set the VBOs
|
// set the VBOs
|
||||||
obj.normalObject = obj.ctx.createBuffer();
|
obj.normalObject = obj.ctx.createBuffer();
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.normalObject);
|
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.normalObject);
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(normalArray), obj.ctx.STATIC_DRAW);
|
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(normalArray), obj.ctx.STATIC_DRAW);
|
||||||
|
|
||||||
obj.texCoordObject = obj.ctx.createBuffer();
|
obj.texCoordObject = obj.ctx.createBuffer();
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.texCoordObject);
|
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.texCoordObject);
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(textureArray), obj.ctx.STATIC_DRAW);
|
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(textureArray), obj.ctx.STATIC_DRAW);
|
||||||
|
|
||||||
obj.vertexObject = obj.ctx.createBuffer();
|
obj.vertexObject = obj.ctx.createBuffer();
|
||||||
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.vertexObject);
|
obj.ctx.bindBuffer(obj.ctx.ARRAY_BUFFER, obj.vertexObject);
|
||||||
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new WebGLFloatArray(vertexArray), obj.ctx.STATIC_DRAW);
|
obj.ctx.bufferData(obj.ctx.ARRAY_BUFFER, new Float32Array(vertexArray), obj.ctx.STATIC_DRAW);
|
||||||
|
|
||||||
obj.numIndices = indexArray.length;
|
obj.numIndices = indexArray.length;
|
||||||
obj.indexObject = obj.ctx.createBuffer();
|
obj.indexObject = obj.ctx.createBuffer();
|
||||||
obj.ctx.bindBuffer(obj.ctx.ELEMENT_ARRAY_BUFFER, obj.indexObject);
|
obj.ctx.bindBuffer(obj.ctx.ELEMENT_ARRAY_BUFFER, obj.indexObject);
|
||||||
obj.ctx.bufferData(obj.ctx.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray(indexArray), obj.ctx.STREAM_DRAW);
|
obj.ctx.bufferData(obj.ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexArray), obj.ctx.STREAM_DRAW);
|
||||||
|
|
||||||
obj.loaded = true;
|
obj.loaded = true;
|
||||||
}
|
}
|
||||||
@@ -699,7 +707,7 @@ function doLoadImageTexture(ctx, image, texture)
|
|||||||
{
|
{
|
||||||
ctx.enable(ctx.TEXTURE_2D);
|
ctx.enable(ctx.TEXTURE_2D);
|
||||||
ctx.bindTexture(ctx.TEXTURE_2D, texture);
|
ctx.bindTexture(ctx.TEXTURE_2D, texture);
|
||||||
ctx.texImage2D(ctx.TEXTURE_2D, 0, image);
|
ctx.texImage2D(ctx.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MAG_FILTER, ctx.LINEAR);
|
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MAG_FILTER, ctx.LINEAR);
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MIN_FILTER, ctx.LINEAR_MIPMAP_LINEAR);
|
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_MIN_FILTER, ctx.LINEAR_MIPMAP_LINEAR);
|
||||||
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.CLAMP_TO_EDGE);
|
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.CLAMP_TO_EDGE);
|
||||||
|
|||||||
BIN
content/canvas/test/webgl/conformance/resources/zero-alpha.png
Executable file
|
After Width: | Height: | Size: 89 B |
@@ -0,0 +1,65 @@
|
|||||||
|
add_int_float.vert
|
||||||
|
add_int_mat2.vert
|
||||||
|
add_int_mat3.vert
|
||||||
|
add_int_mat4.vert
|
||||||
|
add_int_vec2.vert
|
||||||
|
add_int_vec3.vert
|
||||||
|
add_int_vec4.vert
|
||||||
|
add_ivec2_vec2.vert
|
||||||
|
add_ivec3_vec3.vert
|
||||||
|
add_ivec4_vec4.vert
|
||||||
|
assign_int_to_float.vert
|
||||||
|
assign_ivec2_to_vec2.vert
|
||||||
|
assign_ivec3_to_vec3.vert
|
||||||
|
assign_ivec4_to_vec4.vert
|
||||||
|
construct_struct.vert
|
||||||
|
divide_int_float.vert
|
||||||
|
divide_int_mat2.vert
|
||||||
|
divide_int_mat3.vert
|
||||||
|
divide_int_mat4.vert
|
||||||
|
divide_int_vec2.vert
|
||||||
|
divide_int_vec3.vert
|
||||||
|
divide_int_vec4.vert
|
||||||
|
divide_ivec2_vec2.vert
|
||||||
|
divide_ivec3_vec3.vert
|
||||||
|
divide_ivec4_vec4.vert
|
||||||
|
equal_int_float.vert
|
||||||
|
equal_ivec2_vec2.vert
|
||||||
|
equal_ivec3_vec3.vert
|
||||||
|
equal_ivec4_vec4.vert
|
||||||
|
function_int_float.vert
|
||||||
|
function_ivec2_vec2.vert
|
||||||
|
function_ivec3_vec3.vert
|
||||||
|
function_ivec4_vec4.vert
|
||||||
|
greater_than.vert
|
||||||
|
greater_than_equal.vert
|
||||||
|
less_than.vert
|
||||||
|
less_than_equal.vert
|
||||||
|
multiply_int_float.vert
|
||||||
|
multiply_int_mat2.vert
|
||||||
|
multiply_int_mat3.vert
|
||||||
|
multiply_int_mat4.vert
|
||||||
|
multiply_int_vec2.vert
|
||||||
|
multiply_int_vec3.vert
|
||||||
|
multiply_int_vec4.vert
|
||||||
|
multiply_ivec2_vec2.vert
|
||||||
|
multiply_ivec3_vec3.vert
|
||||||
|
multiply_ivec4_vec4.vert
|
||||||
|
not_equal_int_float.vert
|
||||||
|
not_equal_ivec2_vec2.vert
|
||||||
|
not_equal_ivec3_vec3.vert
|
||||||
|
not_equal_ivec4_vec4.vert
|
||||||
|
subtract_int_float.vert
|
||||||
|
subtract_int_mat2.vert
|
||||||
|
subtract_int_mat3.vert
|
||||||
|
subtract_int_mat4.vert
|
||||||
|
subtract_int_vec2.vert
|
||||||
|
subtract_int_vec3.vert
|
||||||
|
subtract_int_vec4.vert
|
||||||
|
subtract_ivec2_vec2.vert
|
||||||
|
subtract_ivec3_vec3.vert
|
||||||
|
subtract_ivec4_vec4.vert
|
||||||
|
ternary_int_float.vert
|
||||||
|
ternary_ivec2_vec2.vert
|
||||||
|
ternary_ivec3_vec3.vert
|
||||||
|
ternary_ivec4_vec4.vert
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = 1.0 + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
mat2 f = mat2(1.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
mat3 f = mat3(1.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
mat4 f = mat4(1.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 f = vec2(1.0, 2.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 f = vec3(1.0, 2.0, 3.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 f = vec4(1.0, 2.0, 3.0, 4.0) + 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 f = vec2(1.0, 2.0) + ivec2(1, 2);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 f = vec3(1.0, 2.0, 3.0) + ivec3(1, 2, 3);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 f = vec4(1.0, 2.0, 3.0, 4.0) + ivec4(1, 2, 3, 4);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = -123;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 f = ivec2(1, 2);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 f = ivec3(1, 2, 3);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 f = ivec4(1, 2, 3, 4);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
struct Foo {
|
||||||
|
float bar;
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Foo foo = Foo(1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = 1.0 / 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
void main()
|
||||||
|
{
|
||||||
|
mat2 f = mat2(1.0) / 1;
|
||||||
|
}
|
||||||