summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/js/tests/ext-color-buffer-half-float.js
blob: 51509e8a6e46ce80186d3c242b0cf0a0943c4330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
"use strict";

function allocateTexture()
{
    var texture = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, texture);
    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);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texture parameter setup should succeed");
    return texture;
}

function checkRenderingResults()
{
    wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
}

function arrayToString(arr, size) {
    var mySize;
    if (!size)
        mySize = arr.length;
    else
        mySize = size;
    var out = "[";
    for (var ii = 0; ii < mySize; ++ii) {
    if (ii > 0) {
        out += ", ";
    }
    out += arr[ii];
    }
    return out + "]";
}

function runReadbackTest(testProgram, subtractor)
{
    // Verify floating point readback
    debug("Checking readback of floating-point values");
    var buf = new Float32Array(4);
    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, buf);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "readPixels from floating-point framebuffer should succeed");
    var ok = true;
    var tolerance = 8.0; // TODO: factor this out from both this test and the subtractor shader above.
    for (var ii = 0; ii < buf.length; ++ii) {
        if (Math.abs(buf[ii] - subtractor[ii]) > tolerance) {
        ok = false;
        break;
        }
    }
    if (ok) {
        testPassed("readPixels of float-type data from floating-point framebuffer succeeded");
    } else {
        testFailed("readPixels of float-type data from floating-point framebuffer failed: expected "
                   + arrayToString(subtractor, 4) + ", got " + arrayToString(buf));
    }
}

function runFloatTextureRenderTargetTest(enabled, internalFormatString, format, type, testProgram, numberOfChannels, subtractor, texSubImageCover)
{
    let internalFormat = eval(internalFormatString);
    debug("");
    debug("testing floating-point " + internalFormatString + " texture render target" + (texSubImageCover > 0 ? " after calling texSubImage" : ""));

    var texture = allocateTexture();
    var width = 2;
    var height = 2;
    gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, null);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "floating-point texture allocation should succeed");

    // Try to use this texture as a render target.
    var fbo = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
    gl.bindTexture(gl.TEXTURE_2D, null);

    var completeStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    if (!enabled) {
        if (completeStatus == gl.FRAMEBUFFER_COMPLETE && !enabled)
            testFailed("floating-point " + internalFormatString + " render target should not be supported");
        else
            testPassed("floating-point " + internalFormatString + " render target should not be supported");
        return;
    }

    if (completeStatus != gl.FRAMEBUFFER_COMPLETE) {
        if (version == 1 && format == gl.RGB)
            testPassed("floating-point " + internalFormatString + " render target not supported; this is allowed.")
        else
            testFailed("floating-point " + internalFormatString + " render target not supported");
        return;
    }

    if (texSubImageCover > 0) {
        // Ensure that replacing the whole texture or a part of it with texSubImage2D doesn't affect renderability
        gl.bindTexture(gl.TEXTURE_2D, texture);
        var data = new Float32Array(width * height * numberOfChannels * texSubImageCover);
        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height * texSubImageCover, format, type, data);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed if EXT_color_buffer_half_float is enabled");
        gl.bindTexture(gl.TEXTURE_2D, null);
        if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
            testFailed("render target support changed after calling texSubImage2D");
            return;
        }
    }

    var renderProgram =
        wtu.setupProgram(gl,
                         [wtu.simpleVertexShader, `void main()
                                                    {
                                                        gl_FragColor = vec4(1000.0, 1000.0, 1000.0, 1000.0);
                                                    }`],
                         ['vPosition'],
                         [0]);
    wtu.clearAndDrawUnitQuad(gl);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "rendering to floating-point texture should succeed");

    // Now sample from the floating-point texture and verify we got the correct values.
    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.useProgram(testProgram);
    gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0);
    gl.uniform4fv(gl.getUniformLocation(testProgram, "subtractor"), subtractor);
    wtu.clearAndDrawUnitQuad(gl);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture should succeed");
    checkRenderingResults();

    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
    runReadbackTest(testProgram, subtractor);
}

