chromium/third_party/blink/web_tests/fast/webgl/webgl-sharedarraybuffer.html

<!DOCTYPE html>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/sab-polyfill.js"></script>
<script src="resources/webgl-test.js"></script>
<script src="resources/webgl-test-utils.js"></script>
</head>
<body>
<script>
if (window.SharedArrayBuffer) {
  var canvas = document.createElement("canvas");
  var gl;
  for (var name of ['webgl2', 'webgl']) {
    try {
      gl = canvas.getContext(name);
    } catch(e) {
    }
    if (gl)
      break;
  }
  var has_webgl2 = name == 'webgl2';

  if (gl) {
    // Nearly all of the tests below are invalid (e.g. will set the GL error),
    // but we don't really care; we just want to ensure that passing a
    // SharedArrayBuffer view is allowed and doesn't throw.
    var sab = new SharedArrayBuffer(16);
    var u8array = new Uint8Array(sab);
    var i32array = new Int32Array(sab);
    var u32array = new Uint32Array(sab);
    var f32array = new Float32Array(sab);

    var vs = "attribute float a; uniform float u; void main() {}";
    var fs = "precision mediump float; void main() {}";
    var program = WebGLTestUtils.loadProgram(gl, vs, fs);
    var uniform = gl.getUniformLocation(program, 'u');
    var attribute = gl.getAttribLocation(program, 'a');

    test(() => {
      gl.bufferData(gl.ARRAY_BUFFER, u8array, gl.STATIC_DRAW);
      if (has_webgl2) {
        gl.bufferData(gl.ARRAY_BUFFER, u8array, gl.STATIC_DRAW, 0, 1);
      }
    }, "bufferData");

    test(() => {
      gl.compressedTexImage2D(gl.TEXTURE_2D, 0, 0, 1, 1, 0, u8array);
      if (has_webgl2) {
        gl.compressedTexImage2D(gl.TEXTURE_2D, 0, 0, 1, 1, 0, u8array, 0);
      }
    }, "compressedTexImage2D");

    test(() => {
      gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 1, 1, 0, 0, u8array);
      if (has_webgl2) {
        gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 1, 1, 0, 0, u8array, 0);
      }
    }, "compressedTexSubImage2D");

    test(() => {
      gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, u8array);
      if (has_webgl2) {
        gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, u8array, 0);
      }
    }, "readPixels");

    test(() => {
      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA,
                    gl.UNSIGNED_BYTE, u8array);
      if (has_webgl2) {
        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA,
                      gl.UNSIGNED_BYTE, u8array, 0);
      }
    }, "texImage2D");

    test(() => {
      gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE,
                       u8array);
      if (has_webgl2) {
        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA,
                         gl.UNSIGNED_BYTE, u8array, 0);
      }
    }, "texSubImage2D");

    test(() => {
      gl.uniformMatrix2fv(uniform, false, f32array);
    }, "uniformMatrix2fv");

    test(() => {
      gl.uniformMatrix3fv(uniform, false, f32array);
    }, "uniformMatrix3fv");

    test(() => {
      gl.uniformMatrix4fv(uniform, false, f32array);
    }, "uniformMatrix4fv");

    test(() => {
      gl.vertexAttrib1fv(attribute, f32array);
    }, "vertexAttrib1fv");

    test(() => {
      gl.vertexAttrib2fv(attribute, f32array);
    }, "vertexAttrib2fv");

    test(() => {
      gl.vertexAttrib3fv(attribute, f32array);
    }, "vertexAttrib3fv");

    test(() => {
      gl.vertexAttrib4fv(attribute, f32array);
    }, "vertexAttrib4fv");

    if (has_webgl2) {
      test(() => {
        gl.bufferSubData(gl.ARRAY_BUFFER, 0, u8array, 0, 1);
      }, "bufferSubData");

      test(() => {
        gl.getBufferSubData(gl.ARRAY_BUFFER, 0, u8array);
      }, "getBufferSubData");

      test(() => {
        gl.compressedTexImage3D(gl.TEXTURE_3D, 0, 0, 1, 1, 1, 0, u8array);
      }, "compressedTexImage3D");

      test(() => {
        gl.compressedTexSubImage3D(gl.TEXTURE_3D, 0, 0, 1, 1, 1, 0, 0, 0,
                                   u8array);
      }, "compressedTexSubImage3D");

      test(() => {
        gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA, 1, 1, 1, 0, 0,
                      gl.UNSIGNED_BYTE, u8array);
        gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA, 1, 1, 1, 0, 0,
                      gl.UNSIGNED_BYTE, u8array, 0);
      }, "texImage3D");

      test(() => {
        gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, gl.RGBA,
                         gl.UNSIGNED_BYTE, u8array);
      }, "texSubImage3D");

      test(() => {
        gl.uniformMatrix2x3fv(uniform, false, f32array);
      }, "uniformMatrix2x3fv");

      test(() => {
        gl.uniformMatrix3x2fv(uniform, false, f32array);
      }, "uniformMatrix3x2fv");

      test(() => {
        gl.uniformMatrix2x4fv(uniform, false, f32array);
      }, "uniformMatrix2x4fv");

      test(() => {
        gl.uniformMatrix4x2fv(uniform, false, f32array);
      }, "uniformMatrix4x2fv");

      test(() => {
        gl.uniformMatrix3x4fv(uniform, false, f32array);
      }, "uniformMatrix3x4fv");

      test(() => {
        gl.uniformMatrix4x3fv(uniform, false, f32array);
      }, "uniformMatrix4x3fv");

      test(() => {
        gl.vertexAttribI4iv(attribute, i32array);
      }, "vertexAttribI4iv");

      test(() => {
        gl.vertexAttribI4uiv(attribute, u32array);
      }, "vertexAttribI4uiv");

      test(() => {
        gl.clearBufferiv(gl.COLOR, 0, i32array);
      }, "clearBufferiv");

      test(() => {
        gl.clearBufferuiv(gl.COLOR, 0, u32array);
      }, "clearBufferuiv");

      test(() => {
        gl.clearBufferfv(gl.COLOR, 0, f32array);
      }, "clearBufferfv");
    }
  }
}
done();
</script>
</body>
</html>