Move Khronos WebGL tests to /_webgl/

This commit is contained in:
Anthony Ramine 2018-08-25 00:46:42 +02:00
parent d827370804
commit 4852f7d616
7200 changed files with 53650 additions and 228616 deletions

View file

@ -481,7 +481,7 @@ def check_manifest_dirs(config_file, print_text=True):
p = parser.parse(lines) p = parser.parse(lines)
paths = rec_parse(wpt_path("web-platform-tests"), p) paths = rec_parse(wpt_path("web-platform-tests"), p)
for idx, path in enumerate(paths): for idx, path in enumerate(paths):
if path.endswith("_mozilla"): if path.endswith("_mozilla") or path.endswith("_webgl"):
continue continue
if not os.path.isdir(path): if not os.path.isdir(path):
yield(config_file, idx + 1, "Path in manifest was not found: {}".format(path)) yield(config_file, idx + 1, "Path in manifest was not found: {}".format(path))

View file

@ -60,7 +60,9 @@ files = [
"./tests/wpt/metadata/MANIFEST.json", "./tests/wpt/metadata/MANIFEST.json",
"./support/android/openssl.sh", "./support/android/openssl.sh",
# Upstream code from Khronos/WebGL uses tabs for indentation # Upstream code from Khronos/WebGL uses tabs for indentation
"./tests/wpt/mozilla/tests/webgl", "./tests/wpt/webgl/tests",
# Our import script is not currently respecting the lint.
"./tests/wpt/webgl/tools/import-conformance-tests.py",
# Ignore those files since the issues reported are on purpose # Ignore those files since the issues reported are on purpose
"./tests/html/bad-line-ends.html", "./tests/html/bad-line-ends.html",
"./tests/wpt/mozilla/tests/css/fonts", "./tests/wpt/mozilla/tests/css/fonts",

View file

@ -1,2 +1,3 @@
/,./ /,./
/_mozilla/,../mozilla/tests /_mozilla/,../mozilla/tests
/_webgl/,../webgl/tests

View file

@ -20,3 +20,8 @@ url-base = /
tests = mozilla/tests tests = mozilla/tests
metadata = mozilla/meta metadata = mozilla/meta
url_base = /_mozilla/ url_base = /_mozilla/
[manifest:webgl]
tests = webgl/tests
metadata = webgl/meta
url_base = /_webgl/

View file

@ -1,6 +1,8 @@
skip: true skip: true
[_mozilla] [_mozilla]
skip: false skip: false
[_webgl]
skip: false
[2dcontext] [2dcontext]
skip: false skip: false
[cors] [cors]

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
disabled: for now

View file

@ -1,6 +0,0 @@
// files that end in .txt list other tests
// other lines are assumed to be .html files
conformance/00_test_list.txt
conformance/more/00_test_list.txt

View file

@ -1,132 +0,0 @@
Rules for Claiming a Conformant WebGL Implementation
====================================================
The WebGL API is a web standard, and many web browser implementers
deliver their browser on multiple operating systems (OSs). WebGL
implementations also typically rely on the presence of an OpenGL or
OpenGL ES implementation on the OS. It can be appreciated that a WebGL
implementation therefore has many dependencies. This document attempts
to clarify to potential implementers the rules the Khronos Group uses
to judge whether a particular WebGL implementation is conformant.
There are two primary reasons to submit conformance results:
A) A web browser implementer desires to certify their WebGL
implementation as conformant.
B) A GPU manufacturer delivering an embedded system including web
browser with WebGL support desires to certify their WebGL
implementation as conformant.
Each of these situations carries different constraints, so the
conformance rules are phrased differently for each. Typically, a web
browser implementer aims to certify that the WebGL "layer" is correct.
A GPU vendor typically aims to certify that a given device is
physically capable of passing the tests.
A newly-developed WebGL implementation should not support the "webgl"
HTML Canvas context type by default in a shipping version of the
product until reaching conformance. It is acceptable to give end users
an option to turn on WebGL support in a non-conformant implementation
as long as the documentation for that option clearly indicates that
the implementation is not yet conformant and may have compatibility
issues. It is suggested that the Canvas context type
"experimental-webgl" may be supported by default in such
implementations.
A WebGL implementation might reach conformance, but a subsequent
graphics driver release on a particular OS might introduce a
regression causing failures of one or more of the WebGL conformance
tests. In this situation it is not required to revoke support for the
"webgl" HTML Canvas context type. The WebGL implementer should work
with the GPU vendor to ensure the driver regression is fixed. A
situation like this would, however, prevent the WebGL implementer from
conforming to a subsequent version of the test suite.
(A) Conformance Rules for a Web Browser Implementer
===================================================
1. Conformance on a particular operating system
On a given OS, a WebGL implementation will be considered to conform to
a particular version of the conformance suite if the suite passes with
no test failures on at least two GPUs, each from a different
vendor. If the OS only supports a GPU from one vendor, the two-GPU
requirement is dropped.
2. Conformance across multiple operating systems
A WebGL implementation will be considered to conform to a particular
version of the conformance suite if it passes rule (1) on all of the
OSs on which the WebGL implementation is intended to be supported.
3. Conformance as the web browser is upgraded
WebGL conformance results submitted for an earlier version of the
browser carry forward to later versions of the browser, unless the
WebGL implementation changes substantially enough that it is expected
that conformance may have been affected. In that case, the browser
implementer should submit new conformance results.
4. Conformance as the operating system is upgraded
If a new version is released of one of the OSs on which a WebGL
implementation is intended to run, then WebGL conformance results
submitted for earlier versions of that OS carry forward. Future
conformance results must be submitted against the new version of the
OS. If it is anticipated that the older OS version will be supported
for some time, then future conformance results must be submitted
separately for both the old and new versions of the OS.
(B) Conformance Rules for a GPU Vendor
======================================
A GPU vendor submitting conformance results for a WebGL implementation
typically does so because the device containing the GPU includes a
built-in web browser. In this case the following rules apply:
1. Conformance results must be submitted for each GPU and operating
system combination to be certified. It is not required to submit
results for different devices containing the same GPU and running the
same operating system.
2. Conformance results may be submitted up to three months in advance
of the product reaching initial shipment.
3. Conformance results carry forward for a given GPU as the operating
system and graphics driver are upgraded, unless there is an
expectation that conformance may have been affected. In that case, the
GPU vendor should submit new conformance results.
Discussion
==========
A WebGL implementation intended to ship on three OSs may reach
conformance on two of them, but due to graphics driver bugs, may be
unable to reach conformance on the third. In this situation the
implementation is not yet considered to be conformant.
An existing WebGL implementation which conformed to an earlier version
of the test suite is not required to remove support for the "webgl"
HTML Canvas context type while in the process of conforming to a later
version of the test suite. However, the implementer must not advertise
conformance to the later version until it has been reached. It is
acceptable for the implementer to advertise details of their
conformance, for example number or percentage of passing or failing
tests, or names of passing or failing tests.
A GPU vendor might submit conformance results in order to use the
WebGL logo in a marketing campaign. In this situation, results may be
submitted in advance of the product becoming available through sales
channels, per the rules above.
The WebGL API has strict security requirements. Even one failing test
may indicate a serious security issue in the WebGL implementation. For
this reason, no exceptions for failing conformance tests will be
granted.
The Khronos Group determines whether a particular WebGL implementation
is conformant based on the implementer's conformance suite
submissions, on multiple OSs and on multiple GPUs as necessary, using
the rules above. An implementer shall not judge their own
implementation conformant simply by applying the above rules.

View file

@ -1,77 +0,0 @@
Welcome to the WebGL Conformance Test Suite
===========================================
Note: Before adding a new test or editing an existing test
[please read these guidelines](test-guidelines.md).
This is the WebGL conformance test suite. You can find a the current "live"
version at [https://www.khronos.org/registry/webgl/sdk/tests/webgl-conformance-tests.html](https://www.khronos.org/registry/webgl/sdk/tests/webgl-conformance-tests.html)
NOTE TO USERS: Unless you are a WebGL implementor, there is no need to submit
a conformance result using this process. Should you discover bugs in your
browser's WebGL implementation, either via this test suite or otherwise,
please report them through your browser vendor's bug tracking system.
FOR WEBGL IMPLEMENTORS: Please follow the instructions below to create
a formal conformance submission.
1. Open webgl-conformance-tests.html in your target browser
2. Press the "run tests" button
3. At the end of the run, press "display text summary"
4. Verify that the User Agent and WebGL renderer strings identify your browser and target correctly.
5. Copy the contents of the text summary (starting with "WebGL Conformance Test Results") and send via email to
webgl_conformance_submissions@khronos.org
Please see CONFORMANCE_RULES.txt in this directory for guidelines
about what constitutes a conformant WebGL implementation.
Usage Notes:
------------
There are various URL options you can pass in.
run: Set to 1 to start the tests automatically
Example: webgl-conformance-tests.html?run=1
version: Set to the version of the harness you wish to run. Tests
at this version or below will be run
Example: webgl-conformance-tests.html?version=1.3.2
minVersion: Set to the minimum version of each test to include. Only tests
at this version or above will be included.
Example: webgl-conformance-tests.html?minVersion=1.3.2
fast: Only run tests not marked with --slow
Example: webgl-conformance-tests.html?fast=true
skip: Comma separated list of regular expressions of which tests to skip.
Example: webgl-conformance-tests.html?skip=glsl,.*destruction\.html
include: Comma separated list of regular expressions of which tests to include.
Example: webgl-conformance-tests.html?include=glsl,.*destruction\.html
frames: The number of iframes to use to run tests in parallel.
Example: webgl-conformance-tests.html?frames=8
Note the tests are not required to run with anything other than frames = 1.
History
-------
- 2011/02/24: Version 1.0.0
- 2012/02/23: Version 1.0.1
- 2012/03/20: Version 1.0.2
- 2013/02/14: Version 1.0.3
- 2013/10/11: Version 2.0.0 (beta)

View file

@ -1,173 +0,0 @@
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
// This block needs to be outside the onload handler in order for this
// test to run reliably in WebKit's test harness (at least the
// Chromium port). https://bugs.webkit.org/show_bug.cgi?id=87448
initTestingHarness();
var old = debug;
var debug = function(msg) {
console.log(msg);
old(msg);
};
function generateTest(pixelFormat, pixelType, prologue) {
var wtu = WebGLTestUtils;
var gl = null;
var textureLoc = null;
var successfullyParsed = false;
// Test each format separately because many browsers implement each
// differently. Some might be GPU accelerated, some might not. Etc...
var videos = [
{ src: "../conformance/resources/red-green.mp4" , type: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', },
{ src: "../conformance/resources/red-green.webmvp8.webm", type: 'video/webm; codecs="vp8, vorbis"', },
{ src: "../conformance/resources/red-green.theora.ogv", type: 'video/ogg; codecs="theora, vorbis"', },
];
var videoNdx = 0;
var video;
function runNextVideo() {
if (video) {
video.pause();
}
if (videoNdx == videos.length) {
finishTest();
return;
}
var info = videos[videoNdx++];
debug("");
debug("testing: " + info.type);
video = document.createElement("video");
var canPlay = true;
if (!video.canPlayType) {
testFailed("video.canPlayType required method missing");
runNextVideo();
return;
}
if(!video.canPlayType(info.type).replace(/no/, '')) {
debug(info.type + " unsupported");
runNextVideo();
return;
};
document.body.appendChild(video);
video.type = info.type;
video.crossOrigin = 'anonymous';
video.src = info.src;
wtu.startPlayingAndWaitForVideo(video, runTest);
}
var init = function()
{
description('Verify texImage2D and texSubImage2D code paths taking video elements (' + pixelFormat + '/' + pixelType + ')');
gl = wtu.create3DContext("example");
if (!prologue(gl)) {
finishTest();
return;
}
var program = wtu.setupTexturedQuad(gl);
gl.clearColor(0,0,0,1);
gl.clearDepth(1);
textureLoc = gl.getUniformLocation(program, "tex");
runNextVideo();
}
function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bottomColor)
{
debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
' with flipY=' + flipY);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// Disable any writes to the alpha channel
gl.colorMask(1, 1, 1, 0);
var texture = gl.createTexture();
// Bind the texture to texture unit 0
gl.bindTexture(gl.TEXTURE_2D, texture);
// Set up texture parameters
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_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);
// Set up pixel store parameters
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
// Upload the videoElement into the texture
if (useTexSubImage2D) {
// Initialize the texture to black first
gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat],
videoElement.videoWidth, videoElement.videoHeight, 0,
gl[pixelFormat], gl[pixelType], null);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelType], videoElement);
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl[pixelType], videoElement);
}
var c = document.createElement("canvas");
c.width = 16;
c.height = 16;
c.style.border = "1px solid black";
var ctx = c.getContext("2d");
ctx.drawImage(videoElement, 0, 0, 16, 16);
document.body.appendChild(c);
// Point the uniform sampler to texture unit 0
gl.uniform1i(textureLoc, 0);
// Draw the triangles
wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);
// Check a few pixels near the top and bottom and make sure they have
// the right color.
var tolerance = 5;
debug("Checking lower left corner");
wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
"shouldBe " + bottomColor, tolerance);
debug("Checking upper left corner");
wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
"shouldBe " + topColor, tolerance);
}
function runTest(videoElement)
{
var red = [255, 0, 0];
var green = [0, 255, 0];
runOneIteration(videoElement, false, true, red, green);
runOneIteration(videoElement, false, false, green, red);
runOneIteration(videoElement, true, true, red, green);
runOneIteration(videoElement, true, false, green, red);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
runNextVideo();
}
return init;
}

View file

@ -1,12 +0,0 @@
.pass {
font-weight: bold;
color: green;
}
.fail {
font-weight: bold;
color: red;
}
#console {
white-space: pre-wrap;
font-family: monospace;
}

View file

@ -1,174 +0,0 @@
Contributing WebGL conformance tests Guidelines
===============================================
Thank you for contributing to the WebGL conformance tests.
Please try to follow these guidelines when submitting a test.
* If you're new to git [here's a terse set of instructions](http://www.khronos.org/webgl/wiki/Using_Github_To_Contribute "Using Github to Contribute").
* All changes and/or new tests should go in the sdk/tests/conformance folder
The tests under conformance-suites are snapshots and are only to be updated by
the WebGL Working Group when "official" snapshots are taken.
* Please use the Khronos Group License (MIT)
These lines appears at the top of every html and js file under sdk/tests/conformance
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
* Please use code similar to the code in existing tests
Ideally, copy an existing test and modify it for your new test. Try not to duplicate
code that already exists where appropriate. In particular
* use the functions in WebGLTestUtils rather than duplicating functionality.
In particular, as much as possible, keep the WebGL code in your test specific
to the issue being tested and try to use the helper functions to handle
common setup.
Examples:
* to create a WebGL context call `WebGLTestUtils.create3DContext`. Passed nothing
it will create an offscreen canvas. Passed a canvas element it will create
a context on that element. Passed a string it will look up the canvas element
with the matching id and create a context from that element.
* use `WebGLTestUtils.checkCanvas` or `WebGLTestUtils.checkCanvasRect` rather
than checking rendering results by hand.
* use the various quad and draw functions
* `WebGLTestUtils.setupUnitQuad` and `WebGLTestUtils.clearAndDrawUnitQuad` for
simple drawing.
* `WebGLTestUtils.setupColorQuad`, `WebGLTestUtils.drawFloatColorQuad`, and
`WebGLTestUilts.drawUByteColorQuad` for drawing in a particular color.
* `WebGLTestUtils.setupIndexedQuad` and `WebGLTestUtils.clearAndDrawIndexedQuad`
if you need a higher subdivision of vertices and/or vertex colors.
* use `WebgLTestUtils.setupTexturedQuad` if you need a unit quad with texture coords.
By default the positions will be at location 0 and the texture coords at location 1.
* If you need a custom shader use `WebGLTestUtils.setupProgram`. Note that it takes
the following arguments. `gl`, `shaders`, `opt_attribs`, `opt_locations` where:
`gl` is the WebGL context.
`shaders` are an array of either script element ids, shader source, or WebGLShader
objects. The first element in the array is the vertex shader, the second the fragment
shader.
`opt_attribs` is an optional array of attribute names. If provided the named attributes
will have their locations bound to their index in this array.
`opt_locations` is an optional array of attribute locations. If provided each attribute
name in `opt_attribs` is bound to the corresponding location in `opt_locations`.
* If you need to wait for a composite call `WebGLTestUtils.waitForComposite`.
As compositing is a browser specific thing this provides a central place to
update all tests that rely on compositing to function.
* Code/Tag Order
Most tests run inline. They don't use window.onload or the load event. This works by placing
the script tag inside the body, *after* the canvas and required divs.
<canvas id="example"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
var wtu = WebGLDebugUtils;
var gl = wtu.create3DContext("example");
...
* Ending Tests
* Tests that are short and run synchronously end with
<script src="../../resources/js-test-post.js"></script>
* Tests that take a long time use setTimeout so as not to freeze the browser.
Many browsers will terminate JavaScript that takes more than a few seconds to execute
without returning control to the browser. The workaround is code like this
var numTests = 10;
var currenTest = 0;
function runNextTest() {
if (currentTest == numTests) {
finishTest(); // Tells the harness you're done.
return;
}
// Run your test.
...
++currentTest;
setTimeout(runNextTest, 100);
}
runNextTest();
Remember the tests need to run without timing out even and slow mobile devices.
The harness resets the timeout timer every time a test reports success or failure
so as long as some part of your test calls `testPassed` or `testFailed` or one of the
many wrappers (`shouldXXX`, `glErrorShouldBe`, `WebGLTestUtils.checkCanvasXXX`, etc..)
every so often the harness will not timeout your test.
* The test harness requires the global variable `successfullyParse` to be set to true.
This usually appears at the end of a file.
var successfullyParsed = true;
* Do not use browser specific code.
* Do not check the browser version. Use feature detection.
* If you do need feature detection consider putting it into WebGLTestUtils so that
other tests can go through the same abstraction and the workaround is isolated
to one place.
* Vendors may place test harness specific code in the testing infrastructure.
resources/js-test-pre.js
conformance/more/unit.js
* Indent with spaces not tabs. (not everyone uses your tab settings).
* All HTML files must have a `<!DOCTYPE html>`
* All HTML files must have a `<meta charset="utf-8">`
* All JavaScript must start with "use strict";
* If adding a new test edit the appropriate 00_test_list.txt file
Each folder has a 00_test_list.txt file that lists the test in that folder.
Each new test should be prefixed with the option `--min-version <version>` where
version is 1 more than the newest official version. At the time of this writing
all new tests should be prefixed with `--min-version 1.0.2`

View file

@ -1,13 +0,0 @@
This file "00_test_list.txt" lists which files the test harness should run.
If you add new tests you can update it with
on windows
dir /b *.html >00_test_list.txt
on OSX / Linux
ls -1 *.html >00_test_list.txt

View file

@ -1,18 +0,0 @@
attribs/00_test_list.txt
buffers/00_test_list.txt
canvas/00_test_list.txt
context/00_test_list.txt
extensions/00_test_list.txt
glsl/00_test_list.txt
limits/00_test_list.txt
misc/00_test_list.txt
--min-version 1.0.2 ogles/00_test_list.txt
programs/00_test_list.txt
reading/00_test_list.txt
renderbuffers/00_test_list.txt
rendering/00_test_list.txt
state/00_test_list.txt
textures/00_test_list.txt
typedarrays/00_test_list.txt
uniforms/00_test_list.txt

View file

@ -1,11 +0,0 @@
--min-version 1.0.3 gl-bindAttribLocation-aliasing.html
--min-version 1.0.3 gl-bindAttribLocation-matrix.html
--min-version 1.0.4 gl-bindAttribLocation-repeated.html
--min-version 1.0.2 gl-disabled-vertex-attrib.html
gl-enable-vertex-attrib.html
--min-version 1.0.3 gl-matrix-attributes.html
--max-version 1.9.9 gl-vertex-attrib.html
gl-vertexattribpointer.html
gl-vertexattribpointer-offsets.html
--min-version 1.0.2 gl-vertex-attrib-render.html
gl-vertex-attrib-zero-issues.html

View file

@ -1,92 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<title>bindAttribLocation with aliasing</title>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>
<script id="vertexShader" type="text/something-not-javascript">
precision mediump float;
attribute $(type_1) a_1;
attribute $(type_2) a_2;
void main() {
gl_Position = $(gl_Position_1) + $(gl_Position_2);
}
</script>
<script>
"use strict";
description("This test verifies combinations of valid, active attribute types cannot be bound to the same location with bindAttribLocation.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, {antialias: false});
var glFragmentShader = wtu.loadShader(gl, wtu.simpleColorFragmentShader, gl.FRAGMENT_SHADER);
var typeInfo = [
{ type: 'float', asVec4: 'vec4(0.0, $(var), 0.0, 1.0)' },
{ type: 'vec2', asVec4: 'vec4($(var), 0.0, 1.0)' },
{ type: 'vec3', asVec4: 'vec4($(var), 1.0)' },
{ type: 'vec4', asVec4: '$(var)' },
];
var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
// Test all type combinations of a_1 and a_2.
typeInfo.forEach(function(typeInfo1) {
typeInfo.forEach(function(typeInfo2) {
debug('attribute_1: ' + typeInfo1.type + ' attribute_2: ' + typeInfo2.type);
var replaceParams = {
type_1: typeInfo1.type,
type_2: typeInfo2.type,
gl_Position_1: wtu.replaceParams(typeInfo1.asVec4, {var: 'a_1'}),
gl_Position_2: wtu.replaceParams(typeInfo2.asVec4, {var: 'a_2'})
};
var strVertexShader = wtu.replaceParams(wtu.getScript('vertexShader'), replaceParams);
var glVertexShader = wtu.loadShader(gl, strVertexShader, gl.VERTEX_SHADER);
assertMsg(glVertexShader != null, "Vertex shader compiled successfully.");
// Bind both a_1 and a_2 to the same position and verify the link fails.
// Do so for all valid positions available.
for (var l = 0; l < maxAttributes; l++) {
var glProgram = gl.createProgram();
gl.bindAttribLocation(glProgram, l, 'a_1');
gl.bindAttribLocation(glProgram, l, 'a_2');
gl.attachShader(glProgram, glVertexShader);
gl.attachShader(glProgram, glFragmentShader);
gl.linkProgram(glProgram);
assertMsg(!gl.getProgramParameter(glProgram, gl.LINK_STATUS), "Link should fail when both types are aliased to location " + l);
}
});
});
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,121 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<title>WebGL bindAttribLocation with Matrix Attributes Conformance Test</title>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>
<script>
"use strict";
description("This test verifies that vectors placed via bindAttribLocation right after matricies will fail if there is insufficient room for the matrix.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, {antialias: false});
// Make sure we have room for at least a mat4.
var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
debug('MAX_VERTEX_ATTRIBUTES is ' + maxAttributes);
shouldBeGreaterThanOrEqual('maxAttributes', '4');
var glFragmentShader = wtu.loadShader(gl, wtu.simpleColorFragmentShader, gl.FRAGMENT_SHADER);
// Given a matrix dimension, load a vertex shader with a matrix of that dimension
// and a vector. Ensure that both the vector and matrix are active attributes.
// Return the compiled vertex shader.
function loadVertexShader(numMatrixDimensions) {
var strVertexShader =
'attribute mat' + numMatrixDimensions + ' matrix;\n' +
'attribute vec' + numMatrixDimensions + ' vector;\n' +
'void main(void) { gl_Position = vec4(vector*matrix';
// Ensure the vec4 has the correct number of dimensions in order to be assignable
// to gl_Position.
for (var ii = numMatrixDimensions; ii < 4; ++ii) {
strVertexShader += ",0.0";
}
strVertexShader += ");}\n";
return wtu.loadShader(gl, strVertexShader, gl.VERTEX_SHADER);
}
// Given a vertex shader, matrix location and vector location, create and link
// a program with glFragmentShader and a vertex shader returned by loadVertexShader
// attached. Bind the matrix to matrixLocation and the vector to vectorLocation.
// Return whether the link was successful.
function createAndLinkProgram(glVertexShader, matrixLocation, vectorLocation) {
var glProgram = gl.createProgram();
gl.bindAttribLocation(glProgram, matrixLocation, 'matrix');
gl.bindAttribLocation(glProgram, vectorLocation, 'vector');
gl.attachShader(glProgram, glVertexShader);
gl.attachShader(glProgram, glFragmentShader);
gl.linkProgram(glProgram);
return gl.getProgramParameter(glProgram, gl.LINK_STATUS);
}
// For each matrix dimension (mat2, mat3 and mat4)
for (var mm = 2; mm <= 4; ++mm) {
debug('Testing ' + mm + ' dimensional matrices');
var glVertexShader = loadVertexShader(mm);
// Per the WebGL spec: "LinkProgram will fail if the attribute bindings assigned
// by bindAttribLocation do not leave enough space to assign a location for an
// active matrix attribute which requires multiple contiguous generic attributes."
// We will test this by placing the vector after the matrix attribute such that there
// is not enough room for the matrix. Vertify the link operation fails.
// Run the test for each available attribute slot. Go to maxAttributes-mm to leave enough room
// for the matrix itself. Leave another slot open for the vector following the matrix.
for (var pp = 0; pp <= maxAttributes - mm - 1; ++pp) {
// For each matrix dimension, bind the vector right after the matrix such that we leave
// insufficient room for the matrix. Verify doing this will fail the link operation.
for (var ll = 0; ll < mm; ++ll) {
var vectorLocation = pp + ll;
assertMsg(!createAndLinkProgram(glVertexShader, /*matrixLocation*/pp, vectorLocation),
"Matrix with location " + pp + " and vector with location " + vectorLocation + " should not link.");
}
// Ensure that once we have left enough room for the matrix, the program links successfully.
var vectorLocation = pp + ll;
assertMsg(createAndLinkProgram(glVertexShader, /*matrixLocation*/pp, vectorLocation),
"Matrix with location " + pp + " and vector with location " + vectorLocation + " should link.");
debug('');
}
debug('');
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,102 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Disabled Vertex Attrib Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="50" height="50">
</canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
bool isCorrectColor(vec4 v) {
return v.x == 0.0 && v.y == 0.0 && v.z == 0.0 && v.w == 1.0;
}
void main() {
gl_Position = a_position;
v_color = isCorrectColor(a_color) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}
</script>
<script>
"use strict";
var wtu = WebGLTestUtils;
description();
var gl = wtu.create3DContext("example");
var numVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
for (var ii = 0; ii < numVertexAttribs; ++ii) {
var colorLocation = (ii + 1) % numVertexAttribs;
var positionLocation = colorLocation ? 0 : 1;
if (positionLocation != 0) {
// We need to create a new 3d context for testing attrib 0
// since we've already effected attrib 0 on other tests.
gl = wtu.create3DContext();
}
debug("testing attrib: " + colorLocation);
var program = wtu.setupProgram(
gl,
['vshader', 'fshader'],
['a_position', 'a_color'],
[positionLocation, colorLocation]);
var gridRes = 1;
wtu.setupIndexedQuad(gl, gridRes, positionLocation);
wtu.clearAndDrawIndexedQuad(gl, gridRes);
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,84 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Enable Vertex Attrib Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="50" height="50">
</canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script>
"use strict";
description("tests that turning on attribs that have no buffer bound fails to draw");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
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.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(3);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
gl.drawArrays(gl.TRIANGLES, 0, 3);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,159 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<title>WebGL Matrix Attribute Conformance Test</title>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>
<script>
"use strict";
description("This tests ensures that matrix attribute locations do not clash with other shader attributes.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, {antialias: false});
// Make sure we have room for at least a mat4.
var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
debug('MAX_VERTEX_ATTRIBUTES is ' + maxAttributes);
shouldBeGreaterThanOrEqual('maxAttributes', '4');
var glFragmentShader = wtu.loadShader(gl, wtu.simpleColorFragmentShader, gl.FRAGMENT_SHADER);
// prepareMatrixProgram creates a program with glFragmentShader as the fragment shader.
// The vertex shader has numVector number of vectors and a matrix with numMatrixDimensions
// dimensions at location numMatrixPosition in the list of attributes.
// Ensures that every vector and matrix is used by the program.
// Returns a valid program on successfull link; null on link failure.
function prepareMatrixProgram(numVectors, numMatrixDimensions, numMatrixPosition) {
// Add the matrix and vector attribute declarations. Declare the vectors
// to have the same number of components as the matrix so we can perform
// operations on them when we assign to gl_Position later on.
var strVertexShader = "";
for (var ii = 1; ii <= numVectors; ++ii) {
if (numMatrixPosition === ii) {
strVertexShader += "attribute mat" + numMatrixDimensions + " matrix;\n";
}
strVertexShader += "attribute vec" + numMatrixDimensions + " vec_" + ii + ";\n";
}
// numMatrixPosition will be one past numVectors if the caller wants it to be
// last. Hence, we need this check outside the loop as well as inside.
if (numMatrixPosition === ii) {
strVertexShader += "attribute mat" + numMatrixDimensions + " matrix;\n";
}
// Add the body of the shader. Add up all of the vectors and multiply by the matrix.
// The operations we perform do not matter. We just need to ensure that all the vector and
// matrix attributes are used.
strVertexShader += "void main(void) { \ngl_Position = vec4((";
for (var ii = 1; ii <= numVectors; ++ii) {
if (ii > 1) {
strVertexShader += "+"
}
strVertexShader += "vec_" + ii;
}
strVertexShader += ")*matrix";
// Ensure the vec4 has the correct number of dimensions in order to be assignable
// to gl_Position.
for (var ii = numMatrixDimensions; ii < 4; ++ii) {
strVertexShader += ",0.0";
}
strVertexShader += ");}\n";
// Load the shader, attach it to a program, and return the link results
var glVertexShader = wtu.loadShader(gl, strVertexShader, gl.VERTEX_SHADER);
var strTest = 'Load shader with ' + numVectors + ' vectors and 1 matrix';
if (glVertexShader !== null) {
testPassed(strTest);
var glProgram = gl.createProgram();
gl.attachShader(glProgram, glVertexShader);
gl.attachShader(glProgram, glFragmentShader);
gl.linkProgram(glProgram);
if (gl.getProgramParameter(glProgram, gl.LINK_STATUS)) {
wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'linkProgram');
return glProgram;
}
} else {
testFailed(strTest);
}
return null;
}
debug('');
// Test mat2, mat3 and mat4.
for (var mm = 2; mm <= 4; ++mm) {
// Add maxAttribute number of attributes by saving enough room in the attribute
// list for a matrix of mm dimensions. All of the other attribute slots will be
// filled with vectors.
var numVectors = maxAttributes - mm;
for (var pp = 1; pp <= numVectors + 1; ++pp) {
debug('Test ' + mm + ' dimensional matrix at position ' + pp);
var glProgram = prepareMatrixProgram(numVectors, /*numMatrixDimensions*/mm, /*numMatrixPosition*/pp);
shouldBeNonNull('glProgram');
var attribMatrix = gl.getAttribLocation(glProgram, 'matrix');
debug('Matrix is at attribute location ' + attribMatrix);
shouldBeTrue('attribMatrix > -1');
// Per the spec, when an attribute is a matrix attribute, getAttribLocation
// returns the index of the first component of the matrix. The implementation must
// leave sufficient room for all the components. Here we ensure none of the vectors
// in the shader are assigned attribute locations that belong to the matrix.
for (var vv = 1; vv <= numVectors; ++vv) {
var strVector = 'vec_' + vv
var attribVector = gl.getAttribLocation(glProgram, strVector);
debug(strVector + ' is at attribute location ' + attribVector);
// Begin with the first attribute location where the matrix begins and ensure
// the vector's attribute location is not assigned to the matrix. Loop until
// we've checked all of the attribute locations that belong to the matrix.
for (var ii = attribMatrix; ii < attribMatrix + mm; ++ii) {
var testStr = strVector + ' attribute location: ' + attribVector + '. Should not be ' + ii;
if (attribVector !== ii) {
testPassed(testStr);
} else {
testFailed(testStr);
}
}
}
debug('');
}
debug('');
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,112 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script id='vshader' type='x-shader'>
attribute vec4 a;
attribute vec2 p;
void main() {
gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y, 0.0, 1.0);
}
</script>
<script id='fshader' type='x-shader'>
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
</script>
<script>
"use strict";
function checkRedPortion(gl, w, low, high) {
var buf = new Uint8Array(w * w * 4);
gl.readPixels(0, 0, w, w, gl.RGBA, gl.UNSIGNED_BYTE, buf);
var i = 0;
for (; i < w; ++i) {
if (buf[i * 4 + 0] == 255 && buf[i * 4 + 1] == 0 && buf[i * 4 + 2] == 0 && buf[i * 4 + 3] == 255) {
break;
}
}
return low <= i && i <= high;
}
function runTest() {
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext('testbed', { preserveDrawingBuffer : true });
if (!gl) {
testFailed('could not create context');
return;
}
var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['p', 'a'])
gl.enableVertexAttribArray(gl.p);
var pos = gl.createBuffer();
pos.type = gl.FLOAT;
pos.size = 2;
pos.num = 4;
gl.bindBuffer(gl.ARRAY_BUFFER, pos);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, pos.size, pos.type, false, 0, 0);
debug('Test vertexAttrib[1..4]fv by setting different combinations that add up to 1.5 and use that when rendering.');
var vals = [[0.5], [0.1,0.4], [0.2,-0.2,0.5], [-1.0,0.3,0.2,2.0]];
for (var j = 0; j < 4; ++j) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl['vertexAttrib' + (j+1) + 'fv'](1, vals[j]);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, pos.num);
if (checkRedPortion(gl, 50, 50 * 0.7, 50 * 0.8)) {
testPassed('Attribute of size ' + (j+1) + ' was set correctly');
} else {
testFailed('Attribute of size ' + (j+1) + ' was not set correctly');
}
}
}
</script>
</head>
<body>
<canvas id="testbed" width="50" height="50"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verify that using constant attributes works.');
runTest();
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,154 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Enable Vertex Attrib Zero Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="50" height="50">
</canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
}
</script>
<script>
"use strict";
description("Test some of the issues of the difference between attrib 0 on OpenGL vs WebGL");
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var g_program;
var g_attribLocation;
function setup(attribIndex) {
var program = wtu.setupProgram(
gl, ['vshader', 'fshader'], ['vPosition'], [attribIndex]);
g_program = program;
g_attribLocation = attribIndex;
shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')");
return program;
}
function setupVerts(numVerts) {
var verts = [
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 positions = new Float32Array(numVerts * 3);
var indices = new Uint16Array(numVerts);
for (var ii = 0; ii < numVerts; ++ii) {
var ndx = ii % 6;
var dst = ii * 3;
var src = ndx * 3;
for (var jj = 0; jj < 3; ++jj) {
positions[dst + jj] = verts[src + jj];
}
indices[ii] = ii;
}
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
}
var p0 = setup(0);
var p3 = setup(3);
setupVerts(60000);
for (var ii = 0; ii < 5; ++ii) {
// test drawing with attrib 0
gl.useProgram(p0);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawElements(gl.TRIANGLES, 60000, gl.UNSIGNED_SHORT, 0);
wtu.glErrorShouldBe(
gl, gl.NO_ERROR,
"drawing using attrib 0 with 6 verts");
wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
gl.disableVertexAttribArray(0);
// test drawing without attrib 0
gl.useProgram(p3);
gl.enableVertexAttribArray(3);
gl.vertexAttribPointer(3, 3, gl.FLOAT, false, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 60000);
wtu.glErrorShouldBe(
gl, gl.NO_ERROR,
"drawing using attrib 3 with 60000 verts");
wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
gl.disableVertexAttribArray(3);
// This second test of drawing without attrib0 unconvered a bug in chrome
// where after the draw without attrib0 the attrib 0 emulation code disabled
// attrib 0 and it was never re-enabled so this next draw failed.
gl.useProgram(p3);
gl.enableVertexAttribArray(3);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawElements(gl.TRIANGLES, 60000, gl.UNSIGNED_SHORT, 0);
wtu.glErrorShouldBe(
gl, gl.NO_ERROR,
"drawing using attrib 3 with 60000 verts");
wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
gl.disableVertexAttribArray(3);
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,51 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL vertexAttrib Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
var contextVersion = 1;
</script>
<script src="../../js/tests/gl-vertex-attrib.js"></script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,183 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vertexattribpointer offsets test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="50" height="50">
There is supposed to be an example drawing here, but it's not important.
</canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
</script>
<script>
"use strict";
function init()
{
description("test vertexattribpointer offsets work");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
var tests = [
{ data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.FLOAT,
componentSize: 4,
normalize: false,
},
{ data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.FLOAT,
componentSize: 4,
normalize: false,
},
{ data: new Uint16Array([ 0, 32767, 0, 32767, 0, 0, 0, 0, 0 ]),
type: gl.SHORT,
componentSize: 2,
normalize: true,
},
{ data: new Uint16Array([ 0, 65535, 0, 65535, 0, 0, 0, 0, 0 ]),
type: gl.UNSIGNED_SHORT,
componentSize: 2,
normalize: true,
},
{ data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.UNSIGNED_SHORT,
componentSize: 2,
normalize: false,
},
{ data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.SHORT,
componentSize: 2,
normalize: false,
},
{ data: new Uint8Array([ 0, 127, 0, 127, 0, 0, 0, 0, 0 ]),
type: gl.BYTE,
componentSize: 1,
normalize: true,
},
{ data: new Uint8Array([ 0, 255, 0, 255, 0, 0, 0, 0, 0 ]),
type: gl.UNSIGNED_BYTE,
componentSize: 1,
normalize: true,
},
{ data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.BYTE,
componentSize: 1,
normalize: false,
},
{ data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.UNSIGNED_BYTE,
componentSize: 1,
normalize: false,
}
];
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
var colorLoc = gl.getUniformLocation(program, "color");
var kNumVerts = 3;
var kNumComponents = 3;
var count = 0;
for (var tt = 0; tt < tests.length; ++tt) {
var test = tests[tt];
for (var oo = 0; oo < 3; ++oo) {
for (var ss = 0; ss < 3; ++ss) {
var offset = (oo + 1) * test.componentSize;
var color = (count % 2) ? [1, 0, 0, 1] : [0, 1, 0, 1];
var stride = test.componentSize * kNumComponents + test.componentSize * ss;
debug("");
debug("check with " + wtu.glEnumToString(gl, test.type) + " at offset: " + offset + " with stride:" + stride + " normalize: " + test.normalize);
gl.uniform4fv(colorLoc, color);
var data = new Uint8Array(test.componentSize * kNumVerts * kNumComponents + stride * (kNumVerts - 1));
var view = new Uint8Array(test.data.buffer);
var size = test.componentSize * kNumComponents;
for (var jj = 0; jj < kNumVerts; ++jj) {
var off1 = jj * size;
var off2 = jj * stride;
for (var zz = 0; zz < size; ++zz) {
data[off2 + zz] = view[off1 + zz];
}
}
gl.bufferSubData(gl.ARRAY_BUFFER, offset, data);
gl.vertexAttribPointer(0, 3, test.type, test.normalize, stride, offset);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 3);
var buf = new Uint8Array(50 * 50 * 4);
gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
var black = [0, 0, 0, 0];
var other = [color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255];
var otherMsg = "should be " + ((count % 2) ? "red" : "green")
wtu.checkCanvasRect(gl, 0, 0, 1, 1, black, "should be black", 0);
wtu.checkCanvasRect(gl, 0, 49, 1, 1, black, "should be black", 0);
wtu.checkCanvasRect(gl, 26, 40, 1, 1, other, otherMsg, 0);
wtu.checkCanvasRect(gl, 26, 27, 1, 1, other, otherMsg, 0);
wtu.checkCanvasRect(gl, 40, 27, 1, 1, other, otherMsg, 0);
++count;
}
}
}
}
init();
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,180 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL vertexAttribPointer Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
"use strict";
description("This test checks vertexAttribPointer behaviors in WebGL.");
debug("");
debug("Canvas.getContext");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking gl.vertexAttribPointer.");
if (!gl.FIXED) {
gl.FIXED = 0x140C;
}
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(0), gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 4);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
"vertexAttribPointer should fail if no buffer is bound and `offset` is non-zero.");
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
//gl.bindBuffer(gl.ARRAY_BUFFER, null);
//gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0);
//wtu.glErrorShouldBe(gl, gl.NO_ERROR,
// "vertexAttribPointer should succeed if no buffer is bound and `offset` is zero.");
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
if (wtu.getDefault3DContextVersion() < 2) {
gl.vertexAttribPointer(0, 1, gl.INT, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support INT");
gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support UNSIGNED_INT");
gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support FIXED");
}
var checkVertexAttribPointer = function(
gl, err, reason, size, type, normalize, stride, offset) {
gl.vertexAttribPointer(0, size, type, normalize, stride, offset);
var succeeded = (err == gl.NO_ERROR);
wtu.glErrorShouldBe(gl, err,
"gl.vertexAttribPointer(0, " + size +
", gl." + wtu.glEnumToString(gl, type) +
", " + normalize +
", " + stride +
", " + offset +
") should " + (succeeded ? "succeed " : "fail ") + reason);
if (succeeded) {
shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE)', size.toString());
shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.' + wtu.glEnumToString(gl, type));
shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', normalize.toString());
shouldBe('gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', stride.toString());
shouldBe('gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER)', offset.toString());
}
}
var types = [
{ type:gl.BYTE, bytesPerComponent: 1 },
{ type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 },
{ type:gl.SHORT, bytesPerComponent: 2 },
{ type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 },
{ type:gl.FLOAT, bytesPerComponent: 4 },
];
for (var ii = 0; ii < types.length; ++ii) {
var info = types[ii];
debug("");
for (var size = 1; size <= 4; ++size) {
debug("");
debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + size);
var bytesPerElement = size * info.bytesPerComponent;
var offsetSet = [
0,
1,
info.bytesPerComponent - 1,
info.bytesPerComponent,
info.bytesPerComponent + 1,
info.bytesPerComponent * 2];
for (var jj = 0; jj < offsetSet.length; ++jj) {
var offset = offsetSet[jj];
for (var kk = 0; kk < offsetSet.length; ++kk) {
var stride = offsetSet[kk];
var err = gl.NO_ERROR;
var reason = ""
if (offset % info.bytesPerComponent != 0) {
reason = "because offset is bad";
err = gl.INVALID_OPERATION;
}
if (stride % info.bytesPerComponent != 0) {
reason = "because stride is bad";
err = gl.INVALID_OPERATION;
}
checkVertexAttribPointer(
gl, err, reason, size, info.type, false, stride, offset);
}
var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent;
if (offset == 0) {
checkVertexAttribPointer(
gl, gl.NO_ERROR, "at stride limit",
size, info.type, false, stride, offset);
checkVertexAttribPointer(
gl, gl.INVALID_VALUE, "over stride limit",
size, info.type, false,
stride + info.bytesPerComponent, offset);
}
}
}
}
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,12 +0,0 @@
buffer-bind-test.html
buffer-data-and-buffer-sub-data.html
--min-version 1.0.3 buffer-data-array-buffer-delete.html
--min-version 1.0.4 buffer-uninitialized.html
--min-version 1.0.2 element-array-buffer-delete-recreate.html
index-validation-copies-indices.html
index-validation-crash-with-buffer-sub-data.html
--min-version 1.0.2 index-validation-large-buffer.html
index-validation-verifies-too-many-indices.html
index-validation-with-resized-buffer.html
index-validation.html