function runFloatRenderbufferRenderTargetTest(enabled, internalFormatString, testProgram, numberOfChannels, subtractor)
{
    var internalFormat = eval(internalFormatString);
    var samples = [0];
    if (enabled && version > 1) {
        samples = Array.prototype.slice.call(gl.getInternalformatParameter(gl.RENDERBUFFER, internalFormat, gl.SAMPLES));
        samples.push(0);
    }
    for (var ndx = 0; ndx < samples.length; ++ndx) {
        debug("");
        debug("testing floating-point " + internalFormatString + " renderbuffer render target with number of samples " + samples[ndx]);

        var colorbuffer = gl.createRenderbuffer();
        var width = 2;
        var height = 2;
        gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
        if (samples[ndx] == 0)
            gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
        else
            gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples[ndx], internalFormat, width, height);
        if (!enabled) {
            wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "floating-point renderbuffer allocation should fail if EXT_color_buffer_half_float is not enabled or this is a 32 bit format");
            return;
        } else {
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "floating-point renderbuffer allocation should succeed if EXT_color_buffer_half_float is enabled");
        }

        // Try to use this renderbuffer as a render target.
        var fbo = gl.createFramebuffer();
        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
        gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer);

        var completeStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
        if (completeStatus != gl.FRAMEBUFFER_COMPLETE) {
            testFailed("floating-point " + internalFormatString + " render target not supported");
            return;
        }
        var resolveColorRbo = null;
        var resolveFbo = null;
        if (samples[ndx] > 0) {
            resolveColorRbo = gl.createRenderbuffer();
            gl.bindRenderbuffer(gl.RENDERBUFFER, resolveColorRbo);
            gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
            resolveFbo = gl.createFramebuffer();
            gl.bindFramebuffer(gl.FRAMEBUFFER, resolveFbo);
            gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, resolveColorRbo);
            completeStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
            if (completeStatus != gl.FRAMEBUFFER_COMPLETE) {
                testFailed("Failed to create resolve framebuffer");
                return;
            }
        }
        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
        gl.clearColor(1000.0, 1000.0, 1000.0, 1000.0);
        gl.clear(gl.COLOR_BUFFER_BIT);

        if (samples[ndx] > 0) {
            gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, resolveFbo);
            gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
            gl.bindFramebuffer(gl.READ_FRAMEBUFFER, resolveFbo);
        }
        runReadbackTest(testProgram, subtractor);
    }
}

function runRGB16FNegativeTest()
{
    debug("");
    debug("testing RGB16F isn't color renderable");

    var texture = allocateTexture();
    var width = 2;
    var height = 2;
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB16F, width, height, 0, gl.RGB, gl.FLOAT, null);
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "RGB16F texture allocation should succeed");

    // Try to use this texture as a render target.
    var fbo = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
    gl.bindTexture(gl.TEXTURE_2D, null);

    var completeStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    if (completeStatus == gl.FRAMEBUFFER_COMPLETE)
        testFailed("RGB16F render target should not be supported with or without enabling EXT_color_buffer_half_float");
    else
        testPassed("RGB16F render target should not be supported with or without enabling EXT_color_buffer_half_float");
    gl.deleteTexture(texture);

    var colorbuffer = gl.createRenderbuffer();
    gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
    gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB16F, width, height);
    wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "RGB16F renderbuffer allocation should fail with or without enabling EXT_color_buffer_half_float");
    gl.bindRenderbuffer(gl.RENDERBUFFER, null);
    gl.deleteRenderbuffer(colorbuffer);

    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
    gl.deleteFramebuffer(fbo);
}

function runUniqueObjectTest()
{
    debug("");
    debug("Testing that getExtension() returns the same object each time");
    gl.getExtension("EXT_color_buffer_half_float").myProperty = 2;
    webglHarnessCollectGarbage();
    shouldBe('gl.getExtension("EXT_color_buffer_half_float").myProperty', '2');
}

