index.js 723 Bytes
Newer Older
1
const invariant = require("invariant");
2
const { Shaders } = require("gl-react");
3 4
const Surface = require("./Surface");
const { NativeModules: { RNGLContext } } = require("react-native");
5 6 7 8 9 10
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);
11 12

// Hook Shaders to RNGLContext
13 14 15 16 17 18 19 20 21
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)
});
22 23 24 25

module.exports = {
  Surface
};