View file

@ -1,89 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL BindBuffer conformance test.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/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>
"use strict";
description("Checks a buffer can only be bound to 1 target.");
debug("");
debug("Canvas.getContext");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
var buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
wtu.glErrorShouldBe(gl, gl.NO_ERROR,
"should be able to bind array buffer.");
gl.bindBuffer(gl.ARRAY_BUFFER, null);
wtu.glErrorShouldBe(gl, gl.NO_ERROR,
"should be able to unbind array buffer.");
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buf);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
"should get INVALID_OPERATION if attempting to bind array buffer to different target");
var buf = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buf);
wtu.glErrorShouldBe(gl, gl.NO_ERROR,
"should be able to bind element array buffer.");
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
wtu.glErrorShouldBe(gl, gl.NO_ERROR,
"should be able to unbind element array buffer.");
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
"should get INVALID_OPERATION if attempting to bind element array buffer to different target");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,82 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Test ARRAY_BUFFER deletion when a vertex attrib array with location != 0 is pointing to it and preserveDrawingBuffer is true.");
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.addEventListener(
"webglcontextlost",
function(event) {
testFailed("Context lost");
event.preventDefault();
},
false);
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext(canvas, {preserveDrawingBuffer: true});
shouldBeNonNull("gl");
var array = new Float32Array([0]);
var buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
var attribLocation = 1;
gl.enableVertexAttribArray(attribLocation);
gl.vertexAttribPointer(attribLocation, 1, gl.FLOAT, false, 0, 0);
gl.deleteBuffer(buf);
setTimeout(function() {
// Wait for possible context loss
finishTest();
}, 2000);
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,92 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Element Array Buffer Deletion and Recreation Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
var wtu = WebGLTestUtils;
function init()
{
description();
// Clear the background with red.
var gl = wtu.create3DContext("example");
wtu.setupSimpleColorProgram(gl);
var color = [0, 255, 0, 255];
wtu.setUByteDrawColor(gl, color);
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
-1, -1,
1, -1,
-1, 1,
1, 1
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
// Create an element array buffer.
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([0, 1, 2, 3]), gl.STATIC_DRAW);
// Delete the element array buffer.
gl.deleteBuffer(indexBuffer);
// Create a new element array buffer.
indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([0, 1, 2, 3]), gl.STATIC_DRAW);
// Draw with the new element array buffer.
// If the geometry is drawn successfully, the fragment shader will color it green.
gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from draw");
wtu.checkCanvas(gl, color, "should be green")
}
init();
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,77 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
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.')
var wtu = WebGLTestUtils;
var context = wtu.create3DContext();
var program = wtu.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();
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
var indices = new Uint16Array([ 10000, 0, 1, 2, 3, 10000 ]);
context.bufferData(context.ELEMENT_ARRAY_BUFFER, indices, context.STATIC_DRAW);
wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
var indexValidationError = wtu.shouldGenerateGLError(context,
[context.INVALID_OPERATION, context.NO_ERROR],
"context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
wtu.shouldGenerateGLError(context, indexValidationError, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)");
indices[0] = 2;
indices[5] = 1;
wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
wtu.shouldGenerateGLError(context, indexValidationError, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
wtu.shouldGenerateGLError(context, indexValidationError, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)");
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,61 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verifies that the index validation code which is within bufferSubData does not crash.')
var wtu = WebGLTestUtils;
var gl = wtu.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");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,79 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Tests that index validation for drawElements works with large attribute buffers');
var wtu = WebGLTestUtils;
var context = wtu.create3DContext();
var program = wtu.loadStandardProgram(context);
context.useProgram(program);
// Create a small index buffer.
var indexObject = context.createBuffer();
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
var indexArray = new Uint16Array([0, 1, 2]);
context.bufferData(context.ELEMENT_ARRAY_BUFFER, indexArray, context.STATIC_DRAW);
// Create a large attribute buffer.
var vertexObject = context.createBuffer();
context.enableVertexAttribArray(0);
context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
context.bufferData(context.ARRAY_BUFFER, new Float32Array(3 * 65536), context.STATIC_DRAW);
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
debug("Test large attribute buffer")
wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 0)");
// Enlarge the attribute buffer slightly.
debug("Test even larger attribute buffer")
context.bufferData(context.ARRAY_BUFFER, new Float32Array(3 * 65536 + 3), context.STATIC_DRAW);
wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_SHORT, 0)");
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,73 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Tests that index validation for drawElements does not examine too many indices');
var wtu = WebGLTestUtils;
var context = wtu.create3DContext();
var program = wtu.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);
var indexValidationError = wtu.shouldGenerateGLError(context, [context.INVALID_OPERATION, context.NO_ERROR], "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)");
wtu.shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 2)");
wtu.shouldGenerateGLError(context, indexValidationError, "context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)");
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,130 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="1" height="1"></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">
precision mediump float;
varying vec4 color;
void main() {
gl_FragColor = color;
}
</script>
<script>
"use strict";
description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vColor"]);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initialization");
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);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup");
var texCoordObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
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);
wtu.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);
wtu.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);
wtu.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);
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");
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,140 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Tests that index validation verifies the correct number of indices");
function sizeInBytes(type) {
switch (type) {
case gl.BYTE:
case gl.UNSIGNED_BYTE:
return 1;
case gl.SHORT:
case gl.UNSIGNED_SHORT:
return 2;
case gl.INT:
case gl.UNSIGNED_INT:
case gl.FLOAT:
return 4;
default:
throw "unknown type";
}
}
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();
var program = wtu.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 * sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
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 * sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.disableVertexAttribArray(normalLoc);
debug("Enable vertices, valid");
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
debug("Enable normals, out-of-range");
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
wtu.glErrorShouldBe(gl, [gl.INVALID_OPERATION, gl.NO_ERROR]);
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");
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
debug("Enable an extra attribute with insufficient data buffer");
gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
debug("Pass large negative index to vertexAttribPointer");
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT));
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,15 +0,0 @@
buffer-offscreen-test.html
buffer-preserve-test.html
canvas-test.html
canvas-zero-size.html
drawingbuffer-static-canvas-test.html
--min-version 1.0.2 drawingbuffer-hd-dpi-test.html
drawingbuffer-test.html
--min-version 1.0.3 draw-webgl-to-canvas-test.html
--min-version 1.0.3 draw-static-webgl-to-multiple-canvas-test.html
--min-version 1.0.2 framebuffer-bindings-unaffected-on-resize.html
--min-version 1.0.4 framebuffer-bindings-affected-by-to-data-url.html
--min-version 1.0.3 rapid-resizing.html
--min-version 1.0.2 texture-bindings-unaffected-on-resize.html
--min-version 1.0.2 to-data-url-test.html
viewport-unchanged-upon-resize.html

View file

@ -1,101 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL required buffer clear behaviour test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
<style type="text/css">
body {
height: 3000px;
}
</style>
</head>
<body>
<div id="description"></div>
<canvas width="20" height="20" style="border: 1px solid blue;" id="c"></canvas>
<div id="console"></div>
<script>
description("This test ensures WebGL implementations correctly clear " +
"the drawing buffer on composite if preserveDrawingBuffer is false.");
debug("");
var wtu = WebGLTestUtils;
var gl1 = wtu.create3DContext("c");
var gl2 = wtu.create3DContext();
shouldBeTrue("gl1 != null");
shouldBeTrue("gl2 != null");
shouldBeTrue('gl1.getContextAttributes().preserveDrawingBuffer == false');
shouldBeTrue('gl2.getContextAttributes().preserveDrawingBuffer == false');
function init(gl) {
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
// enable scissor here, before compositing, to make sure it's correctly
// ignored and restored
gl.scissor(0, 10, 10, 10);
gl.enable(gl.SCISSOR_TEST);
}
init(gl1);
init(gl2);
wtu.waitForComposite(function() {
function clear(gl) {
// scissor was set earlier
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
}
clear(gl1);
clear(gl2);
debug("check on screen canvas");
wtu.checkCanvasRect(gl1, 0, 10, 10, 10, [0, 0, 255, 255],
"cleared corner should be blue, stencil should be preserved");
wtu.checkCanvasRect(gl1, 0, 0, 10, 10, [0, 0, 0, 0],
"remainder of buffer should be cleared");
debug("check off screen canvas");
wtu.checkCanvasRect(gl2, 0, 10, 10, 10, [0, 0, 255, 255],
"cleared corner should be blue, stencil should be preserved");
wtu.checkCanvasRect(gl2, 0, 0, 10, 10, [255, 0, 0, 255],
"remainder of buffer should be un-cleared red");
finishTest();
});
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,89 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL required buffer clear behaviour test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
<style type="text/css">
body {
height: 3000px;
}
</style>
</head>
<body>
<!-- Important to put the canvas at the top so that it's always visible even in the test suite runner.
Otherwise it just doesn't get composited in Firefox. -->
<canvas width="20" height="20" style="border: 1px solid blue;" id="c"></canvas>
<div id="description"></div>
<div id="console"></div>
<script type="application/javascript">
"use strict";
description("This test ensures WebGL implementations correctly clear the drawing buffer " +
"on composite if preserveDrawingBuffer is false.");
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("c");
shouldBeTrue("gl != null");
shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer == false');
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
// enable scissor here, before compositing, to make sure it's correctly
// ignored and restored
gl.scissor(0, 10, 10, 10);
gl.enable(gl.SCISSOR_TEST);
function clear() {
// scissor was set earlier
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 10, 10, 10, [0, 0, 255, 255],
"cleared corner should be blue, stencil should be preserved");
wtu.checkCanvasRect(gl, 0, 0, 10, 10, [0, 0, 0, 0],
"remainder of buffer should be cleared");
finishTest();
return;
}
wtu.waitForComposite(clear);
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,214 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<canvas id="canvas2d" width="40" height="40"> </canvas>
<script>
"use strict";
description("This test ensures WebGL implementations interact correctly with the canvas tag.");
debug("");
debug("Canvas.getContext");
var err;
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var canvas2d = document.getElementById("canvas2d");
var ctx2d = canvas2d.getContext("2d");
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking canvas and WebGL interaction");
// Check that a canvas with no width or height is 300x150 pixels
shouldBe('canvas.width', '300');
shouldBe('canvas.height', '150');
// Check get a 4 value gl parameter as a csv string.
var getValue4v = function(name) {
var v = gl.getParameter(name);
var result = '' +
v[0] + ',' +
v[1] + ',' +
v[2] + ',' +
v[3];
return result;
}
var getViewport = function() {
return getValue4v(gl.VIEWPORT);
}
var getClearColor = function() {
return getValue4v(gl.COLOR_CLEAR_VALUE);
}
var isAboutEqual = function(a, b) {
return Math.abs(a - b) < 0.01;
}
var isAboutEqualInt = function(a, b) {
return Math.abs(a - b) < 3;
}
var checkCanvasContentIs = function(r3d,g3d,b3d,a3d) {
var r2d;
var g2d;
var b2d;
var a2d;
var checkPixel = function(x, y, r3d,g3d,b3d,a3d) {
var offset = (y * 40 + x) * 4;
r2d = imgData.data[offset];
g2d = imgData.data[offset + 1];
b2d = imgData.data[offset + 2];
a2d = imgData.data[offset + 3];
//debug('' + x + ', ' + y + "(" + offset + ") = " + r2d + ", " + g2d + ", " + b2d + ", " + a2d);
return isAboutEqualInt(r2d, r3d) &&
isAboutEqualInt(g2d, g3d) &&
isAboutEqualInt(b2d, b3d) &&
isAboutEqualInt(a2d, a3d);
}
var checkPixels = function(r3d,g3d,b3d,a3d) {
return checkPixel(0, 0, r3d, g3d, b3d, a3d) &&
checkPixel(0, 39, r3d, g3d, b3d, a3d) &&
checkPixel(39, 0, r3d, g3d, b3d, a3d) &&
checkPixel(39, 39, r3d, g3d, b3d, a3d) &&
checkPixel(0, 0, r3d, g3d, b3d, a3d);
};
// Set to just take the color from the 3d canvas
ctx2d.globalCompositeOperation = 'copy';
// fill 2d canvas with orange
ctx2d.fillStyle = "rgb(255,192,128)";
ctx2d.fillRect (0, 0, 40, 40);
// get the image data
var imgData = ctx2d.getImageData(0, 0, 40, 40);
// check it got cleared.
if (!checkPixels(255, 192, 128, 255)) {
testFailed("unable to fill 2d context.");
return;
}
// draw 3d canvas on top.
ctx2d.drawImage(canvas, 0,0, 40, 40);
// get the image data
var imgData = ctx2d.getImageData(0, 0, 40, 40);
// Check it's the expected color.
if (!checkPixels(r3d, g3d, b3d, a3d)) {
testFailed("pixels are " + r2d + "," + g2d + "," + b2d + "," + a2d +
" expected " + r3d + "," + g3d + "," + b3d + "," + a3d);
} else {
testPassed("pixels are " + r3d + "," + g3d + "," + b3d + "," + a3d);
}
}
checkCanvasContentIs(0, 0, 0, 0);
shouldBe('getViewport()', '"0,0,300,150"');
// Change the display size of the canvas and check
// the viewport size does not change.
debug("");
debug("change display size of canvas and see that viewport does not change");
canvas.style.width = "100px";
canvas.style.height = "25px";
var intervalId;
intervalId = window.setInterval(function() {
if (canvas.clientWidth == 100 &&
canvas.clientHeight == 25) {
window.clearInterval(intervalId);
shouldBe('getViewport()', '"0,0,300,150"');
shouldBe('canvas.width', '300');
shouldBe('canvas.height', '150');
// Change the actual size of the canvas
// Check that the viewport does not change.
// Check that the clear color does not change.
// Check that the color mask does not change.
debug("");
debug("change the actual size of the canvas and see that the viewport does not change");
gl.clearColor(0.25, 0.5, 0.75, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
checkCanvasContentIs(64, 128, 192, 255);
gl.colorMask(0,0,0,0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL errors before resizing the canvas");
canvas.width = 400;
canvas.height = 10;
err = gl.getError();
// Some implementations might lost the context when resizing
if (err != gl.CONTEXT_LOST_WEBGL) {
shouldBe("err", "gl.NO_ERROR");
var v = gl.getParameter(gl.COLOR_CLEAR_VALUE);
assertMsg(isAboutEqual(v[0], 0.25) &&
isAboutEqual(v[1], 0.5) &&
isAboutEqual(v[2], 0.75) &&
isAboutEqual(v[3], 1),
"gl.clearColor should not change after canvas resize");
v = gl.getParameter(gl.COLOR_WRITEMASK);
assertMsg(isAboutEqual(v[0], 0) &&
isAboutEqual(v[1], 0) &&
isAboutEqual(v[2], 0) &&
isAboutEqual(v[3], 0),
"gl.colorMask should not change after canvas resize");
shouldBe('getViewport()', '"0,0,300,150"');
checkCanvasContentIs(0, 0, 0, 0);
}
debug("");
finishTest();
}
}, 1000/30);
}
</script>
</body>
</html>

View file

@ -1,66 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Zero Size Canvas Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Tests that a zero size canvas does not fail.");
var wtu = WebGLTestUtils;
var canvas = document.createElement('canvas');
var gl = wtu.create3DContext(canvas);
canvas.width = 0;
canvas.height = 0;
gl.viewport(0, 0, 0, 0);
var program = wtu.setupTexturedQuad(gl);
shouldBeTrue("program != null");
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
var pixel = new Uint8Array([0, 255, 0, 255]);
gl.texImage2D(
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,98 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas2d_0" width="128" height="128"> </canvas>
<canvas id="canvas2d_1" width="400" height="400"> </canvas>
<canvas id="canvas2d_2" width="128" height="128"> </canvas>
<canvas id="webgl" width="400" height="400"> </canvas>
<script>
"use strict";
description("This test ensures WebGL implementations interact correctly with the canvas 2D drawImage call when drawing the same content.");
var err;
var wtu = WebGLTestUtils;
var canvas2d = [];
var ctx2d = [];
for (var i = 0; i < 3; i ++) {
canvas2d[i] = document.getElementById("canvas2d_" + i);
ctx2d[i] = canvas2d[i].getContext("2d");
}
var canvas = document.getElementById("webgl");
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("Checking drawing the same WebGL content to HW accelerated canvas and SW Canvases");
debug("");
var color = [[0.25, 0.5, 0.75, 1], [1, 0, 0, 1], [1, 0, 1, 1]];
var colorValue = [[64, 128, 192, 255], [255, 0, 0, 255], [255, 0, 255, 255]];
for (var count = 0; count < 10; count ++) {
for (var i = 0; i < 3; i++) {
gl.clearColor(color[i][0], color[i][1], color[i][2], color[i][3]);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
ctx2d[0].drawImage(canvas, 0, 0, canvas2d[0].width, canvas2d[0].height);
ctx2d[1].drawImage(canvas, 0, 0, canvas2d[1].width, canvas2d[1].height);
ctx2d[2].drawImage(canvas, 0, 0, canvas2d[2].width, canvas2d[2].height);
wtu.checkCanvasRect(ctx2d[0], 0, 0, canvas2d[0].width, canvas2d[0].height, colorValue[i],
"drawImage: Should be (" + colorValue[i][0] + "," + colorValue[i][1] +
"," + colorValue[i][2] + "," + colorValue[i][3] + ").", 2);
wtu.checkCanvasRect(ctx2d[1], 0, 0, canvas2d[1].width, canvas2d[1].height, colorValue[i],
"drawImage: Should be (" + colorValue[i][0] + "," + colorValue[i][1] +
"," + colorValue[i][2] + "," + colorValue[i][3] + ").", 2);
wtu.checkCanvasRect(ctx2d[2], 0, 0, canvas2d[2].width, canvas2d[2].height, colorValue[i],
"drawImage: Should be (" + colorValue[i][0] + "," + colorValue[i][1] +
"," + colorValue[i][2] + "," + colorValue[i][3] + ").", 2);
}
}
err = gl.getError();
debug("");
finishTest();
}
</script>
</body>
</html>

View file

@ -1,101 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas2d_0" width="400" height="400"> </canvas>
<canvas id="canvas2d_1" width="400" height="400"> </canvas>
<canvas id="canvas2d_2" width="400" height="400"> </canvas>
<canvas id="webgl" width="400" height="400"> </canvas>
<script>
"use strict";
description("This test ensures WebGL implementations interact correctly with the canvas 2D drawImage call.");
var err;
var wtu = WebGLTestUtils;
var canvas2d = [];
var ctx2d = [];
for (var i = 0; i < 3; i ++) {
canvas2d[i] = document.getElementById("canvas2d_" + i);
ctx2d[i] = canvas2d[i].getContext("2d");
}
var canvas = document.getElementById("webgl");
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking canvas and WebGL drawImage interaction");
for (var count = 0; count < 10; count ++) {
gl.clearColor(0.25, 0.5, 0.75, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
ctx2d[0].drawImage(canvas, 0, 0, canvas2d[0].width, canvas2d[0].height);
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
ctx2d[1].drawImage(canvas, 0, 0, canvas2d[1].width, canvas2d[1].height);
gl.clearColor(1, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
ctx2d[2].drawImage(canvas, 0, 0, canvas2d[2].width, canvas2d[2].height);
gl.clearColor(1, 1, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
wtu.checkCanvasRect(ctx2d[0], 0, 0, canvas2d[0].width, canvas2d[0].height, [64, 128, 192, 255],
"drawImage: Should be [64, 128, 192, 255]", 2);
wtu.checkCanvasRect(ctx2d[1], 0, 0, canvas2d[1].width, canvas2d[1].height, [255, 0, 0, 255],
"drawImage: Should be [255, 0, 0, 255]", 2);
wtu.checkCanvasRect(ctx2d[2], 0, 0, canvas2d[2].width, canvas2d[2].height, [255, 0, 255, 255],
"drawImage: Should be [255, 0, 255, 255]", 2);
}
err = gl.getError();
debug("");
finishTest();
}
</script>
</body>
</html>

View file

@ -1,227 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL DrawingBuffer dimensions on HD-DPI machines test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vshaderGrid" type="x-shader/x-vertex">
attribute vec4 a_position;
void main()
{
gl_Position = a_position;
}
</script>
<script id="fshaderGrid" type="x-shader/x-fragment">
precision mediump float;
void main()
{
float r = mod(gl_FragCoord.x, 2.0) < 1.0 ? 0.0 : 1.0;
float g = mod(gl_FragCoord.y, 2.0) < 1.0 ? 0.0 : 1.0;
gl_FragColor = vec4(r, g, 0, 1);
}
</script>
<script>
"use strict";
description();
debug("");
var gl;
var canvas;
function checkDimensions() {
// We expect that for the sizes being testing drawingBufferWidth and drawingBufferHeight
// will match canvas.width and canvas.height.
// We need to test that devicePixelRatio does not effect the backbuffer size of a canvas.
shouldBe('gl.drawingBufferWidth', 'canvas.width');
shouldBe('gl.drawingBufferHeight', 'canvas.height');
}
// This uses gl_FragCoord to draw a device pixel relavent pattern.
// If drawBufferWidth or drawBufferHeight are not in device pixels
// this test should fail.
function checkGrid(gl, width, height) {
var program = wtu.setupProgram(gl, ["vshaderGrid", "fshaderGrid"], ["a_position"]);
wtu.setupUnitQuad(gl);
gl.useProgram(program);
shouldBe('gl.getError()', 'gl.NO_ERROR');
wtu.clearAndDrawUnitQuad(gl);
var pixels = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
var colors = [
[ { color: [0, 0, 0, 255], name: "black" }, { color: [255, 0, 0, 255], name: "red" } ],
[ { color: [0, 255, 0, 255], name: "green" }, { color: [255, 255, 0, 255], name: "yellow" } ],
];
for (var yy = 0; yy < height; ++yy) {
for (var xx = 0; xx < width; ++xx) {
var info = colors[yy % 2][xx % 2];
var color = info.color;
var offset = (yy * width + xx) * 4;
for (var jj = 0; jj < 4; ++jj) {
if (pixels[offset + jj] != color[jj]) {
var actual = [pixels[offset], pixels[offset + 1], pixels[offset + 2], pixels[offset + 3]];
testFailed("at " + xx + ", " + yy + " expected " + color + "(" + info.name + ") was " + actual);
return;
}
}
}
}
testPassed("grid rendered correctly");
}
// This passes device coordinate vertices in to make sure gl.viewport is not being mucked with.
function checkQuad(gl, width, height) {
var deviceToClipSpace = function(value, range) {
return value / range * 2 - 1;
}
var program = wtu.setupColorQuad(gl);
// draw a small green square in the top right corner.
var deviceX1 = width - 4;
var deviceX2 = width;
var deviceY1 = height - 4;
var deviceY2 = height;
var clipX1 = deviceToClipSpace(deviceX1, width);
var clipX2 = deviceToClipSpace(deviceX2, width);
var clipY1 = deviceToClipSpace(deviceY1, height);
var clipY2 = deviceToClipSpace(deviceY2, height);
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array(
[ clipX2, clipY2,
clipX1, clipY2,
clipX1, clipY1,
clipX2, clipY2,
clipX1, clipY1,
clipX2, clipY1]),
gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
var green = [0, 255, 0, 255];
var black = [0, 0, 0, 0];
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.drawUByteColorQuad(gl, [0, 255, 0, 255]);
var squareWidth = deviceX2 - deviceX1;
var squareHeight = deviceY2 - deviceY1;
// check the square.
wtu.checkCanvasRect(gl, deviceX1, deviceY1, squareWidth, squareHeight, green, "should be green");
// check outside the square.
wtu.checkCanvasRect(gl, 0, 0, width, height - squareHeight, black, "should be black");
wtu.checkCanvasRect(gl, 0, height - squareHeight, width - squareWidth, squareHeight, black, "should be black");
}
function test(desiredWidth, desiredHeight) {
debug("");
debug("testing canvas width = " + desiredWidth + ", height = " + desiredHeight);
// Make a fresh canvas.
canvas = document.createElement("canvas");
canvas.width = desiredWidth;
canvas.height = desiredHeight;
// This 'gl' must be global for shouldBe to work.
gl = wtu.create3DContext(canvas, {antialias: false});
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
// Check the dimensions are correct.
checkDimensions();
// Draw a pixel grid using a shader that draws in device coordinates
checkGrid(gl, desiredWidth, desiredHeight);
// Draw a quad in the top right corner.
checkQuad(gl, desiredWidth, desiredHeight);
shouldBe('gl.getError()', 'gl.NO_ERROR');
debug("");
debug("testing resizing canvas to width = " + desiredWidth + ", height = " + desiredHeight);
var oldViewport = gl.getParameter(gl.VIEWPORT);
// flip width and height
canvas.width = desiredHeight;
canvas.height = desiredWidth;
// fix the viewport
gl.viewport(0, 0, desiredHeight, desiredWidth);
// Check the dimensions are correct.
checkDimensions();
// Draw a pixel grid using a shader that draws in device coordinates
checkGrid(gl, desiredHeight, desiredWidth);
// Draw a quad in the top right corner.
checkQuad(gl, desiredHeight, desiredWidth);
shouldBe('gl.getError()', 'gl.NO_ERROR');
}
}
var wtu = WebGLTestUtils;
// test a few sizes
test(32, 16);
test(128, 64);
test(256, 512);
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,139 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="50" height="50"> </canvas>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script>
"use strict";
function drawTriangleTest(gl)
{
var width = 50;
var height = 50;
gl.viewport(0, 0, width, height);
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
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.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 3);
// Test several locations
wtu.checkCanvasRect(gl, 0, 0, width, 1, [0, 0, 0, 255],
'First line should be all black');
wtu.checkCanvasRect(gl, 20, 15, 10, 1, [255, 0, 0, 255],
'Line 15 should be red for at least 10 red pixels starting 20 pixels in');
wtu.checkCanvasRect(gl, 0, height - 1, width, 1, [0, 0, 0, 255],
'Last line should be all black');
}
description("This test ensures WebGL implementations correctly implement drawingbufferWidth/Height with compositing.");
debug("");
var wtu = WebGLTestUtils;
var err;
var maxSize;
var gl = wtu.create3DContext("canvas");
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
shouldBeNonNull("program");
gl.enable(gl.DEPTH_TEST);
gl.clearColor(0, 0, 0, 1);
shouldBe('gl.getError()', 'gl.NO_ERROR');
debug("");
debug("Checking drawingBufferWidth/drawingBufferHeight");
shouldBe('gl.drawingBufferWidth', 'gl.canvas.width');
shouldBe('gl.drawingBufferHeight', 'gl.canvas.height');
// Check that changing the canvas size to something too large falls back to reasonable values.
maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
shouldBeTrue('maxSize[0] > 0');
shouldBeTrue('maxSize[1] > 0');
// debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]);
gl.canvas.width = maxSize[0] * 4;
gl.canvas.height = maxSize[1] * 4;
shouldBeTrue('gl.drawingBufferWidth > 0');
shouldBeTrue('gl.drawingBufferHeight > 0');
shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]');
shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]');
shouldBe('gl.getError()', 'gl.NO_ERROR');
debug("");
debug("Checking scaling up then back down to 50/50, drawing still works.");
gl.canvas.width = 50;
gl.canvas.height = 50;
shouldBeTrue('gl.drawingBufferWidth == 50');
shouldBeTrue('gl.drawingBufferHeight == 50');
shouldBe('gl.getError()', 'gl.NO_ERROR');
drawTriangleTest(gl);
shouldBe('gl.getError()', 'gl.NO_ERROR');
}
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,140 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas.drawingBufferWidth,drawingBufferHeight Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description();
debug("");
var gl;
var oldViewport;
function getMaxViewportDimensions() {
// create a fresh canvas. This canvas will be discarded
// after exiting this function.
var canvas = document.createElement("canvas");
gl = wtu.create3DContext(canvas, {antialias: false});
if (!gl) {
testFailed("context does not exist");
return [0, 0];
} else {
testPassed("context exists");
// For a default size canvas these should be equal.
// WebGL contexts are not allowed to change the size of the drawingBuffer
// for things like hi-res displays.
shouldBe('gl.drawingBufferWidth', 'gl.canvas.width');
shouldBe('gl.drawingBufferHeight', 'gl.canvas.height');
return gl.getParameter(gl.MAX_VIEWPORT_DIMS);
}
}
function test(desiredWidth, desiredHeight) {
debug("");
debug("testing canvas width = " + desiredWidth + ", height = " + desiredHeight);
// Make a fresh canvas.
var canvas = document.createElement("canvas");
canvas.width = desiredWidth;
canvas.height = desiredHeight;
// This 'gl' must be global for shouldBe to work.
gl = wtu.create3DContext(canvas, {antialias: false});
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
// Verify these stats didn't change since they come from a different
// context.
shouldBe('gl.getParameter(gl.MAX_VIEWPORT_DIMS)[0]', 'maxSize[0]');
shouldBe('gl.getParameter(gl.MAX_VIEWPORT_DIMS)[1]', 'maxSize[1]');
// check the initial viewport matches the drawingBufferWidth and drawingBufferHeight
shouldBe('gl.getParameter(gl.VIEWPORT)[0]', '0');
shouldBe('gl.getParameter(gl.VIEWPORT)[1]', '0');
shouldBe('gl.getParameter(gl.VIEWPORT)[2]', 'gl.drawingBufferWidth');
shouldBe('gl.getParameter(gl.VIEWPORT)[3]', 'gl.drawingBufferHeight');
debug("");
debug("testing resizing canvas to width = " + desiredWidth + ", height = " + desiredHeight);
oldViewport = gl.getParameter(gl.VIEWPORT);
// flip width and height
canvas.width = desiredHeight;
canvas.height = desiredWidth;
// Verify the viewport didn't change.
shouldBe('gl.getParameter(gl.VIEWPORT)[0]', 'oldViewport[0]');
shouldBe('gl.getParameter(gl.VIEWPORT)[1]', 'oldViewport[1]');
shouldBe('gl.getParameter(gl.VIEWPORT)[2]', 'oldViewport[2]');
shouldBe('gl.getParameter(gl.VIEWPORT)[3]', 'oldViewport[3]');
// fix the viewport
// gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
shouldBe('gl.getError()', 'gl.NO_ERROR');
}
}
var wtu = WebGLTestUtils;
var maxSize = getMaxViewportDimensions();
debug("MAX_VIEWPORT_DIMS: " + maxSize[0] + ", " + maxSize[1]);
shouldBeTrue('maxSize[0] > 0');
shouldBeTrue('maxSize[1] > 0');
// test a small size to make sure it works at all.
test(16, 32);
// Make a canvas slightly larger than the max size WebGL can handle.
// From section 2.2 of the spec the WebGL implementation should allow this to work.
// test a size larger than MAX_VIEWPORT_DIMS in both dimensions
test(maxSize[0] + 32, 8);
debug("")
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,108 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Verifies that GL framebuffer bindings do not change when canvas is resized</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="4" height="4"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
enableJSTestPreVerboseLogging();
description("Verifies that GL framebuffer bindings do not change when canvas is resized");
var err;
var wtu = WebGLTestUtils;
var canvas = document.getElementById("example");
var gl = wtu.create3DContext(canvas);
var green = [0, 255, 0, 255];
var blue = [0, 0, 255, 255];
var fboSize = 2;
shouldBeTrue("fboSize < canvas.width");
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
var fboTex = gl.createTexture();
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, fboTex);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fboTex, 0);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, fboSize, fboSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
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.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
function checkFBO(color, msg) {
wtu.checkCanvasRect(gl, 0, 0, fboSize, fboSize, color, msg);
wtu.checkCanvasRect(gl, fboSize, fboSize, fboSize, fboSize, [0, 0, 0, 0], "area outside fbo should be transparent black");
}
// The FBO is 2x2 and it's bound so clearing should clear a 2x2 area
// and calling read pixels should read the clear color in that 2x2 area
// and 0,0,0,0 outside that area.
//
// If the FBO is no longer bound because of a WebGL implementation error
// then likely the clear will clear the backbuffer and reading outside
// the 2x2 area will not be 0,0,0,0
function test() {
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
checkFBO(blue, "should be blue");
gl.clearColor(0, 1, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
checkFBO(green, "should be green");
}
debug("test before resizing canvas");
test();
debug("test after resizing canvas");
canvas.width = 8;
test();
debug("test after resizing canvas and waiting for compositing");
canvas.width = 16;
wtu.waitForComposite(function() {
test();
finishTest();
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
});
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,192 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Rapid Resizing Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas1" style="width: 256px; height: 256px;"> </canvas>
<canvas id="canvas2" style="width: 256px; height: 256px;"> </canvas>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
}
</script>
<script>
"use strict";
description("Verifies that rapidly resizing the canvas works correctly.");
debug("");
debug("Regression test for Chromium <a href='http://crbug.com/299371'>Issue 299371</a> and <a href='http://crbug.com/557848'>Issue 557848</a>");
debug("");
var err;
var wtu = WebGLTestUtils;
var canvas;
var largeSize = 256;
var smallSize = 128;
var currentSize;
var gl;
var program;
var numFrames = 0;
var testNumber = 0;
function nextTest() {
++testNumber;
numFrames = 0;
currentSize = largeSize;
if (testNumber > 2) {
finishTest();
return;
}
canvas = document.getElementById("canvas" + testNumber);
canvas.width = currentSize;
canvas.height = currentSize;
var usePreserveDrawingBuffer = (testNumber == 1) ? true : false;
debug("Testing preserveDrawingBuffer = " + usePreserveDrawingBuffer);
gl = wtu.create3DContext(canvas, { preserveDrawingBuffer: usePreserveDrawingBuffer });
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
gl.clearColor(0, 0, 0, 1);
program = wtu.setupProgram(gl, ["vshader", "fshader"], ["position"]);
shouldBeNonNull("program");
// Prepare to draw quads
var quadSize = 0.1;
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
// Lower left
-1, -1 + quadSize,
-1, -1,
-1 + quadSize, -1,
-1 + quadSize, -1 + quadSize,
// Lower right
1 - quadSize, -1 + quadSize,
1 - quadSize, -1,
1, -1,
1, -1 + quadSize,
// Upper right
1 - quadSize, 1,
1 - quadSize, 1 - quadSize,
1, 1 - quadSize,
1, 1,
// Upper left
-1, 1,
-1, 1 - quadSize,
-1 + quadSize, 1 - quadSize,
-1 + quadSize, 1
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15
]), gl.STATIC_DRAW);
wtu.requestAnimFrame(render);
}
}
function render() {
if (++numFrames < 30) {
if (currentSize == largeSize) {
canvas.height = smallSize;
currentSize = smallSize;
} else {
canvas.height = largeSize;
currentSize = largeSize;
}
}
gl.viewport(0, 0, largeSize, currentSize);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawElements(gl.TRIANGLES, 24, gl.UNSIGNED_SHORT, 0);
// Check the four corners
var green = [ 0, 255, 0, 255 ];
var inset = 3;
wtu.checkCanvasRect(gl, inset, inset, 1, 1, green, "lower left should be green", 1);
wtu.checkCanvasRect(gl, largeSize - inset, inset, 1, 1, green, "lower right should be green", 1);
wtu.checkCanvasRect(gl, inset, currentSize - inset, 1, 1, green, "upper left should be green", 1);
wtu.checkCanvasRect(gl, largeSize - inset, currentSize - inset, 1, 1, green, "upper right should be green", 1);
if (numFrames < 60) {
wtu.requestAnimFrame(render);
} else {
wtu.requestAnimFrame(nextTest);
}
}
wtu.requestAnimFrame(nextTest);
</script>
</body>
</html>

View file

