null-object-behaviour.html (5080B)
1 <!-- 2 Copyright (c) 2019 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 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 12 <script src="../../js/js-test-pre.js"></script> 13 <script src="../../js/webgl-test-utils.js"></script> 14 </head> 15 <body> 16 <div id="description"></div> 17 <div id="console"></div> 18 19 <script> 20 "use strict"; 21 var wtu = WebGLTestUtils; 22 description("Tests calling WebGL APIs without providing the necessary objects"); 23 24 var context = wtu.create3DContext(); 25 var program = wtu.loadStandardProgram(context); 26 var shader = wtu.loadStandardVertexShader(context); 27 var shouldGenerateGLError = wtu.shouldGenerateGLError; 28 29 assertMsg(program != null, "Program Compiled"); 30 assertMsg(shader != null, "Shader Compiled"); 31 shouldThrow("context.compileShader(undefined)"); 32 shouldThrow("context.linkProgram(undefined)"); 33 shouldThrow("context.attachShader(undefined, undefined)"); 34 shouldThrow("context.attachShader(program, undefined)"); 35 shouldThrow("context.attachShader(undefined, shader)"); 36 shouldThrow("context.detachShader(program, undefined)"); 37 shouldThrow("context.detachShader(undefined, shader)"); 38 shouldThrow("context.shaderSource(undefined, undefined)"); 39 shouldThrow("context.shaderSource(undefined, 'foo')"); 40 shouldThrow("context.bindAttribLocation(undefined, 0, 'foo')"); 41 shouldThrow("context.bindBuffer(context.ARRAY_BUFFER, 0)"); 42 shouldThrow("context.bindFramebuffer(context.FRAMEBUFFER, 0)"); 43 shouldThrow("context.bindRenderbuffer(context.RENDERBUFFER, 0)"); 44 shouldThrow("context.bindTexture(context.TEXTURE_2D, 0)"); 45 shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, null)"); 46 shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, null)"); 47 shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, null)"); 48 shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, null)"); 49 shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, undefined)"); 50 shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, undefined)"); 51 shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, undefined)"); 52 shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, undefined)"); 53 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, null)"); 54 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, null, 0)"); 55 shouldThrow("context.getProgramParameter(undefined, 0)"); 56 shouldThrow("context.getProgramInfoLog(undefined, 0)"); 57 shouldThrow("context.getShaderParameter(undefined, 0)"); 58 shouldThrow("context.getShaderInfoLog(undefined, 0)"); 59 shouldThrow("context.getShaderSource(undefined)"); 60 shouldThrow("context.getUniform(undefined, null)"); 61 shouldThrow("context.getUniformLocation(undefined, 'foo')"); 62 63 debug(""); 64 debug("check with bindings"); 65 context.bindBuffer(context.ARRAY_BUFFER, context.createBuffer()); 66 context.bindTexture(context.TEXTURE_2D, context.createTexture()); 67 shouldGenerateGLError(context, context.NO_ERROR, "context.bufferData(context.ARRAY_BUFFER, 1, context.STATIC_DRAW)"); 68 shouldGenerateGLError(context, context.NO_ERROR, "context.getBufferParameter(context.ARRAY_BUFFER, context.BUFFER_SIZE)"); 69 shouldGenerateGLError(context, context.NO_ERROR, "context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, 1, 1, 0, context.RGBA, context.UNSIGNED_BYTE, new Uint8Array([0,0,0,0]))"); 70 shouldGenerateGLError(context, context.NO_ERROR, "context.texParameteri(context.TEXTURE_2D, context.TEXTURE_MIN_FILTER, context.NEAREST)"); 71 shouldGenerateGLError(context, context.NO_ERROR, "context.getTexParameter(context.TEXTURE_2D, context.TEXTURE_MIN_FILTER)"); 72 73 debug(""); 74 debug("check without bindings"); 75 context.bindBuffer(context.ARRAY_BUFFER, null); 76 context.bindTexture(context.TEXTURE_2D, null); 77 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.bufferData(context.ARRAY_BUFFER, 1, context.STATIC_DRAW)"); 78 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.getBufferParameter(context.ARRAY_BUFFER, context.BUFFER_SIZE)"); 79 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, 1, 1, 0, context.RGBA, context.UNSIGNED_BYTE, new Uint8Array([0,0,0,0]))"); 80 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.texParameteri(context.TEXTURE_2D, context.TEXTURE_MIN_FILTER, context.NEAREST)"); 81 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.getTexParameter(context.TEXTURE_2D, context.TEXTURE_MIN_FILTER)"); 82 83 84 var successfullyParsed = true; 85 </script> 86 87 <script src="../../js/js-test-post.js"></script> 88 </body> 89 </html>