Auto merge of #21747 - servo:webgl, r=jdm

A couple of WebGL changes before lunch time

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21747)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-20 05:33:08 -04:00 committed by GitHub
commit d60b14bed5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 140 additions and 12 deletions

View file

@ -414,7 +414,7 @@ impl WebGLProgram {
/// glGetProgramInfoLog /// glGetProgramInfoLog
pub fn get_info_log(&self) -> WebGLResult<String> { pub fn get_info_log(&self) -> WebGLResult<String> {
if self.is_deleted() { if self.is_deleted() {
return Err(WebGLError::InvalidOperation); return Err(WebGLError::InvalidValue);
} }
if self.link_called.get() { if self.link_called.get() {
let shaders_compiled = match (self.fragment_shader.get(), self.vertex_shader.get()) { let shaders_compiled = match (self.fragment_shader.get(), self.vertex_shader.get()) {

View file

@ -1303,19 +1303,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// GL_OES_read_format support (assuming an underlying GLES // GL_OES_read_format support (assuming an underlying GLES
// driver. Desktop is happy to format convert for us). // driver. Desktop is happy to format convert for us).
constants::IMPLEMENTATION_COLOR_READ_FORMAT => { constants::IMPLEMENTATION_COLOR_READ_FORMAT => {
handle_potential_webgl_error!(
self,
self.validate_framebuffer(),
return NullValue()
);
return Int32Value(constants::RGBA as i32); return Int32Value(constants::RGBA as i32);
}, },
constants::IMPLEMENTATION_COLOR_READ_TYPE => { constants::IMPLEMENTATION_COLOR_READ_TYPE => {
handle_potential_webgl_error!(
self,
self.validate_framebuffer(),
return NullValue()
);
return Int32Value(constants::UNSIGNED_BYTE as i32); return Int32Value(constants::UNSIGNED_BYTE as i32);
}, },
constants::COMPRESSED_TEXTURE_FORMATS => { constants::COMPRESSED_TEXTURE_FORMATS => {

View file

@ -15010,6 +15010,12 @@
{} {}
] ]
], ],
"conformance/textures/misc/canvas-teximage-after-multiple-drawimages.html": [
[
"/_webgl/conformance/textures/misc/canvas-teximage-after-multiple-drawimages.html",
{}
]
],
"conformance/textures/misc/compressed-tex-image.html": [ "conformance/textures/misc/compressed-tex-image.html": [
[ [
"/_webgl/conformance/textures/misc/compressed-tex-image.html", "/_webgl/conformance/textures/misc/compressed-tex-image.html",
@ -36878,9 +36884,13 @@
"testharness" "testharness"
], ],
"conformance/textures/misc/00_test_list.txt": [ "conformance/textures/misc/00_test_list.txt": [
"3c7636158223c16d24707ee209016b4c715d88c9", "8a561de6f6f5b5ca80f11c7e5c353468225e4a67",
"support" "support"
], ],
"conformance/textures/misc/canvas-teximage-after-multiple-drawimages.html": [
"aac3306a7d4c3c08201e7d55e7ef549f3d8ad8e6",
"testharness"
],
"conformance/textures/misc/compressed-tex-image.html": [ "conformance/textures/misc/compressed-tex-image.html": [
"af234ab29614fc3e566b27fe11df1854db333aa3", "af234ab29614fc3e566b27fe11df1854db333aa3",
"testharness" "testharness"

View file

@ -1,4 +1,5 @@
[copy-tex-image-2d-formats.html] [copy-tex-image-2d-formats.html]
bug: https://github.com/servo/servo/issues/20595
[WebGL test #32: getError expected: INVALID_OPERATION. Was NO_ERROR : should not be able to copyTexImage2D ALPHA from RGB] [WebGL test #32: getError expected: INVALID_OPERATION. Was NO_ERROR : should not be able to copyTexImage2D ALPHA from RGB]
expected: FAIL expected: FAIL

View file

@ -1,4 +1,5 @@
[tex-input-validation.html] [tex-input-validation.html]
bug: https://github.com/servo/servo/issues/20595
[WebGL test #45: getError expected: INVALID_OPERATION. Was NO_ERROR : colorBufferFormat: RGB565 internalFormat: RGBA target: TEXTURE_2D] [WebGL test #45: getError expected: INVALID_OPERATION. Was NO_ERROR : colorBufferFormat: RGB565 internalFormat: RGBA target: TEXTURE_2D]
expected: FAIL expected: FAIL

View file

@ -1,3 +1,4 @@
--min-version 1.0.4 canvas-teximage-after-multiple-drawimages.html
--max-version 1.9.9 compressed-tex-image.html --max-version 1.9.9 compressed-tex-image.html
copy-tex-image-and-sub-image-2d.html copy-tex-image-and-sub-image-2d.html
--min-version 1.0.2 copy-tex-image-2d-formats.html --min-version 1.0.2 copy-tex-image-2d-formats.html

View file

@ -0,0 +1,125 @@
<!--
/*
** Copyright (c) 2018 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>TexImage2D of 2D Canvas after multiple drawImages</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>
"use strict";
const wtu = WebGLTestUtils;
const sz = 512;
let greenImage = null;
function loadImageAndStart(startFunc) {
let c = document.createElement('canvas');
c.width = sz;
c.height = sz;
let ctx = c.getContext('2d');
ctx.fillStyle = 'rgb(0,255,0)';
ctx.fillRect(0, 0, sz, sz);
greenImage = wtu.makeImageFromCanvas(c, startFunc);
}
function runTest() {
description();
debug('Regression test for <a href="http://crbug.com/878545">http://crbug.com/878545</a>');
// Mimics the image-to-texture upload path from the old JavaScript
// port of O3D, salvaged at https://github.com/petersont/o3d .
// Create a canvas and draw the entire image into it.
let bigCanvas = document.createElement('canvas');
bigCanvas.width = greenImage.naturalWidth;
bigCanvas.height = greenImage.naturalHeight;
let bc = bigCanvas.getContext('2d');
bc.drawImage(greenImage, 0, 0, bigCanvas.width, bigCanvas.height);
// Create a temp canvas to flip vertically.
let tempCanvas = document.createElement('canvas');
tempCanvas.width = bigCanvas.width;
tempCanvas.height = bigCanvas.height;
let tc = tempCanvas.getContext('2d');
tc.translate(0, tempCanvas.height);
tc.scale(1, -1);
tc.drawImage(bigCanvas, 0, 0, tempCanvas.width, tempCanvas.height);
// Set up to draw via WebGL.
let c3d = document.getElementById('canvas');
let gl = wtu.create3DContext(c3d);
let prog = wtu.setupTexturedQuad(gl);
gl.uniform1i(gl.getUniformLocation(prog, 'tex'), 0);
let tex = gl.createTexture();
// Iterate through the large canvas, drawing pieces of it to a
// scratch canvas.
let scratchCanvas = document.createElement('canvas');
const width = tempCanvas.width / 2;
const height = tempCanvas.height / 2;
let bb = new Uint8Array(4 * c3d.width * c3d.height);
for (let jj = 0; jj < 2; ++jj) {
for (let ii = 0; ii < 2; ++ii) {
// Prepare texture.
scratchCanvas.width = width;
scratchCanvas.height = height;
let ctx = scratchCanvas.getContext('2d');
ctx.save();
ctx.translate(-(ii * width), -(jj * height));
ctx.scale(1.0, 1.0);
ctx.drawImage(tempCanvas, 0, 0, tempCanvas.width, tempCanvas.height);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
scratchCanvas);
ctx.restore();
gl.generateMipmap(gl.TEXTURE_2D);
// Draw and check that rendering occurred properly.
gl.uniform1i(gl.getUniformLocation(prog, 'tex'), 0);
wtu.drawUnitQuad(gl);
let tolerance = 2;
wtu.checkCanvasRect(gl, 1, 1, c3d.width - 2, c3d.height - 2,
[ 0, 255, 0, 255 ],
"should be green",
tolerance);
}
}
finishTest();
}
loadImageAndStart(runTest);
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="40" height="40"></canvas>
</body>
</html>