-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for fb with mismatched attachment rb/tex-targets. #3148
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
161 changes: 161 additions & 0 deletions
161
sdk/tests/conformance2/rendering/framebuffer-mismatched-attachment-targets.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,161 @@ | ||
<!-- | ||
Copyright (c) 2020 The Khronos Group Inc. | ||
Use of this source code is governed by an MIT-style license that can be | ||
found in the LICENSE.txt file. | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebGL2 can render to framebuffer attachments with different targets</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> | ||
<script id="vshader" type="x-shader/x-vertex">#version 300 es | ||
void main(void) { | ||
gl_Position = vec4(-0.5, -0.5, 0, 1); | ||
gl_PointSize = 1.0; | ||
} | ||
</script> | ||
<script id="fshader" type="x-shader/x-fragment">#version 300 es | ||
precision mediump float; | ||
out vec4 outColor; | ||
void main() { | ||
outColor = vec4(0, 1, 0, 1); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<canvas id="example" width="1", height="1"></canvas> | ||
<div id="description"></div> | ||
<div id="console"></div> | ||
<script> | ||
"use strict"; | ||
debug(""); | ||
|
||
description("Test that WebGL2 can render to layers in 3D textures"); | ||
|
||
const wtu = WebGLTestUtils; | ||
const gl = wtu.create3DContext("example", undefined, 2); | ||
|
||
if (!gl) { | ||
testFailed("WebGL context creation failed"); | ||
} else { | ||
testPassed("WebGL context creation succeeded"); | ||
runTest(); | ||
} | ||
|
||
function newResource(target, mipLevels, format, size) { | ||
let ret; | ||
switch (target) { | ||
case gl.RENDERBUFFER: { | ||
ret = gl.createRenderbuffer(); | ||
ret.mips = [ ret ]; | ||
for (let i = 1; i < mipLevels; i++) { | ||
ret.mips.push(gl.createRenderbuffer()); | ||
} | ||
for (const i in ret.mips) { | ||
const rb = ret.mips[i]; | ||
gl.bindRenderbuffer(target, rb); | ||
gl.renderbufferStorage(target, format, size>>i, size>>i); | ||
} | ||
ret.attach = (attachEnum, mipLevel) => { | ||
const rb = ret.mips[mipLevel]; | ||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachEnum, gl.RENDERBUFFER, rb); | ||
}; | ||
break; | ||
} | ||
case gl.TEXTURE_2D: | ||
case gl.TEXTURE_CUBE_MAP: { | ||
ret = gl.createTexture(); | ||
gl.bindTexture(target, ret); | ||
gl.texStorage2D(target, mipLevels, format, size, size); | ||
let imageTarget = target; | ||
if (imageTarget == gl.TEXTURE_CUBE_MAP) { | ||
imageTarget = gl.TEXTURE_CUBE_MAP_POSITIVE_X+2; // Deliberately don't choose the first image. | ||
} | ||
ret.attach = (attachEnum, mipLevel) => { | ||
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachEnum, imageTarget, ret, mipLevel); | ||
}; | ||
break; | ||
} | ||
case gl.TEXTURE_3D: | ||
case gl.TEXTURE_2D_ARRAY: { | ||
ret = gl.createTexture(); | ||
gl.bindTexture(target, ret); | ||
gl.texStorage3D(target, mipLevels, format, size, size, 1); | ||
ret.attach = (attachEnum, mipLevel) => { | ||
gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachEnum, ret, mipLevel, 0); | ||
}; | ||
break; | ||
} | ||
default: | ||
throw new Error(); | ||
} | ||
ret.target = wtu.glEnumToString(gl, target); | ||
ret.format = wtu.glEnumToString(gl, format); | ||
return ret; | ||
} | ||
|
||
function runTest() { | ||
const MIP_LEVELS = 2; | ||
const SIZE = 2; | ||
|
||
gl.clearColor(1, 0, 0, 1); | ||
|
||
const program = wtu.setupProgram(gl, ['vshader','fshader'], [], console.log.bind(console)); | ||
gl.useProgram(program); | ||
|
||
const colorResList = [ | ||
newResource(gl.RENDERBUFFER, MIP_LEVELS, gl.RGBA8, SIZE), | ||
newResource(gl.TEXTURE_2D, MIP_LEVELS, gl.RGBA8, SIZE), | ||
newResource(gl.TEXTURE_CUBE_MAP, MIP_LEVELS, gl.RGBA8, SIZE), | ||
newResource(gl.TEXTURE_3D, MIP_LEVELS, gl.RGBA8, SIZE), | ||
newResource(gl.TEXTURE_2D_ARRAY, MIP_LEVELS, gl.RGBA8, SIZE), | ||
]; | ||
|
||
const depthResList = [ | ||
newResource(gl.RENDERBUFFER, MIP_LEVELS, gl.DEPTH_COMPONENT16, SIZE), | ||
newResource(gl.TEXTURE_2D, MIP_LEVELS, gl.DEPTH_COMPONENT16, SIZE), | ||
newResource(gl.TEXTURE_CUBE_MAP, MIP_LEVELS, gl.DEPTH_COMPONENT16, SIZE), | ||
//newResource(gl.TEXTURE_3D, MIP_LEVELS, gl.DEPTH_COMPONENT16, SIZE), // Depth formats forbidden for TEXTURE_3D. | ||
newResource(gl.TEXTURE_2D_ARRAY, MIP_LEVELS, gl.DEPTH_COMPONENT16, SIZE), | ||
]; | ||
|
||
const fb = gl.createFramebuffer(); | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, fb); | ||
for (const color of colorResList) { | ||
for (const depth of depthResList) { | ||
debug(`\ncolor: ${color.target}; depth: ${depth.target}`); | ||
for (let mipLevel = 0; mipLevel < MIP_LEVELS; mipLevel++) { | ||
debug(`mipLevel: ${mipLevel}`); | ||
color.attach(gl.COLOR_ATTACHMENT0, mipLevel); | ||
depth.attach(gl.DEPTH_ATTACHMENT, mipLevel); | ||
if (!wtu.framebufferStatusShouldBe(gl, gl.FRAMEBUFFER, [gl.FRAMEBUFFER_COMPLETE, gl.FRAMEBUFFER_UNSUPPORTED])) { | ||
kenrussell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
|
||
gl.clear(gl.COLOR_BUFFER_BIT); | ||
wtu.checkCanvas(gl, [255, 0, 0, 255], `framebuffer layer ${mipLevel} should be cleared red`); | ||
|
||
gl.drawArrays(gl.POINTS, 0, 1); | ||
wtu.checkCanvas(gl, [0, 255, 0, 255], `framebuffer layer ${mipLevel} should be drawn green`); | ||
|
||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, `No errors`); | ||
} | ||
} | ||
} | ||
|
||
// make sure we were not rendering to the canvas. | ||
gl.bindFramebuffer(gl.FRAMEBUFFER, null) | ||
wtu.checkCanvas(gl, [0, 0, 0, 0], "canvas should be zero"); | ||
} | ||
|
||
debug(""); | ||
var successfullyParsed = true; | ||
</script> | ||
<script src="../../js/js-test-post.js"></script> | ||
|
||
</body> | ||
</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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description needs updating.