@ -1,89 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="4" height="4"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verifies that GL texture bindings do not change when canvas is resized');
var err;
var wtu = WebGLTestUtils;
var canvas = document.getElementById("example");
var gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
var green = [0, 255, 0, 255];
var blue = [0, 0, 255, 255];
var tex0 = gl.createTexture();
wtu.fillTexture(gl, tex0, 1, 1, blue, 0);
gl.activeTexture(gl.TEXTURE1)
var tex1 = gl.createTexture();
wtu.fillTexture(gl, tex1, 1, 1, green, 0);
var loc = gl.getUniformLocation(program, "tex");
function test() {
gl.viewport(0, 0, canvas.width, canvas.height);
gl.uniform1i(loc, 0);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, blue, "should be blue");
gl.uniform1i(loc, 1);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, green, "should be green");
}
debug("test before resizing canvas");
test();
debug("test after resizing canvas");
canvas.width = 8;
test();
debug("test after resizing canvas and waiting for compositing");
canvas.width = 16;
wtu.waitForComposite(function() {
test();
finishTest();
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
});
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,131 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL toDataURL test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas width="20" height="20" style="border: 1px solid black; width: 16px; height: 16px" id="c3d"></canvas>
<canvas width="20" height="20" style="border: 1px solid black; width: 16px; height: 16px" id="c2d"></canvas>
<div id="description"></div>
<div id="console"></div>
<script type="application/javascript">
var wtu = WebGLTestUtils;
var numTests = 10;
var gl;
var ctx;
var main = function() {
description();
ctx = document.getElementById("c2d").getContext("2d");
gl = wtu.create3DContext("c3d");
if (!gl) {
testFailed("can't create 3d context");
return;
}
var clearRect = function(gl, x, y, width, height, color) {
gl.clearColor(color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
gl.scissor(x, y, width, height);
gl.clear(gl.COLOR_BUFFER_BIT);
};
var testSize = function(gl, width, height, callback) {
debug("testing " + width + " by " + height);
gl.canvas.width = width;
gl.canvas.height = height;
gl.viewport(0, 0, width, height);
gl.enable(gl.SCISSOR_TEST);
var bottomColor = [255, 0, 0, 255];
var topColor = [0, 255, 0, 255];
var rightColor = [0, 0, 255, 255];
var halfHeight = Math.floor(height / 2);
var topHeight = height - halfHeight;
var canvasTopHeight = height - topHeight;
clearRect(gl, 0, 0, width, halfHeight, bottomColor);
clearRect(gl, 0, halfHeight, width, topHeight, topColor);
clearRect(gl, width - 1, 0, 1, height, rightColor);
// Performs gl.canvas.toDataURL() internally
var img = wtu.makeImageFromCanvas(gl.canvas, function() {
ctx.canvas.width = width;
ctx.canvas.height = height;
ctx.imageSmoothingEnabled = false;
ctx.drawImage(img, 0, 0);
wtu.checkCanvasRect(ctx, 0, 0, width - 1, topHeight, topColor);
wtu.checkCanvasRect(ctx, 0, topHeight, width - 1, halfHeight, bottomColor);
wtu.checkCanvasRect(ctx, width - 1, 0, 1, height, rightColor);
debug("");
callback();
});
};
var tests = [
{ width: 16 , height: 16 , },
{ width: 16 - 1, height: 16 , },
{ width: 16 - 1, height: 16 - 1, },
{ width: 16 + 1, height: 16 - 1, },
{ width: 16 - 1, height: 16 + 1, },
{ width: 256 , height: 256 , },
{ width: 256 - 1, height: 256 , },
{ width: 256 - 1, height: 256 - 1, },
{ width: 256 + 1, height: 256 - 1, },
{ width: 256 - 1, height: 256 + 1, },
{ width: 512 , height: 512 , },
{ width: 512 - 1, height: 512 , },
{ width: 512 - 1, height: 512 - 1, },
{ width: 512 + 1, height: 512 - 1, },
{ width: 512 - 1, height: 512 + 1, },
];
var testIndex = 0;
var runNextTest = function() {
if (testIndex == tests.length) {
finishTest();
return;
}
var test = tests[testIndex++];
testSize(gl, test.width, test.height, function() {
setTimeout(runNextTest, 0);
})
};
runNextTest();
};
main();
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,115 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script id="vshader" type="x-shader/x-vertex">
attribute vec3 g_Position;
void main()
{
gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
</script>
</head>
<body>
<canvas id="example" width="4" height="4"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verifies that GL viewport does not change when canvas is resized');
var err;
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["g_Position"]);
var vertices = new Float32Array([
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 vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
// Clear and set up
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.useProgram(program);
// Draw the triangle pair to the frame buffer
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Ensure that the frame buffer is red at the sampled pixel
wtu.checkCanvasRect(gl, 2, 2, 1, 1, [255, 0, 0, 255]);
// Now resize the canvas
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL errors before resizing the canvas");
var canvas = gl.canvas;
canvas.width = 8;
canvas.height = 8;
err = gl.getError();
// Some implementations might lost the context when resizing
if (err == gl.CONTEXT_LOST_WEBGL) {
testPassed("canvas lost context on resize");
} else {
shouldBe("err", "gl.NO_ERROR");
// Do another render
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
// This time, because we did not change the viewport, it should
// still be (0, 0, 4, 4), so only the lower-left quadrant should
// have been filled.
wtu.checkCanvasRect(gl, 6, 6, 1, 1, [0, 0, 255, 255]);
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,19 +0,0 @@
--max-version 1.9.9 constants-and-properties.html
--min-version 1.0.2 context-attribute-preserve-drawing-buffer.html
context-attributes-alpha-depth-stencil-antialias.html
--min-version 1.0.4 context-size-change.html
--min-version 1.0.4 context-no-alpha-fbo-with-alpha.html
--min-version 1.0.2 --slow context-creation-and-destruction.html
--min-version 1.0.3 --slow context-creation.html
--min-version 1.0.3 --slow context-eviction-with-garbage-collection.html
--min-version 1.0.3 context-hidden-alpha.html
--min-version 1.0.2 context-release-upon-reload.html
--min-version 1.0.2 context-release-with-workers.html
context-lost-restored.html
context-lost.html
--max-version 1.9.9 context-type-test.html
incorrect-context-object-behaviour.html
--max-version 1.9.9 methods.html
premultiplyalpha-test.html
resource-sharing-test.html
--min-version 1.0.4 user-defined-properties-on-context.html

View file

@ -1,568 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Constants and Properties Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<script>
"use strict";
description("This test ensures that the WebGL context has all the constants and (non-function) properties in the specification.");
var constants = {
/* ClearBufferMask */
DEPTH_BUFFER_BIT : 0x00000100,
STENCIL_BUFFER_BIT : 0x00000400,
COLOR_BUFFER_BIT : 0x00004000,
/* BeginMode */
POINTS : 0x0000,
LINES : 0x0001,
LINE_LOOP : 0x0002,
LINE_STRIP : 0x0003,
TRIANGLES : 0x0004,
TRIANGLE_STRIP : 0x0005,
TRIANGLE_FAN : 0x0006,
/* AlphaFunction (not supported in ES20) */
/* NEVER */
/* LESS */
/* EQUAL */
/* LEQUAL */
/* GREATER */
/* NOTEQUAL */
/* GEQUAL */
/* ALWAYS */
/* BlendingFactorDest */
ZERO : 0,
ONE : 1,
SRC_COLOR : 0x0300,
ONE_MINUS_SRC_COLOR : 0x0301,
SRC_ALPHA : 0x0302,
ONE_MINUS_SRC_ALPHA : 0x0303,
DST_ALPHA : 0x0304,
ONE_MINUS_DST_ALPHA : 0x0305,
/* BlendingFactorSrc */
/* ZERO */
/* ONE */
DST_COLOR : 0x0306,
ONE_MINUS_DST_COLOR : 0x0307,
SRC_ALPHA_SATURATE : 0x0308,
/* SRC_ALPHA */
/* ONE_MINUS_SRC_ALPHA */
/* DST_ALPHA */
/* ONE_MINUS_DST_ALPHA */
/* BlendEquationSeparate */
FUNC_ADD : 0x8006,
BLEND_EQUATION : 0x8009,
BLEND_EQUATION_RGB : 0x8009, /* same as BLEND_EQUATION */
BLEND_EQUATION_ALPHA : 0x883D,
/* BlendSubtract */
FUNC_SUBTRACT : 0x800A,
FUNC_REVERSE_SUBTRACT : 0x800B,
/* Separate Blend Functions */
BLEND_DST_RGB : 0x80C8,
BLEND_SRC_RGB : 0x80C9,
BLEND_DST_ALPHA : 0x80CA,
BLEND_SRC_ALPHA : 0x80CB,
CONSTANT_COLOR : 0x8001,
ONE_MINUS_CONSTANT_COLOR : 0x8002,
CONSTANT_ALPHA : 0x8003,
ONE_MINUS_CONSTANT_ALPHA : 0x8004,
BLEND_COLOR : 0x8005,
/* Buffer Objects */
ARRAY_BUFFER : 0x8892,
ELEMENT_ARRAY_BUFFER : 0x8893,
ARRAY_BUFFER_BINDING : 0x8894,
ELEMENT_ARRAY_BUFFER_BINDING : 0x8895,
STREAM_DRAW : 0x88E0,
STATIC_DRAW : 0x88E4,
DYNAMIC_DRAW : 0x88E8,
BUFFER_SIZE : 0x8764,
BUFFER_USAGE : 0x8765,
CURRENT_VERTEX_ATTRIB : 0x8626,
/* CullFaceMode */
FRONT : 0x0404,
BACK : 0x0405,
FRONT_AND_BACK : 0x0408,
/* DepthFunction */
/* NEVER */
/* LESS */
/* EQUAL */
/* LEQUAL */
/* GREATER */
/* NOTEQUAL */
/* GEQUAL */
/* ALWAYS */
/* EnableCap */
/* TEXTURE_2D */
CULL_FACE : 0x0B44,
BLEND : 0x0BE2,
DITHER : 0x0BD0,
STENCIL_TEST : 0x0B90,
DEPTH_TEST : 0x0B71,
SCISSOR_TEST : 0x0C11,
POLYGON_OFFSET_FILL : 0x8037,
SAMPLE_ALPHA_TO_COVERAGE : 0x809E,
SAMPLE_COVERAGE : 0x80A0,
/* ErrorCode */
NO_ERROR : 0,
INVALID_ENUM : 0x0500,
INVALID_VALUE : 0x0501,
INVALID_OPERATION : 0x0502,
OUT_OF_MEMORY : 0x0505,
/* FrontFaceDirection */
CW : 0x0900,
CCW : 0x0901,
/* GetPName */
LINE_WIDTH : 0x0B21,
ALIASED_POINT_SIZE_RANGE : 0x846D,
ALIASED_LINE_WIDTH_RANGE : 0x846E,
CULL_FACE_MODE : 0x0B45,
FRONT_FACE : 0x0B46,
DEPTH_RANGE : 0x0B70,
DEPTH_WRITEMASK : 0x0B72,
DEPTH_CLEAR_VALUE : 0x0B73,
DEPTH_FUNC : 0x0B74,
STENCIL_CLEAR_VALUE : 0x0B91,
STENCIL_FUNC : 0x0B92,
STENCIL_FAIL : 0x0B94,
STENCIL_PASS_DEPTH_FAIL : 0x0B95,
STENCIL_PASS_DEPTH_PASS : 0x0B96,
STENCIL_REF : 0x0B97,
STENCIL_VALUE_MASK : 0x0B93,
STENCIL_WRITEMASK : 0x0B98,
STENCIL_BACK_FUNC : 0x8800,
STENCIL_BACK_FAIL : 0x8801,
STENCIL_BACK_PASS_DEPTH_FAIL : 0x8802,
STENCIL_BACK_PASS_DEPTH_PASS : 0x8803,
STENCIL_BACK_REF : 0x8CA3,
STENCIL_BACK_VALUE_MASK : 0x8CA4,
STENCIL_BACK_WRITEMASK : 0x8CA5,
VIEWPORT : 0x0BA2,
SCISSOR_BOX : 0x0C10,
/* SCISSOR_TEST */
COLOR_CLEAR_VALUE : 0x0C22,
COLOR_WRITEMASK : 0x0C23,
UNPACK_ALIGNMENT : 0x0CF5,
PACK_ALIGNMENT : 0x0D05,
MAX_TEXTURE_SIZE : 0x0D33,
MAX_VIEWPORT_DIMS : 0x0D3A,
SUBPIXEL_BITS : 0x0D50,
RED_BITS : 0x0D52,
GREEN_BITS : 0x0D53,
BLUE_BITS : 0x0D54,
ALPHA_BITS : 0x0D55,
DEPTH_BITS : 0x0D56,
STENCIL_BITS : 0x0D57,
POLYGON_OFFSET_UNITS : 0x2A00,
/* POLYGON_OFFSET_FILL */
POLYGON_OFFSET_FACTOR : 0x8038,
TEXTURE_BINDING_2D : 0x8069,
SAMPLE_BUFFERS : 0x80A8,
SAMPLES : 0x80A9,
SAMPLE_COVERAGE_VALUE : 0x80AA,
SAMPLE_COVERAGE_INVERT : 0x80AB,
/* GetTextureParameter */
/* TEXTURE_MAG_FILTER */
/* TEXTURE_MIN_FILTER */
/* TEXTURE_WRAP_S */
/* TEXTURE_WRAP_T */
COMPRESSED_TEXTURE_FORMATS : 0x86A3,
/* HintMode */
DONT_CARE : 0x1100,
FASTEST : 0x1101,
NICEST : 0x1102,
/* HintTarget */
GENERATE_MIPMAP_HINT : 0x8192,
/* DataType */
BYTE : 0x1400,
UNSIGNED_BYTE : 0x1401,
SHORT : 0x1402,
UNSIGNED_SHORT : 0x1403,
INT : 0x1404,
UNSIGNED_INT : 0x1405,
FLOAT : 0x1406,
/* PixelFormat */
DEPTH_COMPONENT : 0x1902,
ALPHA : 0x1906,
RGB : 0x1907,
RGBA : 0x1908,
LUMINANCE : 0x1909,
LUMINANCE_ALPHA : 0x190A,
/* PixelType */
/* UNSIGNED_BYTE */
UNSIGNED_SHORT_4_4_4_4 : 0x8033,
UNSIGNED_SHORT_5_5_5_1 : 0x8034,
UNSIGNED_SHORT_5_6_5 : 0x8363,
/* Shaders */
FRAGMENT_SHADER : 0x8B30,
VERTEX_SHADER : 0x8B31,
MAX_VERTEX_ATTRIBS : 0x8869,
MAX_VERTEX_UNIFORM_VECTORS : 0x8DFB,
MAX_VARYING_VECTORS : 0x8DFC,
MAX_COMBINED_TEXTURE_IMAGE_UNITS : 0x8B4D,
MAX_VERTEX_TEXTURE_IMAGE_UNITS : 0x8B4C,
MAX_TEXTURE_IMAGE_UNITS : 0x8872,
MAX_FRAGMENT_UNIFORM_VECTORS : 0x8DFD,
SHADER_TYPE : 0x8B4F,
DELETE_STATUS : 0x8B80,
LINK_STATUS : 0x8B82,
VALIDATE_STATUS : 0x8B83,
ATTACHED_SHADERS : 0x8B85,
ACTIVE_UNIFORMS : 0x8B86,
ACTIVE_ATTRIBUTES : 0x8B89,
SHADING_LANGUAGE_VERSION : 0x8B8C,
CURRENT_PROGRAM : 0x8B8D,
/* StencilFunction */
NEVER : 0x0200,
LESS : 0x0201,
EQUAL : 0x0202,
LEQUAL : 0x0203,
GREATER : 0x0204,
NOTEQUAL : 0x0205,
GEQUAL : 0x0206,
ALWAYS : 0x0207,
/* StencilOp */
/* ZERO */
KEEP : 0x1E00,
REPLACE : 0x1E01,
INCR : 0x1E02,
DECR : 0x1E03,
INVERT : 0x150A,
INCR_WRAP : 0x8507,
DECR_WRAP : 0x8508,
/* StringName */
VENDOR : 0x1F00,
RENDERER : 0x1F01,
VERSION : 0x1F02,
/* TextureMagFilter */
NEAREST : 0x2600,
LINEAR : 0x2601,
/* TextureMinFilter */
/* NEAREST */
/* LINEAR */
NEAREST_MIPMAP_NEAREST : 0x2700,
LINEAR_MIPMAP_NEAREST : 0x2701,
NEAREST_MIPMAP_LINEAR : 0x2702,
LINEAR_MIPMAP_LINEAR : 0x2703,
/* TextureParameterName */
TEXTURE_MAG_FILTER : 0x2800,
TEXTURE_MIN_FILTER : 0x2801,
TEXTURE_WRAP_S : 0x2802,
TEXTURE_WRAP_T : 0x2803,
/* TextureTarget */
TEXTURE_2D : 0x0DE1,
TEXTURE : 0x1702,
TEXTURE_CUBE_MAP : 0x8513,
TEXTURE_BINDING_CUBE_MAP : 0x8514,
TEXTURE_CUBE_MAP_POSITIVE_X : 0x8515,
TEXTURE_CUBE_MAP_NEGATIVE_X : 0x8516,
TEXTURE_CUBE_MAP_POSITIVE_Y : 0x8517,
TEXTURE_CUBE_MAP_NEGATIVE_Y : 0x8518,
TEXTURE_CUBE_MAP_POSITIVE_Z : 0x8519,
TEXTURE_CUBE_MAP_NEGATIVE_Z : 0x851A,
MAX_CUBE_MAP_TEXTURE_SIZE : 0x851C,
/* TextureUnit */
TEXTURE0 : 0x84C0,
TEXTURE1 : 0x84C1,
TEXTURE2 : 0x84C2,
TEXTURE3 : 0x84C3,
TEXTURE4 : 0x84C4,
TEXTURE5 : 0x84C5,
TEXTURE6 : 0x84C6,
TEXTURE7 : 0x84C7,
TEXTURE8 : 0x84C8,
TEXTURE9 : 0x84C9,
TEXTURE10 : 0x84CA,
TEXTURE11 : 0x84CB,
TEXTURE12 : 0x84CC,
TEXTURE13 : 0x84CD,
TEXTURE14 : 0x84CE,
TEXTURE15 : 0x84CF,
TEXTURE16 : 0x84D0,
TEXTURE17 : 0x84D1,
TEXTURE18 : 0x84D2,
TEXTURE19 : 0x84D3,
TEXTURE20 : 0x84D4,
TEXTURE21 : 0x84D5,
TEXTURE22 : 0x84D6,
TEXTURE23 : 0x84D7,
TEXTURE24 : 0x84D8,
TEXTURE25 : 0x84D9,
TEXTURE26 : 0x84DA,
TEXTURE27 : 0x84DB,
TEXTURE28 : 0x84DC,
TEXTURE29 : 0x84DD,
TEXTURE30 : 0x84DE,
TEXTURE31 : 0x84DF,
ACTIVE_TEXTURE : 0x84E0,
/* TextureWrapMode */
REPEAT : 0x2901,
CLAMP_TO_EDGE : 0x812F,
MIRRORED_REPEAT : 0x8370,
/* Uniform Types */
FLOAT_VEC2 : 0x8B50,
FLOAT_VEC3 : 0x8B51,
FLOAT_VEC4 : 0x8B52,
INT_VEC2 : 0x8B53,
INT_VEC3 : 0x8B54,
INT_VEC4 : 0x8B55,
BOOL : 0x8B56,
BOOL_VEC2 : 0x8B57,
BOOL_VEC3 : 0x8B58,
BOOL_VEC4 : 0x8B59,
FLOAT_MAT2 : 0x8B5A,
FLOAT_MAT3 : 0x8B5B,
FLOAT_MAT4 : 0x8B5C,
SAMPLER_2D : 0x8B5E,
SAMPLER_CUBE : 0x8B60,
/* Vertex Arrays */
VERTEX_ATTRIB_ARRAY_ENABLED : 0x8622,
VERTEX_ATTRIB_ARRAY_SIZE : 0x8623,
VERTEX_ATTRIB_ARRAY_STRIDE : 0x8624,
VERTEX_ATTRIB_ARRAY_TYPE : 0x8625,
VERTEX_ATTRIB_ARRAY_NORMALIZED : 0x886A,
VERTEX_ATTRIB_ARRAY_POINTER : 0x8645,
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
/* Read Format */
IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
/* Shader Source */
COMPILE_STATUS : 0x8B81,
/* Shader Precision-Specified Types */
LOW_FLOAT : 0x8DF0,
MEDIUM_FLOAT : 0x8DF1,
HIGH_FLOAT : 0x8DF2,
LOW_INT : 0x8DF3,
MEDIUM_INT : 0x8DF4,
HIGH_INT : 0x8DF5,
/* Framebuffer Object. */
FRAMEBUFFER : 0x8D40,
RENDERBUFFER : 0x8D41,
RGBA4 : 0x8056,
RGB5_A1 : 0x8057,
RGB565 : 0x8D62,
DEPTH_COMPONENT16 : 0x81A5,
STENCIL_INDEX : 0x1901,
STENCIL_INDEX8 : 0x8D48,
DEPTH_STENCIL : 0x84F9,
RENDERBUFFER_WIDTH : 0x8D42,
RENDERBUFFER_HEIGHT : 0x8D43,
RENDERBUFFER_INTERNAL_FORMAT : 0x8D44,
RENDERBUFFER_RED_SIZE : 0x8D50,
RENDERBUFFER_GREEN_SIZE : 0x8D51,
RENDERBUFFER_BLUE_SIZE : 0x8D52,
RENDERBUFFER_ALPHA_SIZE : 0x8D53,
RENDERBUFFER_DEPTH_SIZE : 0x8D54,
RENDERBUFFER_STENCIL_SIZE : 0x8D55,
FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE : 0x8CD0,
FRAMEBUFFER_ATTACHMENT_OBJECT_NAME : 0x8CD1,
FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL : 0x8CD2,
FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
COLOR_ATTACHMENT0 : 0x8CE0,
DEPTH_ATTACHMENT : 0x8D00,
STENCIL_ATTACHMENT : 0x8D20,
DEPTH_STENCIL_ATTACHMENT : 0x821A,
NONE : 0,
FRAMEBUFFER_COMPLETE : 0x8CD5,
FRAMEBUFFER_INCOMPLETE_ATTACHMENT : 0x8CD6,
FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : 0x8CD7,
FRAMEBUFFER_INCOMPLETE_DIMENSIONS : 0x8CD9,
FRAMEBUFFER_UNSUPPORTED : 0x8CDD,
FRAMEBUFFER_BINDING : 0x8CA6,
RENDERBUFFER_BINDING : 0x8CA7,
MAX_RENDERBUFFER_SIZE : 0x84E8,
INVALID_FRAMEBUFFER_OPERATION : 0x0506,
/* WebGL-specific enums */
UNPACK_FLIP_Y_WEBGL : 0x9240,
UNPACK_PREMULTIPLY_ALPHA_WEBGL : 0x9241,
CONTEXT_LOST_WEBGL : 0x9242,
UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
BROWSER_DEFAULT_WEBGL : 0x9244
};
// Other non-function properties on the WebGL object
var otherProperties = {
drawingBufferWidth : "number",
drawingBufferHeight : "number",
canvas : "implementation-dependent"
};
// Properties to be ignored (as a list of strings) because they were
// added in versions of the spec that are backward-compatible with
// this version
var ignoredProperties = [
];
// Constants removed from the WebGL spec compared to ES 2.0
var removedConstants = {
NUM_COMPRESSED_TEXTURE_FORMATS : 0x86A2,
FIXED : 0x140C,
ACTIVE_UNIFORM_MAX_LENGTH : 0x8B87,
ACTIVE_ATTRIBUTE_MAX_LENGTH : 0x8B8A,
EXTENSIONS : 0x1F03,
INFO_LOG_LENGTH : 0x8B84,
SHADER_SOURCE_LENGTH : 0x8B88,
SHADER_COMPILER : 0x8DFA,
SHADER_BINARY_FORMATS : 0x8DF8,
NUM_SHADER_BINARY_FORMATS : 0x8DF9,
};
function assertProperty(v, p) {
if (p in v) {
return true;
} else {
testFailed("Property does not exist: " + p)
return false;
}
}
function assertNoProperty(v, p) {
if (p in v) {
testFailed("Property is defined and should not be: " + p)
return false;
} else {
return true;
}
}
function assertMsg_(bool, msg) {
if (!bool) // show only failures to avoid spamming result list
assertMsg(bool, msg);
return bool;
}
debug("");
debug("Canvas.getContext");
var canvas = document.getElementById("canvas");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext(canvas);
var passed = true;
for (var i in constants) {
var r = assertProperty(gl, i) && assertMsg_(gl[i] == constants[i], "Property "+i+" value test "+gl[i]+" == "+constants[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL constants found to have correct values.");
}
passed = true;
for (var i in removedConstants) {
var r = assertNoProperty(gl, i);
passed = passed && r;
}
if (passed) {
testPassed("All constants removed from WebGL spec were absent from WebGL context.");
}
var extended = false;
for (var i in gl) {
if (constants[i] !== undefined) {
// OK; known constant
} else if (ignoredProperties.indexOf(i) != -1) {
// OK; constant that should be ignored because it was added in a later version of the spec
} else if (otherProperties[i] !== undefined &&
(otherProperties[i] == "implementation-dependent" || typeof gl[i] == otherProperties[i])) {
// OK; known property of known type
} else if (typeof gl[i] != "function" && removedConstants[i] === undefined) {
if (!extended) {
extended = true;
testFailed("Also found the following extra properties:");
}
testFailed(i);
}
}
if (!extended) {
testPassed("No extra properties found on WebGL context.");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,131 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<style>
.pattern {
white-space: nowrap;
display: inline-block;
}
canvas {
width:50px;
height:50px;
}
.square {
display:inline-block;
width:50px;
height:50px;
background-color:red;
}
</style>
<script>
"use strict";
var wtu = WebGLTestUtils;
function checkResult(ctx1, ctx2, preserve) {
var imgData1 = ctx1.getImageData(0,0,1,1);
var imgData2 = ctx2.getImageData(0,0,1,1);
var correct1 = [255,0,0,255];
var correct2 = preserve ? [255,0,0,255] : [0,0,0,255];
var ok1 = true;
var ok2 = true;
for (var p = 0; p < 4; ++p) {
if (imgData1.data[p] != correct1[p])
ok1 = false;
if (imgData2.data[p] != correct2[p])
ok2 = false;
}
if (ok1 && ok2)
testPassed('Rendered ok with preserveDrawingBuffer ' + preserve +'.');
else
testFailed('Did not render ok with preserveDrawingBuffer ' + preserve + '.');
if (preserve) {
finishTest()
} else {
runTest(true);
}
}
function runTest(preserve) {
var c1 = document.getElementById('c' + (preserve * 3 + 1));
var c2 = document.getElementById('c' + (preserve * 3 + 2));
var c3 = document.getElementById('c' + (preserve * 3 + 3));
var ctx1 = c1.getContext('2d');
var ctx2 = c2.getContext('2d');
var gl = wtu.create3DContext(c3, { alpha:false, preserveDrawingBuffer:preserve });
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
ctx1.drawImage(c3, 0, 0);
wtu.waitForComposite(function() {
ctx2.drawImage(c3, 0, 0);
checkResult(ctx1, ctx2, preserve);
});
}
</script>
</head>
<body>
<div class="pattern">
<canvas id='c1'></canvas>
<canvas id='c2'></canvas>
<canvas id='c3'></canvas>
</div>
<span>should look like</span>
<div class="pattern">
<div class='square'></div>
<div class='square' style='background-color:black'></div>
<div class='square'></div>
</div>
<hr />
<div class="pattern">
<canvas id='c4'></canvas>
<canvas id='c5'></canvas>
<canvas id='c6'></canvas>
</div>
<span>should look like</span>
<div class="pattern">
<div class='square'></div>
<div class='square'></div>
<div class='square'></div>
</div>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verify that preserveDrawingBuffer attribute is honored.');
runTest(false);
var successfullyParsed = true;
shouldBeTrue("successfullyParsed");
</script>
</body>
</html>

View file

@ -1,356 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.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">
precision mediump float;
varying vec4 color;
void main()
{
gl_FragColor = color;
}
</script>
<script>
"use strict";
// These four declarations need to be global for "shouldBe" to see them
var wtu = WebGLTestUtils;
var gl;
var contextAttribs = null;
var redChannels = [0, 0, 0];
var correctColor = null;
var framebuffer;
var fbHasColor;
var fbHasDepth;
var fbHasStencil;
function init()
{
description('Verify WebGLContextAttributes are working as specified, including alpha, depth, stencil, antialias, but not premultipliedAlpha');
runTest();
}
function getWebGL(canvasWidth, canvasHeight, contextAttribs, clearColor, clearDepth, clearStencil)
{
var canvas = document.createElement("canvas");
if (!canvas)
return null;
canvas.width = canvasWidth;
canvas.height = canvasHeight;
gl = wtu.create3DContext(canvas, contextAttribs);
if (!gl)
return null;
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["pos", "colorIn"]);
if (!program)
return null;
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.STENCIL_TEST);
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
gl.clearDepth(clearDepth);
gl.clearStencil(clearStencil);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.canvas.width, gl.canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
fbHasStencil = false;
fbHasDepth = false;
fbHasColor = gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
if (fbHasColor) {
var depthStencil = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencil);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, gl.canvas.width, gl.canvas.height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencil);
fbHasDepth = gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
if (!fbHasDepth) {
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
} else {
fbHasStencil = true;
}
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
return gl;
}
function drawAndReadPixel(gl, vertices, colors)
{
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);
}
function testDefault()
{
debug("Testing default attributes: { stencil:false }");
shouldBeNonNull("gl = getWebGL(1, 1, null, [ 0, 0, 0, 0 ], 1, 0)");
shouldBeFalse("gl.getContextAttributes().stencil");
shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0");
}
function testAlpha(alpha)
{
debug("Testing alpha = " + alpha);
if (alpha) {
shouldBeNonNull("gl = getWebGL(1, 1, { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
} else {
shouldBeNonNull("gl = getWebGL(1, 1, { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) == 0");
}
shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0");
shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
shouldBeTrue("contextAttribs.alpha == " + alpha);
var correctColor = (contextAttribs.alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, correctColor);
if (fbHasColor) {
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.clearColor(0.5, 0.5, 0.5, 0.5);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [127, 127, 127, 127], undefined, 1);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
}
function testDepth(depth)
{
debug("Testing depth = " + depth);
if (depth) {
shouldBeNonNull("gl = getWebGL(1, 1, { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) >= 16");
} else {
shouldBeNonNull("gl = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
}
shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
gl.depthFunc(gl.NEVER);
var vertices = new Float32Array([
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 Uint8Array([
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255]);
drawAndReadPixel(gl, vertices, colors, 0, 0);
correctColor = (contextAttribs.depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, correctColor);
if (fbHasDepth) {
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
drawAndReadPixel(gl, vertices, colors, 0, 0);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255]);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
}
function testStencilAndDepth(stencil, depth)
{
debug("Testing stencil = " + stencil + ", depth = " + depth);
var creationString =
"gl = getWebGL(1, 1, { depth: " + depth + ", stencil: " + stencil + ", antialias: false }, [ 0, 0, 0, 1 ], 1, 0)";
shouldBeNonNull(creationString);
shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
if (depth)
shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) >= 16");
else
shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
if (stencil)
shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) >= 8");
else
shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0");
shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
if (!depth && contextAttribs.depth) {
testFailed("WebGL implementation provided a depth buffer when it should not have");
}
if (!contextAttribs.depth)
depth = false;
if (!stencil && contextAttribs.stencil) {
testFailed("WebGL implementation provided a stencil buffer when it should not have");
}
if (!contextAttribs.stencil)
stencil = false;
gl.depthFunc(gl.ALWAYS);
gl.stencilFunc(gl.NEVER, 1, 1);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
var vertices = new Float32Array([
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 Uint8Array([
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255]);
drawAndReadPixel(gl, vertices, colors, 0, 0);
correctColor = (stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, correctColor)
if (fbHasStencil) {
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
drawAndReadPixel(gl, vertices, colors, 0, 0);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255]);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
}
function testAntialias(antialias)
{
debug("Testing antialias = " + antialias);
// Both the width and height of canvas are N.
// Note that "N = 2" doesn't work for some post processing AA per the discussion at https://github.com/KhronosGroup/WebGL/pull/1977.
var N = 3;
if (antialias)
shouldBeNonNull("gl = getWebGL(" + N + ", " + N + ", { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0)");
else
shouldBeNonNull("gl = getWebGL(" + N + ", " + N + ", { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
var vertices = new Float32Array([
1.0, 1.0, 0.0,
-1.0, 1.0, 0.0,
-1.0, -1.0, 0.0]);
var colors = new Uint8Array([
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255]);
drawAndReadPixel(gl, vertices, colors, 0, 0);
var buf = new Uint8Array(N * N * 4);
gl.readPixels(0, 0, N, N, gl.RGBA, gl.UNSIGNED_BYTE, buf);
redChannels[0] = buf[4 * (N + 1)]; // (1, 1)
redChannels[1] = buf[4 * N * (N - 1)]; // left top
redChannels[2] = buf[4 * (N - 1)]; // right bottom
shouldBeTrue("redChannels[1] == 255 && redChannels[2] == 0");
shouldBe("redChannels[0] != 255 && redChannels[0] != 0", "contextAttribs.antialias");
}
function runTest()
{
testDefault();
testAlpha(true);
testAlpha(false);
testDepth(true);
testDepth(false);
testStencilAndDepth(true, false);
testStencilAndDepth(false, false);
testStencilAndDepth(true, true);
testStencilAndDepth(false, true);
testAntialias(true);
testAntialias(false);
finishTest();
}
</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,58 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test that contexts are freed and garbage collected reasonably</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
<script src="../../js/tests/iterable-test.js"> </script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description();
var wtu = WebGLTestUtils;
var test = IterableTest.createContextCreationAndDestructionTest();
var iterations = parseInt(wtu.getUrlOptions().iterations, 10) || 50;
IterableTest.run(test, iterations);
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,58 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test that you can create large numbers of WebGL contexts.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
<script src="../../js/tests/iterable-test.js"> </script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description();
var wtu = WebGLTestUtils;
var test = IterableTest.createContextCreationTest();
var iterations = parseInt(wtu.getUrlOptions().iterations, 10) || 50;
IterableTest.run(test, iterations);
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,80 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test that context eviction and garbage collection do not interfere with each other</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
// See http://crbug.com/374086 for original failing case.
description("Test that context eviction and garbage collection do not interfere with each other.");
var wtu = WebGLTestUtils;
var total_iteration = 50;
var array_count = 10;
var bank = [];
for (var i = 0; i < array_count; i++)
bank[i] = [];
for (var iter = 0; iter < total_iteration; ++iter) {
for (var i = 0; i < array_count; i++)
bank[i][iter * i] = iter;
var canvas = document.createElement('canvas');
var gl = wtu.create3DContext(canvas);
canvas.width = 50;
canvas.height = 50;
var program = wtu.setupTexturedQuad(gl);
shouldBeTrue("program != null");
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
var pixel = new Uint8Array([0, 255, 0, 255]);
gl.texImage2D(
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from iteration " + iter);
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,189 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script id='vs' type='x-shader/x-vertex'>
attribute vec2 aPosCoord;
void main(void) {
gl_Position = vec4(aPosCoord, 0.0, 1.0);
}
</script>
<script id='fs' type='x-shader/x-fragment'>
precision mediump float;
void main(void) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
</script>
<script>
"use strict";
var posCoords_arr = new Float32Array(2 * 4);
var posCoords_buff = null;
function DrawQuad(gl, prog, x0, y0, x1, y1) {
gl.useProgram(prog);
if (!posCoords_buff) {
posCoords_buff = gl.createBuffer();
}
gl.bindBuffer(gl.ARRAY_BUFFER, posCoords_buff);
posCoords_arr[0] = x0;
posCoords_arr[1] = y0;
posCoords_arr[2] = x1;
posCoords_arr[3] = y0;
posCoords_arr[4] = x0;
posCoords_arr[5] = y1;
posCoords_arr[6] = x1;
posCoords_arr[7] = y1;
gl.bufferData(gl.ARRAY_BUFFER, posCoords_arr, gl.STREAM_DRAW);
gl.enableVertexAttribArray(prog.aPosCoord);
gl.vertexAttribPointer(prog.aPosCoord, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
function DrawSquare(gl, prog, size) {
DrawQuad(gl, prog, -size, -size, size, size);
}
function Reset(gl) {
gl.canvas.width += 1;
gl.canvas.width -= 1;
}
var iColor;
var pixel;
var dataURL_pre;
var dataURL_post;
function Test(gl, prog, shouldFinish) {
gl.enable(gl.BLEND);
gl.blendFunc(gl.ZERO, gl.DST_ALPHA);
iColor = 64;
var fColor = iColor / 255.0;
//////////////////
debug('clear(R,G,B,0)');
Reset(gl);
gl.clearColor(fColor, fColor, fColor, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT);
dataURL_pre = gl.canvas.toDataURL();
//console.log('Before blending: ' + dataURL_pre);
DrawSquare(gl, prog, 0.7);
WebGLTestUtils.checkCanvasRect(gl, gl.drawingBufferWidth/2,
gl.drawingBufferHeight/2, 1, 1,
[iColor, iColor, iColor, 255],
'Should blend as if alpha is 1.0.');
dataURL_post = gl.canvas.toDataURL();
//console.log('After blending: ' + dataURL_post);
shouldBe("dataURL_post", "dataURL_pre");
//////////////////
debug('mask(R,G,B,0), clear(R,G,B,1)');
Reset(gl);
gl.colorMask(true, true, true, false);
gl.clearColor(fColor, fColor, fColor, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.colorMask(true, true, true, true);
dataURL_pre = gl.canvas.toDataURL();
//console.log('Before blending: ' + dataURL_pre);
DrawSquare(gl, prog, 0.7);
WebGLTestUtils.checkCanvasRect(gl, gl.drawingBufferWidth/2,
gl.drawingBufferHeight/2, 1, 1,
[iColor, iColor, iColor, 255],
'Should blend as if alpha is 1.0.');
dataURL_post = gl.canvas.toDataURL();
//console.log('After blending: ' + dataURL_post);
shouldBe("dataURL_post", "dataURL_pre");
////////////////
WebGLTestUtils.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
if (shouldFinish)
finishTest();
}
var gl;
function init() {
var canvas = document.getElementById('canvas');
var attribs = {
alpha: false,
antialias: false,
premultipliedAlpha: false,
};
gl = canvas.getContext('experimental-webgl', attribs);
shouldBeNonNull(gl);
shouldBe("gl.getParameter(gl.ALPHA_BITS)", "0");
var prog = WebGLTestUtils.setupProgram(gl, ['vs', 'fs']);
shouldBeNonNull(prog);
prog.aPosCoord = gl.getAttribLocation(prog, 'aPosCoord');
Test(gl, prog, false);
requestAnimationFrame(function(){ Test(gl, prog, true); });
}
</script>
</head>
<body onload="init()">
<canvas id='canvas'></canvas>
<br/>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,308 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script>
"use strict";
var wtu = WebGLTestUtils;
var canvas;
var gl;
var shouldGenerateGLError;
var WEBGL_lose_context;
var new_WEBGL_lose_context;
var bufferObjects;
var program;
var texture;
var texColor = [255, 10, 20, 255];
var allowRestore;
var contextLostEventFired;
var contextRestoredEventFired;
var OES_vertex_array_object;
var old_OES_vertex_array_object;
var vertexArrayObject;
var OES_texture_float;
var newExtension;
function init()
{
enableJSTestPreVerboseLogging();
description("Tests behavior under a restored context.");
shouldGenerateGLError = wtu.shouldGenerateGLError;
testLosingContext();
}
function setupTest()
{
canvas = document.createElement("canvas");
canvas.width = 1;
canvas.height = 1;
gl = wtu.create3DContext(canvas);
WEBGL_lose_context = getExtensionAndAddProperty(gl, "WEBGL_lose_context");
if (!WEBGL_lose_context) {
debug("Could not find WEBGL_lose_context extension");
return false;
}
// Try to get a few extensions
OES_vertex_array_object = getExtensionAndAddProperty(gl, "OES_vertex_array_object");
OES_texture_float = getExtensionAndAddProperty(gl, "OES_texture_float");
return true;
}
function getExtensionAndAddProperty(gl, name) {
var ext = wtu.getExtensionWithKnownPrefixes(gl, name);
if (ext) {
ext.webglTestProperty = true;
}
return ext;
}
function reGetExtensionAndTestForProperty(gl, name, expectProperty) {
newExtension = wtu.getExtensionWithKnownPrefixes(gl, name);
// NOTE: while getting a extension after context lost/restored is allowed to fail
// for the purpose the conformance tests it is not.
//
// Hypothetically the user can switch GPUs live. For example on Windows, install 2 GPUs,
// then in the control panen enable 1, disable the others and visa versa. Since the GPUs
// have different capabilities one or the other may not support a particlar extension.
//
// But, for the purpose of the conformance tests the context is expected to restore
// on the same GPU and therefore the extensions that succeeded previously should
// succeed on restore.
shouldBeTrue("newExtension != null");
if (expectProperty) {
shouldBeTrue("newExtension.webglTestProperty === true");
} else {
shouldBeTrue("newExtension.webglTestProperty === undefined");
}
return newExtension;
}
function testLosingContext()
{
if (!setupTest()) {
finishTest();
return;
}
debug("Test losing a context and inability to restore it.");
canvas.addEventListener("webglcontextlost", function(e) {
testLostContext(e);
// restore the context after this event has exited.
setTimeout(function() {
// we didn't call prevent default so we should not be able to restore the context
shouldGenerateGLError(gl, gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()");
testLosingAndRestoringContext();
}, 0);
});
canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext);
allowRestore = false;
contextLostEventFired = false;
contextRestoredEventFired = false;
testOriginalContext();
WEBGL_lose_context.loseContext();
// The context should be lost immediately.
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
shouldBe("gl.getError()", "gl.NO_ERROR");
// gl methods should be no-ops
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
// but the event should not have been fired.
shouldBeFalse("contextLostEventFired");
}
function testLosingAndRestoringContext()
{
if (!setupTest())
finishTest();
debug("");
debug("Test losing and restoring a context.");
canvas.addEventListener("webglcontextlost", function(e) {
testLostContext(e);
// restore the context after this event has exited.
setTimeout(function() {
shouldGenerateGLError(gl, gl.NO_ERROR, "WEBGL_lose_context.restoreContext()");
// The context should still be lost. It will not get restored until the
// webglrestorecontext event is fired.
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.NO_ERROR");
// gl methods should still be no-ops
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
}, 0);
});
canvas.addEventListener("webglcontextrestored", function() {
testRestoredContext();
finishTest();
});
allowRestore = true;
contextLostEventFired = false;
contextRestoredEventFired = false;
testOriginalContext();
WEBGL_lose_context.loseContext();
// The context should be lost immediately.
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
shouldBe("gl.getError()", "gl.NO_ERROR");
// gl methods should be no-ops
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
// but the event should not have been fired.
shouldBeFalse("contextLostEventFired");
}
function testRendering()
{
gl.clearColor(0, 0, 0, 255);
gl.colorMask(1, 1, 1, 0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
program = wtu.setupSimpleTextureProgram(gl);
bufferObjects = wtu.setupUnitQuad(gl);
texture = wtu.createColoredTexture(gl, canvas.width, canvas.height, texColor);
gl.uniform1i(gl.getUniformLocation(program, "tex"), 0);
wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);
var compare = texColor.slice(0, 3);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, compare, "shouldBe " + compare);
shouldBe("gl.getError()", "gl.NO_ERROR");
}
function testOriginalContext()
{
debug("Test valid context");
shouldBeFalse("gl.isContextLost()");
shouldBe("gl.getError()", "gl.NO_ERROR");
testRendering();
debug("");
}
function testLostContext(e)
{
debug("Test lost context");
shouldBeFalse("contextLostEventFired");
contextLostEventFired = true;
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.NO_ERROR");
debug("");
if (allowRestore)
e.preventDefault();
}
function testShouldNotRestoreContext(e)
{
testFailed("Should not restore the context unless preventDefault is called on the context lost event");
debug("");
}
function testResources(expected)
{
var tests = [
"gl.bindTexture(gl.TEXTURE_2D, texture)",
"gl.useProgram(program)",
"gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0])",
];
for (var i = 0; i < tests.length; ++i)
shouldGenerateGLError(gl, expected, tests[i]);
}
function testOESTextureFloat() {
if (OES_texture_float) {
// Extension must still be lost.
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, null)");
// Try re-enabling extension
OES_texture_float = reGetExtensionAndTestForProperty(gl, "OES_texture_float", false);
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, null)");
}
}
function testOESVertexArrayObject() {
if (OES_vertex_array_object) {
// Extension must still be lost.
shouldBeNull("OES_vertex_array_object.createVertexArrayOES()");
// Try re-enabling extension
old_OES_vertex_array_object = OES_vertex_array_object;
OES_vertex_array_object = reGetExtensionAndTestForProperty(gl, "OES_vertex_array_object", false);
shouldBeTrue("OES_vertex_array_object.createVertexArrayOES() != null");
shouldBeTrue("old_OES_vertex_array_object.createVertexArrayOES() == null");
}
}
function testExtensions() {
testOESTextureFloat();
testOESVertexArrayObject();
// Only the WEBGL_lose_context extension should be the same object after context lost.
new_WEBGL_lose_context = reGetExtensionAndTestForProperty(gl, "WEBGL_lose_context", true);
}
function testRestoredContext()
{
debug("Test restored context");
shouldBeFalse("contextRestoredEventFired");
contextRestoredEventFired = true;
shouldBeFalse("gl.isContextLost()");
shouldBe("gl.getError()", "gl.NO_ERROR");
// Validate that using old resources fails.
testResources(gl.INVALID_OPERATION);
testRendering();
// Validate new resources created in testRendering().
testResources(gl.NO_ERROR);
testExtensions();
debug("");
}
</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,376 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script>
"use strict";
var wtu;
var canvas;
var gl;
var shouldGenerateGLError;
var extensionName;
var extension;
var buffer;
var framebuffer;
var program;
var renderbuffer;
var shader;
var texture;
var uniformLocation;
var arrayBuffer;
var arrayBufferView
var image;
var video;
var canvas2d;
var ctx2d;
var imageData;
var float32array;
var int32array;
var OES_vertex_array_object;
var vertexArrayObject;
function init()
{
wtu = WebGLTestUtils;
canvas = document.getElementById("canvas");
gl = wtu.create3DContext(canvas);
shouldGenerateGLError = wtu.shouldGenerateGLError;
description("Tests behavior under a lost context");
// call testValidContext() before checking for the extension, because this is where we check
// for the isContextLost() method, which we want to do regardless of the extension's presence.
testValidContext();
extensionName = wtu.getSupportedExtensionWithKnownPrefixes(gl, "WEBGL_lose_context");
if (!extensionName) {
debug("Could not find WEBGL_lose_context extension");
finishTest();
return false;
}
extension = gl.getExtension(extensionName);
// need an extension that exposes new API methods.
OES_vertex_array_object = wtu.getExtensionWithKnownPrefixes(gl, "OES_vertex_array_object");
canvas.addEventListener("webglcontextlost", testLostContext, false);
// We need to initialize |uniformLocation| before losing context.
// Otherwise gl.getUniform() when context is lost will throw.
uniformLocation = gl.getUniformLocation(program, "tex");
loseContext();
}
function loseContext()
{
debug("");
debug("Lose context");
// Note: this will cause the context to be lost, but the
// webglcontextlost event listener to be queued.
extension.loseContext();
debug("");
}
function testValidContext()
{
debug("Test valid context");
shouldBeFalse("gl.isContextLost()");
arrayBuffer = new ArrayBuffer(4);
arrayBufferView = new Int8Array(arrayBuffer);
// Generate resources for testing.
buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
program = wtu.setupSimpleTextureProgram(gl);
renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
shader = gl.createShader(gl.VERTEX_SHADER);
texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
shouldBe("gl.getError()", "gl.NO_ERROR");
// Test is queries that will later be false
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.enable(gl.BLEND)");
shouldBeTrue("gl.isBuffer(buffer)");
shouldBeTrue("gl.isEnabled(gl.BLEND)");
shouldBeTrue("gl.isFramebuffer(framebuffer)");
shouldBeTrue("gl.isProgram(program)");
shouldBeTrue("gl.isRenderbuffer(renderbuffer)");
shouldBeTrue("gl.isShader(shader)");
shouldBeTrue("gl.isTexture(texture)");
if (OES_vertex_array_object) {
vertexArrayObject = OES_vertex_array_object.createVertexArrayOES();
shouldBe("gl.getError()", "gl.NO_ERROR");
shouldBeTrue("OES_vertex_array_object.isVertexArrayOES(vertexArrayObject)");
}
}
function testGLNOErrorFunctions(tests) {
tests.forEach(function(test) {
shouldGenerateGLError(gl, gl.NO_ERROR, test);
});
}
function testFunctionsThatReturnNULL(tests) {
tests.forEach(function(test) {
shouldBeNull(test);
});
}
function testLostContext()
{
debug("Test lost context");
// Functions with special return values.
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
shouldBe("gl.getError()", "gl.NO_ERROR");
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UNSUPPORTED");
shouldBe("gl.getAttribLocation(program, 'u_modelViewProjMatrix')", "-1");
shouldBe("gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER)", "0");
// Test the extension itself.
shouldGenerateGLError(gl, gl.INVALID_OPERATION, "extension.loseContext()");
image = document.createElement("img");
video = document.createElement("video");
canvas2d = document.createElement("canvas");
ctx2d = canvas2d.getContext("2d");
imageData = ctx2d.createImageData(1, 1);
float32array = new Float32Array(1);
int32array = new Int32Array(1);
// Functions returning void should return immediately.
// This is untestable, but we can at least be sure they cause no errors
// and the codepaths are exercised.
var voidTests = [
"gl.activeTexture(gl.TEXTURE0)",
"gl.attachShader(program, shader)",
"gl.bindBuffer(gl.ARRAY_BUFFER, buffer)",
"gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)",
"gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer)",
"gl.bindTexture(gl.TEXTURE_2D, texture)",
"gl.blendColor(1.0, 1.0, 1.0, 1.0)",
"gl.blendEquation(gl.FUNC_ADD)",
"gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD)",
"gl.blendFunc(gl.ONE, gl.ONE)",
"gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE)",
"gl.bufferData(gl.ARRAY_BUFFER, 0, gl.STATIC_DRAW)",
"gl.bufferData(gl.ARRAY_BUFFER, arrayBufferView, gl.STATIC_DRAW)",
"gl.bufferData(gl.ARRAY_BUFFER, arrayBuffer, gl.STATIC_DRAW)",
"gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBufferView)",
"gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBuffer)",
"gl.clear(gl.COLOR_BUFFER_BIT)",
"gl.clearColor(1, 1, 1, 1)",
"gl.clearDepth(1)",
"gl.clearStencil(0)",
"gl.colorMask(1, 1, 1, 1)",
"gl.compileShader(shader)",
"gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, 0, 0)",
"gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 0, 0)",
"gl.cullFace(gl.FRONT)",
"gl.deleteBuffer(buffer)",
"gl.deleteFramebuffer(framebuffer)",
"gl.deleteProgram(program)",
"gl.deleteRenderbuffer(renderbuffer)",
"gl.deleteShader(shader)",
"gl.deleteTexture(texture)",
"gl.depthFunc(gl.NEVER)",
"gl.depthMask(0)",
"gl.depthRange(0, 1)",
"gl.detachShader(program, shader)",
"gl.disable(gl.BLEND)",
"gl.disableVertexAttribArray(0)",
"gl.drawArrays(gl.POINTS, 0, 0)",
"gl.drawElements(gl.POINTS, 0, gl.UNSIGNED_SHORT, 0)",
"gl.enable(gl.BLEND)",
"gl.enableVertexAttribArray(0)",
"gl.finish()",
"gl.flush()",
"gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer)",
"gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0)",
"gl.frontFace(gl.CW)",
"gl.generateMipmap(gl.TEXTURE_2D)",
"gl.hint(gl.GENERATE_MIPMAP_HINT, gl.FASTEST)",
"gl.lineWidth(0)",
"gl.linkProgram(program)",
"gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0)",
"gl.polygonOffset(0, 0)",
"gl.readPixels(0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0)",
"gl.sampleCoverage(0, 0)",
"gl.scissor(0, 0, 0, 0)",
"gl.shaderSource(shader, '')",
"gl.stencilFunc(gl.NEVER, 0, 0)",
"gl.stencilFuncSeparate(gl.FRONT, gl.NEVER, 0, 0)",
"gl.stencilMask(0)",
"gl.stencilMaskSeparate(gl.FRONT, 0)",
"gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP)",
"gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video)",
"gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
"gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, video)",
"gl.uniform1f(uniformLocation, 0)",
"gl.uniform1fv(uniformLocation, float32array)",
"gl.uniform1fv(uniformLocation, [0])",
"gl.uniform1i(uniformLocation, 0)",
"gl.uniform1iv(uniformLocation, int32array)",
"gl.uniform1iv(uniformLocation, [0])",
"gl.uniform2f(uniformLocation, 0, 0)",
"gl.uniform2fv(uniformLocation, float32array)",
"gl.uniform2fv(uniformLocation, [0, 0])",
"gl.uniform2i(uniformLocation, 0, 0)",
"gl.uniform2iv(uniformLocation, int32array)",
"gl.uniform2iv(uniformLocation, [0, 0])",
"gl.uniform3f(uniformLocation, 0, 0, 0)",
"gl.uniform3fv(uniformLocation, float32array)",
"gl.uniform3fv(uniformLocation, [0, 0, 0])",
"gl.uniform3i(uniformLocation, 0, 0, 0)",
"gl.uniform3iv(uniformLocation, int32array)",
"gl.uniform3iv(uniformLocation, [0, 0, 0])",
"gl.uniform4f(uniformLocation, 0, 0, 0, 0)",
"gl.uniform4fv(uniformLocation, float32array)",
"gl.uniform4fv(uniformLocation, [0, 0, 0, 0])",
"gl.uniform4i(uniformLocation, 0, 0, 0, 0)",
"gl.uniform4iv(uniformLocation, int32array)",
"gl.uniform4iv(uniformLocation, [0, 0, 0, 0])",
"gl.uniformMatrix2fv(uniformLocation, false, float32array)",
"gl.uniformMatrix2fv(uniformLocation, false, [0, 0, 0, 0])",
"gl.uniformMatrix3fv(uniformLocation, false, float32array)",
"gl.uniformMatrix3fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0])",
"gl.uniformMatrix4fv(uniformLocation, false, float32array)",
"gl.uniformMatrix4fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])",
"gl.useProgram(program)",
"gl.validateProgram(program)",
"gl.vertexAttrib1f(0, 0)",
"gl.vertexAttrib1fv(0, float32array)",
"gl.vertexAttrib1fv(0, [0])",
"gl.vertexAttrib2f(0, 0, 0)",
"gl.vertexAttrib2fv(0, float32array)",
"gl.vertexAttrib2fv(0, [0, 0])",
"gl.vertexAttrib3f(0, 0, 0, 0)",
"gl.vertexAttrib3fv(0, float32array)",
"gl.vertexAttrib3fv(0, [0, 0, 0])",
"gl.vertexAttrib4f(0, 0, 0, 0, 0)",
"gl.vertexAttrib4fv(0, float32array)",
"gl.vertexAttrib4fv(0, [0, 0, 0, 0])",
"gl.vertexAttribPointer(0, 0, gl.FLOAT, false, 0, 0)",
"gl.viewport(0, 0, 0, 0)",
];
testGLNOErrorFunctions(voidTests);
// Functions return nullable values should all return null.
var nullTests = [
"gl.createBuffer()",
"gl.createFramebuffer()",
"gl.createProgram()",
"gl.createRenderbuffer()",
"gl.createShader(gl.GL_VERTEX_SHADER)",
"gl.createTexture()",
"gl.getActiveAttrib(program, 0)",
"gl.getActiveUniform(program, 0)",
"gl.getAttachedShaders(program)",
"gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)",
"gl.getContextAttributes()",
"gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)",
"gl.getParameter(gl.CURRENT_PROGRAM)",
"gl.getProgramInfoLog(program)",
"gl.getProgramParameter(program, gl.LINK_STATUS)",
"gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)",
"gl.getShaderInfoLog(shader)",
"gl.getShaderParameter(shader, gl.SHADER_TYPE)",
"gl.getShaderSource(shader)",
"gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)",
"gl.getUniform(program, uniformLocation)",
"gl.getUniformLocation(program, 'vPosition')",
"gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)",
"gl.getSupportedExtensions()",
"gl.getExtension('" + extensionName + "')",
];
testFunctionsThatReturnNULL(nullTests);
// "Is" queries should all return false.
shouldBeFalse("gl.isBuffer(buffer)");
shouldBeFalse("gl.isEnabled(gl.BLEND)");
shouldBeFalse("gl.isFramebuffer(framebuffer)");
shouldBeFalse("gl.isProgram(program)");
shouldBeFalse("gl.isRenderbuffer(renderbuffer)");
shouldBeFalse("gl.isShader(shader)");
shouldBeFalse("gl.isTexture(texture)");
shouldBe("gl.getError()", "gl.NO_ERROR");
// test extensions
if (OES_vertex_array_object) {
testGLNOErrorFunctions(
[
"OES_vertex_array_object.bindVertexArrayOES(vertexArrayObject)",
"OES_vertex_array_object.isVertexArrayOES(vertexArrayObject)",
"OES_vertex_array_object.deleteVertexArrayOES(vertexArrayObject)",
]);
testFunctionsThatReturnNULL(
[
"OES_vertex_array_object.createVertexArrayOES()",
]);
}
debug("");
finishTest();
}
</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas">
</body>
</html>

View file

@ -1,95 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Context Release Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<iframe id="host" style="width: 256px; height: 256px; border: 0;"></iframe>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test ensures that WebGL contexts are released properly upon page reload");
var wtu = WebGLTestUtils;
var host = document.getElementById("host");
var testIterations = 25;
var currentIteration = 0;
function refreshFrame() {
if(currentIteration < testIterations) {
currentIteration++;
debug("");
debug("Test " + currentIteration + " of " + testIterations);
host.src = "resources/context-release-upon-reload-child.html";
} else {
finishTest();
}
}
function testContext() {
var gl = host.contentWindow.glContext;
assertMsg(gl != null, "context was created properly");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
if(gl.canvas.width != gl.drawingBufferWidth ||
gl.canvas.height != gl.drawingBufferHeight) {
testFailed("Buffer was the wrong size: " +
gl.drawingBufferWidth + "x" + gl.drawingBufferHeight);
} else {
testPassed("Buffer was the correct size: " +
gl.drawingBufferWidth + "x" + gl.drawingBufferHeight);
refreshFrame();
}
gl = null;
}
window.addEventListener("message", function(event) {
if(event.data == "Ready") {
testContext();
}
});
refreshFrame();
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,95 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Context Release Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<iframe id="host" style="width: 256px; height: 256px; border: 0;"></iframe>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test ensures that WebGL contexts are released properly when a worker is used");
var wtu = WebGLTestUtils;
var host = document.getElementById("host");
var testIterations = 25;
var currentIteration = 0;
function refreshFrame() {
if(currentIteration < testIterations) {
currentIteration++;
debug("");
debug("Test " + currentIteration + " of " + testIterations);
host.src = "resources/context-release-child-with-worker.html";
} else {
finishTest();
}
}
function testContext() {
var gl = host.contentWindow.glContext;
assertMsg(gl != null, "context was created properly");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
if(gl.canvas.width != gl.drawingBufferWidth ||
gl.canvas.height != gl.drawingBufferHeight) {
testFailed("Buffer was the wrong size: " +
gl.drawingBufferWidth + "x" + gl.drawingBufferHeight);
} else {
testPassed("Buffer was the correct size: " +
gl.drawingBufferWidth + "x" + gl.drawingBufferHeight);
refreshFrame();
}
gl = null;
}
window.addEventListener("message", function(event) {
if(event.data == "Ready") {
testContext();
}
});
refreshFrame();
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,76 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Canvas Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<canvas id="canvas2d" width="40" height="40"> </canvas>
<script>
"use strict";
description("This test ensures WebGL implementations interact correctly with the canvas tag.");
debug("");
debug("Canvas.getContext");
assertMsg(window.WebGLRenderingContext,
"WebGLRenderingContext should be a member of window");
assertMsg('WebGLRenderingContext' in window,
"WebGLRenderingContext should be 'in' window");
assertMsg(Object.getPrototypeOf(WebGLRenderingContext.prototype) === Object.prototype,
"WebGLRenderingContext should only have Object in it's prototype chain");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("Checking context type");
assertMsg(gl instanceof WebGLRenderingContext,
"context type should be WebGLRenderingContext");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,90 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Tests calling WebGL APIs with objects from other contexts");
var wtu = WebGLTestUtils;
var contextA = wtu.create3DContext();
var contextB = wtu.create3DContext();
var programA = wtu.loadStandardProgram(contextA);
var programB = wtu.loadStandardProgram(contextB);
var shaderA = wtu.loadStandardVertexShader(contextA);
var shaderB = wtu.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');
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.compileShader(shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.linkProgram(programB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programA, shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderA)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programA, shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderA)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.shaderSource(shaderB, 'foo')");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindAttribLocation(programB, 0, 'foo')");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindFramebuffer(contextA.FRAMEBUFFER, frameBufferB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindRenderbuffer(contextA.RENDERBUFFER, renderBufferB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindTexture(contextA.TEXTURE_2D, textureB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferRenderbuffer(contextA.FRAMEBUFFER, contextA.DEPTH_ATTACHMENT, contextA.RENDERBUFFER, renderBufferB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferTexture2D(contextA.FRAMEBUFFER, contextA.COLOR_ATTACHMENT0, contextA.TEXTURE_2D, textureB, 0)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramParameter(programB, 0)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramInfoLog(programB, 0)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderParameter(shaderB, 0)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderInfoLog(shaderB, 0)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderSource(shaderB)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniform(programB, locationA)");
wtu.shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniformLocation(programB, 'u_modelViewProjMatrix')");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,241 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Methods Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<script>
"use strict";
description("This test ensures that the WebGL context has all the methods in the specification.");
var methods = [
"getContextAttributes",
"activeTexture",
"attachShader",
"bindAttribLocation",
"bindBuffer",
"bindFramebuffer",
"bindRenderbuffer",
"bindTexture",
"blendColor",
"blendEquation",
"blendEquationSeparate",
"blendFunc",
"blendFuncSeparate",
"bufferData",
"bufferSubData",
"checkFramebufferStatus",
"clear",
"clearColor",
"clearDepth",
"clearStencil",
"colorMask",
"compileShader",
"compressedTexImage2D",
"compressedTexSubImage2D",
"copyTexImage2D",
"copyTexSubImage2D",
"createBuffer",
"createFramebuffer",
"createProgram",
"createRenderbuffer",
"createShader",
"createTexture",
"cullFace",
"deleteBuffer",
"deleteFramebuffer",
"deleteProgram",
"deleteRenderbuffer",
"deleteShader",
"deleteTexture",
"depthFunc",
"depthMask",
"depthRange",
"detachShader",
"disable",
"disableVertexAttribArray",
"drawArrays",
"drawElements",
"enable",
"enableVertexAttribArray",
"finish",
"flush",
"framebufferRenderbuffer",
"framebufferTexture2D",
"frontFace",
"generateMipmap",
"getActiveAttrib",
"getActiveUniform",
"getAttachedShaders",
"getAttribLocation",
"getParameter",
"getBufferParameter",
"getError",
"getExtension",
"getFramebufferAttachmentParameter",
"getProgramParameter",
"getProgramInfoLog",
"getRenderbufferParameter",
"getShaderParameter",
"getShaderInfoLog",
"getShaderPrecisionFormat",
"getShaderSource",
"getSupportedExtensions",
"getTexParameter",
"getUniform",
"getUniformLocation",
"getVertexAttrib",
"getVertexAttribOffset",
"hint",
"isBuffer",
"isContextLost",
"isEnabled",
"isFramebuffer",
"isProgram",
"isRenderbuffer",
"isShader",
"isTexture",
"lineWidth",
"linkProgram",
"pixelStorei",
"polygonOffset",
"readPixels",
"renderbufferStorage",
"sampleCoverage",
"scissor",
"shaderSource",
"stencilFunc",
"stencilFuncSeparate",
"stencilMask",
"stencilMaskSeparate",
"stencilOp",
"stencilOpSeparate",
"texImage2D",
"texParameterf",
"texParameteri",
"texSubImage2D",
"uniform1f",
"uniform1fv",
"uniform1i",
"uniform1iv",
"uniform2f",
"uniform2fv",
"uniform2i",
"uniform2iv",
"uniform3f",
"uniform3fv",
"uniform3i",
"uniform3iv",
"uniform4f",
"uniform4fv",
"uniform4i",
"uniform4iv",
"uniformMatrix2fv",
"uniformMatrix3fv",
"uniformMatrix4fv",
"useProgram",
"validateProgram",
"vertexAttrib1f",
"vertexAttrib1fv",
"vertexAttrib2f",
"vertexAttrib2fv",
"vertexAttrib3f",
"vertexAttrib3fv",
"vertexAttrib4f",
"vertexAttrib4fv",
"vertexAttribPointer",
"viewport"
];
// Properties to be ignored because they were added in versions of the
// spec that are backward-compatible with this version
var ignoredMethods = [
// There is no official spec for the commit API yet, the proposal link is:
// https://wiki.whatwg.org/wiki/OffscreenCanvas
"commit"
];
function assertFunction(v, f) {
try {
if (typeof v[f] != "function") {
testFailed("Property either does not exist or is not a function: " + f);
return false;
} else {
return true;
}
} catch(e) {
testFailed("Trying to access the property '" + f + "' threw an error: "+e.toString());
}
}
debug("");
debug("Canvas.getContext");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var passed = true;
for (var i=0; i<methods.length; i++) {
var r = assertFunction(gl, methods[i]);
passed = passed && r;
}
if (passed) {
testPassed("All WebGL methods found.");
}
var extended = false;
for (var i in gl) {
if (typeof gl[i] == "function" && methods.indexOf(i) == -1 && ignoredMethods.indexOf(i) == -1) {
if (!extended) {
extended = true;
testFailed("Also found the following extra methods:");
}
testFailed(i);
}
}
if (!extended) {
testPassed("No extra methods found on WebGL context.");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,268 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test the WebGL premultipliedAlpha context creation flag.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<div id="description"></div><div id="console"></div>
<script>
"use strict";
var wtu = WebGLTestUtils;
// wtu.create3DContext(...) will set antialias to false by default
// if the antialias property is not set to true explicitly.
// To cover the antialias case, it needs to set antialias to true
// explicitly.
var tests = [
// If premultipliedAlpha is true and antialias is false then
// [texture] [canvas] [dataURL]
// 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
{ creationAttributes: {},
sentColor: [32, 64, 128, 128],
expectedColor: [64, 128, 255, 128],
errorRange: 2,
imageFormat: "image/png"
},
// If premultipliedAlpha is true and antialias is true then
// [texture] [canvas] [dataURL]
// 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
{ creationAttributes: {antialias: true},
sentColor: [32, 64, 128, 128],
expectedColor: [64, 128, 255, 128],
errorRange: 2,
imageFormat: "image/png"
},
// If premultipliedAlpha is true and antialias is false then
// [texture] [canvas] [texture]
// 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
{ creationAttributes: {},
sentColor: [32, 64, 128, 128],
expectedColor: [64, 128, 255, 128],
errorRange: 2,
},
// If premultipliedAlpha is true and antialias is true then
// [texture] [canvas] [texture]
// 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128
{ creationAttributes: {antialias: true},
sentColor: [32, 64, 128, 128],
expectedColor: [64, 128, 255, 128],
errorRange: 2,
},
// If premultipliedAlpha is false and antialias is false then
// [texture] [canvas] [dataURL]
// 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
{ creationAttributes: {premultipliedAlpha: false},
sentColor: [255, 192, 128, 1],
expectedColor: [255, 192, 128, 1],
errorRange: 0,
imageFormat: "image/png"
},
// If premultipliedAlpha is false and antialias is true then
// [texture] [canvas] [dataURL]
// 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
{ creationAttributes: {premultipliedAlpha: false, antialias: true},
sentColor: [255, 192, 128, 1],
expectedColor: [255, 192, 128, 1],
errorRange: 0,
imageFormat: "image/png"
},
// If premultipliedAlpha is false and antialias is false then
// [texture] [canvas] [texture]
// 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
{ creationAttributes: {premultipliedAlpha: false},
sentColor: [255, 192, 128, 1],
expectedColor: [255, 192, 128, 1],
errorRange: 0,
},
// If premultipliedAlpha is false and antialias is true then
// [texture] [canvas] [texture]
// 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1
{ creationAttributes: {premultipliedAlpha: false, antialias: true},
sentColor: [255, 192, 128, 1],
expectedColor: [255, 192, 128, 1],
errorRange: 0,
},
// If premultipliedAlpha is false and antialias is false then
// [texture] [canvas] [dataURL]
// 255, 255, 255, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
{ creationAttributes: {premultipliedAlpha: false},
sentColor: [255, 255, 255, 128],
expectedColor: [128, 128, 128, 255],
errorRange: 2,
imageFormat: "image/jpeg"
},
// If premultipliedAlpha is false and antialias is true then
// [texture] [canvas] [dataURL]
// 255, 255, 255, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
{ creationAttributes: {premultipliedAlpha: false, antialias: true},
sentColor: [255, 255, 255, 128],
expectedColor: [128, 128, 128, 255],
errorRange: 2,
imageFormat: "image/jpeg"
},
// If premultipliedAlpha is true and antialias is false then
// [texture] [canvas] [dataURL]
// 128, 128, 128, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
{ creationAttributes: {},
sentColor: [128, 128, 128, 128],
expectedColor: [128, 128, 128, 255],
errorRange: 2,
imageFormat: "image/jpeg"
},
// If premultipliedAlpha is true and antialias is true then
// [texture] [canvas] [dataURL]
// 128, 128, 128, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255
{ creationAttributes: {antialias: true},
sentColor: [128, 128, 128, 128],
expectedColor: [128, 128, 128, 255],
errorRange: 2,
imageFormat: "image/jpeg"
}
];
var g_count = 0;
var gl;
var canvas;
var premultipliedAlpha;
enableJSTestPreVerboseLogging();
description("Test the WebGL premultipliedAlpha context creation flag.");
doNextTest();
function doNextTest() {
if (g_count < tests.length) {
var test = tests[g_count++];
canvas = document.createElement("canvas");
// Need to preserve drawing buffer to load it in a callback
test.creationAttributes.preserveDrawingBuffer = true;
gl = wtu.create3DContext(canvas, test.creationAttributes);
var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != false;
var antialias = test.creationAttributes.antialias == true;
debug("")
debug("testing: premultipliedAlpha: " + premultipliedAlpha
+ ", antialias: " + antialias
+ ", imageFormat: " + test.imageFormat);
shouldBe('gl.getContextAttributes().premultipliedAlpha', premultipliedAlpha.toString());
shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer');
wtu.log(gl.getContextAttributes());
var program = wtu.setupTexturedQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
var tex = gl.createTexture();
wtu.fillTexture(gl, tex, 2, 2, test.sentColor, 0);
var loc = gl.getUniformLocation(program, "tex");
gl.uniform1i(loc, 0);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
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);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from drawing.");
var loadTexture = function() {
debug("loadTexture called");
var pngTex = gl.createTexture();
// not needed as it's the default
// gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
wtu.failIfGLError(gl, 'gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);');
gl.bindTexture(gl.TEXTURE_2D, pngTex);
if (test.imageFormat) {
// create texture from image
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this);
} else {
// create texture from canvas
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
}
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
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);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from creating copy.");
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from 2nd drawing.");
wtu.checkCanvas(
gl, test.expectedColor,
"should draw with " + test.expectedColor, test.errorRange);
doNextTest();
}
var loadTextureError = function() {
testFailed("Creating image from canvas failed. Image src: " + this.src);
finishTest();
}
var shrinkString = function(string) {
if (string.length < 63) {
return string;
}
return string.substr(0, 30) + "..." + string.substr(string.length - 30);
}
if (test.imageFormat) {
// Load canvas into string using toDataURL
debug("Calling canvas.toDataURL('" + test.imageFormat + "')");
var imageUrl = canvas.toDataURL(test.imageFormat);
debug("imageUrl = '" + shrinkString(imageUrl) + "'");
if (test.imageFormat != "image/png" &&
(imageUrl.indexOf("data:image/png,") == 0 ||
imageUrl.indexOf("data:image/png;") == 0)) {
debug("Image format " + test.imageFormat + " not supported; skipping");
setTimeout(doNextTest, 0);
} else {
// Load string into the texture
debug("Waiting for image.onload");
var input = wtu.makeImage(imageUrl, loadTexture, loadTextureError);
}
} else {
// Load canvas into the texture asynchronously (to prevent unbounded stack consumption)
debug("Waiting for setTimeout");
setTimeout(loadTexture, 0);
}
} else {
var successfullyParsed = true;
finishTest();
}
}
</script>
</body>
</html>

View file

@ -1,66 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Resource Sharing.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example1" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
<canvas id="example2" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Tests that resources can not be shared.");
debug("");
var wtu = WebGLTestUtils;
var gl1 = wtu.create3DContext("example1");
var gl2 = wtu.create3DContext("example2");
assertMsg(gl1 && gl2,
"Got 3d context.");
var vertexObject = gl1.createBuffer();
gl2.bindBuffer(gl2.ARRAY_BUFFER, vertexObject);
assertMsg(
gl2.getError() == gl2.INVALID_OPERATION,
"attempt to use a resource from the wrong context should fail with INVALID_OPERATION");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,76 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html style="margin: 0; padding: 0;">
<head>
<meta charset="utf-8">
<title>Simple WebGL context with Worker</title>
<script src="../../../js/webgl-test-utils.js"> </script>
</head>
<body style="margin: 0; padding: 0; overflow: hidden;">
<canvas id="c" width="1680" height="1050" style="width: 256px; height: 256px;"> <!-- scaled to fit page better -->
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script>
"use strict";
var wtu = WebGLTestUtils;
var myWorker = new Worker("context-release-worker.js");
var gl = wtu.create3DContext("c", { antialias: false });
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.75,0, -0.75,-0.75,0, 0.75,-0.75,0 ]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 3);
if (parent) {
window.glContext = gl;
parent.postMessage("Ready", "*");
}
</script>
</body>
</html>

View file

@ -1,75 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html style="margin: 0; padding: 0;">
<head>
<meta charset="utf-8">
<title>Simple WebGL context</title>
<script src="../../../js/webgl-test-utils.js"> </script>
</head>
<body style="margin: 0; padding: 0; overflow: hidden;">
<canvas id="c" width="1680" height="1050" style="width: 256px; height: 256px;"> <!-- scaled to fit page better -->
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script>
"use strict";
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("c", { antialias: false });
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.75,0, -0.75,-0.75,0, 0.75,-0.75,0 ]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 3);
if (parent) {
window.glContext = gl;
parent.postMessage("Ready", "*");
}
</script>
</body>
</html>

View file

@ -1,4 +0,0 @@
// Simple worker used to provoke WebGL context release bugs on Chrome
postMessage("Hello World");
close();

View file

@ -1,39 +0,0 @@
--min-version 1.0.3 --max-version 1.9.9 angle-instanced-arrays.html
--min-version 1.0.3 --max-version 1.9.9 angle-instanced-arrays-out-of-bounds.html
--min-version 1.0.3 --max-version 1.9.9 ext-blend-minmax.html
--min-version 1.0.4 ext-disjoint-timer-query.html
--min-version 1.0.3 --max-version 1.9.9 ext-frag-depth.html
--min-version 1.0.3 --max-version 1.9.9 ext-shader-texture-lod.html
--min-version 1.0.3 --max-version 1.9.9 ext-sRGB.html
--min-version 1.0.2 ext-texture-filter-anisotropic.html
--min-version 1.0.2 get-extension.html
--max-version 1.9.9 oes-standard-derivatives.html
--max-version 1.9.9 oes-texture-float-with-canvas.html
--max-version 1.9.9 oes-texture-float-with-image-data.html
--max-version 1.9.9 oes-texture-float-with-image.html
--max-version 1.9.9 oes-texture-float-with-video.html
--max-version 1.9.9 oes-texture-float.html
--max-version 1.9.9 oes-vertex-array-object.html
--min-version 1.0.3 --max-version 1.9.9 oes-vertex-array-object-bufferData.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float.html
--min-version 1.0.3 oes-texture-float-linear.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float-linear.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float-with-canvas.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float-with-image-data.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float-with-image.html
--min-version 1.0.3 --max-version 1.9.9 oes-texture-half-float-with-video.html
--min-version 1.0.2 --max-version 1.9.9 oes-element-index-uint.html
webgl-debug-renderer-info.html
webgl-debug-shaders.html
//--min-version 1.0.3 webgl-compressed-texture-atc.html // Removed for WebGL 2.0.0
--min-version 1.0.4 webgl-compressed-texture-etc.html
--min-version 1.0.3 webgl-compressed-texture-pvrtc.html
--min-version 1.0.2 webgl-compressed-texture-s3tc.html
--min-version 1.0.4 webgl-compressed-texture-s3tc-srgb.html
--min-version 1.0.3 webgl-compressed-texture-size-limit.html
--min-version 1.0.2 --max-version 1.9.9 webgl-depth-texture.html
--min-version 1.0.3 --max-version 1.9.9 webgl-draw-buffers.html
--min-version 1.0.4 --max-version 1.9.9 webgl-draw-buffers-framebuffer-unsupported.html
--min-version 1.0.4 --max-version 1.9.9 webgl-draw-buffers-max-draw-buffers.html
--min-version 1.0.3 webgl-shared-resources.html

View file

@ -1,79 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/out-of-bounds-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Test of drawArraysInstancedANGLE and drawElementsInstancedANGLE with out-of-bounds parameters");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();
var ext = wtu.getExtensionWithKnownPrefixes(gl, "ANGLE_instanced_arrays");
if (!ext) {
testPassed("No ANGLE_instanced_arrays support -- this is legal");
} else {
testPassed("Successfully enabled ANGLE_instanced_arrays extension");
debug("");
debug("Test with 1 instance without instanced attributes");
debug("");
OutOfBoundsTest.runDrawArraysTest("ext.drawArraysInstancedANGLE(gl.TRIANGLES, $(offset), $(count), 1)", gl, wtu, ext);
debug("");
OutOfBoundsTest.runDrawElementsTest("ext.drawElementsInstancedANGLE(gl.TRIANGLES, $(count), $(type), $(offset), 1)", gl, wtu, ext);
debug("");
debug("Test with 2 instances without instanced attributes");
debug("");
OutOfBoundsTest.runDrawArraysTest("ext.drawArraysInstancedANGLE(gl.TRIANGLES, $(offset), $(count), 2)", gl, wtu, ext);
debug("");
OutOfBoundsTest.runDrawElementsTest("ext.drawElementsInstancedANGLE(gl.TRIANGLES, $(count), $(type), $(offset), 2)", gl, wtu, ext);
debug("");
OutOfBoundsTest.runDrawArraysInstancedTest("ext.drawArraysInstancedANGLE(gl.TRIANGLES, $(offset), $(count), $(primcount))", gl, wtu, ext);
debug("");
OutOfBoundsTest.runDrawElementsInstancedTest("ext.drawElementsInstancedANGLE(gl.TRIANGLES, $(count), $(type), $(offset), $(primcount))", gl, wtu, ext);
debug("");
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,654 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL ANGLE_instanced_arrays Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/desktop-gl-constants.js"></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing instanced draws -->
<script id="outputVertexShader" type="x-shader/x-vertex">
attribute vec4 aPosition;
attribute vec2 aOffset;
attribute vec4 aColor;
varying vec4 vColor;
void main() {
vColor = aColor;
gl_Position = aPosition + vec4(aOffset, 0.0, 0.0);
}
</script>
<script id="outputFragmentShader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 vColor;
void main() {
gl_FragColor = vColor;
}
</script>
<script id="drawArraysTestVertexShader" type="x-shader/x-vertex">
attribute vec3 aPosition;
attribute vec3 aInstancePos;
uniform vec3 uOffset;
void main() {
gl_Position = vec4(aPosition.xyz + aInstancePos.xyz + uOffset, 1.0);
}
</script>
<script id="drawArraysTestFragmentShader" type="x-shader/x-fragment">
void main() {
gl_FragColor = vec4(1.0, 0, 0, 1.0);
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the ANGLE_instanced_arrays extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
var vaoext = null;
var positionLoc = 0;
var offsetLoc = 2;
var colorLoc = 3;
var program;
if (!gl) {
testFailed("WebGL context does not exist");
finishTest();
} else {
testPassed("WebGL context exists");
runDivisorTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "ANGLE_instanced_arrays");
if (!ext) {
testPassed("No ANGLE_instanced_arrays support -- this is legal");
runSupportedTest(false);
finishTest();
} else {
testPassed("Successfully enabled ANGLE_instanced_arrays extension");
runSupportedTest(true);
runDivisorTestEnabled();
runUniqueObjectTest();
setupCanvas();
runOutputTests();
runDrawArraysWithOffsetTest();
runVAOInstancingInteractionTest();
runANGLECorruptionTest();
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("ANGLE_instanced_arrays") >= 0) {
if (extensionEnabled) {
testPassed("ANGLE_instanced_arrays listed as supported and getExtension succeeded");
} else {
testFailed("ANGLE_instanced_arrays listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("ANGLE_instanced_arrays not listed as supported but getExtension succeeded");
} else {
testPassed("ANGLE_instanced_arrays not listed as supported and getExtension failed -- this is legal");
}
}
}
function runDivisorTestDisabled() {
debug("Testing VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE with extension disabled");
var VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE;
gl.getVertexAttrib(0, VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE should not be queryable if extension is disabled");
}
function runDivisorTestEnabled() {
debug("Testing VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE with extension enabled");
shouldBe("ext.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE", "0x88FE");
var max_vertex_attribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
for (var i = 0; i < max_vertex_attribs; ++i) {
var queried_value = gl.getVertexAttrib(i, ext.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
if(queried_value == 0){
testPassed("Vertex attribute " + i + " must has a default divisor of 0");
}
else{
testFailed("Default divisor of vertex attribute " + i + " should be: 0, returned value was: " + queried_value);
}
}
ext.vertexAttribDivisorANGLE(max_vertex_attribs, 2);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "vertexAttribDivisorANGLE index set greater than or equal to MAX_VERTEX_ATTRIBS should be an invalid value");
ext.vertexAttribDivisorANGLE(max_vertex_attribs-1, 2);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "vertexAttribDivisorANGLE index set less than MAX_VERTEX_ATTRIBS should succeed");
var queried_value = gl.getVertexAttrib(max_vertex_attribs-1, ext.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
if(queried_value == 2){
testPassed("Set value of VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE matches expecation");
}
else{
testFailed("Set value of VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE should be: 2, returned value was: " + queried_value);
}
}
function setupCanvas() {
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 0);
program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['aPosition', 'aOffset', 'aColor'], [positionLoc, offsetLoc, colorLoc]);
ext = gl.getExtension("ANGLE_instanced_arrays");
}
function runOutputTests() {
var instanceCount = 4;
debug("Testing various draws for valid built-in function behavior");
var offsets = new Float32Array([
-1.0, 1.0,
1.0, 1.0,
-1.0, -1.0,
1.0, -1.0,
]);
var offsetBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer);
gl.bufferData(gl.ARRAY_BUFFER, offsets, gl.STATIC_DRAW);
gl.enableVertexAttribArray(offsetLoc);
gl.vertexAttribPointer(offsetLoc, 2, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(offsetLoc, 1);
var colors = new Float32Array([
1.0, 0.0, 0.0, 1.0, // Red
0.0, 1.0, 0.0, 1.0, // Green
0.0, 0.0, 1.0, 1.0, // Blue
1.0, 1.0, 0.0, 1.0, // Yellow
]);
var colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(colorLoc, 1);
wtu.setupUnitQuad(gl, 0);
// Draw 1: Regular drawArrays
debug("");
debug("Testing drawArrays with non-zero divisor");
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "vertex attrib divisor should affect regular drawArrays when the extension is enabled");
wtu.checkCanvasRect(gl, 0, canvas.height/2, canvas.width/2, canvas.height/2, [255, 0, 0, 255]);
// Draw 2: Draw Non-indexed instances
debug("");
debug("Testing drawArraysInstancedANGLE");
gl.clear(gl.COLOR_BUFFER_BIT);
// Test drawArraysInstancedANGLE error conditions
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, instanceCount);
wtu.checkCanvasRect(gl, 0, canvas.height/2, canvas.width/2, canvas.height/2, [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, canvas.width/2, canvas.height/2, canvas.width/2, canvas.height/2, [0, 255, 0, 255]);
wtu.checkCanvasRect(gl, 0, 0, canvas.width/2, canvas.height/2, [0, 0, 255, 255]);
wtu.checkCanvasRect(gl, canvas.width/2, 0, canvas.width/2, canvas.height/2, [255, 255, 0, 255]);
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, -1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "drawArraysInstancedANGLE cannot have a primcount less than 0");
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, -1, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "drawArraysInstancedANGLE cannot have a count less than 0");
ext.vertexAttribDivisorANGLE(positionLoc, 1);
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "There must be at least one vertex attribute with a divisor of zero when calling drawArraysInstancedANGLE");
ext.vertexAttribDivisorANGLE(positionLoc, 0);
ext.drawArraysInstancedANGLE(gl.POINTS, 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawArraysInstancedANGLE with POINTS should succeed");
ext.drawArraysInstancedANGLE(gl.LINES, 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawArraysInstancedANGLE with LINES should succeed");
ext.drawArraysInstancedANGLE(gl.LINE_LIST, 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawArraysInstancedANGLE with LINE_LIST should return succeed");
ext.drawArraysInstancedANGLE(gl.TRIANGLE_LIST, 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawArraysInstancedANGLE with TRIANGLE_LIST should succeed");
ext.drawArraysInstancedANGLE(desktopGL['QUAD_STRIP'], 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawArraysInstancedANGLE with QUAD_STRIP should return INVALID_ENUM");
ext.drawArraysInstancedANGLE(desktopGL['QUADS'], 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawArraysInstancedANGLE with QUADS should return INVALID_ENUM");
ext.drawArraysInstancedANGLE(desktopGL['POLYGON'], 0, 6, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawArraysInstancedANGLE with POLYGON should return INVALID_ENUM");
debug("");
debug("Testing drawArraysInstancedANGLE with param 'first' > 0");
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.setupQuad(gl, {
positionLocation: 0,
scale: 0.5
});
var offsetsHalf = new Float32Array([
-0.5, 0.5,
0.5, 0.5,
-0.5, -0.5,
0.5, -0.5
]);
gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer);
gl.bufferData(gl.ARRAY_BUFFER, offsetsHalf, gl.STATIC_DRAW);
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 3, 3, instanceCount);
var w = Math.floor(0.25*canvas.width),
h = Math.floor(0.25*canvas.height);
wtu.checkCanvasRect(gl, Math.ceil(0.25*canvas.width), 0.5*canvas.height, w, h, [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, Math.ceil(0.75*canvas.width), 0.5*canvas.height, w, h, [0, 255, 0, 255]);
wtu.checkCanvasRect(gl, Math.ceil(0.25*canvas.width), 0, w, h, [0, 0, 255, 255]);
wtu.checkCanvasRect(gl, Math.ceil(0.75*canvas.width), 0, w, h, [255, 255, 0, 255]);
wtu.setupUnitQuad(gl, 0);
wtu.setupIndexedQuad(gl, 1, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer);
gl.bufferData(gl.ARRAY_BUFFER, offsets, gl.STATIC_DRAW);
// Draw 3: Regular drawElements
debug("");
debug("Testing drawElements with non-zero divisor");
gl.clear(gl.COLOR_BUFFER_BIT);
// Point to another location in the buffer so that the draw would overflow without the divisor
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 48);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "vertex attrib divisor should affect regular drawElements when the extension is enabled");
wtu.checkCanvasRect(gl, 0, canvas.height/2, canvas.width/2, canvas.height/2, [255, 255, 0, 255]);
// Restore the vertex attrib pointer
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
// Draw 4: Draw indexed instances
debug("");
debug("Testing drawElementsInstancedANGLE");
gl.clear(gl.COLOR_BUFFER_BIT);
ext.drawElementsInstancedANGLE(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.checkCanvasRect(gl, 0, canvas.height/2, canvas.width/2, canvas.height/2, [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, canvas.width/2, canvas.height/2, canvas.width/2, canvas.height/2, [0, 255, 0, 255]);
wtu.checkCanvasRect(gl, 0, 0, canvas.width/2, canvas.height/2, [0, 0, 255, 255]);
wtu.checkCanvasRect(gl, canvas.width/2, 0, canvas.width/2, canvas.height/2, [255, 255, 0, 255]);
// Test drawElementsInstancedANGLE error conditions
ext.drawElementsInstancedANGLE(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0, -1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "drawElementsInstancedANGLE cannot have a primcount less than 0");
ext.drawElementsInstancedANGLE(gl.TRIANGLES, -1, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "drawElementsInstancedANGLE cannot have a count less than 0");
ext.vertexAttribDivisorANGLE(positionLoc, 1);
ext.drawElementsInstancedANGLE(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "There must be at least one vertex attribute with a divisor of zero when calling drawElementsInstancedANGLE");
ext.vertexAttribDivisorANGLE(positionLoc, 0);
ext.drawElementsInstancedANGLE(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawElementsInstancedANGLE with UNSIGNED_BYTE should succeed");
ext.drawElementsInstancedANGLE(gl.POINTS, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawElementsInstancedANGLE with POINTS should succeed");
ext.drawElementsInstancedANGLE(gl.LINES, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawElementsInstancedANGLE with LINES should succeed");
ext.drawElementsInstancedANGLE(gl.LINE_LIST, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawElementsInstancedANGLE with LINE_LIST should return succeed");
ext.drawElementsInstancedANGLE(gl.TRIANGLE_LIST, 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawElementsInstancedANGLE with TRIANGLE_LIST should succeed");
ext.drawElementsInstancedANGLE(desktopGL['QUAD_STRIP'], 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawElementsInstancedANGLE with QUAD_STRIP should return INVALID_ENUM");
ext.drawElementsInstancedANGLE(desktopGL['QUADS'], 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawElementsInstancedANGLE with QUADS should return INVALID_ENUM");
ext.drawElementsInstancedANGLE(desktopGL['POLYGON'], 6, gl.UNSIGNED_SHORT, 0, instanceCount);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "drawElementsInstancedANGLE with POLYGON should return INVALID_ENUM");
}
function runDrawArraysTest(program, first, count, instanceCount, offset)
{
// Get the attribute and uniform locations
var positionLoc = gl.getAttribLocation(program, "aPosition");
var instancePosLoc = gl.getAttribLocation(program, "aInstancePos");
var uniformLoc = gl.getUniformLocation(program, "uOffset");
// Load the vertex positions
var positions = new Float32Array([
-1, -1,
-1, 0,
0, 0,
0, 0,
0, -1,
-1, -1,
1, -1,
1, 0,
0, 0,
0, 0,
0, -1,
1, -1,
]);
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
gl.enableVertexAttribArray(positionLoc);
gl.vertexAttribPointer(positionLoc, 2, gl.FLOAT, false, 0, 0);
// Load the instance positions
var instancePositions = new Float32Array([
0, 0,
1, 0
]);
var instancePositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, instancePositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, instancePositions, gl.STATIC_DRAW);
gl.enableVertexAttribArray(instancePosLoc);
gl.vertexAttribPointer(instancePosLoc, 2, gl.FLOAT, false, 0, 0);
// Enable instancing
ext.vertexAttribDivisorANGLE(instancePosLoc, 1);
// Offset
gl.uniform3fv(uniformLoc, offset);
// Do the instanced draw
ext.drawArraysInstancedANGLE(gl.TRIANGLES, first, count, instanceCount);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawArraysInstancedANGLE should succeed");
}
function runDrawArraysWithOffsetTest()
{
debug("");
debug("Testing that the 'first' parameter to drawArraysInstancedANGLE is only an offset into the non-instanced vertex attributes.");
// See: http://crbug.com/457269 and http://crbug.com/447140
var drawArraysProgram = wtu.setupProgram(gl, ["drawArraysTestVertexShader", "drawArraysTestFragmentShader"]);
gl.clear(gl.COLOR_BUFFER_BIT);
runDrawArraysTest(drawArraysProgram, 0, 6, 2, [0, 0, 0]);
runDrawArraysTest(drawArraysProgram, 6, 6, 2, [-1, 1, 0]);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255]);
}
function runUniqueObjectTest()
{
debug("");
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("ANGLE_instanced_arrays").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("ANGLE_instanced_arrays").myProperty', '2');
}
function runVAOInstancingInteractionTest()
{
debug("")
debug("Testing that ANGLE_instanced_arrays interacts correctly with OES_vertex_array_object if present");
// See: https://github.com/KhronosGroup/WebGL/issues/1228
// Query the extension and store globally so shouldBe can access it
vaoext = gl.getExtension("OES_vertex_array_object");
if (!vaoext) {
testPassed("No OES_vertex_array_object support -- this is legal");
return;
}
testPassed("Successfully enabled OES_vertex_array_object extension");
gl.useProgram(program);
var positions = new Float32Array([
0.0, 1.0, // Left quad
-1.0, 1.0,
-1.0, -1.0,
0.0, 1.0,
-1.0, -1.0,
0.0, -1.0,
1.0, 1.0, // Right quad
0.0, 1.0,
0.0, -1.0,
1.0, 1.0,
0.0, -1.0,
1.0, -1.0
]);
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
var colors = new Float32Array([
1.0, 0.0, 0.0, 1.0, // Red
1.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, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
0.0, 0.0, 1.0, 1.0, // Blue
0.0, 0.0, 1.0, 1.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,
0.0, 0.0, 1.0, 1.0,
]);
var colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
// Reset the divisor of the default VAO to 0
ext.vertexAttribDivisorANGLE(colorLoc, 0);
// Set up VAO with an attrib divisor
var vao1 = vaoext.createVertexArrayOES();
vaoext.bindVertexArrayOES(vao1);
{
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.enableVertexAttribArray(positionLoc);
gl.vertexAttribPointer(positionLoc, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(colorLoc, 1);
gl.vertexAttrib2fv(offsetLoc, [0.0, 0.0]);
}
vaoext.bindVertexArrayOES(null);
// Set up VAO with no attrib divisor
var vao2 = vaoext.createVertexArrayOES();
vaoext.bindVertexArrayOES(vao2);
{
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.enableVertexAttribArray(positionLoc);
gl.vertexAttribPointer(positionLoc, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
// Note that no divisor is set here, which implies that it's 0
gl.vertexAttrib2fv(offsetLoc, [0.0, 0.0]);
}
vaoext.bindVertexArrayOES(null);
debug("");
debug("Ensure that Vertex Array Objects retain attrib divisors");
vaoext.bindVertexArrayOES(vao1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 12);
// If the divisor is properly managed by the VAO a single red quad will be drawn
wtu.checkCanvas(gl, [255, 0, 0, 255], "entire canvas should be red");
vaoext.bindVertexArrayOES(vao2);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 12);
// If the divisor is properly managed by the VAO a red and blue quad will be drawn.
wtu.checkCanvasRects(gl, [
wtu.makeCheckRect(0, 0, canvas.width * 0.5, canvas.height, [255, 0, 0, 255], "left half of canvas should be red", 1),
wtu.makeCheckRect(canvas.width * 0.5, 0, canvas.width * 0.5, canvas.height, [0, 0, 255, 255], "right half of canvas should be blue", 1)
]);
vaoext.bindVertexArrayOES(null);
}
function runANGLECorruptionTest()
{
debug("")
debug("Testing to ensure that rendering isn't corrupt due to an ANGLE bug");
// See: https://code.google.com/p/angleproject/issues/detail?id=467
setupCanvas();
var tolerance = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
var instanceCount = 10; // Must be higher than 6
var iteration = 0;
var totalIterations = 10;
var offsets = new Float32Array([
0.0, 0.0,
0.2, 0.0,
0.4, 0.0,
0.6, 0.0,
0.8, 0.0,
1.0, 0.0,
1.2, 0.0,
1.4, 0.0,
1.6, 0.0,
1.8, 0.0,
]);
var offsetBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer);
gl.bufferData(gl.ARRAY_BUFFER, offsets.byteLength * 2, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, 0, offsets);
gl.enableVertexAttribArray(offsetLoc);
gl.vertexAttribPointer(offsetLoc, 2, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(offsetLoc, 1);
var colors = new Float32Array([
1.0, 0.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.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, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 1.0, 1.0,
]);
var colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, colors.byteLength * 2, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, 0, colors);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(colorLoc, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.setupUnitQuad(gl, 0);
function cycleAndTest() {
// Update the instanced data buffers outside the accessed range.
// This, plus rendering more instances than vertices, triggers the bug.
var nullData = new Float32Array(offsets.length);
gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer);
gl.bufferSubData(gl.ARRAY_BUFFER, offsets.byteLength, nullData);
nullData = new Float32Array(colors.length);
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferSubData(gl.ARRAY_BUFFER, colors.byteLength, nullData);
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, instanceCount);
// Make sure each color was drawn correctly
var i;
var passed = true;
for (i = 0; i < instanceCount; ++i) {
var w = canvas.width / instanceCount;
var x = w * i;
var color = [colors[(i*4)] * 255, colors[(i*4)+1] * 255, colors[(i*4)+2] * 255, 255]
wtu.checkCanvasRectColor(
gl, x, 0, w, canvas.height, color, tolerance,
function() {},
function() {
passed = false;
}, debug);
}
if (passed) {
testPassed("Passed test " + iteration + " of " + totalIterations);
if (iteration < totalIterations) {
++iteration;
setTimeout(cycleAndTest, 0);
} else {
finishTest();
}
} else {
testFailed("Failed test " + iteration + " of " + totalIterations);
finishTest();
}
}
cycleAndTest();
}
</script>
</body>
</html>

View file

@ -1,248 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL EXT_blend_minmax Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders to test output -->
<script id="outputVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
}
</script>
<script id="outputFragmentShader" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 uColor;
void main() {
gl_FragColor = uColor;
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
// Use the constant directly when we don't have the extension
var MIN_EXT = 0x8007;
var MAX_EXT = 0x8008;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
runBlendTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_blend_minmax");
if (!ext) {
testPassed("No EXT_blend_minmax support -- this is legal");
runSupportedTest(false);
} else {
debug("");
testPassed("Successfully enabled EXT_blend_minmax extension");
runSupportedTest(true);
runBlendTestEnabled();
runOutputTests();
runUniqueObjectTest();
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("EXT_blend_minmax") >= 0) {
if (extensionEnabled) {
testPassed("EXT_blend_minmax listed as supported and getExtension succeeded");
} else {
testFailed("EXT_blend_minmax listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
} else {
testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
}
}
}
function runBlendTestDisabled() {
debug("");
debug("Testing blending enums with extension disabled");
// Set the blend equation to a known-good enum first
gl.blendEquation(gl.FUNC_ADD);
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MIN_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MAX_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MIN_EXT, gl.FUNC_ADD)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MIN_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MAX_EXT, gl.FUNC_ADD)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MAX_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
}
function runBlendTestEnabled() {
debug("");
debug("Testing blending enums with extension enabled");
shouldBe("ext.MIN_EXT", "0x8007");
shouldBe("ext.MAX_EXT", "0x8008");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MIN_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MIN_EXT");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MAX_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MAX_EXT");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MIN_EXT, gl.FUNC_ADD)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MIN_EXT");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MIN_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MIN_EXT");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MAX_EXT, gl.FUNC_ADD)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MAX_EXT");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MAX_EXT)");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MAX_EXT");
}
function runOutputTests() {
var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
debug("");
debug("Testing various draws for valid blending behavior");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE);
var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
var colorUniform = gl.getUniformLocation(program, "uColor");
// Draw 1
gl.blendEquation(ext.MIN_EXT);
gl.clearColor(0.2, 0.4, 0.6, 0.8);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 51]);
// Draw 2:
gl.blendEquation(ext.MAX_EXT);
gl.clearColor(0.2, 0.4, 0.6, 0.8);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 204]);
// Draw 3
gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);
gl.clearColor(0.2, 0.4, 0.6, 0.8);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 204]);
// Draw 4
gl.blendEquationSeparate(ext.MAX_EXT, ext.MIN_EXT);
gl.clearColor(0.2, 0.4, 0.6, 0.8);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 51]);
}
function runUniqueObjectTest()
{
debug("");
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("EXT_blend_minmax").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,312 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL EXT_frag_depth Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing fragment depth writing -->
<!-- Shader omitting the required #extension pragma -->
<script id="missingPragmaFragmentShader" type="x-shader/x-fragment">
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepthEXT = 1.0;
}
</script>
<!-- Shader to test macro definition -->
<script id="macroFragmentShader" type="x-shader/x-fragment">
precision mediump float;
void main() {
#ifdef GL_EXT_frag_depth
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
#else
// Error expected
#error no GL_EXT_frag_depth;
#endif
}
</script>
<!-- Shader with required #extension pragma -->
<script id="testFragmentShader" type="x-shader/x-fragment">
#extension GL_EXT_frag_depth : enable
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepthEXT = 1.0;
}
</script>
<!-- Shaders to link with test fragment shaders -->
<script id="goodVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
}
</script>
<!-- Shaders to test output -->
<script id="outputVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
}
</script>
<script id="outputFragmentShader" type="x-shader/x-fragment">
#extension GL_EXT_frag_depth : enable
precision mediump float;
uniform float uDepth;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepthEXT = uDepth;
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the EXT_frag_depth extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
// Run all tests once.
runAllTests();
// Run all tests against with a new context to test for any cache issues.
debug("");
debug("Testing new context to catch cache errors");
gl = wtu.create3DContext();
ext = null;
runAllTests();
function runAllTests() {
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
runShaderTests(false);
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_frag_depth");
if (!ext) {
testPassed("No EXT_frag_depth support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled EXT_frag_depth extension");
runSupportedTest(true);
runShaderTests(true);
runOutputTests();
runUniqueObjectTest();
// Run deferred link tests.
runDeferredLinkTests();
}
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("EXT_frag_depth") >= 0) {
if (extensionEnabled) {
testPassed("EXT_frag_depth listed as supported and getExtension succeeded");
} else {
testFailed("EXT_frag_depth listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("EXT_frag_depth not listed as supported but getExtension succeeded");
} else {
testPassed("EXT_frag_depth not listed as supported and getExtension failed -- this is legal");
}
}
}
function runShaderTests(extensionEnabled) {
debug("");
debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));
// Expect the macro shader to succeed ONLY if enabled
var macroFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "macroFragmentShader");
if (extensionEnabled) {
if (macroFragmentProgram) {
// Expected result
testPassed("GL_EXT_frag_depth defined in shaders when extension is enabled");
} else {
testFailed("GL_EXT_frag_depth not defined in shaders when extension is enabled");
}
} else {
if (macroFragmentProgram) {
testFailed("GL_EXT_frag_depth defined in shaders when extension is disabled");
} else {
testPassed("GL_EXT_frag_depth not defined in shaders when extension disabled");
}
}
// Always expect the shader missing the #pragma to fail (whether enabled or not)
var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
if (missingPragmaFragmentProgram) {
testFailed("Shader built-ins allowed without #extension pragma");
} else {
testPassed("Shader built-ins disallowed without #extension pragma");
}
// Try to compile a shader using the built-ins that should only succeed if enabled
var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "testFragmentShader");
if (extensionEnabled) {
if (testFragmentProgram) {
testPassed("Shader built-ins compiled successfully when extension enabled");
} else {
testFailed("Shader built-ins failed to compile when extension enabled");
}
} else {
if (testFragmentProgram) {
testFailed("Shader built-ins compiled successfully when extension disabled");
} else {
testPassed("Shader built-ins failed to compile when extension disabled");
}
}
}
function runOutputTests() {
var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
debug("Testing various draws for valid built-in function behavior");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
// Enable depth testing with a clearDepth of 0.5
// This makes it so that fragments are only rendered when
// gl_fragDepthEXT is < 0.5
gl.clearDepth(0.5);
gl.enable(gl.DEPTH_TEST);
var positionLoc = 0;
var texcoordLoc = 1;
var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
var depthUniform = gl.getUniformLocation(program, "uDepth");
// Draw 1: Greater than clear depth
gl.uniform1f(depthUniform, 1.0);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 255, 255, 255]);
// Draw 2: Less than clear depth
gl.uniform1f(depthUniform, 0.0);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255]);
}
function runUniqueObjectTest()
{
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("EXT_frag_depth").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("EXT_frag_depth").myProperty', '2');
}
function runDeferredLinkTests() {
debug("");
debug("Testing deferred shader compilation tests.");
// Test for compilation failures that are caused by missing extensions
// do not succeed if extensions are enabled during linking. This would
// only happen for deferred shader compilations.
// First test if link succeeds with extension enabled.
var glEnabled = wtu.create3DContext();
var extEnabled = glEnabled.getExtension("EXT_frag_depth");
if (!extEnabled) {
testFailed("Deferred link test expects the extension to be supported");
}
var vertexShader = wtu.loadShaderFromScript(glEnabled, "goodVertexShader");
var fragmentShader = wtu.loadShaderFromScript(glEnabled, "macroFragmentShader");
if (!vertexShader || !fragmentShader) {
testFailed("Could not create good shaders.");
return;
}
var program = wtu.setupProgram(glEnabled, [vertexShader, fragmentShader]);
if (!program) {
testFailed("Compilation with extension enabled failed.");
return;
}
// Create new context to test link failure without extension enabled.
var glDeferred = wtu.create3DContext();
var vertexShader = wtu.loadShaderFromScript(glDeferred, "goodVertexShader", glDeferred.VERTEX_SHADER, undefined, undefined, true);
var fragmentShader = wtu.loadShaderFromScript(glDeferred, "macroFragmentShader", glDeferred.FRAGMENT_SHADER, undefined, undefined, true);
if (vertexShader == null || fragmentShader == null) {
testFailed("Could not create shaders.");
return;
}
// Shader compilations should have failed due to extensions not enabled.
glDeferred.getExtension("EXT_frag_depth");
var program = wtu.setupProgram(glDeferred, [vertexShader, fragmentShader]);
if (program) {
testFailed("Compilation with extension disabled then linking with extension enabled should have failed.");
return;
}
testPassed("Compilation with extension disabled then linking with extension enabled.");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,432 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="16" height="16" style="width: 50px; height: 50px; border: 1px solid black;"></canvas>
<!-- Shaders to test output -->
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec4 aPosition;
void main() {
gl_Position = aPosition;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision mediump float;
uniform float uColor;
void main() {
gl_FragColor = vec4(uColor, uColor, uColor, 1);
}
</script>
<script>
"use strict";
var wtu = WebGLTestUtils;
var canvas;
var gl;
var ext = null;
var extConstants = {
"SRGB_EXT": 0x8C40,
"SRGB_ALPHA_EXT": 0x8C42,
"SRGB8_ALPHA8_EXT": 0x8C43,
"FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT": 0x8210
};
function getExtension() {
ext = gl.getExtension("EXT_sRGB");
}
function listsExtension() {
var supported = gl.getSupportedExtensions();
return (supported.indexOf("EXT_sRGB") >= 0);
}
function toVec3String(val) {
if (typeof(val) == 'number') {
return toVec3String([val, val, val]);
}
return '[' + val[0] + ', ' + val[1] + ', ' + val[2] + ']';
}
var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
function expectResult(target) {
wtu.checkCanvasRect(gl,
Math.floor(gl.drawingBufferWidth / 2),
Math.floor(gl.drawingBufferHeight / 2),
1,
1,
[target, target, target, 255],
undefined,
e);
}
function createGreysRGBTexture(gl, color, format) {
var numPixels = gl.drawingBufferWidth * gl.drawingBufferHeight;
var elements;
switch (format) {
case ext.SRGB_EXT: elements = 3; break;
case ext.SRGB_ALPHA_EXT: elements = 4; break;
default: return null;
}
var size = numPixels * elements;
var buf = new Uint8Array(size);
for (var ii = 0; ii < numPixels; ++ii) {
var off = ii * elements;
buf[off + 0] = color;
buf[off + 1] = color;
buf[off + 2] = color;
if (format == ext.SRGB_ALPHA_EXT) {
buf[off + 3] = 255;
}
}
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D,
0,
format,
gl.drawingBufferWidth,
gl.drawingBufferHeight,
0,
format,
gl.UNSIGNED_BYTE,
buf);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
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);
return tex;
}
function testValidFormat(fn, internalFormat, formatName, enabled) {
if (enabled) {
fn(internalFormat);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "was able to create type " + formatName);
} else {
testInvalidFormat(fn, internalFormat, formatName, enabled);
}
}
function testInvalidFormat(fn, internalFormat, formatName, enabled) {
fn(internalFormat);
var err = gl.getError();
if (err == gl.NO_ERROR) {
testFailed("should NOT be able to create type " + formatName);
} else if (err == gl.INVALID_ENUM || err == gl.INVALID_VALUE) {
testPassed("not able to create invalid format: " + formatName);
}
}
var textureFormatFixture = {
desc: "Checking texture formats",
create: function(format) {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D,
0, // level
format, // internalFormat
gl.drawingBufferWidth, // width
gl.drawingBufferHeight, // height
0, // border
format, // format
gl.UNSIGNED_BYTE, // type
null); // data
},
tests: [
{
desc: "Checking valid formats",
fn: testValidFormat,
formats: [ 'SRGB_EXT', 'SRGB_ALPHA_EXT' ]
},
{
desc: "Checking invalid formats",
fn: testInvalidFormat,
formats: [ 'SRGB8_ALPHA8_EXT' ]
}
]
};
var renderbufferFormatFixture = {
desc: "Checking renderbuffer formats",
create: function(format) {
var rbo = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rbo);
gl.renderbufferStorage(gl.RENDERBUFFER,
format,
gl.drawingBufferWidth,
gl.drawingBufferHeight);
},
tests: [
{
desc: "Checking valid formats",
fn: testValidFormat,
formats: [ 'SRGB8_ALPHA8_EXT' ]
},
{
desc: "Checking invalid formats",
fn: testInvalidFormat,
formats: [ 'SRGB_EXT', 'SRGB_ALPHA_EXT' ]
}
]
};
description("Test sRGB texture support");
debug("");
debug("Canvas.getContext");
canvas = document.getElementById("canvas");
gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking sRGB texture support with extension disabled");
runFormatTest(textureFormatFixture, false);
runFormatTest(renderbufferFormatFixture, false);
debug("");
debug("Checking sRGB texture support");
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("EXT_sRGB");
if (!ext) {
testPassed("No EXT_sRGB support -- this is legal");
runSupportedTest(false);
finishTest();
} else {
testPassed("Successfully enabled EXT_sRGB extension");
runSupportedTest(true);
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
runConstantsTest();
runFormatTest(textureFormatFixture, true);
runFormatTest(renderbufferFormatFixture, true);
runTextureReadConversionTest();
runFramebufferTextureConversionTest(ext.SRGB_EXT);
runFramebufferTextureConversionTest(ext.SRGB_ALPHA_EXT);
runFramebufferRenderbufferConversionTest();
runLoadFromImageTest(function() {
finishTest();
});
}
}
function runConstantsTest() {
debug("");
debug("Checking extension constants values");
for (var constant in extConstants) {
if (constant in ext) {
if (extConstants[constant] != ext[constant]) {
testFailed("Value of " + constant + " should be: " + extConstants[constant] + ", was: " + ext[constant]);
} else {
testPassed("Value of " + constant + " was expected value: " + extConstants[constant]);
}
} else {
testFailed(constant + " not found in extension object");
}
}
}
function runSupportedTest(extensionEnabled) {
if (listsExtension()) {
if (extensionEnabled) {
testPassed("EXT_sRGB listed as supported and getExtension succeeded");
} else {
testFailed("EXT_sRGB listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("EXT_sRGB not listed as supported but getExtension succeeded");
} else {
testPassed("EXT_sRGB not listed as supported and getExtension failed -- this is legal");
}
}
}
function runFormatTest(fixture, enabled) {
debug("");
debug(fixture.desc);
for (var tt = 0; tt < fixture.tests.length; ++tt) {
var test = fixture.tests[tt];
debug(test.desc);
for (var ii = 0; ii < test.formats.length; ++ii) {
var formatName = test.formats[ii];
test.fn(fixture.create, extConstants[formatName], "ext." + formatName, enabled);
}
if (tt != fixture.tests.length - 1)
debug("");
}
}
function runTextureReadConversionTest() {
debug("");
debug("Test the conversion of colors from sRGB to linear on texture read");
// Draw
var conversions = [
[ 0, 0 ],
[ 63, 13 ],
[ 127, 54 ],
[ 191, 133 ],
[ 255, 255 ]
];
var program = wtu.setupTexturedQuad(gl);
gl.uniform1i(gl.getUniformLocation(program, "tex"), 0);
for (var ii = 0; ii < conversions.length; ii++) {
var tex = createGreysRGBTexture(gl, conversions[ii][0], ext.SRGB_EXT);
wtu.drawUnitQuad(gl);
expectResult(conversions[ii][1]);
}
}
function runFramebufferTextureConversionTest(format) {
var formatString;
var validFormat;
switch (format) {
case ext.SRGB_EXT: formatString = "sRGB"; validFormat = false; break;
case ext.SRGB_ALPHA_EXT: formatString = "sRGB_ALPHA"; validFormat = true; break;
default: return null;
}
debug("");
debug("Test " + formatString + " framebuffer attachments." + (validFormat ? "" : " (Invalid)"));
var program = wtu.setupProgram(gl, ['vertexShader', 'fragmentShader'], ['aPosition'], [0]);
var tex = createGreysRGBTexture(gl, 0, format);
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, ext.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT)', 'ext.SRGB_EXT');
if (validFormat) {
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
debug("");
debug("Test the conversion of colors from linear to " + formatString + " on framebuffer (texture) write");
// Draw
var conversions = [
[ 0, 0 ],
[ 13, 63 ],
[ 54, 127 ],
[ 133, 191 ],
[ 255, 255 ]
];
wtu.setupUnitQuad(gl, 0);
for (var ii = 0; ii < conversions.length; ii++) {
gl.uniform1f(gl.getUniformLocation(program, "uColor"), conversions[ii][0]/255.0);
wtu.drawUnitQuad(gl, [0, 0, 0, 0]);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
expectResult(conversions[ii][1]);
}
} else {
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
wtu.setupUnitQuad(gl, 0);
gl.uniform1f(gl.getUniformLocation(program, "uColor"), 0.5);
wtu.drawUnitQuad(gl, [0, 0, 0, 0]);
wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
function runFramebufferRenderbufferConversionTest() {
debug("");
debug("Test the conversion of colors from linear to sRGB on framebuffer (renderbuffer) write");
function createsRGBFramebuffer(gl, width, height) {
var rbo = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rbo);
gl.renderbufferStorage(gl.RENDERBUFFER, ext.SRGB8_ALPHA8_EXT, width, height);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.RENDERBUFFER, rbo);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, ext.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT)', 'ext.SRGB_EXT');
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
return fbo;
}
// Draw
var conversions = [
[ 0, 0 ],
[ 13, 63 ],
[ 54, 127 ],
[ 133, 191 ],
[ 255, 255 ]
];
var program = wtu.setupProgram(gl, ['vertexShader', 'fragmentShader'], ['aPosition'], [0]);
wtu.setupUnitQuad(gl, 0);
var fbo = createsRGBFramebuffer(gl, gl.drawingBufferWidth, gl.drawingBufferHeight);
for (var ii = 0; ii < conversions.length; ii++) {
gl.uniform1f(gl.getUniformLocation(program, "uColor"), conversions[ii][0]/255.0);
wtu.drawUnitQuad(gl, [0, 0, 0, 0]);
expectResult(conversions[ii][1]);
}
}
function runLoadFromImageTest(callback) {
debug("");
debug("Tests to ensure that SRGB textures can successfully use image elements as their source");
var img = wtu.makeImage("../../resources/gray-1024x1024.jpg", function() {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, ext.SRGB_EXT, ext.SRGB_EXT, gl.UNSIGNED_BYTE, img);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
gl.texImage2D(gl.TEXTURE_2D, 0, ext.SRGB_ALPHA_EXT, ext.SRGB_ALPHA_EXT, gl.UNSIGNED_BYTE, img);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
callback();
}, function() {
testFailed("Image could not be loaded");
callback();
});
}
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,364 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL EXT_shader_texture_lod Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/desktop-gl-constants.js"></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 256px; height: 256px;"> </canvas>
<canvas id="canvas2" style="width: 256px; height: 256px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing texture LOD functions -->
<!-- Shader omitting the required #extension pragma -->
<script id="missingPragmaFragmentShader" type="x-shader/x-fragment">
precision mediump float;
varying vec2 texCoord0v;
uniform float lod;
uniform sampler2D tex;
void main() {
vec4 color = texture2DLodEXT(tex, texCoord0v, lod);
gl_FragColor = color;
}
</script>
<!-- Shader to test macro definition -->
<script id="macroFragmentShader" type="x-shader/x-fragment">
precision mediump float;
void main() {
#ifdef GL_EXT_shader_texture_lod
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#else
// Error expected
#error no GL_EXT_shader_texture_lod;
#endif
}
</script>
<!-- Shader with required #extension pragma -->
<script id="testFragmentShader" type="x-shader/x-fragment">
#extension GL_EXT_shader_texture_lod : enable
precision mediump float;
varying vec2 texCoord0v;
uniform float lod;
uniform sampler2D tex;
void main() {
vec4 color = texture2DLodEXT(tex, texCoord0v, lod);
gl_FragColor = color;
}
</script>
<!-- Shaders to link with test fragment shaders -->
<script id="goodVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec2 texCoord0;
varying vec2 texCoord0v;
void main() {
texCoord0v = texCoord0;
gl_Position = vPosition;
}
</script>
<!-- Shaders to test output -->
<script id="outputVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec2 texCoord0;
varying vec2 texCoord0v;
void main() {
texCoord0v = texCoord0;
gl_Position = vPosition;
}
</script>
<script id="outputFragmentShader" type="x-shader/x-fragment">
#extension GL_EXT_shader_texture_lod : require
precision mediump float;
varying vec2 texCoord0v;
uniform float lod;
uniform sampler2D tex;
void main() {
vec4 color = texture2DLodEXT(tex, texCoord0v, lod);
gl_FragColor = color;
}
</script>
<script>
description("This test verifies the functionality of the EXT_shader_texture_lod extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
// Run all tests once.
runAllTests();
// Run all tests against with a new context to test for any cache issues.
debug("");
debug("Testing new context to catch cache errors");
var canvas2 = document.getElementById("canvas2");
gl = wtu.create3DContext(canvas2);
ext = null;
runAllTests();
function runAllTests() {
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runShaderTests(false);
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("EXT_shader_texture_lod");
if (!ext) {
testPassed("No EXT_shader_texture_lod support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled EXT_shader_texture_lod extension");
runSupportedTest(true);
runShaderTests(true);
runOutputTests();
runUniqueObjectTest();
runReferenceCycleTest();
// Run deferred link tests.
runDeferredLinkTests();
}
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("EXT_shader_texture_lod") >= 0) {
if (extensionEnabled) {
testPassed("EXT_shader_texture_lod listed as supported and getExtension succeeded");
} else {
testFailed("EXT_shader_texture_lod listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("EXT_shader_texture_lod not listed as supported but getExtension succeeded");
} else {
testPassed("EXT_shader_texture_lod not listed as supported and getExtension failed -- this is legal");
}
}
}
function runShaderTests(extensionEnabled) {
debug("");
debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));
// Expect the macro shader to succeed ONLY if enabled
var macroFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "macroFragmentShader");
if (extensionEnabled) {
if (macroFragmentProgram) {
// Expected result
testPassed("GL_EXT_shader_texture_lod defined in shaders when extension is enabled");
} else {
testFailed("GL_EXT_shader_texture_lod not defined in shaders when extension is enabled");
}
} else {
if (macroFragmentProgram) {
testFailed("GL_EXT_shader_texture_lod defined in shaders when extension is disabled");
} else {
testPassed("GL_EXT_shader_texture_lod not defined in shaders when extension disabled");
}
}
// Always expect the shader missing the #pragma to fail (whether enabled or not)
var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
if (missingPragmaFragmentProgram) {
testFailed("Shader built-ins allowed without #extension pragma");
} else {
testPassed("Shader built-ins disallowed without #extension pragma");
}
// Try to compile a shader using the built-ins that should only succeed if enabled
var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "testFragmentShader");
if (extensionEnabled) {
if (testFragmentProgram) {
testPassed("Shader built-ins compiled successfully when extension enabled");
} else {
testFailed("Shader built-ins failed to compile when extension enabled");
}
} else {
if (testFragmentProgram) {
testFailed("Shader built-ins compiled successfully when extension disabled");
} else {
testPassed("Shader built-ins failed to compile when extension disabled");
}
}
}
function runOutputTests() {
debug("");
debug("Testing various draws for valid built-in function behavior");
gl.viewport(0, 0, canvas.width, canvas.height);
var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition', 'texCoord0'], [0, 1]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
var colors = [
{name: 'red', color:[255, 0, 0, 255]},
{name: 'green', color:[0, 255, 0, 255]},
{name: 'blue', color:[0, 0, 255, 255]},
{name: 'yellow', color:[255, 255, 0, 255]},
{name: 'magenta', color:[255, 0, 255, 255]},
{name: 'cyan', color:[0, 255, 255, 255]},
{name: 'pink', color:[255, 128, 128, 255]},
{name: 'gray', color:[128, 128, 128, 255]},
{name: 'light green', color:[128, 255, 128, 255]},
];
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
for (var ii = 0; ii < colors.length; ++ii) {
var color = colors[ii];
var size = Math.pow(2, colors.length - ii - 1);
wtu.fillTexture(gl, tex, size, size, color.color, ii);
}
var loc = gl.getUniformLocation(program, "lod");
for (var ii = 0; ii < colors.length; ++ii) {
gl.uniform1f(loc, ii);
var color = colors[ii];
wtu.drawUnitQuad(gl);
wtu.checkCanvas(
gl, color.color,
"256x256 texture drawn to 256x256 dest with lod = " + ii +
" should be " + color.name);
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
}
function runUniqueObjectTest()
{
debug("");
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("EXT_shader_texture_lod").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("EXT_shader_texture_lod").myProperty', '2');
}
function runReferenceCycleTest()
{
// create some reference cycles. The goal is to see if they cause leaks. The point is that
// some browser test runners have instrumentation to detect leaked refcounted objects.
debug("");
debug("Testing reference cycles between context and extension objects");
var ext = gl.getExtension("EXT_shader_texture_lod");
// create cycle between extension and context, since the context has to hold a reference to the extension
ext.context = gl;
// create a self-cycle on the extension object
ext.ext = ext;
}
function runDeferredLinkTests() {
debug("");
debug("Testing deferred shader compilation tests.");
// Test for compilation failures that are caused by missing extensions
// do not succeed if extensions are enabled during linking. This would
// only happen for deferred shader compilations.
// First test if link succeeds with extension enabled.
var glEnabled = wtu.create3DContext();
var extEnabled = glEnabled.getExtension("EXT_shader_texture_lod");
if (!extEnabled) {
testFailed("Deferred link test expects the extension to be supported");
}
var vertexShader = wtu.loadShaderFromScript(glEnabled, "goodVertexShader");
var fragmentShader = wtu.loadShaderFromScript(glEnabled, "macroFragmentShader");
if (!vertexShader || !fragmentShader) {
testFailed("Could not create good shaders.");
return;
}
var program = wtu.setupProgram(glEnabled, [vertexShader, fragmentShader]);
if (!program) {
testFailed("Compilation with extension enabled failed.");
return;
}
// Create new context to test link failure without extension enabled.
var glDeferred = wtu.create3DContext();
var vertexShader = wtu.loadShaderFromScript(glDeferred, "goodVertexShader", glDeferred.VERTEX_SHADER, undefined, undefined, true);
var fragmentShader = wtu.loadShaderFromScript(glDeferred, "macroFragmentShader", glDeferred.FRAGMENT_SHADER, undefined, undefined, true);
if (vertexShader == null || fragmentShader == null) {
testFailed("Could not create shaders.");
return;
}
// Shader compilations should have failed due to extensions not enabled.
glDeferred.getExtension("EXT_shader_texture_lod");
var program = wtu.setupProgram(glDeferred, [vertexShader, fragmentShader]);
if (program) {
testFailed("Compilation with extension disabled then linking with extension enabled should have failed.");
return;
}
testPassed("Compilation with extension disabled then linking with extension enabled.");
}
debug("");
successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,192 +0,0 @@
<!--
/*
** Copyright (c) 2012 Florian Boesch <pyalot@gmail.com>.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL EXT_texture_filter_anisotropic Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the EXT_texture_filter_anisotropic extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runHintTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_texture_filter_anisotropic");
if (!ext) {
testPassed("No EXT_texture_filter_anisotropic support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled EXT_texture_filter_anisotropic extension");
runSupportedTest(true);
runHintTestEnabled();
}
}
function runSupportedTest(extensionEnabled) {
if (wtu.getSupportedExtensionWithKnownPrefixes(gl, "EXT_texture_filter_anisotropic") !== undefined) {
if (extensionEnabled) {
testPassed("EXT_texture_filter_anisotropic listed as supported and getExtension succeeded");
} else {
testFailed("EXT_texture_filter_anisotropic listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("EXT_texture_filter_anisotropic not listed as supported but getExtension succeeded");
} else {
testPassed("EXT_texture_filter_anisotropic not listed as supported and getExtension failed -- this is legal");
}
}
}
function runHintTestDisabled() {
debug("Testing MAX_TEXTURE_MAX_ANISOTROPY_EXT with extension disabled");
var MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
gl.getParameter(MAX_TEXTURE_MAX_ANISOTROPY_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "MAX_TEXTURE_MAX_ANISOTROPY_EXT should not be queryable if extension is disabled");
debug("Testing TEXTURE_MAX_ANISOTROPY_EXT with extension disabled");
var TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.getTexParameter(gl.TEXTURE_2D, TEXTURE_MAX_ANISOTROPY_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "TEXTURE_MAX_ANISOTROPY_EXT should not be queryable if extension is disabled");
gl.texParameterf(gl.TEXTURE_2D, TEXTURE_MAX_ANISOTROPY_EXT, 1);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "TEXTURE_MAX_ANISOTROPY_EXT should not be settable if extension is disabled");
gl.texParameteri(gl.TEXTURE_2D, TEXTURE_MAX_ANISOTROPY_EXT, 1);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "TEXTURE_MAX_ANISOTROPY_EXT should not be settable if extension is disabled");
gl.deleteTexture(texture);
}
function runHintTestEnabled() {
debug("Testing MAX_TEXTURE_MAX_ANISOTROPY_EXT with extension enabled");
shouldBe("ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT", "0x84FF");
var max_anisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "MAX_TEXTURE_MAX_ANISOTROPY_EXT query should succeed if extension is enabled");
if(max_anisotropy >= 2){
testPassed("Minimum value of MAX_TEXTURE_MAX_ANISOTROPY_EXT is 2.0");
}
else{
testFailed("Minimum value of MAX_TEXTURE_MAX_ANISOTROPY_EXT is 2.0, returned values was: " + max_anisotropy);
}
// TODO make a texture and verify initial value == 1 and setting to less than 1 is invalid value
debug("Testing TEXTURE_MAX_ANISOTROPY_EXT with extension disabled");
shouldBe("ext.TEXTURE_MAX_ANISOTROPY_EXT", "0x84FE");
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
var queried_value = gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "TEXTURE_MAX_ANISOTROPY_EXT query should succeed if extension is enabled");
if(queried_value == 1){
testPassed("Initial value of TEXTURE_MAX_ANISOTROPY_EXT is 1.0");
}
else{
testFailed("Initial value of TEXTURE_MAX_ANISOTROPY_EXT should be 1.0, returned value was: " + queried_value);
}
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "texParameterf TEXTURE_MAX_ANISOTROPY_EXT set to < 1 should be an invalid value");
gl.texParameteri(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "texParameteri TEXTURE_MAX_ANISOTROPY_EXT set to < 1 should be an invalid value");
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texParameterf TEXTURE_MAX_ANISOTROPY_EXT set to >= 2 should succeed");
gl.texParameteri(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texParameteri TEXTURE_MAX_ANISOTROPY_EXT set to >= 2 should succeed");
var queried_value = gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT);
if(queried_value == max_anisotropy){
testPassed("Set value of TEXTURE_MAX_ANISOTROPY_EXT matches expecation");
}
else{
testFailed("Set value of TEXTURE_MAX_ANISOTROPY_EXT should be: " + max_anisotropy + " , returned value was: " + queried_value);
}
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 1.5);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texParameterf TEXTURE_MAX_ANISOTROPY_EXT set to 1.5 should succeed");
queried_value = gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT);
if(queried_value == 1.5){
testPassed("Set value of TEXTURE_MAX_ANISOTROPY_EXT matches expecation");
}
else{
testFailed("Set value of TEXTURE_MAX_ANISOTROPY_EXT should be: " + 1.5 + " , returned value was: " + queried_value);
}
gl.deleteTexture(texture);
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,122 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Extension Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script>
"use strict";
var pseudoRandom = (function() {
var seed = 3;
return function() {
seed = (seed * 11 + 17) % 25;
return seed / 25;
};
})();
var randomizeCase = function(str) {
var newChars = [];
for (var ii = 0; ii < str.length; ++ii) {
var c = str.substr(ii, 1);
var m = (pseudoRandom() > 0.5) ? c.toLowerCase() : c.toUpperCase();
newChars.push(m);
}
return newChars.join("");
};
description();
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ii;
debug("check every extension advertised can be enabled");
debug("");
var extensionNames = gl.getSupportedExtensions();
var extensionNamesLower = [];
for (ii = 0; ii < extensionNames.length; ++ii) {
extensionNamesLower.push(extensionNames[ii].toLowerCase());
}
for (ii = 0; ii < extensionNames.length; ++ii) {
var originalName = extensionNames[ii];
var mixedName = randomizeCase(originalName);
var extension = gl.getExtension(mixedName);
assertMsg(extension, "able to get " + originalName + " as " + mixedName);
if (extension) {
var kTestString = "this is a test";
var kTestNumber = 123;
var kTestFunction = function() { };
var kTestObject = { };
extension.testStringProperty = kTestString;
extension.testNumberProperty = kTestNumber;
extension.testFunctionProperty = kTestFunction;
extension.testObjectProperty = kTestObject;
webglHarnessCollectGarbage();
var extension2 = gl.getExtension(originalName);
assertMsg(
extension === extension2,
"calling getExtension twice for the same extension returns the same object");
assertMsg(
extension2.testStringProperty === kTestString &&
extension2.testFunctionProperty === kTestFunction &&
extension2.testObjectProperty === kTestObject &&
extension2.testNumberProperty === kTestNumber,
"object returned by 2nd call to getExtension has same properties");
var prefixedVariants = wtu.getExtensionPrefixedNames(originalName);
for (var jj = 0; jj < prefixedVariants.length; ++jj) {
assertMsg(
gl.getExtension(prefixedVariants[jj]) === null ||
extensionNamesLower.indexOf(prefixedVariants[jj].toLowerCase()) !== -1,
"getExtension('" + prefixedVariants[jj] + "') returns an object only if the name is returned by getSupportedExtensions");
}
}
debug("");
}
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,451 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_element_index_uint Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<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">
precision mediump float;
varying vec4 color;
void main() {
gl_FragColor = color;
}
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the OES_element_index_uint extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var gl = null;
var ext = null;
var canvas = null;
// Test both STATIC_DRAW and DYNAMIC_DRAW as a regression test
// for a bug in ANGLE which has since been fixed.
for (var ii = 0; ii < 2; ++ii) {
canvas = document.createElement("canvas");
canvas.width = 50;
canvas.height = 50;
gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
var drawType = (ii == 0) ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW;
debug("Testing " + ((ii == 0) ? "STATIC_DRAW" : "DYNAMIC_DRAW"));
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("OES_element_index_uint");
if (!ext) {
testPassed("No OES_element_index_uint support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled OES_element_index_uint extension");
runSupportedTest(true);
runDrawTests(drawType);
// These tests are tweaked duplicates of the buffers/index-validation* tests
// using unsigned int indices to ensure that behavior remains consistent
runIndexValidationTests(drawType);
runCopiesIndicesTests(drawType);
runResizedBufferTests(drawType);
runVerifiesTooManyIndicesTests(drawType);
runCrashWithBufferSubDataTests(drawType);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("OES_element_index_uint") >= 0) {
if (extensionEnabled) {
testPassed("OES_element_index_uint listed as supported and getExtension succeeded");
} else {
testFailed("OES_element_index_uint listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("OES_element_index_uint not listed as supported but getExtension succeeded");
} else {
testPassed("OES_element_index_uint not listed as supported and getExtension failed -- this is legal");
}
}
}
function runDrawTests(drawType) {
debug("Test that draws with unsigned integer indices produce the expected results");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
var program = wtu.setupSimpleColorProgram(gl);
function setupDraw(s) {
// Create a vertex buffer that cannot be fully indexed via shorts
var quadArrayLen = 65537 * 3;
var quadArray = new Float32Array(quadArrayLen);
// Leave all but the last 4 values zero-ed out
var idx = quadArrayLen - 12;
// Initialized the last 4 values to a quad
quadArray[idx++] = 1.0 * s;
quadArray[idx++] = 1.0 * s;
quadArray[idx++] = 0.0;
quadArray[idx++] = -1.0 * s;
quadArray[idx++] = 1.0 * s;
quadArray[idx++] = 0.0;
quadArray[idx++] = -1.0 * s;
quadArray[idx++] = -1.0 * s;
quadArray[idx++] = 0.0;
quadArray[idx++] = 1.0 * s;
quadArray[idx++] = -1.0 * s;
quadArray[idx++] = 0.0;
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, quadArray, drawType);
// Create an unsigned int index buffer that indexes the last 4 vertices
var baseIndex = (quadArrayLen / 3) - 4;
var indexObject = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array([
baseIndex + 0,
baseIndex + 1,
baseIndex + 2,
baseIndex + 2,
baseIndex + 3,
baseIndex + 0]), drawType);
var opt_positionLocation = 0;
gl.enableVertexAttribArray(opt_positionLocation);
gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0);
};
function testPixel(blackList, whiteList) {
function testList(list, expected) {
for (var n = 0; n < list.length; n++) {
var l = list[n];
var x = -Math.floor(l * canvas.width / 2) + canvas.width / 2;
var y = -Math.floor(l * canvas.height / 2) + canvas.height / 2;
wtu.checkCanvasRect(gl, x, y, 1, 1, [expected, expected, expected],
"Draw should pass", 2);
}
}
testList(blackList, 0);
testList(whiteList, 255);
};
function verifyDraw(s) {
gl.clearColor(1.0, 1.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
wtu.setFloatDrawColor(gl, [0.0, 0.0, 0.0, 1.0]);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, 0);
var blackList = [];
var whiteList = [];
var points = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];
for (var n = 0; n < points.length; n++) {
if (points[n] <= s) {
blackList.push(points[n]);
} else {
whiteList.push(points[n]);
}
}
testPixel(blackList, whiteList);
};
setupDraw(0.5);
verifyDraw(0.5);
}
function runIndexValidationTests(drawType) {
description("Tests that index validation verifies the correct number of indices");
function sizeInBytes(type) {
switch (type) {
case gl.BYTE:
case gl.UNSIGNED_BYTE:
return 1;
case gl.SHORT:
case gl.UNSIGNED_SHORT:
return 2;
case gl.INT:
case gl.UNSIGNED_INT:
case gl.FLOAT:
return 4;
default:
throw "unknown type";
}
}
var program = wtu.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 Uint32Array([0, 1, 2]);
debug("Testing with valid indices");
var bufferComplete = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
gl.bufferData(gl.ARRAY_BUFFER, dataComplete, drawType);
var elements = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, drawType);
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 * sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
debug("Testing with out-of-range indices");
var bufferIncomplete = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, drawType);
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.disableVertexAttribArray(normalLoc);
debug("Enable vertices, valid");
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
debug("Enable normals, out-of-range");
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
wtu.shouldGenerateGLError(gl, [gl.INVALID_OPERATION, gl.NO_ERROR],
'gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
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");
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
debug("Enable an extra attribute with insufficient data buffer");
gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
debug("Pass large negative index to vertexAttribPointer");
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT));
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE);
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_INT, 0)');
}
function runCopiesIndicesTests(drawType) {
debug("Test that client data is always copied during bufferData and bufferSubData calls");
var program = wtu.loadStandardProgram(gl);
gl.useProgram(program);
var vertexObject = gl.createBuffer();
gl.enableVertexAttribArray(0);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
// 4 vertices -> 2 triangles
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), drawType);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
var indexObject = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
var indices = new Uint32Array([ 10000, 0, 1, 2, 3, 10000 ]);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, drawType);
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 4)");
var indexValidationError = wtu.shouldGenerateGLError(gl, [gl.INVALID_OPERATION, gl.NO_ERROR],
"gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 0)");
wtu.shouldGenerateGLError(gl, indexValidationError, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 8)");
indices[0] = 2;
indices[5] = 1;
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 4)");
wtu.shouldGenerateGLError(gl, indexValidationError, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 0)");
wtu.shouldGenerateGLError(gl, indexValidationError, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 8)");
}
function runResizedBufferTests(drawType) {
debug("Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.");
var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vColor"]);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initialization");
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]), drawType);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup");
var texCoordObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
[0,0, 1,0, 0,1,
0,1, 1,0, 1,1]), drawType);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
wtu.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]), drawType);
wtu.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]), drawType);
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition");
var numQuads = 2;
var indices = new Uint32Array(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, drawType);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");
gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_INT, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
}
function runVerifiesTooManyIndicesTests(drawType) {
description("Tests that index validation for drawElements does not examine too many indices");
var program = wtu.loadStandardProgram(gl);
gl.useProgram(program);
var vertexObject = gl.createBuffer();
gl.enableVertexAttribArray(0);
gl.disableVertexAttribArray(1);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
// 4 vertices -> 2 triangles
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0,0, 0,1,0, 1,0,0, 1,1,0 ]), drawType);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
var indexObject = gl.createBuffer();
debug("Test out of range indices")
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array([ 10000, 0, 1, 2, 3, 10000 ]), drawType);
wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 4)");
var indexValidationError = wtu.shouldGenerateGLError(gl, [gl.INVALID_OPERATION, gl.NO_ERROR],
"gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 0)");
wtu.shouldGenerateGLError(gl, indexValidationError, "gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 8)");
}
function runCrashWithBufferSubDataTests(drawType) {
debug('Verifies that the index validation code which is within bufferSubData does not crash.')
var elementBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 256, drawType);
var data = new Uint32Array(127);
gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 64, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "after attempting to update a buffer outside of the allocated bounds");
testPassed("bufferSubData, when buffer object was initialized with null, did not crash");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,423 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_standard_derivatives Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing standard derivatives -->
<!-- Shader omitting the required #extension pragma -->
<script id="missingPragmaFragmentShader" type="x-shader/x-fragment">
precision mediump float;
varying vec2 texCoord;
void main() {
float dx = dFdx(texCoord.x);
float dy = dFdy(texCoord.y);
float w = fwidth(texCoord.x);
gl_FragColor = vec4(dx, dy, w, 1.0);
}
</script>
<!-- Shader to test macro definition -->
<script id="macroFragmentShader" type="x-shader/x-fragment">
precision mediump float;
void main() {
#ifdef GL_OES_standard_derivatives
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#else
// Error expected
#error no GL_OES_standard_derivatives;
#endif
}
</script>
<!-- Shader with required #extension pragma -->
<script id="testFragmentShader" type="x-shader/x-fragment">
#extension GL_OES_standard_derivatives : enable
precision mediump float;
varying vec2 texCoord;
void main() {
float dx = dFdx(texCoord.x);
float dy = dFdy(texCoord.y);
float w = fwidth(texCoord.x);
gl_FragColor = vec4(dx, dy, w, 1.0);
}
</script>
<!-- Shaders to link with test fragment shaders -->
<script id="goodVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
varying vec2 texCoord;
void main() {
texCoord = vPosition.xy;
gl_Position = vPosition;
}
</script>
<!-- Shaders to test output -->
<script id="outputVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
varying vec4 position;
void main() {
position = vPosition;
gl_Position = vPosition;
}
</script>
<script id="outputFragmentShader" type="x-shader/x-fragment">
#extension GL_OES_standard_derivatives : enable
precision mediump float;
varying vec4 position;
void main() {
float dzdx = dFdx(position.z);
float dzdy = dFdy(position.z);
float fw = fwidth(position.z);
gl_FragColor = vec4(abs(dzdx) * 40.0, abs(dzdy) * 40.0, fw * 40.0, 1.0);
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the OES_standard_derivatives extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
// Run all tests once.
runAllTests();
// Run all tests against with a new context to test for any cache issues.
debug("");
debug("Testing new context to catch cache errors");
gl = wtu.create3DContext();
ext = null;
runAllTests();
function runAllTests() {
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runHintTestDisabled();
runShaderTests(false);
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("OES_standard_derivatives");
if (!ext) {
testPassed("No OES_standard_derivatives support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled OES_standard_derivatives extension");
runSupportedTest(true);
runHintTestEnabled();
runShaderTests(true);
runOutputTests();
runUniqueObjectTest();
// Run deferred link tests.
runDeferredLinkTests();
}
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("OES_standard_derivatives") >= 0) {
if (extensionEnabled) {
testPassed("OES_standard_derivatives listed as supported and getExtension succeeded");
} else {
testFailed("OES_standard_derivatives listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("OES_standard_derivatives not listed as supported but getExtension succeeded");
} else {
testPassed("OES_standard_derivatives not listed as supported and getExtension failed -- this is legal");
}
}
}
function runHintTestDisabled() {
debug("Testing FRAGMENT_SHADER_DERIVATIVE_HINT_OES with extension disabled");
// Use the constant directly as we don't have the extension
var FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B;
gl.getParameter(FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "FRAGMENT_SHADER_DERIVATIVE_HINT_OES should not be queryable if extension is disabled");
gl.hint(FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.DONT_CARE);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "hint should not accept FRAGMENT_SHADER_DERIVATIVE_HINT_OES if extension is disabled");
}
function runHintTestEnabled() {
debug("Testing FRAGMENT_SHADER_DERIVATIVE_HINT_OES with extension enabled");
shouldBe("ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES", "0x8B8B");
gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "FRAGMENT_SHADER_DERIVATIVE_HINT_OES query should succeed if extension is enabled");
// Default value is DONT_CARE
if (gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES) == gl.DONT_CARE) {
testPassed("Default value of FRAGMENT_SHADER_DERIVATIVE_HINT_OES is DONT_CARE");
} else {
testFailed("Default value of FRAGMENT_SHADER_DERIVATIVE_HINT_OES is not DONT_CARE");
}
// Ensure that we can set the target
gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.DONT_CARE);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "hint should accept FRAGMENT_SHADER_DERIVATIVE_HINT_OES");
// Test all the hint modes
var validModes = ["FASTEST", "NICEST", "DONT_CARE"];
var anyFailed = false;
for (var n = 0; n < validModes.length; n++) {
var mode = validModes[n];
gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl[mode]);
if (gl.getParameter(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES) != gl[mode]) {
testFailed("Round-trip of hint()/getParameter() failed on mode " + mode);
anyFailed = true;
}
}
if (!anyFailed) {
testPassed("Round-trip of hint()/getParameter() with all supported modes");
}
}
function runShaderTests(extensionEnabled) {
debug("");
debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));
// Expect the macro shader to succeed ONLY if enabled
var macroFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "macroFragmentShader");
if (extensionEnabled) {
if (macroFragmentProgram) {
// Expected result
testPassed("GL_OES_standard_derivatives defined in shaders when extension is enabled");
} else {
testFailed("GL_OES_standard_derivatives not defined in shaders when extension is enabled");
}
} else {
if (macroFragmentProgram) {
testFailed("GL_OES_standard_derivatives defined in shaders when extension is disabled");
} else {
testPassed("GL_OES_standard_derivatives not defined in shaders when extension disabled");
}
}
// Always expect the shader missing the #pragma to fail (whether enabled or not)
var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
if (missingPragmaFragmentProgram) {
testFailed("Shader built-ins allowed without #extension pragma");
} else {
testPassed("Shader built-ins disallowed without #extension pragma");
}
// Try to compile a shader using the built-ins that should only succeed if enabled
var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "testFragmentShader");
if (extensionEnabled) {
if (testFragmentProgram) {
testPassed("Shader built-ins compiled successfully when extension enabled");
} else {
testFailed("Shader built-ins failed to compile when extension enabled");
}
} else {
if (testFragmentProgram) {
testFailed("Shader built-ins compiled successfully when extension disabled");
} else {
testPassed("Shader built-ins failed to compile when extension disabled");
}
}
}
function runOutputTests() {
// This tests does several draws with various values of z.
// The output of the fragment shader is:
// [dFdx(z), dFdy(z), fwidth(z), 1.0]
// The expected math: (note the conversion to uint8)
// canvas.width = canvas.height = 50
// dFdx = totalChange.x / canvas.width = 0.5 / 50.0 = 0.01
// dFdy = totalChange.y / canvas.height = 0.5 / 50.0 = 0.01
// fw = abs(dFdx + dFdy) = 0.01 + 0.01 = 0.02
// r = floor(dFdx * 40.0 * 255) = 102
// g = floor(dFdy * 40.0 * 255) = 102
// b = floor(fw * 40.0 * 255) = 204
var e = 5; // Amount of variance to allow in result pixels - may need to be tweaked higher
debug("Testing various draws for valid built-in function behavior");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.hint(ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES, gl.NICEST);
var positionLoc = 0;
var texcoordLoc = 1;
var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition', 'texCoord0'], [0, 1]);
var quadParameters = wtu.setupUnitQuad(gl, positionLoc, texcoordLoc);
function expectResult(target, message) {
var locations = [
[ 0.1, 0.1 ],
[ 0.9, 0.1 ],
[ 0.1, 0.9 ],
[ 0.9, 0.9 ],
[ 0.5, 0.5 ]
];
for (var n = 0; n < locations.length; n++) {
var loc = locations[n];
var px = Math.floor(loc[0] * canvas.width);
var py = Math.floor(loc[1] * canvas.height);
wtu.checkCanvasRect(gl, px, py, 1, 1, target, message, 4);
}
};
function setupBuffers(tl, tr, bl, br) {
gl.bindBuffer(gl.ARRAY_BUFFER, quadParameters[0]);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
1.0, 1.0, tr,
-1.0, 1.0, tl,
-1.0, -1.0, bl,
1.0, 1.0, tr,
-1.0, -1.0, bl,
1.0, -1.0, br]), gl.STATIC_DRAW);
gl.vertexAttribPointer(positionLoc, 3, gl.FLOAT, false, 0, 0);
};
// Draw 1: (no variation)
setupBuffers(0.0, 0.0, 0.0, 0.0);
wtu.clearAndDrawUnitQuad(gl);
expectResult([0, 0, 0, 255],
"Draw 1 (no variation) should pass");
// Draw 2: (variation in x)
setupBuffers(1.0, 0.0, 1.0, 0.0);
wtu.clearAndDrawUnitQuad(gl);
expectResult([204, 0, 204, 255],
"Draw 2 (variation in x) should pass");
// Draw 3: (variation in y)
setupBuffers(1.0, 1.0, 0.0, 0.0);
wtu.clearAndDrawUnitQuad(gl);
expectResult([0, 204, 204, 255],
"Draw 3 (variation in y) should pass");
// Draw 4: (variation in x & y)
setupBuffers(1.0, 0.5, 0.5, 0.0);
wtu.clearAndDrawUnitQuad(gl);
expectResult([102, 102, 204, 255],
"Draw 4 (variation in x & y) should pass");
}
function runUniqueObjectTest()
{
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("OES_standard_derivatives").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("OES_standard_derivatives").myProperty', '2');
}
function runDeferredLinkTests() {
debug("");
debug("Testing deferred shader compilation tests.");
// Test for compilation failures that are caused by missing extensions
// do not succeed if extensions are enabled during linking. This would
// only happen for deferred shader compilations.
// First test if link succeeds with extension enabled.
var glEnabled = wtu.create3DContext();
var extEnabled = glEnabled.getExtension("OES_standard_derivatives");
if (!extEnabled) {
testFailed("Deferred link test expects the extension to be supported");
}
var vertexShader = wtu.loadShaderFromScript(glEnabled, "goodVertexShader");
var fragmentShader = wtu.loadShaderFromScript(glEnabled, "macroFragmentShader");
if (!vertexShader || !fragmentShader) {
testFailed("Could not create good shaders.");
return;
}
var program = wtu.setupProgram(glEnabled, [vertexShader, fragmentShader]);
if (!program) {
testFailed("Compilation with extension enabled failed.");
return;
}
// Create new context to test link failure without extension enabled.
var glDeferred = wtu.create3DContext();
var vertexShader = wtu.loadShaderFromScript(glDeferred, "goodVertexShader", glDeferred.VERTEX_SHADER, undefined, undefined, true);
var fragmentShader = wtu.loadShaderFromScript(glDeferred, "macroFragmentShader", glDeferred.FRAGMENT_SHADER, undefined, undefined, true);
if (vertexShader == null || fragmentShader == null) {
testFailed("Could not create shaders.");
return;
}
// Shader compilations should have failed due to extensions not enabled.
glDeferred.getExtension("OES_standard_derivatives");
var program = wtu.setupProgram(glDeferred, [vertexShader, fragmentShader]);
if (program) {
testFailed("Compilation with extension disabled then linking with extension enabled should have failed.");
return;
}
testPassed("Compilation with extension disabled then linking with extension enabled.");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,55 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/oes-texture-float-and-half-float-linear.js"></script>
<script>
"use strict";
function testPrologue(gl, extensionTypeName) {
if (!gl.getExtension(extensionTypeName)) {
testPassed("No " + extensionTypeName + " support -- this is legal");
return false;
}
testPassed("Successfully enabled " + extensionTypeName + " extension");
return true;
}
</script>
</head>
<body onload='generateTest("OES_texture_float", "OES_texture_float_linear", "FLOAT", testPrologue)()'>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
</body>
</html>

View file

@ -1,57 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-canvas.js"></script>
<script>
"use strict";
function testPrologue(gl) {
if (!gl.getExtension("OES_texture_float")) {
testPassed("No OES_texture_float support -- this is legal");
return false;
}
testPassed("Successfully enabled OES_texture_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "FLOAT", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,58 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-image-data.js"></script>
<script>
"use strict";
function testPrologue(gl) {
if (!gl.getExtension("OES_texture_float")) {
testPassed("No OES_texture_float support -- this is legal");
return false;
}
testPassed("Successfully enabled OES_texture_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "FLOAT", testPrologue, "../../resources/")()'>
<canvas id="texcanvas" width="2" height="2"></canvas>
<canvas id="example" width="2" height="2"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,57 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-image.js"></script>
<script>
"use strict";
function testPrologue(gl) {
if (!gl.getExtension("OES_texture_float")) {
testPassed("No OES_texture_float support -- this is legal");
return false;
}
testPassed("Successfully enabled OES_texture_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "FLOAT", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,62 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-video.js"></script>
<script>
"use strict";
function testPrologue(gl) {
if (!gl.getExtension("OES_texture_float")) {
testPassed("No OES_texture_float support -- this is legal");
return false;
}
testPassed("Successfully enabled OES_texture_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "FLOAT", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
<video width="640" height="228" id="vid" controls>
<source src="../../resources/red-green.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<source src="../../resources/red-green.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
<source src="../../resources/red-green.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
</video>
</body>
</html>

View file

@ -1,293 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_texture_float Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing floating-point textures -->
<script id="testFragmentShader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D tex;
uniform vec4 subtractor;
varying vec2 texCoord;
void main()
{
vec4 color = texture2D(tex, texCoord);
if (abs(color.r - subtractor.r) +
abs(color.g - subtractor.g) +
abs(color.b - subtractor.b) +
abs(color.a - subtractor.a) < 8.0) {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
} else {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
}
</script>
<!-- Shaders for testing floating-point render targets -->
<script id="positionVertexShader" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="floatingPointFragmentShader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(10000.0, 10000.0, 10000.0, 10000.0);
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the OES_texture_float extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
var texturedShaders = [
wtu.simpleTextureVertexShader,
"testFragmentShader"
];
var testProgram =
wtu.setupProgram(gl,
texturedShaders,
['vPosition', 'texCoord0'],
[0, 1]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
// First verify that allocation of floating-point textures fails if
// the extension has not been enabled yet.
runTextureCreationTest(testProgram, false);
if (!gl.getExtension("OES_texture_float")) {
testPassed("No OES_texture_float support -- this is legal");
} else {
testPassed("Successfully enabled OES_texture_float extension");
// If alpha value is missing from a texture it gets filled to 1 when sampling according to GLES2.0 table 3.12
runTextureCreationTest(testProgram, true, gl.RGBA, 4, [10000, 10000, 10000, 10000]);
runTextureCreationTest(testProgram, true, gl.RGB, 3, [10000, 10000, 10000, 1]);
runTextureCreationTest(testProgram, true, gl.LUMINANCE, 1, [10000, 10000, 10000, 1]);
runTextureCreationTest(testProgram, true, gl.ALPHA, 1, [0, 0, 0, 10000]);
runTextureCreationTest(testProgram, true, gl.LUMINANCE_ALPHA, 2, [10000, 10000, 10000, 10000]);
runRenderTargetAndReadbackTest(testProgram, gl.RGBA, 4, [10000, 10000, 10000, 10000], 0);
runRenderTargetAndReadbackTest(testProgram, gl.RGB, 3, [10000, 10000, 10000, 1], 0);
runRenderTargetAndReadbackTest(testProgram, gl.RGBA, 4, [10000, 10000, 10000, 10000], 1);
runRenderTargetAndReadbackTest(testProgram, gl.RGBA, 4, [10000, 10000, 10000, 10000], 0.5);
runUniqueObjectTest();
}
}
function allocateTexture()
{
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_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);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed");
return texture;
}
function checkRenderingResults()
{
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}
function runTextureCreationTest(testProgram, extensionEnabled, opt_format, opt_numChannels, opt_subtractor)
{
var format = opt_format || gl.RGBA;
var numberOfChannels = opt_numChannels || 4;
var expectFailure = !extensionEnabled;
var subtractor = opt_subtractor || [10000, 10000, 10000, 10000];
debug("");
debug("testing format: " + wtu.glEnumToString(gl, format) +
" expect:" + (extensionEnabled ? "success" : "failure"));
var texture = allocateTexture();
// Generate data.
var width = 2;
var height = 2;
var data = new Float32Array(width * height * numberOfChannels);
for (var ii = 0; ii < data.length; ++ii) {
data[ii] = 10000;
}
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.FLOAT, data);
if (expectFailure) {
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "floating-point texture allocation must be disallowed if OES_texture_float isn't enabled");
return;
} else {
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should succeed if OES_texture_float is enabled");
}
// Verify that the texture actually works for sampling and contains the expected data.
gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor);
wtu.clearAndDrawUnitQuad(gl);
checkRenderingResults();
// Check that linear fails.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red");
}
function arrayToString(arr, size) {
var mySize;
if (!size)
mySize = arr.length;
else
mySize = size;
var out = "[";
for (var ii = 0; ii < mySize; ++ii) {
if (ii > 0) {
out += ", ";
}
out += arr[ii];
}
return out + "]";
}
function runRenderTargetAndReadbackTest(testProgram, format, numberOfChannels, subtractor, texSubImageCover)
{
var formatString = wtu.glEnumToString(gl, format);
debug("");
debug("testing floating-point " + formatString + " render target" + (texSubImageCover > 0 ? " after calling texSubImage" : ""));
var texture = allocateTexture();
var width = 2;
var height = 2;
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.FLOAT, null);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should succeed if OES_texture_float is enabled");
// Try to use this texture as a render target.
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
gl.bindTexture(gl.TEXTURE_2D, null);
// It is legal for a WebGL implementation exposing the OES_texture_float extension to
// support floating-point textures but not as attachments to framebuffer objects.
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
debug("floating-point " + formatString + " render target not supported -- this is legal");
return;
}
if (texSubImageCover > 0) {
// Ensure that replacing the whole texture or a part of it with texSubImage2D doesn't affect renderability
gl.bindTexture(gl.TEXTURE_2D, texture);
var data = new Float32Array(width * height * numberOfChannels * texSubImageCover);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height * texSubImageCover, format, gl.FLOAT, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed if OES_texture_float is enabled");
gl.bindTexture(gl.TEXTURE_2D, null);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
testFailed("render target support changed after calling texSubImage2D");
return;
}
}
var renderProgram =
wtu.setupProgram(gl,
["positionVertexShader", "floatingPointFragmentShader"],
['vPosition'],
[0]);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "rendering to floating-point texture should succeed");
// Now sample from the floating-point texture and verify we got the correct values.
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.useProgram(testProgram);
gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0);
gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture should succeed");
checkRenderingResults();
// Finally, if the implementation supports floating-point readback, verify it.
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
var implFormat = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT);
var implType = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "getParameter of IMPLEMENTATION_COLOR_READ_{FORMAT|TYPE} should succeed");
if ((implFormat == gl.RGBA || implFormat == gl.RGB) && implType == gl.FLOAT) {
debug("Checking readback of floating-point values");
var arraySize = (implFormat == gl.RGBA) ? 4 : 3
var buf = new Float32Array(arraySize);
gl.readPixels(0, 0, 1, 1, implFormat, implType , buf);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "readPixels from floating-point renderbuffer should succeed");
var ok = true;
var tolerance = 8.0; // TODO: factor this out from both this test and the subtractor shader above.
for (var ii = 0; ii < buf.length; ++ii) {
if (Math.abs(buf[ii] - subtractor[ii]) > tolerance) {
ok = false;
break;
}
}
if (ok) {
testPassed("readPixels of float-type data from floating-point renderbuffer succeeded");
} else {
testFailed("readPixels of float-type data from floating-point renderbuffer failed: expected "
+ arrayToString(subtractor, arraySize) + ", got " + arrayToString(buf));
}
}
}
function runUniqueObjectTest()
{
debug("");
debug("Testing that getExtension() returns the same object each time");
gl.getExtension("OES_texture_float").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("OES_texture_float").myProperty', '2');
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,58 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/oes-texture-float-and-half-float-linear.js"></script>
<script>
"use strict";
function testPrologue(gl, extensionTypeName) {
var ext = null;
if (!(ext = gl.getExtension(extensionTypeName))) {
testPassed("No " + extensionTypeName + " support -- this is legal");
return false;
}
// Required by the test harness.
gl.HALF_FLOAT_OES = ext.HALF_FLOAT_OES;
testPassed("Successfully enabled " + extensionTypeName + " extension");
return true;
}
</script>
</head>
<body onload='generateTest("OES_texture_half_float", "OES_texture_half_float_linear", "HALF_FLOAT_OES", testPrologue)()'>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
</body>
</html>

View file

@ -1,62 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-canvas.js"></script>
<script>
"use strict";
function testPrologue(gl) {
var ext = null;
if (!(ext = gl.getExtension("OES_texture_half_float"))) {
testPassed("No OES_texture_half_float support -- this is legal");
return false;
}
// Required by the test harness.
gl.HALF_FLOAT_OES = ext.HALF_FLOAT_OES;
testPassed("Successfully enabled OES_texture_half_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "HALF_FLOAT_OES", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,63 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-image-data.js"></script>
<script>
"use strict";
function testPrologue(gl) {
var ext = null;
if (!(ext = gl.getExtension("OES_texture_half_float"))) {
testPassed("No OES_texture_half_float support -- this is legal");
return false;
}
// Required by the test harness.
gl.HALF_FLOAT_OES = ext.HALF_FLOAT_OES;
testPassed("Successfully enabled OES_texture_half_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "HALF_FLOAT_OES", testPrologue, "../../resources/")()'>
<canvas id="texcanvas" width="2" height="2"></canvas>
<canvas id="example" width="2" height="2"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,62 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-image.js"></script>
<script>
"use strict";
function testPrologue(gl) {
var ext = null;
if (!(ext = gl.getExtension("OES_texture_half_float"))) {
testPassed("No OES_texture_half_float support -- this is legal");
return false;
}
// Required by the test harness.
gl.HALF_FLOAT_OES = ext.HALF_FLOAT_OES;
testPassed("Successfully enabled OES_texture_half_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "HALF_FLOAT_OES", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>

View file

@ -1,67 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
<script src="../../js/tests/tex-image-and-sub-image-2d-with-video.js"></script>
<script>
"use strict";
function testPrologue(gl) {
var ext = null;
if (!(ext = gl.getExtension("OES_texture_half_float"))) {
testPassed("No OES_texture_half_float support -- this is legal");
return false;
}
// Required by the test harness.
gl.HALF_FLOAT_OES = ext.HALF_FLOAT_OES;
testPassed("Successfully enabled OES_texture_half_float extension");
return true;
}
</script>
</head>
<body onload='generateTest("RGBA", "RGBA", "HALF_FLOAT_OES", testPrologue, "../../resources/")()'>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
<video width="640" height="228" id="vid" controls>
<source src="../../resources/red-green.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<source src="../../resources/red-green.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
<source src="../../resources/red-green.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
</video>
</body>
</html>

View file

@ -1,498 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_texture_half_float Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<canvas id="canvas2d" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script id="testFragmentShader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D tex;
uniform vec4 subtractor;
varying vec2 texCoord;
void main()
{
vec4 color = texture2D(tex, texCoord);
if (abs(color.r - subtractor.r) +
abs(color.g - subtractor.g) +
abs(color.b - subtractor.b) +
abs(color.a - subtractor.a) < 8.0) {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
} else {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
}
</script>
<!-- Shaders for testing half-floating-point render targets -->
<script id="floatingPointFragmentShader" type="x-shader/x-fragment">
void main()
{
gl_FragColor = vec4(10000.0, 10000.0, 10000.0, 10000.0);
}
</script>
<script>
"use strict"
description("This test verifies the functionality of OES_texture_half_float with null/non-null ArrayBufferView");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var colorCanvas = document.getElementById("canvas2d");
colorCanvas.width = 2;
colorCanvas.height = 2;
var ctx = colorCanvas.getContext("2d");
ctx.fillStyle = "rgb(255,0,0)";
ctx.fillRect(0, 0, 2, 2);
var gl = wtu.create3DContext(canvas);
// This constant must be defined in order to run the texture creation test without the extension enabled.
var halfFloatOESEnum = 0x8D61;
var ext = null;
if (!gl) {
testFailed("WebGL context does not exists");
} else {
testPassed("WebGL context exists");
// Verify that allocation of texture fails if extension is not enabled
runTextureCreationTest(false);
ext = gl.getExtension("OES_texture_half_float")
if (!ext) {
testPassed("No OES_texture_half_float support. This is legal");
} else {
testPassed("Successfully enabled OES_texture_half_float extension");
var program = wtu.setupTexturedQuad(gl);
// Check if creation of texture succeed's with various formats and null ArrayBufferView
var formats = [
{ format: gl.RGBA, expected: [255, 0, 0, 255], },
{ format: gl.RGB, expected: [255, 0, 0, 255], },
{ format: gl.LUMINANCE, expected: [255, 255, 255, 255], },
{ format: gl.ALPHA, expected: [ 0, 0, 0, 255], },
{ format: gl.LUMINANCE_ALPHA, expected: [255, 255, 255, 255], },
];
formats.forEach(function(f) {
runTextureCreationTest(true, f.format, null, f.expected);
});
// Texture creation should fail when passed with non-null, non-Uint16 ArrayBufferView
formats.forEach(function(f) {
var width = 2;
var height = 2;
var format = f.format;
// Float32Array
var float32Data = new Float32Array(width * height * getNumberOfChannels(format));
for (var ii = 0; ii < float32Data.length; ii++) {
float32Data[ii] = 1000;
}
runTextureCreationTest(true, format, float32Data, null);
// Int16Array
var int16Data = new Int16Array(width * height * getNumberOfChannels(format));
for (var ii = 0; ii < int16Data.length; ii++) {
int16Data[ii] = 1000;
}
runTextureCreationTest(true, format, int16Data, null);
});
// Test that Uint16 encoded half float values can be used as texture data.
// First test that values in the 0-1 range can be written and read.
var halfFloatOneThird = 0x3555; // Half float 1/3
var uint16Formats = [
{ format: gl.RGBA, expected: [85, 85, 85, 85], },
{ format: gl.RGB, expected: [85, 85, 85, 255], },
{ format: gl.LUMINANCE, expected: [85, 85, 85, 255], },
{ format: gl.ALPHA, expected: [ 0, 0, 0, 85], },
{ format: gl.LUMINANCE_ALPHA, expected: [85, 85, 85, 85], },
];
uint16Formats.forEach(function(f) {
var width = 2;
var height = 2;
var format = f.format;
var uint16Data = new Uint16Array(width * height * getNumberOfChannels(format));
for (var ii = 0; ii < uint16Data.length; ii++) {
uint16Data[ii] = halfFloatOneThird;
}
runTextureCreationTest(true, format, uint16Data, f.expected);
});
// Next check that values outside the 0-1 range can be written.
var halfFloatTenK = 0x70E2; // Half float 10000
var uint16Formats2 = [
{ format: gl.RGBA, subtractor: [10000, 10000, 10000, 10000], },
{ format: gl.RGB, subtractor: [10000, 10000, 10000, 1], },
];
uint16Formats2.forEach(function(f) {
var width = 2;
var height = 2;
var format = f.format;
var uint16Data = new Uint16Array(width * height * getNumberOfChannels(format));
for (var ii = 0; ii < uint16Data.length; ii++) {
uint16Data[ii] = halfFloatTenK;
}
runRenderTest(format, f.subtractor, uint16Data);
});
// Check if attaching texture as FBO target succeeds (Not mandatory)
runRenderTest(gl.RGBA, [10000, 10000, 10000, 10000], null);
runRenderTest(gl.RGB, [10000, 10000, 10000, 1], null);
runFramebufferTest();
// Check of getExtension() returns same object
runUniqueObjectTest();
}
}
function getNumberOfChannels(format)
{
if (format == gl.RGBA)
return 4;
else if (format == gl.RGB)
return 3;
else if (format == gl.LUMINANCE || format == gl.ALPHA)
return 1;
else if (format == gl.LUMINANCE_ALPHA)
return 2;
}
function getFormatName(format)
{
if (format == gl.RGBA)
return "RGBA";
else if (format == gl.RGB)
return "RGB";
else if (format == gl.LUMINANCE)
return "LUMINANCE";
else if (format == gl.ALPHA)
return "ALPHA";
else if (format == gl.LUMINANCE_ALPHA)
return "LUMINANCE_ALPHA";
}
function getTypeName(type) {
if (type === gl.UNSIGNED_BYTE)
return "UNSIGNED_BYTE";
else if (type === ext.HALF_FLOAT_OES)
return "HALF_FLOAT_OES";
else if (type === gl.UNSIGNED_SHORT_4_4_4_4)
return "UNSIGNED_SHORT_4_4_4_4";
else if (type === gl.UNSIGNED_SHORT_5_5_5_1)
return "UNSIGNED_SHORT_5_6_5";
else if (type === gl.FLOAT)
return "FLOAT";
}
function allocateTexture()
{
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_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);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed");
return texture;
}
function runTextureCreationTest(extensionEnabled, opt_format, opt_data, opt_expected)
{
var format = opt_format || gl.RGBA;
var data = opt_data || null;
var expectSuccess = true;
if (!extensionEnabled || !opt_expected)
expectSuccess = false;
debug("Testing texture creation with extension " + (extensionEnabled ? "enabled" : "disabled") +
", format " + getFormatName(format) + ", and data " + (data ? "non-null" : "null") +
". Expect " + (expectSuccess ? "Success" : "Failure"));
var texture = allocateTexture();
var width = 2;
var height = 2;
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, halfFloatOESEnum, data);
if(!extensionEnabled) {
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "Half floating point texture must be disallowed if OES_texture_half_float isn't enabled");
return;
} else if (!opt_expected) {
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "Half floating point texture allocation must be disallowed when ArrayBufferView is not-null and not-Uint16");
return;
} else {
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Half floating point texture allocation should succeed if OES_texture_half_float is enabled");
if (!data) {
gl.texImage2D(gl.TEXTURE_2D, 0, format, format, halfFloatOESEnum, colorCanvas);
}
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, opt_expected);
// Check that linear fails.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, [0, 0, 0, 255], "should be black");
}
}
function checkRenderingResults()
{
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}
function runRenderTest(format, subtractor, data)
{
var formatString = wtu.glEnumToString(gl, format);
debug("");
if (!data) {
debug("Testing half floating point " + formatString + " render target");
} else {
debug("Testing half floating point " + formatString + " from a Uint16Array");
}
var texture = allocateTexture();
var width = 2;
var height = 2;
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, ext.HALF_FLOAT_OES, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Half floating point texture allocation should succeed if OES_texture_half_float is enabled");
if (!data) {
// Try to use this texture as render target
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
gl.bindTexture(gl.TEXTURE_2D, null);
// It is legal for a WebGL implementation exposing the OES_texture_half_float extension to
// support half floating point textures but not as attachments to framebuffer objects.
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
debug("Half floating point render targets not supported -- this is legal");
return;
}
var renderProgram =
wtu.setupProgram(gl,
[wtu.simpleVertexShader, "floatingPointFragmentShader"],
['vPosition'],
[0]);
wtu.drawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Rendering to half floating point texture should succeed");
}
// Now sample from the half floating-point texture and verify we got the correct values.
var texturedShaders = [
wtu.simpleTextureVertexShader,
"testFragmentShader"
];
var testProgram =
wtu.setupProgram(gl,
[wtu.simpleTextureVertexShader, "testFragmentShader"],
['vPosition', 'texCoord0'],
[0, 1]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.useProgram(testProgram);
gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor);
wtu.drawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "rendering from half floating point texture should succeed");
checkRenderingResults();
}
function runUniqueObjectTest()
{
debug("");
debug("Testing that getExtension() returns the same object each time");
ext = null;
gl.getExtension("OES_texture_half_float").myProperty = 2;
webglHarnessCollectGarbage();
shouldBe('gl.getExtension("OES_texture_half_float").myProperty', '2');
}
// Make sure we can call readPixels with the passed in arrayBufferConstructor and that the color
// channels are the ones we expect. If there is a mismatch between the glType and arrayBuffer type,
// fail the test.
function verifyReadPixelsColors(red, green, blue, alpha, alphaRGB, glFormat, glType, arrayBufferConstructor) {
var typeName = getTypeName(glType);
debug(getFormatName(glFormat) + " framebuffer with " + typeName + " readback.");
var arrayBuffer = new arrayBufferConstructor(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, glType, arrayBuffer);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "readPixels should return NO_ERROR when reading " + typeName + " data.");
assertMsg(arrayBuffer[0] === red, "Red channel should be " + red + " for " + typeName + " readPixels. Received: " + arrayBuffer[0]);
assertMsg(arrayBuffer[1] === green, "Green channel should be " + green + " for " + typeName + " readPixels. Received: " + arrayBuffer[1]);
assertMsg(arrayBuffer[2] === blue, "Blue channel should be " + blue + " for " + typeName + " readPixels. Received: " + arrayBuffer[2]);
if (glFormat === gl.RGBA) {
assertMsg(arrayBuffer[3] === alpha, "Alpha channel should be " + alpha + " for " + typeName + " readPixels. Received: " + arrayBuffer[3]);
} else if (glFormat === gl.RGB) {
assertMsg(arrayBuffer[3] === alphaRGB, "Alpha channel should be " + alphaRGB + " for " + typeName + " readPixels. Received: " + arrayBuffer[3]);
}
// Make sure any arrayBuffer types that are not equal to arrayBufferConstructor fail readPixels.
if (arrayBufferConstructor !== Uint8Array) {
arrayBuffer = new Uint8Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, glType, arrayBuffer);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "readPixels should return INVALID_OPERATION when reading mismatched types. " + Uint8Array.toString());
}
if (arrayBufferConstructor !== Float32Array) {
arrayBuffer = new Float32Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, glType, arrayBuffer);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "readPixels should return INVALID_OPERATION when reading mismatched types. " + Float32Array.toString());
}
if (arrayBufferConstructor !== Uint16Array) {
arrayBuffer = new Uint16Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, glType, arrayBuffer);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "readPixels should return INVALID_OPERATION when reading mismatched types. " + Uint16Array.toString());
}
}
// Verify that half float textures attached to frame buffers function correctly with regard to framebuffer
// completness, IMPLEMENTATION_COLOR_READ_FORMAT/TYPE and readPixels
function runFramebufferTest() {
debug("");
debug("Framebuffer Tests");
var texture = allocateTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, ext.HALF_FLOAT_OES, null);
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
debug("Half floating point render targets not supported -- this is legal");
return;
}
debug("Ensure non-color-renderable formats [LUMINANCE, LUMINANCE_ALPHA, ALPHA] fail");
var arrayBufferFloatOutput = new Float32Array(4); // 4 color channels
[gl.LUMINANCE, gl.LUMINANCE_ALPHA, gl.ALPHA].forEach(function(badFormat) {
debug(getFormatName(badFormat) + " framebuffer");
gl.texImage2D(gl.TEXTURE_2D, 0, badFormat, 1, 1, 0, badFormat, ext.HALF_FLOAT_OES, null);
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
shouldBeNull("gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT)");
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "IMPLEMENTATION_COLOR_READ_FORMAT should fail for incomplete framebuffers.");
shouldBeNull("gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE)");
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "IMPLEMENTATION_COLOR_READ_TYPE should fail for incomplete framebuffers.");
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, arrayBufferFloatOutput);
wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION , "readPixels should fail on incomplete framebuffers.");
debug("");
});
debug("Ensure color renderable formats [RGBA, RGB] succeed.");
var arrayBufferHalfFloatInput = new Uint16Array(4); // 4 color channels
arrayBufferHalfFloatInput[0] = 0; // 0 in half float
arrayBufferHalfFloatInput[1] = 0x3400; // 0.25 in half float
arrayBufferHalfFloatInput[2] = 0x3800; // 0.50 in half float
arrayBufferHalfFloatInput[3] = 0x3A00; // 0.75 in half float
[gl.RGBA, gl.RGB].forEach(function(goodFormat) {
debug(getFormatName(goodFormat) + " framebuffer tests");
debug("");
gl.texImage2D(gl.TEXTURE_2D, 0, goodFormat, 1, 1, 0, goodFormat, ext.HALF_FLOAT_OES, arrayBufferHalfFloatInput);
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
// To avoid GPU idiosyncrasies, dispense with clearing or rendering to the texture. Go straight to readPixels.
// Per the OES_color_buffer_half_float, RGBA/FLOAT should always succeed for readPixels
verifyReadPixelsColors(
0.00, // red
0.25, // green
0.50, // blue
0.75, // alpha
1.0, // alphaRGB
goodFormat,
gl.FLOAT,
Float32Array);
var implementationColorReadFormat = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_FORMAT);
assertMsg(implementationColorReadFormat === gl.RGBA || implementationColorReadFormat === gl.RGB,
"IMPLEMENTATION_COLOR_READ_FORMAT should be color renderable: RGBA or RGB. Received: " + getFormatName(implementationColorReadFormat));
var implementationColorReadType = gl.getParameter(gl.IMPLEMENTATION_COLOR_READ_TYPE);
// There is nothing in the specifications that keeps the
// implementation color read format and type from being the
// same as the implicitly supported one. For this reason, keep
// gl.FLOAT as one of the valid options.
assertMsg(implementationColorReadType === gl.UNSIGNED_BYTE ||
implementationColorReadType === gl.FLOAT ||
implementationColorReadType === ext.HALF_FLOAT_OES ||
implementationColorReadType === gl.UNSIGNED_SHORT_4_4_4_4 ||
implementationColorReadType === gl.UNSIGNED_SHORT_5_5_5_1 ||
implementationColorReadType === gl.UNSIGNED_SHORT_5_6_5,
"IMPLEMENTATION_COLOR_READ_TYPE must be one of UNSIGNED_BYTE, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_5_6_5, FLOAT, or HALF_FLOAT_OES. " +
"Received: " + getTypeName(implementationColorReadType));
// Test the RGBA/HALF_FLOAT_OES combination
if (implementationColorReadFormat === gl.RGBA && implementationColorReadType === ext.HALF_FLOAT_OES) {
verifyReadPixelsColors(
0, // red
0x3400, // green
0x3800, // blue
0x3A00, // alpha
0x3C00, // alphaRGB
goodFormat,
ext.HALF_FLOAT_OES,
Uint16Array);
}
debug("");
});
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,217 +0,0 @@
<!--
/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_vertex_array_object_bufferData Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<!-- comment in the script tag below to test through JS emualation of the extension. -->
<!--
<script src="../../../demos/google/resources/OESVertexArrayObject.js"></script>
-->
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main(void) {
gl_Position = a_position;
v_color = a_color;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 v_color;
void main(void) {
gl_FragColor = v_color;
}
</script>
<script>
"use strict";
description("This test verifies drawing results when using gl.bufferData with the OES_vertex_array_object extension.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
var vao = null;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Setup emulated OESVertexArrayObject if it has been included.
if (window.setupVertexArrayObject) {
debug("using emuated OES_vertex_array_object");
setupVertexArrayObject(gl);
}
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("OES_vertex_array_object");
if (!ext) {
testPassed("No OES_vertex_array_object support -- this is legal");
} else {
testPassed("Successfully enabled OES_vertex_array_object extension");
runBufferDataTest();
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}
}
/**
* The OES_vertex_array_object extension seems to work incorrectly on some handheld devices,
* namely the Nexus 5, and Nexus 7 (in 2014/01) when using bufferData before binding the VAO.
* The tested OS was Android KitKat 4.4.2, the effects were the same in all tested browsers
* (Chrome, Chrome Beta, Firefox, Firefox Beta), so it is likely a driver bug.
* These devices have the similar Adreno 320 and Adreno 330 GPUs respectively.
*
* The issuse resulted from this sequence of actions in a requestAnimationFrame loop:
* 1. upload some vertex buffers with gl.bufferData (eg. colors)
* 2. bind the VAO
* 3. clear the canvas
* 4. draw (some triangles) to the canvas
* 5. unbind the VAO
*
* This caused the drawn triangles to be drawn with black (0) for most of the frames, with some
* rare frames presenting the correct render results. Interestingly on both devices exactly every
* 64th frame passed (starting with the very first one), the others failed.
* (Because of this, we test multiple frames.)
* When positions were uploaded, seemingly nothing was drawn, that's likely because the
* position buffer was also all 0s.
*
* The issue did not occur:
* - if step 1. and 2. were swapped
* - or if step5 was ommited (probably because that makes step 2 a no-op since the VAO is bound)
*/
function runBufferDataTest() {
debug("Testing draws with bufferData");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
var testColor = [0, 255, 0, 255];
var clearColor = [255, 0, 0, 255];
// Where the issue occures, this is the sequence of success/failure every time:
// result: success fail fail fail fail ... success fail fail ...
// currentTestCount: 0 1 2 3 4 ... 64 65 66 ...
// So with just 1 test it passes, but 2 tests are enough. Here we use 3.
var numberOfTests = 3;
var currentTestCount = 0;
var positionLoc = 0;
var colorLoc = 1;
var gridRes = 1;
var program = wtu.setupSimpleVertexColorProgram(gl, positionLoc, colorLoc);
var vao0 = ext.createVertexArrayOES();
ext.bindVertexArrayOES(vao0);
var buffers = wtu.setupIndexedQuadWithOptions(gl,
{ gridRes: gridRes,
positionLocation: positionLoc
});
var colorTypedArray = createColorTypedArray();
var colorBuffer = gl.createBuffer(gl.ARRAY_BUFFER);
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.enableVertexAttribArray(colorLoc);
gl.vertexAttribPointer(colorLoc, 4, gl.FLOAT, false, 0, 0);
ext.bindVertexArrayOES(null);
testDrawing();
function testDrawing() {
// this order works fine:
// ext.bindVertexArrayOES(vao0);
// uploadColor();
// this order doesn't:
uploadColor();
ext.bindVertexArrayOES(vao0);
wtu.clearAndDrawIndexedQuad(gl, 1, clearColor);
ext.bindVertexArrayOES(null);
//debug("<span>"+currentTestCount+"</span");
wtu.checkCanvas(gl, testColor, "should be green")
if (++currentTestCount < numberOfTests) {
testDrawing();
// wtu.requestAnimFrame(testDrawing);
} else {
// clean up
ext.deleteVertexArrayOES(vao0);
}
}
function uploadColor() {
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, colorTypedArray, gl.STREAM_DRAW);
}
function createColorTypedArray() {
var colors = [];
var pOffset = 0;
for (var yy = 0; yy <= gridRes; ++yy) {
for (var xx = 0; xx <= gridRes; ++xx) {
colors[pOffset + 0] = testColor[0];
colors[pOffset + 1] = testColor[1];
colors[pOffset + 2] = testColor[2];
colors[pOffset + 3] = testColor[3];
pOffset += 4;
}
}
return new Float32Array(colors);
}
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,659 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL OES_vertex_array_object Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<!-- comment in the script tag below to test through JS emulation of the extension. -->
<!--
<script src="../../../demos/google/resources/OESVertexArrayObject.js"></script>
-->
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main(void) {
gl_Position = a_position;
v_color = a_color;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 v_color;
void main(void) {
gl_FragColor = v_color;
}
</script>
<script>
"use strict";
description("This test verifies the functionality of the OES_vertex_array_object extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas);
var ext = null;
var vao = null;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Setup emulated OESVertexArrayObject if it has been included.
if (window.setupVertexArrayObject) {
debug("using emulated OES_vertex_array_object");
setupVertexArrayObject(gl);
}
// Run tests with extension disabled
runBindingTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("OES_vertex_array_object");
if (!ext) {
testPassed("No OES_vertex_array_object support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled OES_vertex_array_object extension");
runSupportedTest(true);
runBindingTestEnabled();
runObjectTest();
runAttributeTests();
runAttributeValueTests();
runDrawTests();
runUnboundDeleteTests();
runArrayBufferBindTests();
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("OES_vertex_array_object") >= 0) {
if (extensionEnabled) {
testPassed("OES_vertex_array_object listed as supported and getExtension succeeded");
} else {
testFailed("OES_vertex_array_object listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("OES_vertex_array_object not listed as supported but getExtension succeeded");
} else {
testPassed("OES_vertex_array_object not listed as supported and getExtension failed -- this is legal");
}
}
}
function runBindingTestDisabled() {
debug("");
debug("Testing binding enum with extension disabled");
// Use the constant directly as we don't have the extension
var VERTEX_ARRAY_BINDING_OES = 0x85B5;
gl.getParameter(VERTEX_ARRAY_BINDING_OES);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "VERTEX_ARRAY_BINDING_OES should not be queryable if extension is disabled");
}
function runBindingTestEnabled() {
debug("");
debug("Testing binding enum with extension enabled");
shouldBe("ext.VERTEX_ARRAY_BINDING_OES", "0x85B5");
gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "VERTEX_ARRAY_BINDING_OES query should succeed if extension is enabled");
// Default value is null
if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) === null) {
testPassed("Default value of VERTEX_ARRAY_BINDING_OES is null");
} else {
testFailed("Default value of VERTEX_ARRAY_BINDING_OES is not null");
}
debug("");
debug("Testing binding a VAO");
var vao0 = ext.createVertexArrayOES();
var vao1 = ext.createVertexArrayOES();
shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
ext.bindVertexArrayOES(vao0);
if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao0) {
testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO");
} else {
testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO")
}
ext.bindVertexArrayOES(vao1);
if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao1) {
testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO");
} else {
testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO")
}
ext.deleteVertexArrayOES(vao1);
shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
ext.bindVertexArrayOES(vao1);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted vertex array object");
ext.bindVertexArrayOES(null);
shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
ext.deleteVertexArrayOES(vao1);
}
function runObjectTest() {
debug("");
debug("Testing object creation");
vao = ext.createVertexArrayOES();
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createVertexArrayOES should not set an error");
shouldBeNonNull("vao");
// Expect false if never bound
shouldBeFalse("ext.isVertexArrayOES(vao)");
ext.bindVertexArrayOES(vao);
shouldBeTrue("ext.isVertexArrayOES(vao)");
ext.bindVertexArrayOES(null);
shouldBeTrue("ext.isVertexArrayOES(vao)");
shouldBeFalse("ext.isVertexArrayOES(null)");
ext.deleteVertexArrayOES(vao);
vao = null;
}
function runAttributeTests() {
debug("");
debug("Testing attributes work across bindings");
var states = [];
var attrCount = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
for (var n = 0; n < attrCount; n++) {
gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
var state = {};
states.push(state);
var vao = state.vao = ext.createVertexArrayOES();
ext.bindVertexArrayOES(vao);
var enableArray = (n % 2 == 0);
if (enableArray) {
gl.enableVertexAttribArray(n);
} else {
gl.disableVertexAttribArray(n);
}
if (enableArray) {
var buffer = state.buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
gl.vertexAttribPointer(n, 1 + n % 4, gl.FLOAT, true, n * 4, n * 4);
}
if (enableArray) {
var elbuffer = state.elbuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elbuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
}
ext.bindVertexArrayOES(null);
}
var anyMismatch = false;
for (var n = 0; n < attrCount; n++) {
var state = states[n];
ext.bindVertexArrayOES(state.vao);
var shouldBeEnabled = (n % 2 == 0);
var isEnabled = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
if (shouldBeEnabled != isEnabled) {
testFailed("VERTEX_ATTRIB_ARRAY_ENABLED not preserved");
anyMismatch = true;
}
var buffer = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
if (shouldBeEnabled) {
if (buffer == state.buffer) {
// Matched
if ((gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_SIZE) == 1 + n % 4) &&
(gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_TYPE) == gl.FLOAT) &&
(gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED) == true) &&
(gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == n * 4) &&
(gl.getVertexAttribOffset(n, gl.VERTEX_ATTRIB_ARRAY_POINTER) == n * 4)) {
// Matched
} else {
testFailed("VERTEX_ATTRIB_ARRAY_* not preserved");
anyMismatch = true;
}
} else {
testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved");
anyMismatch = true;
}
} else {
// GL_CURRENT_VERTEX_ATTRIB is not preserved
if (buffer) {
testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved");
anyMismatch = true;
}
}
var elbuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING);
if (shouldBeEnabled) {
if (elbuffer == state.elbuffer) {
// Matched
} else {
testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved");
anyMismatch = true;
}
} else {
if (elbuffer == null) {
// Matched
} else {
testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved");
anyMismatch = true;
}
}
}
ext.bindVertexArrayOES(null);
if (!anyMismatch) {
testPassed("All attributes preserved across bindings");
}
for (var n = 0; n < attrCount; n++) {
var state = states[n];
ext.deleteVertexArrayOES(state.vao);
}
}
function runAttributeValueTests() {
debug("");
debug("Testing that attribute values are not attached to bindings");
var v;
var vao0 = ext.createVertexArrayOES();
var anyFailed = false;
ext.bindVertexArrayOES(null);
gl.vertexAttrib4f(0, 0, 1, 2, 3);
v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) {
testFailed("Vertex attrib value not round-tripped?");
anyFailed = true;
}
ext.bindVertexArrayOES(vao0);
v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) {
testFailed("Vertex attrib value reset across bindings");
anyFailed = true;
}
gl.vertexAttrib4f(0, 4, 5, 6, 7);
ext.bindVertexArrayOES(null);
v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
if (!(v[0] == 4 && v[1] == 5 && v[2] == 6 && v[3] == 7)) {
testFailed("Vertex attrib value bound to buffer");
anyFailed = true;
}
if (!anyFailed) {
testPassed("Vertex attribute values are not attached to bindings")
}
ext.bindVertexArrayOES(null);
ext.deleteVertexArrayOES(vao0);
}
function runDrawTests() {
debug("");
debug("Testing draws with various VAO bindings");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
var vao0 = ext.createVertexArrayOES();
var vao1 = ext.createVertexArrayOES();
var vao2 = ext.createVertexArrayOES();
var positionLocation = 0;
var colorLocation = 1;
var program = wtu.setupSimpleVertexColorProgram(gl, positionLocation, colorLocation);
function setupQuad(s, colorsInArray) {
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
1.0 * s, 1.0 * s, 0.0,
-1.0 * s, 1.0 * s, 0.0,
-1.0 * s, -1.0 * s, 0.0,
1.0 * s, 1.0 * s, 0.0,
-1.0 * s, -1.0 * s, 0.0,
1.0 * s, -1.0 * s, 0.0]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
// Test switching between VAOs that have different number of enabled arrays
if (colorsInArray) {
var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 1.0]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(colorLocation);
gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
} else {
gl.disableVertexAttribArray(colorLocation);
}
};
function verifyDiagonalPixels(s, expectedInside, drawDescription) {
// Tests pixels along a diagonal running from the center of the canvas to the (0, 0) corner.
// Values on the points list indicate relative position along this diagonal.
var points = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];
for (var n = 0; n < points.length; n++) {
var expected = points[n] <= s ? expectedInside : 255;
var x = Math.round((1 - points[n]) * canvas.width / 2);
var y = Math.round((1 - points[n]) * canvas.height / 2);
wtu.checkCanvasRect(gl, x, y, 1, 1, [expected, expected, expected, 255],
"Drawing " + drawDescription + " should pass", 2);
}
};
function verifyDraw(drawDescription, s, colorsInArray) {
wtu.clearAndDrawUnitQuad(gl);
var expectedInside = colorsInArray ? 0 : 128;
verifyDiagonalPixels(s, expectedInside, drawDescription);
};
// Setup all bindings
setupQuad(1, true);
ext.bindVertexArrayOES(vao0);
setupQuad(0.5, true);
ext.bindVertexArrayOES(vao1);
setupQuad(0.25, true);
ext.bindVertexArrayOES(vao2);
setupQuad(0.75, false);
gl.vertexAttrib4f(colorLocation, 0.5, 0.5, 0.5, 1);
// Verify drawing
ext.bindVertexArrayOES(null);
verifyDraw("with the default VAO", 1, true);
ext.bindVertexArrayOES(vao0);
verifyDraw("with VAO #0", 0.5, true);
ext.bindVertexArrayOES(vao1);
verifyDraw("with VAO #1", 0.25, true);
ext.bindVertexArrayOES(vao2);
verifyDraw("with VAO that has the color array disabled", 0.75, false);
// Verify bound VAO after delete
ext.bindVertexArrayOES(vao1);
ext.deleteVertexArrayOES(vao0);
verifyDraw("after deleting another VAO", 0.25, true);
ext.deleteVertexArrayOES(vao1);
verifyDraw("after deleting the VAO that was bound", 1, true);
// Disable global vertex attrib array
gl.disableVertexAttribArray(positionLocation);
gl.disableVertexAttribArray(colorLocation);
// Check that constant values are treated correctly as not being part of VAO state.
var positionLoc = 0;
var colorLoc = 1;
var gridRes = 1;
wtu.setupIndexedQuad(gl, gridRes, positionLoc);
// Set the vertex color to red.
gl.vertexAttrib4f(colorLoc, 1, 0, 0, 1);
var vao0 = ext.createVertexArrayOES();
ext.bindVertexArrayOES(vao0);
var program = wtu.setupSimpleVertexColorProgram(gl, positionLoc, colorLoc);
wtu.setupIndexedQuad(gl, gridRes, positionLoc);
// Set the vertex color to green.
gl.vertexAttrib4f(colorLoc, 0, 1, 0, 1);
wtu.clearAndDrawIndexedQuad(gl, gridRes);
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
ext.deleteVertexArrayOES(vao0);
wtu.clearAndDrawIndexedQuad(gl, gridRes);
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}
function runUnboundDeleteTests() {
debug("");
debug("Testing using buffers that are deleted when attached to unbound VAOs");
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_position", "a_color"]);
gl.useProgram(program);
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array([
1.0, 1.0,
-1.0, 1.0,
-1.0, -1.0,
1.0, -1.0]),
gl.STATIC_DRAW);
var colors = [
[255, 0, 0, 255],
[ 0, 255, 0, 255],
[ 0, 0, 255, 255],
[ 0, 255, 255, 255]
];
var colorBuffers = [];
var elementBuffers = [];
var vaos = [];
for (var ii = 0; ii < colors.length; ++ii) {
var vao = ext.createVertexArrayOES();
vaos.push(vao);
ext.bindVertexArrayOES(vao);
// Set the position buffer
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
var elementBuffer = gl.createBuffer();
elementBuffers.push(elementBuffer);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
gl.bufferData(
gl.ELEMENT_ARRAY_BUFFER,
new Uint8Array([0, 1, 2, 0, 2, 3]),
gl.STATIC_DRAW);
// Setup the color attrib
var color = colors[ii];
if (ii < 3) {
var colorBuffer = gl.createBuffer();
colorBuffers.push(colorBuffer);
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
[ color[0], color[1], color[2], color[3],
color[0], color[1], color[2], color[3],
color[0], color[1], color[2], color[3],
color[0], color[1], color[2], color[3]
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, 0);
} else {
gl.vertexAttrib4f(1, color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
}
}
// delete the color buffers AND the position buffer.
ext.bindVertexArrayOES(null);
for (var ii = 0; ii < colorBuffers.length; ++ii) {
gl.deleteBuffer(colorBuffers[ii]);
gl.deleteBuffer(elementBuffers[ii]);
ext.bindVertexArrayOES(vaos[ii]);
var boundBuffer = gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
// The buffers should still be valid at this point, since it was attached to the VAO
if(boundBuffer != colorBuffers[ii]) {
testFailed("buffer removed even though it is still attached to a VAO");
}
}
ext.bindVertexArrayOES(null);
gl.deleteBuffer(positionBuffer);
// Render with the deleted buffers. As they are referenced by VAOs they
// must still be around.
for (var ii = 0; ii < colors.length; ++ii) {
var color = colors[ii];
ext.bindVertexArrayOES(vaos[ii]);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
wtu.checkCanvas(gl, color, "should be " + color);
}
// Clean up.
for (var ii = 0; ii < colorBuffers.length; ++ii) {
ext.deleteVertexArrayOES(vaos[ii]);
}
for (var ii = 0; ii < colorBuffers.length; ++ii) {
// The buffers should no longer be valid now that the VAOs are deleted
if(gl.isBuffer(colorBuffers[ii])) {
testFailed("buffer not properly cleaned up after VAO deletion");
}
}
}
function runArrayBufferBindTests() {
debug("");
debug("Testing that buffer bindings on VAOs don't affect default VAO ARRAY_BUFFER binding.");
ext.bindVertexArrayOES(null);
var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_color", "a_position"]);
gl.useProgram(program);
// create shared element buffer
var elementBuffer = gl.createBuffer();
// bind to default
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
gl.bufferData(
gl.ELEMENT_ARRAY_BUFFER,
new Uint8Array([0, 1, 2, 0, 2, 3]),
gl.STATIC_DRAW);
// first create the buffers for no VAO draw.
var nonVAOColorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, nonVAOColorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
[ 0, 255, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
]), gl.STATIC_DRAW);
// shared position buffer.
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array([
1.0, 1.0,
-1.0, 1.0,
-1.0, -1.0,
1.0, -1.0]),
gl.STATIC_DRAW);
// attach position buffer to default
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
// now create VAO
var vao = ext.createVertexArrayOES();
ext.bindVertexArrayOES(vao);
// attach the position buffer VAO
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
var vaoColorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vaoColorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
[ 255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 4, gl.UNSIGNED_BYTE, true, 0, 0);
// now set the buffer back to the nonVAOColorBuffer
gl.bindBuffer(gl.ARRAY_BUFFER, nonVAOColorBuffer);
// bind to VAO
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red");
// unbind VAO
ext.bindVertexArrayOES(null);
// At this point the nonVAOColorBuffer should be still be bound.
// If the WebGL impl is emulating VAOs it must make sure
// it correctly restores this binding.
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 4, gl.UNSIGNED_BYTE, true, 0, 0);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,394 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<title>WebGL WEBGL_compressed_texture_pvrtc Conformance Tests</title>
<style>
img {
border: 1px solid black;
margin-right: 1em;
}
.testimages {
}
.testimages br {
clear: both;
}
.testimages > div {
float: left;
margin: 1em;
}
</style>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the WEBGL_compressed_texture_pvrtc extension, if it is available.");
debug("");
var pvrtc_4x4_2bpp = new Uint8Array([
0x77, 0x22, 0x77, 0x22, 0xbb, 0x2b, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);
var pvrtc_4x4_4bpp = new Uint8Array([
0x1b, 0x1b, 0x1b, 0x1b, 0xba, 0x2b, 0x00, 0x80, 0x1b, 0x1b, 0x1b, 0x1b, 0xba, 0x2b, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);
var pvrtc_4x4_rgba_decoded = new Uint8Array([
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x46, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xba, 0x44,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x43, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xb5, 0x44,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x43, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xb5, 0x44,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x46, 0xb8, 0x76, 0x76, 0x71, 0x8a, 0xbd, 0xbd, 0xb7, 0x44,
]);
var pvrtc_4x4_rgb_decoded = new Uint8Array([
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x46, 0xff, 0x76, 0x76, 0x71, 0xff, 0xbd, 0xbd, 0xba, 0xff,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x43, 0xff, 0x76, 0x76, 0x71, 0xff, 0xbd, 0xbd, 0xb5, 0xff,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x43, 0xff, 0x76, 0x76, 0x71, 0xff, 0xbd, 0xbd, 0xb5, 0xff,
0x00, 0x00, 0x00, 0xff, 0x46, 0x46, 0x46, 0xff, 0x76, 0x76, 0x71, 0xff, 0xbd, 0xbd, 0xb7, 0xff,
]);
var wtu = WebGLTestUtils;
var contextVersion = wtu.getDefault3DContextVersion();
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, {antialias: false});
var program = wtu.setupTexturedQuad(gl);
var ext = null;
var vao = null;
var validFormats = {
COMPRESSED_RGB_PVRTC_4BPPV1_IMG : 0x8C00,
COMPRESSED_RGB_PVRTC_2BPPV1_IMG : 0x8C01,
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : 0x8C02,
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG : 0x8C03,
};
var name;
var supportedFormats;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_pvrtc");
if (!ext) {
testPassed("No WEBGL_compressed_texture_pvrtc support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled WEBGL_compressed_texture_pvrtc extension");
runSupportedTest(true);
runTestExtension();
}
}
function runSupportedTest(extensionEnabled) {
var name = wtu.getSupportedExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_pvrtc");
if (name !== undefined) {
if (extensionEnabled) {
testPassed("WEBGL_compressed_texture_pvrtc listed as supported and getExtension succeeded");
} else {
testFailed("WEBGL_compressed_texture_pvrtc listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("WEBGL_compressed_texture_pvrtc not listed as supported but getExtension succeeded");
} else {
testPassed("WEBGL_compressed_texture_pvrtc not listed as supported and getExtension failed -- this is legal");
}
}
}
function runTestDisabled() {
debug("Testing binding enum with extension disabled");
supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
shouldBe("supportedFormats", "[]");
}
function formatExists(format, supportedFormats) {
for (var ii = 0; ii < supportedFormats.length; ++ii) {
if (format == supportedFormats[ii]) {
testPassed("supported format " + formatToString(format) + " is exists");
return;
}
}
testFailed("supported format " + formatToString(format) + " does not exist");
}
function formatToString(format) {
for (var p in ext) {
if (ext[p] == format) {
return p;
}
}
return "0x" + format.toString(16);
}
function runTestExtension() {
debug("Testing WEBGL_compressed_texture_pvrtc");
// check that all format enums exist.
for (name in validFormats) {
var expected = "0x" + validFormats[name].toString(16);
var actual = "ext['" + name + "']";
shouldBe(actual, expected);
}
supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
// There should be exactly 4 formats for both WebGL 1.0 and WebGL 2.0.
shouldBe("supportedFormats.length", "4");
// check that all 4 formats exist
for (var name in validFormats.length) {
formatExists(validFormats[name], supportedFormats);
}
// Test each format
testPVRTC_RGBA_2BPP();
testPVRTC_RGB_2BPP();
testPVRTC_RGBA_4BPP();
testPVRTC_RGB_4BPP();
}
function testPVRTC_RGBA_2BPP() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: pvrtc_4x4_2bpp,
raw: pvrtc_4x4_rgba_decoded,
format: ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
}
];
testPVRTCTextures(tests);
}
function testPVRTC_RGB_2BPP() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: pvrtc_4x4_2bpp,
raw: pvrtc_4x4_rgb_decoded,
format: ext.COMPRESSED_RGB_PVRTC_2BPPV1_IMG
}
];
testPVRTCTextures(tests);
}
function testPVRTC_RGBA_4BPP() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: pvrtc_4x4_4bpp,
raw: pvrtc_4x4_rgba_decoded,
format: ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
}
];
testPVRTCTextures(tests);
}
function testPVRTC_RGB_4BPP() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: pvrtc_4x4_4bpp,
raw: pvrtc_4x4_rgb_decoded,
format: ext.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
}
];
testPVRTCTextures(tests);
}
function testPVRTCTextures(tests) {
debug("<hr/>");
for (var ii = 0; ii < tests.length; ++ii) {
testPVRTCTexture(tests[ii]);
}
}
function testPVRTCTexture(test) {
var data = new Uint8Array(test.data);
var width = test.width;
var height = test.height;
var format = test.format;
var uncompressedData = test.raw;
canvas.width = width;
canvas.height = height;
gl.viewport(0, 0, width, height);
debug("testing " + formatToString(format) + " " + width + "x" + height);
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);
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture");
gl.generateMipmap(gl.TEXTURE_2D);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "trying to generate mipmaps from compressed texture");
wtu.drawQuad(gl);
compareRect(width, height, test.channels, width, height, uncompressedData, data, format, undefined, "NEAREST");
// Test again with linear filtering.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
wtu.clearAndDrawUnitQuad(gl);
compareRect(width, height, test.channels, width, height, uncompressedData, data, format, undefined, "LINEAR");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 1, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "non 0 border");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 1, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 2, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 1, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 2, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, format, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "compressedTexSubImage2D allowed for reloading of complete textures");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width - 2, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allowed for partial texture updates");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height - 2, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allowed for partial texture updates");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 2, 0, width - 2, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allowed for partial texture updates");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 2, width, height - 2, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "compressedTexSubImage2D not allowed for partial texture updates");
}
function insertImg(element, caption, img) {
var div = document.createElement("div");
div.appendChild(img);
var label = document.createElement("div");
label.appendChild(document.createTextNode(caption));
div.appendChild(label);
element.appendChild(div);
}
function makeImage(imageWidth, imageHeight, dataWidth, data, alpha) {
var scale = 8;
var c = document.createElement("canvas");
c.width = imageWidth * scale;
c.height = imageHeight * scale;
var ctx = c.getContext("2d");
for (var yy = 0; yy < imageHeight; ++yy) {
for (var xx = 0; xx < imageWidth; ++xx) {
var offset = (yy * dataWidth + xx) * 4;
ctx.fillStyle = "rgba(" +
data[offset + 0] + "," +
data[offset + 1] + "," +
data[offset + 2] + "," +
(alpha ? data[offset + 3] / 255 : 1) + ")";
ctx.fillRect(xx * scale, yy * scale, scale, scale);
}
}
return wtu.makeImageFromCanvas(c);
}
function compareRect(
actualWidth, actualHeight, actualChannels,
dataWidth, dataHeight, expectedData,
testData, testFormat, tolerance, filteringMode) {
if(typeof(tolerance) == 'undefined') { tolerance = 5; }
var actual = new Uint8Array(actualWidth * actualHeight * 4);
gl.readPixels(
0, 0, actualWidth, actualHeight, gl.RGBA, gl.UNSIGNED_BYTE, actual);
var div = document.createElement("div");
div.className = "testimages";
insertImg(div, "expected", makeImage(
actualWidth, actualHeight, dataWidth, expectedData,
actualChannels == 4));
insertImg(div, "actual", makeImage(
actualWidth, actualHeight, actualWidth, actual,
actualChannels == 4));
div.appendChild(document.createElement('br'));
document.getElementById("console").appendChild(div);
var failed = false;
for (var yy = 0; yy < actualHeight; ++yy) {
for (var xx = 0; xx < actualWidth; ++xx) {
var actualOffset = (yy * actualWidth + xx) * 4;
var expectedOffset = (yy * dataWidth + xx) * 4;
var expected = [
expectedData[expectedOffset + 0],
expectedData[expectedOffset + 1],
expectedData[expectedOffset + 2],
(actualChannels == 3 ? 255 : expectedData[expectedOffset + 3])
];
for (var jj = 0; jj < 4; ++jj) {
if (Math.abs(actual[actualOffset + jj] - expected[jj]) > tolerance) {
failed = true;
var was = actual[actualOffset + 0].toString();
for (var j = 1; j < 4; ++j) {
was += "," + actual[actualOffset + j];
}
testFailed('at (' + xx + ', ' + yy +
') expected: ' + expected + ' was ' + was);
}
}
}
}
if (!failed) {
testPassed("texture rendered correctly with " + filteringMode + " filtering");
}
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,738 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<title>WebGL WEBGL_compressed_texture_s3tc Conformance Tests</title>
<style>
img {
border: 1px solid black;
margin-right: 1em;
}
.testimages {
}
.testimages br {
clear: both;
}
.testimages > div {
float: left;
margin: 1em;
}
</style>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the WEBGL_compressed_texture_s3tc extension, if it is available.");
debug("");
var img_4x4_rgba_raw = new Uint8Array([
0xff,0x00,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
]);
var img_4x4_rgb_dxt1 = new Uint8Array([
0xe0,0x07,0x00,0xf8,0x11,0x10,0x15,0x00,
]);
var img_4x4_rgba_dxt1 = new Uint8Array([
0xe0,0x07,0x00,0xf8,0x13,0x10,0x15,0x00,
]);
var img_4x4_rgba_dxt3 = new Uint8Array([
0xf6,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0xf8,0xe0,0x07,0x44,0x45,0x40,0x55,
]);
var img_4x4_rgba_dxt5 = new Uint8Array([
0xf6,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0xf8,0xe0,0x07,0x44,0x45,0x40,0x55,
]);
var img_8x8_rgba_raw = new Uint8Array([
0xff,0x00,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0x00,0x69,0x00,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0x00,0x69,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0x69,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,
]);
var img_8x8_rgb_dxt1 = new Uint8Array([
0xe0,0x07,0x00,0xf8,0x11,0x10,0x15,0x00,0x1f,0x00,0xe0,0xff,0x11,0x10,0x15,0x00,0xe0,0x07,0x1f,0xf8,0x44,0x45,0x40,0x55,0x1f,0x00,0xff,0x07,0x44,0x45,0x40,0x55,
]);
var img_8x8_rgba_dxt1 = new Uint8Array([
0xe0,0x07,0x00,0xf8,0x13,0x13,0x15,0x00,0x1f,0x00,0xe0,0xff,0x11,0x10,0x15,0x00,0xe0,0x07,0x1f,0xf8,0x44,0x45,0x43,0x57,0x1f,0x00,0xff,0x07,0x44,0x45,0x40,0x55,
]);
var img_8x8_rgba_dxt3 = new Uint8Array([
0xf6,0xff,0xf6,0xff,0xff,0xff,0xff,0xff,0x00,0xf8,0xe0,0x07,0x44,0x45,0x40,0x55,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0xff,0x1f,0x00,0x44,0x45,0x40,0x55,0xff,0xff,0xff,0xff,0xf6,0xff,0xf6,0xff,0x1f,0xf8,0xe0,0x07,0x11,0x10,0x15,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x07,0x1f,0x00,0x11,0x10,0x15,0x00,
]);
var img_8x8_rgba_dxt5 = new Uint8Array([
0xff,0x69,0x01,0x10,0x00,0x00,0x00,0x00,0x00,0xf8,0xe0,0x07,0x44,0x45,0x40,0x55,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0xff,0x1f,0x00,0x44,0x45,0x40,0x55,0xff,0x69,0x00,0x00,0x00,0x01,0x10,0x00,0x1f,0xf8,0xe0,0x07,0x11,0x10,0x15,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x07,0x1f,0x00,0x11,0x10,0x15,0x00,
]);
var wtu = WebGLTestUtils;
var contextVersion = wtu.getDefault3DContextVersion();
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, {antialias: false});
var program = wtu.setupTexturedQuad(gl);
var ext = null;
var vao = null;
var validFormats = {
COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,
};
var name;
var supportedFormats;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = wtu.getExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_s3tc");
if (!ext) {
testPassed("No WEBGL_compressed_texture_s3tc support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled WEBGL_compressed_texture_s3tc extension");
runSupportedTest(true);
runTestExtension();
}
}
function runSupportedTest(extensionEnabled) {
var name = wtu.getSupportedExtensionWithKnownPrefixes(gl, "WEBGL_compressed_texture_s3tc");
if (name !== undefined) {
if (extensionEnabled) {
testPassed("WEBGL_compressed_texture_s3tc listed as supported and getExtension succeeded");
} else {
testFailed("WEBGL_compressed_texture_s3tc listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("WEBGL_compressed_texture_s3tc not listed as supported but getExtension succeeded");
} else {
testPassed("WEBGL_compressed_texture_s3tc not listed as supported and getExtension failed -- this is legal");
}
}
}
function runTestDisabled() {
debug("Testing binding enum with extension disabled");
supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
shouldBe("supportedFormats", "[]");
}
function formatExists(format, supportedFormats) {
for (var ii = 0; ii < supportedFormats.length; ++ii) {
if (format == supportedFormats[ii]) {
testPassed("supported format " + formatToString(format) + " is exists");
return;
}
}
testFailed("supported format " + formatToString(format) + " does not exist");
}
function formatToString(format) {
for (var p in ext) {
if (ext[p] == format) {
return p;
}
}
return "0x" + format.toString(16);
}
function runTestExtension() {
debug("Testing WEBGL_compressed_texture_s3tc");
// check that all format enums exist.
for (name in validFormats) {
var expected = "0x" + validFormats[name].toString(16);
var actual = "ext['" + name + "']";
shouldBe(actual, expected);
}
supportedFormats = gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS);
// There should be exactly 4 formats for both WebGL 1.0 and WebGL 2.0.
shouldBe("supportedFormats.length", "4");
// check that all 4 formats exist
for (var name in validFormats.length) {
formatExists(validFormats[name], supportedFormats);
}
// Test each format
testDXT1_RGB();
testDXT1_RGBA();
testDXT3_RGBA();
testDXT5_RGBA();
}
function testDXT1_RGB() {
var tests = [
{ width: 4,
height: 4,
channels: 3,
data: img_4x4_rgb_dxt1,
format: ext.COMPRESSED_RGB_S3TC_DXT1_EXT,
hasAlpha: false,
},
{ width: 8,
height: 8,
channels: 3,
data: img_8x8_rgb_dxt1,
format: ext.COMPRESSED_RGB_S3TC_DXT1_EXT,
hasAlpha: false,
subX0: 0,
subY0: 0,
subWidth: 4,
subHeight: 4,
subData: img_4x4_rgb_dxt1
}
];
testDXTTextures(tests);
}
function testDXT1_RGBA() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: img_4x4_rgba_dxt1,
format: ext.COMPRESSED_RGBA_S3TC_DXT1_EXT,
// This is a special case -- the texture is still opaque
// though it's RGBA.
hasAlpha: false,
},
{ width: 8,
height: 8,
channels: 4,
data: img_8x8_rgba_dxt1,
format: ext.COMPRESSED_RGBA_S3TC_DXT1_EXT,
// This is a special case -- the texture is still opaque
// though it's RGBA.
}
];
testDXTTextures(tests);
}
function testDXT3_RGBA() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: img_4x4_rgba_dxt3,
format: ext.COMPRESSED_RGBA_S3TC_DXT3_EXT,
hasAlpha: true,
},
{ width: 8,
height: 8,
channels: 4,
data: img_8x8_rgba_dxt3,
format: ext.COMPRESSED_RGBA_S3TC_DXT3_EXT,
hasAlpha: true,
subX0: 0,
subY0: 0,
subWidth: 4,
subHeight: 4,
subData: img_4x4_rgba_dxt3
}
];
testDXTTextures(tests);
}
function testDXT5_RGBA() {
var tests = [
{ width: 4,
height: 4,
channels: 4,
data: img_4x4_rgba_dxt5,
format: ext.COMPRESSED_RGBA_S3TC_DXT5_EXT,
hasAlpha: true,
},
{ width: 8,
height: 8,
channels: 4,
data: img_8x8_rgba_dxt5,
format: ext.COMPRESSED_RGBA_S3TC_DXT5_EXT,
hasAlpha: true,
subX0: 0,
subY0: 0,
subWidth: 4,
subHeight: 4,
subData: img_4x4_rgba_dxt5
}
];
testDXTTextures(tests);
}
function testDXTTextures(tests) {
debug("<hr/>");
for (var ii = 0; ii < tests.length; ++ii) {
testDXTTexture(tests[ii], false);
if (contextVersion >= 2) {
debug("<br/>");
testDXTTexture(tests[ii], true);
}
}
}
function uncompressDXTBlock(
destBuffer, destX, destY, destWidth, src, srcOffset, format) {
function make565(src, offset) {
return src[offset + 0] + src[offset + 1] * 256;
}
function make8888From565(c) {
return [
Math.floor(((c >> 11) & 0x1F) * 255 / 31),
Math.floor(((c >> 5) & 0x3F) * 255 / 63),
Math.floor(((c >> 0) & 0x1F) * 255 / 31),
255
];
}
function mix(mult, c0, c1, div) {
var r = [];
for (var ii = 0; ii < c0.length; ++ii) {
r[ii] = Math.floor((c0[ii] * mult + c1[ii]) / div);
}
return r;
}
var isDXT1 = format == ext.COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == ext.COMPRESSED_RGBA_S3TC_DXT1_EXT;
var colorOffset = srcOffset + (isDXT1 ? 0 : 8);
var color0 = make565(src, colorOffset + 0);
var color1 = make565(src, colorOffset + 2);
var c0gtc1 = color0 > color1 || !isDXT1;
var rgba0 = make8888From565(color0);
var rgba1 = make8888From565(color1);
var colors = [
rgba0,
rgba1,
c0gtc1 ? mix(2, rgba0, rgba1, 3) : mix(1, rgba0, rgba1, 2),
c0gtc1 ? mix(2, rgba1, rgba0, 3) : [0, 0, 0, 255]
];
// yea I know there is a lot of math in this inner loop.
// so sue me.
for (var yy = 0; yy < 4; ++yy) {
var pixels = src[colorOffset + 4 + yy];
for (var xx = 0; xx < 4; ++xx) {
var dstOff = ((destY + yy) * destWidth + destX + xx) * 4;
var code = (pixels >> (xx * 2)) & 0x3;
var srcColor = colors[code];
var alpha;
switch (format) {
case ext.COMPRESSED_RGB_S3TC_DXT1_EXT:
alpha = 255;
break;
case ext.COMPRESSED_RGBA_S3TC_DXT1_EXT:
alpha = (code == 3 && !c0gtc1) ? 0 : 255;
break;
case ext.COMPRESSED_RGBA_S3TC_DXT3_EXT:
{
var alpha0 = src[srcOffset + yy * 2 + Math.floor(xx / 2)];
var alpha1 = (alpha0 >> ((xx % 2) * 4)) & 0xF;
alpha = alpha1 | (alpha1 << 4);
}
break;
case ext.COMPRESSED_RGBA_S3TC_DXT5_EXT:
{
var alpha0 = src[srcOffset + 0];
var alpha1 = src[srcOffset + 1];
var alphaOff = Math.floor(yy / 2) * 3 + 2;
var alphaBits =
src[srcOffset + alphaOff + 0] +
src[srcOffset + alphaOff + 1] * 256 +
src[srcOffset + alphaOff + 2] * 65536;
var alphaShift = (yy % 2) * 12 + xx * 3;
var alphaCode = (alphaBits >> alphaShift) & 0x7;
if (alpha0 > alpha1) {
switch (alphaCode) {
case 0:
alpha = alpha0;
break;
case 1:
alpha = alpha1;
break;
default:
alpha = ((8 - alphaCode) * alpha0 + (alphaCode - 1) * alpha1) / 7;
break;
}
} else {
switch (alphaCode) {
case 0:
alpha = alpha0;
break;
case 1:
alpha = alpha1;
break;
case 6:
alpha = 0;
break;
case 7:
alpha = 255;
break;
default:
alpha = ((6 - alphaCode) * alpha0 + (alphaCode - 1) * alpha1) / 5;
break;
}
}
}
break;
default:
throw "bad format";
}
destBuffer[dstOff + 0] = srcColor[0];
destBuffer[dstOff + 1] = srcColor[1];
destBuffer[dstOff + 2] = srcColor[2];
destBuffer[dstOff + 3] = alpha;
}
}
}
function getBlockSize(format) {
var isDXT1 = format == ext.COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == ext.COMPRESSED_RGBA_S3TC_DXT1_EXT;
return isDXT1 ? 8 : 16;
}
function uncompressDXT(width, height, data, format) {
if (width % 4 || height % 4) throw "bad width or height";
var dest = new Uint8Array(width * height * 4);
var blocksAcross = width / 4;
var blocksDown = height / 4;
var blockSize = getBlockSize(format);
for (var yy = 0; yy < blocksDown; ++yy) {
for (var xx = 0; xx < blocksAcross; ++xx) {
uncompressDXTBlock(
dest, xx * 4, yy * 4, width, data,
(yy * blocksAcross + xx) * blockSize, format);
}
}
return dest;
}
function uncompressDXTIntoSubRegion(width, height, subX0, subY0, subWidth, subHeight, data, format)
{
if (width % 4 || height % 4 || subX0 % 4 || subY0 % 4 || subWidth % 4 || subHeight % 4)
throw "bad dimension";
var dest = new Uint8Array(width * height * 4);
var blocksAcross = subWidth / 4;
var blocksDown = subHeight / 4;
var blockSize = getBlockSize(format);
for (var yy = 0; yy < blocksDown; ++yy) {
for (var xx = 0; xx < blocksAcross; ++xx) {
uncompressDXTBlock(
dest, subX0 + xx * 4, subY0 + yy * 4, width, data,
(yy * blocksAcross + xx) * blockSize, format);
}
}
return dest;
}
function copyRect(data, srcX, srcY, dstX, dstY, width, height, stride) {
var bytesPerLine = width * 4;
var srcOffset = srcX * 4 + srcY * stride;
var dstOffset = dstX * 4 + dstY * stride;
for (; height > 0; --height) {
for (var ii = 0; ii < bytesPerLine; ++ii) {
data[dstOffset + ii] = data[srcOffset + ii];
}
srcOffset += stride;
dstOffset += stride;
}
}
function testDXTTexture(test, useTexStorage) {
var data = new Uint8Array(test.data);
var width = test.width;
var height = test.height;
var format = test.format;
var uncompressedData = uncompressDXT(width, height, data, format);
canvas.width = width;
canvas.height = height;
gl.viewport(0, 0, width, height);
debug("testing " + formatToString(format) + " " + width + "x" + height +
(useTexStorage ? " via texStorage2D" : " via compressedTexImage2D"));
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);
if (useTexStorage) {
if (test.subData) {
var uncompressedDataSub = uncompressDXTIntoSubRegion(
width, height, test.subX0, test.subY0, test.subWidth, test.subHeight, test.subData, format);
var tex1 = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex1);
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);
gl.texStorage2D(gl.TEXTURE_2D, 1, format, width, height);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating compressed texture via texStorage2D");
gl.compressedTexSubImage2D(
gl.TEXTURE_2D, 0, test.subX0, test.subY0, test.subWidth, test.subHeight, format, test.subData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture data via compressedTexSubImage2D");
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad 1");
compareRect(width, height, test.channels, uncompressedDataSub, "NEAREST");
// Clean up and recover
gl.deleteTexture(tex1);
gl.bindTexture(gl.TEXTURE_2D, tex);
}
gl.texStorage2D(gl.TEXTURE_2D, 1, format, width, height);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "allocating compressed texture via texStorage2D");
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad");
var clearColor = (test.hasAlpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
wtu.checkCanvas(gl, clearColor, "texture should be initialized to black");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, format, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture data via compressedTexSubImage2D");
} else {
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture");
}
gl.generateMipmap(gl.TEXTURE_2D);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "trying to generate mipmaps from compressed texture");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after clearing generateMipmap error");
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad 1");
compareRect(width, height, test.channels, uncompressedData, "NEAREST");
// Test again with linear filtering.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad 2");
compareRect(width, height, test.channels, uncompressedData, "LINEAR");
if (!useTexStorage) {
// It's not allowed to redefine textures defined via texStorage2D.
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height, 1, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "non 0 border");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width + 4, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height + 4, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 4, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 4, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 1, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width - 2, height, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 1, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexImage2D(gl.TEXTURE_2D, 0, format, width, height - 2, 0, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
if (width == 4) {
gl.compressedTexImage2D(gl.TEXTURE_2D, 1, format, 1, height, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "valid dimensions for level > 0");
gl.compressedTexImage2D(gl.TEXTURE_2D, 1, format, 2, height, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "valid dimensions for level > 0");
}
if (height == 4) {
gl.compressedTexImage2D(gl.TEXTURE_2D, 1, format, width, 1, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "valid dimensions for level > 0");
gl.compressedTexImage2D(gl.TEXTURE_2D, 1, format, width, 2, 0, data);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "valid dimensions for level > 0");
}
}
// pick a wrong format that uses the same amount of data.
var wrongFormat;
switch (format) {
case ext.COMPRESSED_RGB_S3TC_DXT1_EXT:
wrongFormat = ext.COMPRESSED_RGBA_S3TC_DXT1_EXT;
break;
case ext.COMPRESSED_RGBA_S3TC_DXT1_EXT:
wrongFormat = ext.COMPRESSED_RGB_S3TC_DXT1_EXT;
break;
case ext.COMPRESSED_RGBA_S3TC_DXT3_EXT:
wrongFormat = ext.COMPRESSED_RGBA_S3TC_DXT5_EXT;
break;
case ext.COMPRESSED_RGBA_S3TC_DXT5_EXT:
wrongFormat = ext.COMPRESSED_RGBA_S3TC_DXT3_EXT;
break;
}
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, wrongFormat, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "format does not match");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 4, 0, width, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "dimension out of range");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 4, width, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "dimension out of range");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width + 4, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height + 4, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width - 4, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height - 4, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "data size does not match dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width - 1, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width - 2, height, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height - 1, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height - 2, format, data);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid dimensions");
var subData = new Uint8Array(data.buffer, 0, getBlockSize(format));
if (width == 8 && height == 8) {
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 1, 0, 4, 4, format, subData);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid offset");
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 1, 4, 4, format, subData);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid offset");
}
var stride = width * 4;
for (var yoff = 0; yoff < height; yoff += 4) {
for (var xoff = 0; xoff < width; xoff += 4) {
copyRect(uncompressedData, 0, 0, xoff, yoff, 4, 4, stride);
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, xoff, yoff, 4, 4, format, subData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture");
// First test NEAREST filtering.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
wtu.clearAndDrawUnitQuad(gl);
compareRect(width, height, test.channels, uncompressedData, "NEAREST");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad");
// Next test LINEAR filtering.
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
wtu.clearAndDrawUnitQuad(gl);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "drawing unit quad");
compareRect(width, height, test.channels, uncompressedData, "LINEAR");
}
}
}
function insertImg(element, caption, img) {
var div = document.createElement("div");
div.appendChild(img);
var label = document.createElement("div");
label.appendChild(document.createTextNode(caption));
div.appendChild(label);
element.appendChild(div);
}
function makeImage(imageWidth, imageHeight, data, alpha) {
var scale = 8;
var c = document.createElement("canvas");
c.width = imageWidth * scale;
c.height = imageHeight * scale;
var ctx = c.getContext("2d");
for (var yy = 0; yy < imageHeight; ++yy) {
for (var xx = 0; xx < imageWidth; ++xx) {
var offset = (yy * imageWidth + xx) * 4;
ctx.fillStyle = "rgba(" +
data[offset + 0] + "," +
data[offset + 1] + "," +
data[offset + 2] + "," +
(alpha ? data[offset + 3] / 255 : 1) + ")";
ctx.fillRect(xx * scale, yy * scale, scale, scale);
}
}
return wtu.makeImageFromCanvas(c);
}
function compareRect(width, height, channels, expectedData, filteringMode) {
var actual = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, actual);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "reading back pixels");
var div = document.createElement("div");
div.className = "testimages";
insertImg(div, "expected", makeImage(width, height, expectedData, channels == 4));
insertImg(div, "actual", makeImage(width, height, actual, channels == 4));
div.appendChild(document.createElement('br'));
document.getElementById("console").appendChild(div);
var failed = false;
for (var yy = 0; yy < height; ++yy) {
for (var xx = 0; xx < width; ++xx) {
var offset = (yy * width + xx) * 4;
var expected = [
expectedData[offset + 0],
expectedData[offset + 1],
expectedData[offset + 2],
(channels == 3 ? 255 : expectedData[offset + 3])
];
for (var jj = 0; jj < 4; ++jj) {
if (actual[offset + jj] != expected[jj]) {
failed = true;
var was = actual[offset + 0].toString();
for (var j = 1; j < 4; ++j) {
was += "," + actual[offset + j];
}
testFailed('at (' + xx + ', ' + yy +
') expected: ' + expected + ' was ' + was);
}
}
}
}
if (!failed) {
testPassed("texture rendered correctly with " + filteringMode + " filtering");
}
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