function runInternalFormatQueryTest()
{
    debug("");
    debug("testing the internal format query");

    var maxSamples = gl.getParameter(gl.MAX_SAMPLES);
    const formats = [gl.RGBA16F, gl.R16F, gl.RG16F];
    var firstMultiOnlyFormat = 4;
    for (var fmt = 0; fmt < formats.length; ++fmt) {
        var samples = gl.getInternalformatParameter(gl.RENDERBUFFER, formats[fmt], gl.SAMPLES);
        if (fmt >= firstMultiOnlyFormat && (samples.length == 0 || samples[0] < maxSamples)) {
            testFailed("the maximum value in SAMPLES should be at least " + maxSamples);
            return;
        }

        var prevSampleCount = 0;
        var sampleCount;
        for (var ndx = 0; ndx < samples.length; ++ndx, prevSampleCount = sampleCount) {
            sampleCount = samples[ndx];
            // sample count must be > 0
            if (sampleCount <= 0) {
                testFailed("Expected sample count to be at least one; got " + sampleCount);
                return;
            }

            // samples must be ordered descending
            if (ndx > 0 && sampleCount >= prevSampleCount) {
                testFailed("Expected sample count to be ordered in descending order; got " + prevSampleCount + " at index " + (ndx - 1) + ", and " + sampleCount + " at index " + ndx);
                return;
            }
        }
    }
    testPassed("Internal format query succeeded");
}

function runCopyTexImageTest(enabled)
{
    var width = 16;
    var height = 16;
    var level = 0;
    var cases = [
        { internalformat: "RGBA16F", format: "RGBA", destFormat: "R16F", valid: true, renderable: true, },
        { internalformat: "RGBA16F", format: "RGBA", destFormat: "RG16F", valid: true, renderable: true, },
        { internalformat: "RGBA16F", format: "RGBA", destFormat: "RGB16F", valid: true, renderable: true, },
        { internalformat: "RGBA16F", format: "RGBA", destFormat: "RGBA16F", valid: true, renderable: true, },
        { internalformat: "RGB16F", format: "RGB", destFormat: "R16F", valid: true, renderable: false, },
        { internalformat: "RGB16F", format: "RGB", destFormat: "RG16F", valid: true, renderable: false, },
        { internalformat: "RGB16F", format: "RGB", destFormat: "RGB16F", valid: true, renderable: false, },
        { internalformat: "RGB16F", format: "RGB", destFormat: "RGBA16F", valid: false, renderable: false, },
        { internalformat: "RG16F", format: "RG", destFormat: "R16F", valid: true, renderable: true, },
        { internalformat: "RG16F", format: "RG", destFormat: "RG16F", valid: true, renderable: true, },
        { internalformat: "RG16F", format: "RG", destFormat: "RGB16F", valid: false, renderable: true, },
        { internalformat: "RG16F", format: "RG", destFormat: "RGBA16F", valid: false, renderable: true, },
        { internalformat: "R16F", format: "RED", destFormat: "R16F", valid: true, renderable: true, },
        { internalformat: "R16F", format: "RED", destFormat: "RG16F", valid: false, renderable: true, },
        { internalformat: "R16F", format: "RED", destFormat: "RGB16F", valid: false, renderable: true, },
        { internalformat: "R16F", format: "RED", destFormat: "RGBA16F", valid: false, renderable: true, },
    ];
    if (version == 1) {
        cases = [
            { valid:  true, renderable: true, format: "RGBA",  destFormat: "LUMINANCE", },
            { valid:  true, renderable: true, format: "RGBA",  destFormat: "ALPHA", },
            { valid:  true, renderable: true, format: "RGBA",  destFormat: "LUMINANCE_ALPHA", },
            { valid:  true, renderable: true, format: "RGBA",  destFormat: "RGB", },
            { valid:  true, renderable: true, format: "RGBA",  destFormat: "RGBA", },
            { valid:  true, renderable: true, format: "RGB",   destFormat: "LUMINANCE", },
            { valid: false, renderable: true, format: "RGB",   destFormat: "ALPHA", },
            { valid: false, renderable: true, format: "RGB",   destFormat: "LUMINANCE_ALPHA", },
            { valid:  true, renderable: true, format: "RGB",   destFormat: "RGB", },
            { valid: false, renderable: true, format: "RGB",   destFormat: "RGBA", },
            { valid:  true, renderable: false, format: "ALPHA", destFormat: "ALPHA", },
            { valid:  true, renderable: false, format: "LUMINANCE", destFormat: "LUMINANCE", },
            { valid:  true, renderable: false, format: "LUMINANCE_ALPHA", destFormat: "LUMINANCE_ALPHA", },
        ];
    }
    cases.forEach(function(testcase) {
        debug("");
        debug(`Testing CopyTexImage2D for format: ${testcase.format}, internalformat: ${testcase.internalformat}, destformat: ${testcase.destFormat}`);

        var format = gl[testcase.format];
        var internalformat = version > 1 ? gl[testcase.internalformat] : format;
        var type = version > 1 ? gl.HALF_FLOAT : 0x8D61 /* HALF_FLOAT_OES */;
        var destFormat = gl[testcase.destFormat];
        var texSrc = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, texSrc);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        var data = new Uint16Array(width * height * 4);
        gl.texImage2D(gl.TEXTURE_2D, level, internalformat, width, height, 0, format, type, data);
        var fbo = gl.createFramebuffer();
        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texSrc, level);
        var texDest = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, texDest);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup framebuffer with texture should succeed.");
        if (enabled && testcase.renderable) {
            if (version == 1 && format == gl.RGB && gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
                testPassed("RGB framebuffer attachment not supported. This is allowed.")
            } else {
                shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
                gl.copyTexImage2D(gl.TEXTURE_2D, level, destFormat, 0, 0, width, height, 0);
                wtu.glErrorShouldBe(gl, testcase.valid ? gl.NO_ERROR : [gl.INVALID_ENUM, gl.INVALID_OPERATION], "CopyTexImage2D");
            }
        } else {
            shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
            gl.copyTexImage2D(gl.TEXTURE_2D, level, destFormat, 0, 0, width, height, 0);
            wtu.glErrorShouldBe(gl, [gl.INVALID_ENUM, gl.INVALID_FRAMEBUFFER_OPERATION], "CopyTexImage2D should fail.");
        }

        gl.deleteTexture(texDest);
        gl.deleteTexture(texSrc);
        gl.deleteFramebuffer(fbo);
    });
}

