6 <title>WebGL instanceof test.
</title>
7 <script src=
"../../../resources/js-test.js"></script>
8 <script src=
"resources/webgl-test.js"> </script>
9 <script src=
"resources/webgl-test-utils.js"> </script>
12 <canvas id=
"canvas" width=
"2" height=
"2" style=
"width: 40px; height: 40px;"></canvas>
13 <div id=
"description"></div>
14 <div id=
"console"></div>
15 <script id=
"vshader" type=
"x-shader/x-vertex">
16 attribute vec4 vPosition;
17 varying vec2 texCoord;
20 gl_Position = vPosition;
24 <script id=
"fshader" type=
"x-shader/x-fragment">
25 precision mediump float;
33 var wtu
= WebGLTestUtils
;
34 description(document
.title
);
35 debug("Tests that instanceof works on WebGL objects.");
37 var gl
= create3DContext(document
.getElementById("canvas"));
38 shouldBeTrue('gl instanceof WebGLRenderingContext');
39 shouldBeTrue('gl.createBuffer() instanceof WebGLBuffer');
40 shouldBeTrue('gl.createFramebuffer() instanceof WebGLFramebuffer');
41 shouldBeTrue('gl.createProgram() instanceof WebGLProgram');
42 shouldBeTrue('gl.createRenderbuffer() instanceof WebGLRenderbuffer');
43 shouldBeTrue('gl.createShader(gl.VERTEX_SHADER) instanceof WebGLShader');
44 shouldBeTrue('gl.createTexture() instanceof WebGLTexture');
46 var program
= wtu
.setupProgram(
48 [wtu
.loadShaderFromScript(gl
, 'vshader', gl
.VERTEX_SHADER
),
49 wtu
.loadShaderFromScript(gl
, 'fshader', gl
.FRAGMENT_SHADER
)],
52 shouldBeTrue('gl.getUniformLocation(program, "color") instanceof WebGLUniformLocation');
53 shouldBeTrue('gl.getActiveAttrib(program, 0) instanceof WebGLActiveInfo');
54 shouldBeTrue('gl.getActiveUniform(program, 0) instanceof WebGLActiveInfo');
57 debug("Tests that those WebGL objects can not be constructed through new operator");
60 function shouldThrowWithNew(objectType
, objectName
)
64 testFailed('new ' + objectName
+ ' did not throw');
66 testPassed('new ' + objectName
+ ' threw an error');
70 shouldThrowWithNew(window
.WebGLRenderingContext
, 'WebGLRenderingContext');
71 shouldThrowWithNew(window
.WebGLActiveInfo
, 'WebGLActiveInfo');
72 shouldThrowWithNew(window
.WebGLBuffer
, 'WebGLBuffer');
73 shouldThrowWithNew(window
.WebGLFramebuffer
, 'WebGLFramebuffer');
74 shouldThrowWithNew(window
.WebGLProgram
, 'WebGLProgram');
75 shouldThrowWithNew(window
.WebGLRenderbuffer
, 'WebGLRenderbuffer');
76 shouldThrowWithNew(window
.WebGLShader
, 'WebGLShader');
77 shouldThrowWithNew(window
.WebGLTexture
, 'WebGLTexture');
78 shouldThrowWithNew(window
.WebGLUniformLocation
, 'WebGLUniformLocation');
79 shouldThrowWithNew(window
.WebGLShaderPrecisionFormat
, 'WebGLShaderPrecisionFormat');
81 successfullyParsed
= true;