5 <script src=
"../../../resources/js-test.js"></script>
6 <script src=
"resources/webgl-test.js"></script>
9 <div id=
"description"></div>
10 <div id=
"console"></div>
13 description("Test of get calls against GL objects like getBufferParameter, etc.");
16 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
18 function sizeInBytes(type
) {
21 case gl
.UNSIGNED_BYTE
:
24 case gl
.UNSIGNED_SHORT
:
35 var gl
= create3DContext();
37 var standardVert
= loadStandardVertexShader(gl
);
38 var standardFrag
= loadStandardFragmentShader(gl
);
39 var standardProgram
= gl
.createProgram();
40 gl
.attachShader(standardProgram
, standardVert
);
41 gl
.attachShader(standardProgram
, standardFrag
);
42 gl
.linkProgram(standardProgram
);
43 var shaders
= gl
.getAttachedShaders(standardProgram
);
44 shouldBe('shaders.length', '2');
45 shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag');
46 glErrorShouldBe(gl
, gl
.NO_ERROR
);
47 shouldBeNull('gl.getAttachedShaders(null)');
48 glErrorShouldBe(gl
, gl
.INVALID_VALUE
);
49 shouldThrow('gl.getAttachedShaders(standardVert)');
50 glErrorShouldBe(gl
, gl
.NO_ERROR
);
52 // Test getBufferParameter
53 var buffer
= gl
.createBuffer();
54 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buffer
);
55 gl
.bufferData(gl
.ARRAY_BUFFER
, 16, gl
.DYNAMIC_DRAW
);
56 shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16');
57 shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_DRAW');
59 // Test getFramebufferAttachmentParameter
60 var texture
= gl
.createTexture();
61 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
62 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, 2, 2, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
,
68 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
69 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
70 gl
.bindTexture(gl
.TEXTURE_2D
, null);
71 var framebuffer
= gl
.createFramebuffer();
72 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, framebuffer
);
73 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, texture
, 0);
74 var renderbuffer
= gl
.createRenderbuffer();
75 glErrorShouldBe(gl
, gl
.NO_ERROR
);
76 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, renderbuffer
);
77 glErrorShouldBe(gl
, gl
.NO_ERROR
);
78 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.DEPTH_COMPONENT16
, 2, 2);
79 glErrorShouldBe(gl
, gl
.NO_ERROR
);
80 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.DEPTH_ATTACHMENT
, gl
.RENDERBUFFER
, renderbuffer
);
81 // FIXME: on some machines (in particular the WebKit commit bots) the
82 // framebuffer status is FRAMEBUFFER_UNSUPPORTED; more investigation
83 // is needed why this is the case, because the FBO allocated
84 // internally by the WebKit implementation has almost identical
85 // parameters to this one. See https://bugs.webkit.org/show_bug.cgi?id=31843.
86 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
87 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE');
88 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'texture');
89 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0');
90 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0');
92 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER');
93 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'renderbuffer');
95 // Test getProgramParameter
96 shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false');
97 shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true');
98 shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"');
99 shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2');
100 shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2');
101 shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1');
103 // Test getRenderbufferParameter
104 shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)', '2');
105 shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)', '2');
106 // Note: we can't test the actual value of the internal format since
107 // the implementation is allowed to change it.
108 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)');
109 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE)');
110 var colorbuffer
= gl
.createRenderbuffer();
111 glErrorShouldBe(gl
, gl
.NO_ERROR
);
112 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, renderbuffer
);
113 glErrorShouldBe(gl
, gl
.NO_ERROR
);
114 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA4
, 2, 2);
115 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)');
116 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)');
117 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)');
118 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)');
120 // Test getShaderParameter
121 shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADER');
122 shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false');
123 shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true');
125 // Test getTexParameter
126 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, framebuffer
);
127 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
128 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
129 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
130 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
131 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
132 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST');
133 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST');
134 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_EDGE');
135 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_EDGE');
137 // Test getUniform with all variants of data types
138 // Boolean uniform variables
139 var boolProgram
= loadProgram(gl
, "resources/boolUniformShader.vert", "resources/noopUniformShader.frag");
140 shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true');
141 var bvalLoc
= gl
.getUniformLocation(boolProgram
, "bval");
142 var bval2Loc
= gl
.getUniformLocation(boolProgram
, "bval2");
143 var bval3Loc
= gl
.getUniformLocation(boolProgram
, "bval3");
144 var bval4Loc
= gl
.getUniformLocation(boolProgram
, "bval4");
145 gl
.useProgram(boolProgram
);
146 gl
.uniform1i(bvalLoc
, 1);
147 gl
.uniform2i(bval2Loc
, 1, 0);
148 gl
.uniform3i(bval3Loc
, 1, 0, 1);
149 gl
.uniform4i(bval4Loc
, 1, 0, 1, 0);
150 glErrorShouldBe(gl
, gl
.NO_ERROR
);
151 shouldBe('gl.getUniform(boolProgram, bvalLoc)', 'true');
152 shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[true, false]');
153 shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[true, false, true]');
154 shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[true, false, true, false]');
155 // Integer uniform variables
156 var intProgram
= loadProgram(gl
, "resources/intUniformShader.vert", "resources/noopUniformShader.frag");
157 shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true');
158 var ivalLoc
= gl
.getUniformLocation(intProgram
, "ival");
159 var ival2Loc
= gl
.getUniformLocation(intProgram
, "ival2");
160 var ival3Loc
= gl
.getUniformLocation(intProgram
, "ival3");
161 var ival4Loc
= gl
.getUniformLocation(intProgram
, "ival4");
162 gl
.useProgram(intProgram
);
163 gl
.uniform1i(ivalLoc
, 1);
164 gl
.uniform2i(ival2Loc
, 2, 3);
165 gl
.uniform3i(ival3Loc
, 4, 5, 6);
166 gl
.uniform4i(ival4Loc
, 7, 8, 9, 10);
167 glErrorShouldBe(gl
, gl
.NO_ERROR
);
168 shouldBe('gl.getUniform(intProgram, ivalLoc)', '1');
169 shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]');
170 shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]');
171 shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]');
172 // Float uniform variables
173 var floatProgram
= loadProgram(gl
, "resources/floatUniformShader.vert", "resources/noopUniformShader.frag");
174 shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true');
175 var fvalLoc
= gl
.getUniformLocation(floatProgram
, "fval");
176 var fval2Loc
= gl
.getUniformLocation(floatProgram
, "fval2");
177 var fval3Loc
= gl
.getUniformLocation(floatProgram
, "fval3");
178 var fval4Loc
= gl
.getUniformLocation(floatProgram
, "fval4");
179 gl
.useProgram(floatProgram
);
180 gl
.uniform1f(fvalLoc
, 11);
181 gl
.uniform2f(fval2Loc
, 12, 13);
182 gl
.uniform3f(fval3Loc
, 14, 15, 16);
183 gl
.uniform4f(fval4Loc
, 17, 18, 19, 20);
184 glErrorShouldBe(gl
, gl
.NO_ERROR
);
185 shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11');
186 shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]');
187 shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]');
188 shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]');
189 // Sampler uniform variables
190 var samplerProgram
= loadProgram(gl
, "resources/noopUniformShader.vert", "resources/samplerUniformShader.frag");
191 shouldBe('gl.getProgramParameter(samplerProgram, gl.LINK_STATUS)', 'true');
192 var s2DValLoc
= gl
.getUniformLocation(samplerProgram
, "s2D");
193 var sCubeValLoc
= gl
.getUniformLocation(samplerProgram
, "sCube");
194 gl
.useProgram(samplerProgram
);
195 gl
.uniform1i(s2DValLoc
, 0);
196 gl
.uniform1i(sCubeValLoc
, 1);
197 glErrorShouldBe(gl
, gl
.NO_ERROR
);
198 shouldBe('gl.getUniform(samplerProgram, s2DValLoc)', '0');
199 shouldBe('gl.getUniform(samplerProgram, sCubeValLoc)', '1');
200 // Matrix uniform variables
201 var matProgram
= loadProgram(gl
, "resources/matUniformShader.vert", "resources/noopUniformShader.frag");
202 shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true');
203 var mval2Loc
= gl
.getUniformLocation(matProgram
, "mval2");
204 var mval3Loc
= gl
.getUniformLocation(matProgram
, "mval3");
205 var mval4Loc
= gl
.getUniformLocation(matProgram
, "mval4");
206 gl
.useProgram(matProgram
);
207 gl
.uniformMatrix2fv(mval2Loc
, false, [1, 2, 3, 4]);
208 gl
.uniformMatrix3fv(mval3Loc
, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]);
209 gl
.uniformMatrix4fv(mval4Loc
, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
210 glErrorShouldBe(gl
, gl
.NO_ERROR
);
211 shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]');
212 shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]');
213 shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]');
215 // Test getVertexAttrib
216 var array
= new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
217 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buffer
);
218 gl
.bufferData(gl
.ARRAY_BUFFER
, array
, gl
.DYNAMIC_DRAW
);
219 // Vertex attribute 0 is special in that it has no current state, so
220 // fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute
221 // 1 for these tests instead.
222 gl
.enableVertexAttribArray(1);
223 gl
.vertexAttribPointer(1, 4, gl
.FLOAT
, false, 0, 0);
224 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)', 'buffer');
225 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true');
226 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4');
227 // Stride MUST be the value the user put in.
228 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '0');
229 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT');
230 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false');
231 gl
.vertexAttribPointer(1, 4, gl
.FLOAT
, false, 36, 12);
232 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '36');
233 shouldBe('gl.getVertexAttribOffset(1, gl.VERTEX_ATTRIB_ARRAY_POINTER)', '12');
234 gl
.disableVertexAttribArray(1);
235 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false');
236 gl
.vertexAttrib4f(1, 5, 6, 7, 8);
237 shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]');
238 glErrorShouldBe(gl
, gl
.NO_ERROR
);
240 // Test cases where name == 0
241 gl
.deleteTexture(texture
);
242 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE');
243 gl
.deleteRenderbuffer(renderbuffer
);
244 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE');
245 gl
.deleteBuffer(buffer
);
246 shouldBeNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)');
247 glErrorShouldBe(gl
, gl
.NO_ERROR
);