description("This test verifies the functionality of the EXT_color_buffer_half_float extension, if it is available.");

debug("");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, version);

if (version < 2) {
    // These are exposed on the extension, but we need them before the extension has been requested so we can
    // make sure they don't work.
    gl.R16F = 0x822D;
    gl.RG16F = 0x822F;
    gl.RGB16F = 0x881B;
    gl.RGBA16F = 0x881A;
}

if (!gl) {
  testFailed("WebGL context does not exist");
} else {
  testPassed("WebGL context exists");

  var texturedShaders = [
      wtu.simpleTextureVertexShader,
           `precision mediump float;
            uniform sampler2D tex;
            uniform vec4 subtractor;
            varying vec2 texCoord;
            void main()
            {
                vec4 color = texture2D(tex, texCoord);
                if (abs(color.r - subtractor.r) +
                    abs(color.g - subtractor.g) +
                    abs(color.b - subtractor.b) +
                    abs(color.a - subtractor.a) < 16.0) {
                    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
                } else {
                    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
                }
            }`,
  ];
  var testProgram =
      wtu.setupProgram(gl,
                       texturedShaders,
                       ['vPosition', 'texCoord0'],
                       [0, 1]);
  var quadParameters = wtu.setupUnitQuad(gl, 0, 1);

  if (version > 1) {
    // Ensure these formats can't be used for rendering if the extension is disabled
    runFloatTextureRenderTargetTest(false, "gl.R16F", gl.RED, gl.FLOAT);
    runFloatTextureRenderTargetTest(false, "gl.RG16F", gl.RG, gl.FLOAT);
    runFloatTextureRenderTargetTest(false, "gl.RGBA16F", gl.RGBA, gl.FLOAT);
  }

  runFloatRenderbufferRenderTargetTest(false, "gl.R16F");
  runFloatRenderbufferRenderTargetTest(false, "gl.RG16F");
  runFloatRenderbufferRenderTargetTest(false, "gl.RGBA16F");
  runFloatRenderbufferRenderTargetTest(false, "gl.R32F");
  runFloatRenderbufferRenderTargetTest(false, "gl.RG32F");
  runFloatRenderbufferRenderTargetTest(false, "gl.RGBA32F");
  runFloatRenderbufferRenderTargetTest(false, "gl.R11F_G11F_B10F");

  if (version > 1) {
      runCopyTexImageTest(false);
      // Ensure RGB16F can't be used for rendering.
      runRGB16FNegativeTest();
  }

  let oesTextureHalfFloat = null;
  if (version == 1) {
    // oesTextureHalfFloat implicitly enables EXT_color_buffer_half_float if supported
    oesTextureHalfFloat = gl.getExtension("OES_texture_half_float");
    if (oesTextureHalfFloat && gl.getSupportedExtensions().includes("EXT_color_buffer_half_float")) {
        runFloatTextureRenderTargetTest(true, "gl.RGBA", gl.RGBA, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 4, [1000, 1000, 1000, 1000], 0);
        runFloatTextureRenderTargetTest(true, "gl.RGB", gl.RGB, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 3, [1000, 1000, 1000, 1], 0);
    }
  }

  var ext = null;
  if (!(ext = gl.getExtension("EXT_color_buffer_half_float"))) {
      testPassed("No EXT_color_buffer_half_float support -- this is legal");
  } else {
      testPassed("Successfully enabled EXT_color_buffer_half_float extension");

      shouldBe("ext.RGB16F_EXT", "gl.RGB16F");
      shouldBe("ext.RGBA16F_EXT", "gl.RGBA16F");
      shouldBe("ext.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT", "0x8211");
      shouldBe("ext.UNSIGNED_NORMALIZED_EXT", "0x8C17");

      if (version > 1) {
          runInternalFormatQueryTest();
          runFloatTextureRenderTargetTest(true, "gl.R16F", gl.RED, gl.FLOAT, testProgram, 1, [1000, 1, 1, 1], 0);
          runFloatTextureRenderTargetTest(true, "gl.RG16F", gl.RG, gl.FLOAT, testProgram, 2, [1000, 1000, 1, 1], 0);
          runFloatTextureRenderTargetTest(true, "gl.RGBA16F", gl.RGBA, gl.FLOAT, testProgram, 4, [1000, 1000, 1000, 1000], 0);
          runFloatRenderbufferRenderTargetTest(true, "gl.R16F", testProgram, 1, [1000, 1, 1, 1]);
          runFloatRenderbufferRenderTargetTest(true, "gl.RG16F", testProgram, 2, [1000, 1000, 1, 1]);
          runFloatRenderbufferRenderTargetTest(true, "gl.RGBA16F", testProgram, 4, [1000, 1000, 1000, 1000]);
      }
      if (version == 1) {
          shouldBeNonNull(oesTextureHalfFloat); // Required by spec
          runFloatTextureRenderTargetTest(true, "gl.RGBA", gl.RGBA, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 4, [1000, 1000, 1000, 1000], 0);
          runFloatTextureRenderTargetTest(true, "gl.RGB", gl.RGB, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 3, [1000, 1000, 1000, 1], 0);
          runFloatTextureRenderTargetTest(false, "gl.LUMINANCE_ALPHA", gl.LUMINANCE_ALPHA, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 2, [1000, 1000, 1000, 1000], 0);
          runFloatTextureRenderTargetTest(false, "gl.LUMINANCE", gl.LUMINANCE, oesTextureHalfFloat.HALF_FLOAT_OES, testProgram, 1, [1000, 1, 1, 1], 0);
      }

      if (version > 1)
          runRGB16FNegativeTest(); // Ensure EXT_color_buffer_half_float does not enable RGB16F as color renderable.

      runCopyTexImageTest(true);

      runUniqueObjectTest();
  }
}

debug("");
var successfullyParsed = true;