| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <title>WebGL Framebuffer Test</title> |
| <script src="../../../resources/js-test.js"></script> |
| <script src="resources/webgl-test.js"></script> |
| </head> |
| <body> |
| <div id="description"></div> |
| <div id="console"></div> |
| <canvas id="canvas" width="2" height="2"> </canvas> |
| <script> |
| description("This tests framebuffer/renderbuffer-related functions"); |
| |
| debug(""); |
| debug("Canvas.getContext"); |
| |
| if (window.internals) |
| window.internals.settings.setWebGLErrorsToConsoleEnabled(false); |
| |
| var canvas = document.getElementById("canvas"); |
| var gl = create3DContext(canvas); |
| if (!gl) { |
| testFailed("context does not exist"); |
| } else { |
| testPassed("context exists"); |
| |
| debug(""); |
| debug("Checking framebuffer/renderbuffer stuff."); |
| |
| var value = gl.getFramebufferAttachmentParameter( |
| gl.FRAMEBUFFER, |
| gl.COLOR_ATTACHMENT0, |
| gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); |
| assertMsg(gl.getError() == gl.INVALID_OPERATION, |
| "calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION."); |
| |
| assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE, |
| "calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE."); |
| |
| var tex = gl.createTexture(); |
| gl.bindTexture(gl.TEXTURE_2D, tex); |
| 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, // level |
| gl.RGBA, // internalFormat |
| canvas.width, // width |
| canvas.height, // height |
| 0, // border |
| gl.RGBA, // format |
| gl.UNSIGNED_BYTE, // type |
| null); // data |
| gl.framebufferTexture2D( |
| gl.FRAMEBUFFER, |
| gl.COLOR_ATTACHMENT0, |
| gl.TEXTURE_2D, |
| tex, |
| 0); |
| assertMsg(gl.getError() == gl.INVALID_OPERATION, |
| "trying to attach a texture to default framebuffer should generate INVALID_OPERATION."); |
| |
| gl.framebufferRenderbuffer( |
| gl.FRAMEBUFFER, |
| gl.COLOR_ATTACHMENT0, |
| gl.RENDERBUFFER, |
| null); |
| assertMsg(gl.getError() == gl.INVALID_OPERATION, |
| "trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION."); |
| |
| var rb = gl.createRenderbuffer(); |
| gl.bindRenderbuffer(gl.RENDERBUFFER, rb); |
| gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "allocating renderbuffer storage of a newly created renderbuffer should succeed."); |
| |
| gl.framebufferRenderbuffer( |
| gl.FRAMEBUFFER, |
| gl.COLOR_ATTACHMENT0, |
| gl.RENDERBUFFER, |
| rb); |
| assertMsg(gl.getError() == gl.INVALID_OPERATION, |
| "trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION."); |
| |
| var fbtex = gl.createTexture(); |
| gl.bindTexture(gl.TEXTURE_2D, fbtex); |
| gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
| var fb = gl.createFramebuffer(); |
| |
| gl.bindFramebuffer(gl.FRAMEBUFFER, fb); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "binding a newly created framebuffer should succeed."); |
| |
| var target = 0x8CA8; // GL_READ_FRAMEBUFFER |
| gl.getFramebufferAttachmentParameter( |
| target, |
| gl.COLOR_ATTACHMENT0, |
| gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| assertMsg(gl.checkFramebufferStatus(target) == 0, |
| "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0."); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| gl.bindFramebuffer(target, gl.createFramebuffer()); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING), |
| "calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING."); |
| gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); |
| |
| var attachment = 0x8CE1; // GL_COLOR_ATTACHMENT1 |
| gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM."); |
| gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb); |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM."); |
| |
| gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, |
| gl.COLOR_ATTACHMENT0, |
| 0x8210); // GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING |
| assertMsg(gl.getError() == gl.INVALID_ENUM, |
| "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM."); |
| |
| gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "attaching a texture to a framebuffer should succeed."); |
| |
| gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "detaching a texture from a framebuffer should succeed."); |
| |
| gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 1); |
| assertMsg(gl.getError() == gl.INVALID_VALUE, |
| "calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE."); |
| |
| gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "attaching a renderbuffer to a framebuffer should succeed."); |
| |
| gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "detaching a renderbuffer from a framebuffer should succeed."); |
| |
| gl.bindFramebuffer(gl.FRAMEBUFFER, null); |
| assertMsg(gl.getError() == gl.NO_ERROR, |
| "binding default (null) framebuffer should succeed."); |
| } |
| |
| debug(""); |
| |
| </script> |
| </body> |
| </html> |