-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for having the same read and write buffer using a transform feed…
…back note: there are 2 lines marked as "FIXME" that I believe should be removed assuming the spec changes so that `gl.bindBuffer` is less strict
- Loading branch information
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
transform_feedback.html | ||
transform_feedback_same_buffers_as_input_and_output.html | ||
two-unreferenced-varyings.html | ||
unwritten-output-defaults-to-zero.html |
153 changes: 153 additions & 0 deletions
153
.../conformance2/transform_feedback/transform_feedback_same_buffers_as_input_and_output.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<!-- | ||
/* | ||
** Copyright (c) 2015 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 Transform Feedback Conformance Test - Same Buffers as Input and Output</title> | ||
<link rel="stylesheet" href="../../resources/js-test-style.css"/> | ||
<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 id="vshader" type="x-shader/x-vertex">#version 300 es | ||
in float in_value; | ||
out float out_value; | ||
|
||
void main() { | ||
out_value = in_value * 2.; | ||
} | ||
</script> | ||
<script id="fshader" type="x-shader/x-fragment">#version 300 es | ||
precision mediump float; | ||
out vec4 dummy; | ||
void main() { | ||
dummy = vec4(1); | ||
} | ||
</script> | ||
<script> | ||
"use strict"; | ||
description("This test verifies trying to read and write from the same buffers fails"); | ||
|
||
debug(""); | ||
|
||
var wtu = WebGLTestUtils; | ||
var canvas = document.getElementById("canvas"); | ||
var gl = wtu.create3DContext(canvas, null, 2); | ||
|
||
if (!gl) { | ||
testFailed("WebGL context does not exist"); | ||
} else { | ||
testPassed("WebGL context exists"); | ||
|
||
runSameInputOutputTest(); | ||
finishTest(); | ||
} | ||
|
||
function runSameInputOutputTest() { | ||
const prog = wtu.setupTransformFeedbackProgram(gl, ["vshader", "fshader"], | ||
["out_value"], gl.SEPARATE_ATTRIBS, | ||
["in_value"]); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "linking transform feedback shader should not set an error"); | ||
|
||
const inLoc = 0; | ||
const outLoc = 0; | ||
|
||
const srcBuffer1 = createBuffer(gl, new Float32Array([1, 2, 3])); | ||
const srcVAO1 = createVAO(gl, srcBuffer1, inLoc); | ||
|
||
const dstBuffer = createBuffer(gl, Float32Array.BYTES_PER_ELEMENT * 3); | ||
const srcVAO2 = createVAO(gl, dstBuffer, inLoc); | ||
|
||
const tf = gl.createTransformFeedback(); | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf); | ||
gl.useProgram(prog); | ||
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, dstBuffer); | ||
// this binds the default (id = 0) TRANSFORM_FEEBACK buffer | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null); | ||
|
||
runFeedback(gl, prog, srcVAO1, tf); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); | ||
|
||
const expected = [2, 4, 6]; | ||
gl.bindBuffer(gl.ARRAY_BUFFER, dstBuffer); | ||
wtu.checkFloatBuffer(gl, gl.ARRAY_BUFFER, expected); | ||
|
||
// this should fail because the transform feedback's buffer #0 and the | ||
// srcVAO2's buffer #0 are the same buffer | ||
runFeedback(gl, prog, srcVAO2, tf); | ||
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "reading and writing to same buffer"); | ||
|
||
gl.bindBuffer(gl.ARRAY_BUFFER, dstBuffer); | ||
wtu.checkFloatBuffer(gl, gl.ARRAY_BUFFER, expected, "should be the same as before as nothing has executed"); | ||
|
||
} | ||
|
||
function runFeedback(gl, prog, srcVAO, tf, dstBufferInfo) { | ||
gl.enable(gl.RASTERIZER_DISCARD); | ||
|
||
gl.useProgram(prog); | ||
gl.bindVertexArray(srcVAO); | ||
|
||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf); | ||
gl.beginTransformFeedback(gl.TRIANGLES); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); | ||
gl.drawArrays(gl.TRIANGLES, 0, 3); | ||
gl.endTransformFeedback(); | ||
|
||
// FIXME: this should not be needed once the spec and implementationsa are fixed | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null); | ||
|
||
gl.disable(gl.RASTERIZER_DISCARD); | ||
} | ||
|
||
function createBuffer(gl, dataOrSize) { | ||
const buf = gl.createBuffer(); | ||
gl.bindBuffer(gl.ARRAY_BUFFER, buf); | ||
gl.bufferData(gl.ARRAY_BUFFER, dataOrSize, gl.STATIC_DRAW); | ||
return buf; | ||
} | ||
|
||
function createVAO(gl, buf, inLoc) { | ||
const vao = gl.createVertexArray(); | ||
gl.bindVertexArray(vao); | ||
gl.bindBuffer(gl.ARRAY_BUFFER, buf); | ||
gl.enableVertexAttribArray(inLoc); | ||
gl.vertexAttribPointer(inLoc, 1, gl.FLOAT, false, 0, 0); | ||
// FIXME: this should not be needed once the spec and implementationsa are fixed | ||
gl.bindBuffer(gl.ARRAY_BUFFER, null); // this is not needed | ||
gl.bindVertexArray(null); | ||
return vao; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |