blob: 7c361cc5ee2d7e6140606af85a6d73697b63cfe5 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../external/wpt/resources/chromium/webxr-test.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "Ensure that the framebuffer given by the WebGL layer is opaque";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [
{ mode: 'immersive-vr' },
{ mode: 'inline' }
];
let testFunction =
(session, t, fakeDeviceController) => new Promise((resolve, reject) => {
// Session must have a baseLayer or frame requests will be ignored.
let webglLayer = new XRWebGLLayer(session, gl);
session.updateRenderState({
baseLayer: webglLayer,
outputContext: getOutputContext()
});
let xrFramebuffer = webglLayer.framebuffer;
// Make sure we're starting with a clean error slate.
assert_equals(gl.getError(), gl.NO_ERROR);
assert_not_equals(xrFramebuffer, null);
assert_greater_than(webglLayer.framebufferWidth, 0);
assert_greater_than(webglLayer.framebufferHeight, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, xrFramebuffer);
assert_equals(gl.getError(), gl.NO_ERROR);
gl.deleteFramebuffer(xrFramebuffer);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
// Make sure the framebuffer is still bound after failed attempt to delete.
let boundFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
assert_equals(xrFramebuffer, boundFramebuffer);
assert_equals(gl.getError(), gl.NO_ERROR);
// Ensure the framebuffer attachment properties cannot be inspected.
let attachments = [
gl.COLOR_ATTACHMENT0,
gl.DEPTH_ATTACHMENT,
gl.STENCIL_ATTACHMENT,
];
let parameters = [
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL,
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE,
];
for (let attachment of attachments) {
for (let parameter of parameters) {
let value = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, attachment, parameter);
assert_equals(value, null);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
}
}
let width = 64;
let height = 64;
// Ensure the framebuffer texture 2D attachmentments cannot be changed.
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);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
// Ensure the framebuffer renderbuffer attachmentments cannot be changed.
let renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.DEPTH_ATTACHMENT,
gl.RENDERBUFFER,
renderbuffer);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
// Framebuffer status must be unsupported outside of a XR frame callback.
assert_equals(gl.checkFramebufferStatus(gl.FRAMEBUFFER), gl.FRAMEBUFFER_UNSUPPORTED);
session.requestAnimationFrame((time, xrFrame) => {
// Framebuffer status must be complete inside of a XR frame callback.
assert_equals(gl.checkFramebufferStatus(gl.FRAMEBUFFER), gl.FRAMEBUFFER_COMPLETE);
// Finished.
resolve();
});
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>