View file

@ -1,263 +0,0 @@
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL compressed texture size limit conformance test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="32" height="32" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
enableJSTestPreVerboseLogging();
description("Checks size limit of the webgl compressed textures")
var canvas;
function numLevelsFromSize(size) {
var levels = 0;
while ((size >> levels) > 0) {
++levels;
}
return levels;
}
// More formats can be added here when more texture compression extensions are enabled in WebGL.
var validFormats = {
COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,
};
// format specific restrictions for COMPRESSED_RGB_S3TC_DXT1_EXT and COMPRESSED_RGBA_S3TC_DXT1_EXT
// on the byteLength of the ArrayBufferView, pixels
function func1 (width, height)
{
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
}
// format specific restrictions for COMPRESSED_RGBA_S3TC_DXT3_EXT and COMPRESSED_RGBA_S3TC_DXT5_EXT
// on the byteLength of the ArrayBufferView, pixels
function func2 (width, height)
{
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
}
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var tests = [
// More tests can be added here when more texture compression extensions are enabled in WebGL.
// Level 0 image width and height must be a multiple of the sizeStep.
{ extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGB_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1, sizeStep: 4},
{ extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT1_EXT, dataType: Uint8Array, func: func1, sizeStep: 4},
{ extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT3_EXT, dataType: Uint8Array, func: func2, sizeStep: 4},
{ extension: "WEBGL_compressed_texture_s3tc", format: validFormats.COMPRESSED_RGBA_S3TC_DXT5_EXT, dataType: Uint8Array, func: func2, sizeStep: 4},
];
// Note: We expressly only use 2 textures because first a texture will be defined
// using all mip levels of 1 format, then for a moment it will have mixed formats which
// may uncover bugs.
var targets = [
{ target: gl.TEXTURE_2D,
maxSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
tex: gl.createTexture(),
targets: [gl.TEXTURE_2D]
},
{ target: gl.TEXTURE_CUBE_MAP,
maxSize: gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE),
tex: gl.createTexture(),
targets: [
gl.TEXTURE_CUBE_MAP_POSITIVE_X,
gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
]
}
];
function getSharedArrayBufferSize() {
var sharedArrayBufferSize = 0;
for (var tt = 0; tt < tests.length; ++tt) {
var test = tests[tt];
for (var trg = 0; trg < targets.length; ++trg) {
var t = targets[trg];
var bufferSizeNeeded;
if (t.target === gl.TEXTURE_CUBE_MAP) {
var positiveTestSize = Math.min(2048, t.maxSize);
bufferSizeNeeded = test.func(positiveTestSize, positiveTestSize);
} else {
bufferSizeNeeded = test.func(t.maxSize, test.sizeStep);
}
if (bufferSizeNeeded > sharedArrayBufferSize) {
sharedArrayBufferSize = bufferSizeNeeded;
}
bufferSizeNeeded = test.func(t.maxSize + test.sizeStep, t.maxSize + test.sizeStep);
// ArrayBuffers can be at most 4GB (minus 1 byte), but any allocations larger than 1 GB are unreliable in practice. So limit allocations to 1 GB.
// Textures that are wide in just one dimension can still be used to test max TEXTURE_2D size limit even if we don't allocate space for huge square textures.
if (bufferSizeNeeded > sharedArrayBufferSize && bufferSizeNeeded <= Math.pow(2, 30)) {
sharedArrayBufferSize = bufferSizeNeeded;
}
}
}
return sharedArrayBufferSize;
}
// Share an ArrayBuffer among tests to avoid too many large allocations
var sharedArrayBuffer = new ArrayBuffer(getSharedArrayBufferSize());
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
var trg = 0;
var tt = 0;
runNextTest();
function runNextTest() {
var t = targets[trg];
if (tt == 0) {
var tex = t.tex;
gl.bindTexture(t.target, tex);
debug("");
debug("max size for " + wtu.glEnumToString(gl, t.target) + ": " + t.maxSize);
}
var test = tests[tt];
testFormatType(t, test);
++tt;
if (tt == tests.length) {
tt = 0;
++trg;
if (trg == targets.length) {
finishTest();
return;
}
}
wtu.waitForComposite(runNextTest);
}
function testFormatType(t, test) {
var positiveTestSize = t.maxSize;
var positiveTestOtherDimension = test.sizeStep;
if (t.target === gl.TEXTURE_CUBE_MAP) {
// Can't always test the maximum size since that can cause OOM:
positiveTestSize = Math.min(2048, t.maxSize);
// Cube map textures need to be square:
positiveTestOtherDimension = positiveTestSize;
}
var positiveTestLevels = numLevelsFromSize(positiveTestSize);
var numLevels = numLevelsFromSize(t.maxSize);
debug("");
debug("num levels: " + numLevels + ", levels used in positive test: " + positiveTestLevels);
debug("");
// Query the extension and store globally so shouldBe can access it
var ext = wtu.getExtensionWithKnownPrefixes(gl, test.extension);
if (ext) {
testPassed("Successfully enabled " + test.extension + " extension");
for (var j = 0; j < t.targets.length; ++j) {
var target = t.targets[j];
debug("");
debug(wtu.glEnumToString(gl, target) + " " + wtu.glEnumToString(ext, test.format));
// positive test
var size = positiveTestSize;
var otherDimension = positiveTestOtherDimension;
for (var i = 0; i < positiveTestLevels; i++) {
var pixels = new test.dataType(sharedArrayBuffer, 0, test.func(size, otherDimension));
gl.compressedTexImage2D(target, i, test.format, size, otherDimension, 0, pixels);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "uploading compressed texture should generate NO_ERROR."
+ "level is " + i + ", size is " + size + "x" + otherDimension);
size /= 2;
otherDimension /= 2;
if (otherDimension < 1) {
otherDimension = 1;
}
}
var numLevels = numLevelsFromSize(t.maxSize);
// out of bounds tests
// width and height out of bounds
var dataSize = test.func(t.maxSize + test.sizeStep, t.maxSize + test.sizeStep);
// this check assumes that each element is 1 byte
if (dataSize > sharedArrayBuffer.byteLength) {
if (t.target == gl.TEXTURE_CUBE_MAP) {
testPassed("Unable to test texture larger than maximum size due to ArrayBuffer size limitations -- this is legal");
} else {
var wideAndShortDataSize = test.func(t.maxSize + test.sizeStep, test.sizeStep);
var pixelsNegativeTest1 = new test.dataType(sharedArrayBuffer, 0, wideAndShortDataSize);
gl.compressedTexImage2D(target, 0, test.format, t.maxSize + test.sizeStep, test.sizeStep, 0, pixelsNegativeTest1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "width out of bounds: should generate INVALID_VALUE."
+ " level is 0, size is " + (t.maxSize + test.sizeStep) + "x" + (test.sizeStep));
var narrowAndTallDataSize = test.func(test.sizeStep, t.maxSize + test.sizeStep);
var pixelsNegativeTest1 = new test.dataType(sharedArrayBuffer, 0, narrowAndTallDataSize);
gl.compressedTexImage2D(target, 0, test.format, test.sizeStep, t.maxSize + test.sizeStep, 0, pixelsNegativeTest1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "height out of bounds: should generate INVALID_VALUE."
+ " level is 0, size is " + (test.sizeStep) + "x" + (t.maxSize + test.sizeStep));
}
} else {
var pixelsNegativeTest1 = new test.dataType(sharedArrayBuffer, 0, dataSize);
gl.compressedTexImage2D(target, 0, test.format, t.maxSize + test.sizeStep, t.maxSize + test.sizeStep, 0, pixelsNegativeTest1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "width and height out of bounds: should generate INVALID_VALUE."
+ " level is 0, size is " + (t.maxSize + test.sizeStep) + "x" + (t.maxSize + test.sizeStep));
}
// level out of bounds
var pixelsNegativeTest2 = new test.dataType(sharedArrayBuffer, 0, test.func(256, 256));
gl.compressedTexImage2D(target, numLevels, test.format, 256, 256, 0, pixelsNegativeTest2);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "level out of bounds: should generate INVALID_VALUE."
+ " level is " + numLevels + ", size is 256x256");
//width and height out of bounds for specified level
gl.compressedTexImage2D(target, numLevels - 1, test.format, 256, 256, 0, pixelsNegativeTest2);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bounds for specified level: should generate INVALID_VALUE."
+ " level is " + (numLevels - 1) + ", size is 256x256");
}
}
else
testPassed("No " + test.extension + " extension support -- this is legal");
}
var successfullyParsed = true;
</script>
</body>
</html>

