|
| 1 | +<!-- |
| 2 | +Copyright (c) 2026 The Khronos Group Inc. |
| 3 | +Use of this source code is governed by an MIT-style license that can be |
| 4 | +found in the LICENSE.txt file. |
| 5 | +--> |
| 6 | + |
| 7 | +<!DOCTYPE html> |
| 8 | +<html> |
| 9 | +<head> |
| 10 | +<meta charset="utf-8"> |
| 11 | +<title>WebGL2 PBO Uploads conformance test</title> |
| 12 | +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
| 13 | +<script src="../../../js/js-test-pre.js"></script> |
| 14 | +<script src="../../../js/webgl-test-utils.js"></script> |
| 15 | +</head> |
| 16 | +<body> |
| 17 | +<canvas id="example" width="32" height="32"></canvas> |
| 18 | +<div id="description"></div> |
| 19 | +<div id="console"></div> |
| 20 | +<script> |
| 21 | +"use strict"; |
| 22 | +var wtu = WebGLTestUtils; |
| 23 | +description("Test that WebGL2 texSubImage2D overloads with bound PBO generate INVALID_OPERATION."); |
| 24 | + |
| 25 | +var gl = wtu.create3DContext("example", undefined, 2); |
| 26 | + |
| 27 | +if (!gl) { |
| 28 | + testFailed("WebGL context creation failed"); |
| 29 | +} else { |
| 30 | + runTest(); |
| 31 | +} |
| 32 | + |
| 33 | +function runTest() { |
| 34 | + // 1. Create a texture |
| 35 | + var tex = gl.createTexture(); |
| 36 | + gl.bindTexture(gl.TEXTURE_2D, tex); |
| 37 | + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
| 38 | + |
| 39 | + // 2. Create and bind a PBO |
| 40 | + var pbo = gl.createBuffer(); |
| 41 | + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pbo); |
| 42 | + gl.bufferData(gl.PIXEL_UNPACK_BUFFER, 16 * 16 * 4, gl.STATIC_DRAW); |
| 43 | + |
| 44 | + // 3. Test HTMLVideoElement overload |
| 45 | + var video = document.createElement('video'); |
| 46 | + |
| 47 | + debug("Testing HTMLVideoElement 7-argument overload..."); |
| 48 | + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, video); |
| 49 | + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "should generate INVALID_OPERATION when PBO is bound"); |
| 50 | + |
| 51 | + // 4. Test VideoFrame overload (if supported) |
| 52 | + if (window.VideoFrame) { |
| 53 | + debug("Testing VideoFrame 7-argument overload..."); |
| 54 | + var canvas = document.createElement('canvas'); |
| 55 | + canvas.width = 16; |
| 56 | + canvas.height = 16; |
| 57 | + var frame = new VideoFrame(canvas, {timestamp: 0}); |
| 58 | + |
| 59 | + // Without PBO, it should succeed (or at least no INVALID_OPERATION) |
| 60 | + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null); |
| 61 | + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, frame); |
| 62 | + var err = gl.getError(); |
| 63 | + if (err == gl.INVALID_OPERATION) { |
| 64 | + testFailed("Should not generate INVALID_OPERATION without PBO"); |
| 65 | + } else { |
| 66 | + testPassed("Passed without PBO"); |
| 67 | + } |
| 68 | + |
| 69 | + // With PBO, it must fail with INVALID_OPERATION |
| 70 | + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pbo); |
| 71 | + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, frame); |
| 72 | + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "should generate INVALID_OPERATION when PBO is bound"); |
| 73 | + |
| 74 | + frame.close(); |
| 75 | + } else { |
| 76 | + debug("VideoFrame not supported, skipping test."); |
| 77 | + } |
| 78 | + |
| 79 | + // Clean up |
| 80 | + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null); |
| 81 | + gl.deleteBuffer(pbo); |
| 82 | + gl.deleteTexture(tex); |
| 83 | +} |
| 84 | + |
| 85 | +var successfullyParsed = true; |
| 86 | +</script> |
| 87 | +<script src="../../../js/js-test-post.js"></script> |
| 88 | +</body> |
| 89 | +</html> |
0 commit comments