mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
webgl: Add drawArrays reftest
I also removed flackyness of the clearColor test, hopefully it's fixed now that a lot of race conditions have disappeared thanks to @glennw.
This commit is contained in:
parent
ff568ecc90
commit
eb502bdbb8
4 changed files with 89 additions and 3 deletions
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -1041,7 +1041,6 @@ dependencies = [
|
||||||
"fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"gfx_traits 0.0.1",
|
|
||||||
"html5ever 0.0.0 (git+https://github.com/servo/html5ever)",
|
"html5ever 0.0.0 (git+https://github.com/servo/html5ever)",
|
||||||
"hyper 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"js 0.1.0 (git+https://github.com/servo/rust-mozjs)",
|
"js 0.1.0 (git+https://github.com/servo/rust-mozjs)",
|
||||||
|
|
|
@ -334,7 +334,8 @@ resolution=600x800 == viewport_percentage_vw_vh.html viewport_percentage_vw_vh_b
|
||||||
experimental == viewport_rule.html viewport_rule_ref.html
|
experimental == viewport_rule.html viewport_rule_ref.html
|
||||||
== visibility_hidden.html visibility_hidden_ref.html
|
== visibility_hidden.html visibility_hidden_ref.html
|
||||||
|
|
||||||
flaky_cpu == webgl-context/clearcolor.html webgl-context/clearcolor_ref.html
|
== webgl-context/clearcolor.html webgl-context/clearcolor_ref.html
|
||||||
|
== webgl-context/draw_arrays_simple.html webgl-context/draw_arrays_simple_ref.html
|
||||||
|
|
||||||
== whitespace_nowrap_a.html whitespace_nowrap_ref.html
|
== whitespace_nowrap_a.html whitespace_nowrap_ref.html
|
||||||
== whitespace_pre.html whitespace_pre_ref.html
|
== whitespace_pre.html whitespace_pre_ref.html
|
||||||
|
@ -343,5 +344,5 @@ flaky_cpu == webgl-context/clearcolor.html webgl-context/clearcolor_ref.html
|
||||||
== word_spacing_a.html word_spacing_ref.html
|
== word_spacing_a.html word_spacing_ref.html
|
||||||
|
|
||||||
|
|
||||||
# This file is must be sorted alphabetically.
|
# This file must be sorted alphabetically.
|
||||||
# Please run `./mach test-tidy` to check your changes.
|
# Please run `./mach test-tidy` to check your changes.
|
||||||
|
|
70
tests/ref/webgl-context/draw_arrays_simple.html
Normal file
70
tests/ref/webgl-context/draw_arrays_simple.html
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>WebGL drawArrays test</title>
|
||||||
|
<!--
|
||||||
|
This test should generate a 256x256 green square
|
||||||
|
on a 512x512 canvas
|
||||||
|
-->
|
||||||
|
<style>
|
||||||
|
html, body { margin: 0 }
|
||||||
|
</style>
|
||||||
|
<canvas id="c" width="512" height="512"></canvas>
|
||||||
|
<script id="vertex_shader" type="x-shader/x-vertex">
|
||||||
|
attribute vec2 a_position;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(a_position, 0, 1);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="fragment_shader" type="x-shader/x-fragment">
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = vec4(0, 1, 0, 1); // green
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
var gl = document.getElementById('c').getContext('webgl');
|
||||||
|
|
||||||
|
// Clear white
|
||||||
|
gl.clearColor(1, 1, 1, 1);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Create the program
|
||||||
|
var vertex_shader = gl.createShader(gl.VERTEX_SHADER),
|
||||||
|
fragment_shader = gl.createShader(gl.FRAGMENT_SHADER),
|
||||||
|
program = gl.createProgram();
|
||||||
|
|
||||||
|
gl.shaderSource(vertex_shader,
|
||||||
|
document.getElementById('vertex_shader').textContent);
|
||||||
|
gl.shaderSource(fragment_shader,
|
||||||
|
document.getElementById('fragment_shader').textContent);
|
||||||
|
gl.compileShader(vertex_shader);
|
||||||
|
gl.compileShader(fragment_shader);
|
||||||
|
gl.attachShader(program, vertex_shader);
|
||||||
|
gl.attachShader(program, fragment_shader);
|
||||||
|
gl.linkProgram(program);
|
||||||
|
gl.useProgram(program);
|
||||||
|
|
||||||
|
// Get the position from the fragment shader
|
||||||
|
var position = gl.getAttribLocation(program, "a_position");
|
||||||
|
|
||||||
|
// Square as two triangles
|
||||||
|
var square_data = new Float32Array([
|
||||||
|
-0.5, 0.5, // top left
|
||||||
|
0.5, 0.5, // top right
|
||||||
|
-0.5, -0.5, // bottom left
|
||||||
|
-0.5, -0.5, // bottom left
|
||||||
|
0.5, 0.5, // top right
|
||||||
|
0.5, -0.5 // bottom right
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create a buffer for the square with the square
|
||||||
|
// vertex data
|
||||||
|
var square_buffer = gl.createBuffer();
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, square_buffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, square_data, gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
gl.enableVertexAttribArray(position);
|
||||||
|
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
gl.drawArrays(gl.TRIANGLES, 0, square_data.length);
|
||||||
|
</script>
|
16
tests/ref/webgl-context/draw_arrays_simple_ref.html
Normal file
16
tests/ref/webgl-context/draw_arrays_simple_ref.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>WebGL drawArrays test</title>
|
||||||
|
<style>
|
||||||
|
html, body { margin: 0 }
|
||||||
|
div {
|
||||||
|
position: absolute;
|
||||||
|
left: 128px;
|
||||||
|
top: 128px;
|
||||||
|
width: 256px;
|
||||||
|
height: 256px;
|
||||||
|
/* Totally green */
|
||||||
|
background-color: rgb(0, 255, 0);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div></div>
|
Loading…
Add table
Add a link
Reference in a new issue