View file

@ -1,127 +0,0 @@
<!--
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL WebGL_debug_renderer_info Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 1px; height: 1px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing standard derivatives -->
<script>
"use strict";
description("This test verifies the functionality of the WEBGL_debug_renderer_info extension, if it is available.");
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");
var ext = null;
var vao = null;
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
// Run tests with extension disabled
runTestDisabled();
// Query the extension and store globally so shouldBe can access it
ext = gl.getExtension("WEBGL_debug_renderer_info");
if (!ext) {
testPassed("No WEBGL_debug_renderer_info support -- this is legal");
runSupportedTest(false);
} else {
testPassed("Successfully enabled WEBGL_debug_renderer_info extension");
runSupportedTest(true);
runTestEnabled();
}
}
function runSupportedTest(extensionEnabled) {
var supported = gl.getSupportedExtensions();
if (supported.indexOf("WEBGL_debug_renderer_info") >= 0) {
if (extensionEnabled) {
testPassed("WEBGL_debug_renderer_info listed as supported and getExtension succeeded");
} else {
testFailed("WEBGL_debug_renderer_info listed as supported but getExtension failed");
}
} else {
if (extensionEnabled) {
testFailed("WEBGL_debug_renderer_info not listed as supported but getExtension succeeded");
} else {
testPassed("WEBGL_debug_renderer_info not listed as supported and getExtension failed -- this is legal");
}
}
}
function runTestDisabled() {
debug("Testing enums with extension disabled");
// Use the constants directly as we don't have the extension
var UNMASKED_VENDOR_WEBGL = 0x9245;
gl.getParameter(UNMASKED_VENDOR_WEBGL);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "UNMASKED_VENDOR_WEBGL should not be queryable if extension is disabled");
var UNMASKED_RENDERER_WEBGL = 0x9246;
gl.getParameter(UNMASKED_RENDERER_WEBGL);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "UNMASKED_RENDERER_WEBGL should not be queryable if extension is disabled");
}
function runTestEnabled() {
debug("Testing enums with extension enabled");
shouldBe("ext.UNMASKED_VENDOR_WEBGL", "0x9245");
gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "UNMASKED_VENDOR_WEBGL query should succeed if extension is enable");
shouldBe("ext.UNMASKED_RENDERER_WEBGL", "0x9246");
gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "UNMASKED_RENDERER_WEBGL query should succeed if extension is enable");
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show more