• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// When this file is loaded in, the high level object is "Module";
2var WasmGMTests = Module;
3WasmGMTests.onRuntimeInitialized = function() {
4
5  WasmGMTests.GetWebGLContext = function(canvas, webGLVersion) {
6    if (!canvas) {
7      throw 'null canvas passed into makeWebGLContext';
8    }
9    if (webGLVersion !== 1 && webGLVersion !== 2 ) {
10      throw 'invalid webGLVersion';
11    }
12    var contextAttributes = {
13      'alpha': 1,
14      'depth': 0, // can be 0 because off-screen.
15      'stencil': 0, // can be 0 because off-screen.
16      'antialias': 0,
17      'premultipliedAlpha': 1,
18      'preserveDrawingBuffer': 0,
19      'preferLowPowerToHighPerformance': 0,
20      'failIfMajorPerformanceCaveat': 0,
21      'enableExtensionsByDefault': 1,
22      'explicitSwapControl': 0,
23      'renderViaOffscreenBackBuffer': 0,
24      'majorVersion': webGLVersion,
25    };
26
27    // Creates a WebGL context and sets it to be the current context.
28    // These functions are defined in emscripten's library_webgl.js
29    var handle = GL.createContext(canvas, contextAttributes);
30    if (!handle) {
31      return 0;
32    }
33    GL.makeContextCurrent(handle);
34    return handle;
35  };
36
37  WasmGMTests.LoadResource = function(name, buffer) {
38    // The WASM memory will take ownership of this pointer.
39    var bytePtr = copyArrayBuffer(buffer);
40    WasmGMTests._LoadResource(name, bytePtr, buffer.byteLength);
41  }
42
43  function copyArrayBuffer(buffer) {
44    var ptr = WasmGMTests._malloc(buffer.byteLength);
45    WasmGMTests.HEAPU8.set(new Uint8Array(buffer), ptr);
46    return ptr;
47  }
48
49}
50