index.js 721 Bytes
Newer Older
1 2 3 4 5
import invariant from "invariant";
import { Shaders } from "gl-react";
import Surface from "./Surface";
import {NativeModules} from "react-native";
const {RNGLContext} = NativeModules;
6 7 8 9 10 11
invariant(RNGLContext,
`gl-react-native: the native module is not available.
Make sure you have properly configured it.
See README install instructions.

React.NativeModules.RNGLContext is %s`, RNGLContext);
12 13

// Hook Shaders to RNGLContext
14 15 16 17 18 19 20 21 22
Shaders.setImplementation({
  add: (id, shader) =>
  new Promise((resolve, reject) =>
    RNGLContext.addShader(id, shader, (error, result) => {
      if (error) reject(error);
      else resolve(result);
    })),
  remove: id => RNGLContext.removeShader(id)
});
23 24 25 26

module.exports = {
  Surface
};