Skip to content

Commit

Permalink
update flow & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Jul 4, 2017
1 parent bc4f52e commit 0f50010
Show file tree
Hide file tree
Showing 16 changed files with 530 additions and 245 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.0.0-rc.4",
"lerna": "2.0.0-rc.5",
"version": "3.6.0",
"npmClient": "yarn",
"packages": [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"browserify": "^14.3.0",
"browserify-shim": "^3.8.12",
"documentation": "4.0.0-beta.18",
"flow-bin": "^0.46.0",
"flow-bin": "^0.49.1",
"flow-copy-source": "^1.1.0",
"lerna": "^2.0.0-rc.4",
"prettier": "1.3.1"
"lerna": "^2.0.0-rc.5",
"prettier": "^1.5.2"
}
}
6 changes: 3 additions & 3 deletions packages/cookbook-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"main": "main.js",
"dependencies": {
"@expo/ex-navigation": "^2.11.0",
"cookbook-rn-shared": "^3.3.0",
"expo": "^18.0.1",
"cookbook-rn-shared": "^3.6.0",
"expo": "^18.0.2",
"gl-react-expo": "^3.6.0",
"prop-types": "^15.5.8",
"react": "16.0.0-alpha.12",
"react-native": "github:expo/react-native#sdk-18.0.1"
"react-native": "github:expo/react-native#sdk-18.0.2"
}
}
5 changes: 3 additions & 2 deletions packages/gl-react-dom/src/CanvasTextureLoader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//@flow
import { TextureLoaderRawObject } from "gl-react";
export default class CanvasTextureLoader
extends TextureLoaderRawObject<HTMLCanvasElement> {
export default class CanvasTextureLoader extends TextureLoaderRawObject<
HTMLCanvasElement
> {
canLoad(input: any) {
return input instanceof HTMLCanvasElement;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/gl-react-dom/src/VideoTextureLoader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//@flow
import { TextureLoaderRawObject } from "gl-react";

export default class VideoTextureLoader
extends TextureLoaderRawObject<HTMLVideoElement> {
export default class VideoTextureLoader extends TextureLoaderRawObject<
HTMLVideoElement
> {
canLoad(input: any) {
return input instanceof HTMLVideoElement;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/gl-react-expo/src/ExponentGLObjectTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ function hash(obj) {
return JSON.stringify(obj); // FIXME ikr XD
}

export default class ExponentGLObjectTextureLoader
extends TextureLoader<Object> {
export default class ExponentGLObjectTextureLoader extends TextureLoader<
Object
> {
loads: Map<string, DisposablePromise<*>> = new Map();
textures: Map<string, *> = new Map();
dispose() {}
Expand Down
21 changes: 13 additions & 8 deletions packages/gl-react-expo/src/md5.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
let add32;

function md5cycle(x, k) {
var a = x[0], b = x[1], c = x[2], d = x[3];
var a = x[0],
b = x[1],
c = x[2],
d = x[3];

a = ff(a, b, c, d, k[0], 7, -680876936);
d = ff(d, a, b, c, k[1], 12, -389564586);
Expand Down Expand Up @@ -99,7 +102,9 @@ function ii(a, b, c, d, x, s, t) {
}

function md51(s) {
var n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i;
var n = s.length,
state = [1732584193, -271733879, -1732584194, 271733878],
i;
for (i = 64; i <= s.length; i += 64) {
md5cycle(state, md5blk(s.substring(i - 64, i)));
}
Expand All @@ -110,8 +115,7 @@ function md51(s) {
tail[i >> 2] |= 0x80 << ((i % 4) << 3);
if (i > 55) {
md5cycle(state, tail);
for (i = 0; i < 16; i++)
tail[i] = 0;
for (i = 0; i < 16; i++) tail[i] = 0;
}
tail[14] = n * 8;
md5cycle(state, tail);
Expand All @@ -135,7 +139,8 @@ function md51(s) {
*/
function md5blk(s) {
/* I figured global was faster. */
var md5blks = [], i; /* Andy King said do it this way. */
var md5blks = [],
i; /* Andy King said do it this way. */
for (i = 0; i < 64; i += 4) {
md5blks[i >> 2] =
s.charCodeAt(i) +
Expand All @@ -149,15 +154,15 @@ function md5blk(s) {
var hex_chr = "0123456789abcdef".split("");

function rhex(n) {
var s = "", j = 0;
var s = "",
j = 0;
for (; j < 4; j++)
s += hex_chr[(n >> (j * 8 + 4)) & 0x0f] + hex_chr[(n >> (j * 8)) & 0x0f];
return s;
}

function hex(x) {
for (var i = 0; i < x.length; i++)
x[i] = rhex(x[i]);
for (var i = 0; i < x.length; i++) x[i] = rhex(x[i]);
return x.join("");
}

Expand Down
167 changes: 100 additions & 67 deletions packages/gl-react-native/src/EXGLView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
View,
ViewPropTypes,
Platform,
requireNativeComponent
requireNativeComponent,
} from "react-native";

// A component that acts as an OpenGL render target.
Expand All @@ -26,11 +26,11 @@ export default class EXGLView extends React.Component {
// [iOS only] Number of samples for Apple"s built-in multisampling.
msaaSamples: PropTypes.number,

...ViewPropTypes
...ViewPropTypes,
};

static defaultProps = {
msaaSamples: 4
msaaSamples: 4,
};

render() {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default class EXGLView extends React.Component {
};

static NativeView = requireNativeComponent("EXGLView", EXGLView, {
nativeOnly: { onSurfaceCreate: true }
nativeOnly: { onSurfaceCreate: true },
});
}

Expand Down Expand Up @@ -142,7 +142,7 @@ const wrapMethods = gl => {
[gl.FRAMEBUFFER_BINDING]: WebGLFramebuffer,
[gl.RENDERBUFFER_BINDING]: WebGLRenderbuffer,
[gl.TEXTURE_BINDING_2D]: WebGLTexture,
[gl.TEXTURE_BINDING_CUBE_MAP]: WebGLTexture
[gl.TEXTURE_BINDING_CUBE_MAP]: WebGLTexture,
};
wrap("getParameter", orig => pname => {
let ret = orig.call(gl, pname);
Expand All @@ -156,129 +156,162 @@ const wrapMethods = gl => {

// Buffers
wrap("bindBuffer", orig => (target, buffer) =>
orig.call(gl, target, buffer && buffer.id));
orig.call(gl, target, buffer && buffer.id)
);
wrap("createBuffer", orig => () => wrapObject(WebGLBuffer, orig.call(gl)));
wrap("deleteBuffer", orig => buffer => orig.call(gl, buffer && buffer.id));
wrap("isBuffer", orig => buffer =>
buffer instanceof WebGLBuffer && orig.call(gl, buffer.id));
buffer instanceof WebGLBuffer && orig.call(gl, buffer.id)
);

// Framebuffers
wrap("bindFramebuffer", orig => (target, framebuffer) =>
orig.call(gl, target, framebuffer && framebuffer.id));
orig.call(gl, target, framebuffer && framebuffer.id)
);
wrap("createFramebuffer", orig => () =>
wrapObject(WebGLFramebuffer, orig.call(gl)));
wrapObject(WebGLFramebuffer, orig.call(gl))
);
wrap("deleteFramebuffer", orig => framebuffer =>
orig.call(gl, framebuffer && framebuffer.id));
orig.call(gl, framebuffer && framebuffer.id)
);
wrap("framebufferRenderbuffer", orig => (target, attachment, rbtarget, rb) =>
orig.call(gl, target, attachment, rbtarget, rb && rb.id));
wrap("framebufferTexture2D", orig => (
target,
attachment,
textarget,
tex,
level
) => orig.call(gl, target, attachment, textarget, tex && tex.id, level));
orig.call(gl, target, attachment, rbtarget, rb && rb.id)
);
wrap(
"framebufferTexture2D",
orig => (target, attachment, textarget, tex, level) =>
orig.call(gl, target, attachment, textarget, tex && tex.id, level)
);
wrap("isFramebuffer", orig => framebuffer =>
framebuffer instanceof WebGLFramebuffer && orig.call(gl, framebuffer.id));
framebuffer instanceof WebGLFramebuffer && orig.call(gl, framebuffer.id)
);

// Renderbuffers
wrap("bindRenderbuffer", orig => (target, renderbuffer) =>
orig.call(gl, target, renderbuffer && renderbuffer.id));
orig.call(gl, target, renderbuffer && renderbuffer.id)
);
wrap("createRenderbuffer", orig => () =>
wrapObject(WebGLRenderbuffer, orig.call(gl)));
wrapObject(WebGLRenderbuffer, orig.call(gl))
);
wrap("deleteRenderbuffer", orig => renderbuffer =>
orig.call(gl, renderbuffer && renderbuffer.id));
orig.call(gl, renderbuffer && renderbuffer.id)
);
wrap("isRenderbuffer", orig => renderbuffer =>
renderbuffer instanceof WebGLRenderbuffer &&
orig.call(gl, renderbuffer.id));
renderbuffer instanceof WebGLRenderbuffer && orig.call(gl, renderbuffer.id)
);

// Textures
wrap("bindTexture", orig => (target, texture) =>
orig.call(gl, target, texture && texture.id));
orig.call(gl, target, texture && texture.id)
);
wrap("createTexture", orig => () => wrapObject(WebGLTexture, orig.call(gl)));
wrap("deleteTexture", orig => texture =>
orig.call(gl, texture && texture.id));
orig.call(gl, texture && texture.id)
);
wrap("isTexture", orig => texture =>
texture instanceof WebGLTexture && orig.call(gl, texture.id));
texture instanceof WebGLTexture && orig.call(gl, texture.id)
);

// Programs and shaders
wrap("attachShader", orig => (program, shader) =>
orig.call(gl, program && program.id, shader && shader.id));
orig.call(gl, program && program.id, shader && shader.id)
);
wrap("bindAttribLocation", orig => (program, index, name) =>
orig.call(gl, program && program.id, index, name));
orig.call(gl, program && program.id, index, name)
);
wrap("compileShader", orig => shader => orig.call(gl, shader && shader.id));
wrap("createProgram", orig => () => wrapObject(WebGLProgram, orig.call(gl)));
wrap("createShader", orig => type =>
wrapObject(WebGLShader, orig.call(gl, type)));
wrapObject(WebGLShader, orig.call(gl, type))
);
wrap("deleteProgram", orig => program =>
orig.call(gl, program && program.id));
orig.call(gl, program && program.id)
);
wrap("deleteShader", orig => shader => orig.call(gl, shader && shader.id));
wrap("detachShader", orig => (program, shader) =>
orig.call(gl, program && program.id, shader && shader.id));
orig.call(gl, program && program.id, shader && shader.id)
);
wrap("getAttachedShaders", orig => program =>
orig
.call(gl, program && program.id)
.map(id => wrapObject(WebGLShader, id)));
orig.call(gl, program && program.id).map(id => wrapObject(WebGLShader, id))
);
wrap("getProgramParameter", orig => (program, pname) =>
orig.call(gl, program && program.id, pname));
orig.call(gl, program && program.id, pname)
);
wrap("getProgramInfoLog", orig => program =>
orig.call(gl, program && program.id));
orig.call(gl, program && program.id)
);
wrap("getShaderParameter", orig => (shader, pname) =>
orig.call(gl, shader && shader.id, pname));
orig.call(gl, shader && shader.id, pname)
);
wrap("getShaderPrecisionFormat", orig => (shadertype, precisiontype) =>
new WebGLShaderPrecisionFormat(orig.call(gl, shadertype, precisiontype)));
new WebGLShaderPrecisionFormat(orig.call(gl, shadertype, precisiontype))
);
wrap("getShaderInfoLog", orig => shader =>
orig.call(gl, shader && shader.id));
orig.call(gl, shader && shader.id)
);
wrap("getShaderSource", orig => shader => orig.call(gl, shader && shader.id));
wrap("linkProgram", orig => program => orig.call(gl, program && program.id));
wrap("shaderSource", orig => (shader, source) =>
orig.call(gl, shader && shader.id, source));
orig.call(gl, shader && shader.id, source)
);
wrap("useProgram", orig => program => orig.call(gl, program && program.id));
wrap("validateProgram", orig => program =>
orig.call(gl, program && program.id));
orig.call(gl, program && program.id)
);
wrap("isShader", orig => shader =>
shader instanceof WebGLShader && orig.call(gl, shader.id));
shader instanceof WebGLShader && orig.call(gl, shader.id)
);
wrap("isProgram", orig => program =>
program instanceof WebGLProgram && orig.call(gl, program.id));
program instanceof WebGLProgram && orig.call(gl, program.id)
);

// Uniforms and attributes
wrap("getActiveAttrib", orig => (program, index) =>
new WebGLActiveInfo(orig.call(gl, program && program.id, index)));
new WebGLActiveInfo(orig.call(gl, program && program.id, index))
);
wrap("getActiveUniform", orig => (program, index) =>
new WebGLActiveInfo(orig.call(gl, program && program.id, index)));
new WebGLActiveInfo(orig.call(gl, program && program.id, index))
);
wrap("getAttribLocation", orig => (program, name) =>
orig.call(gl, program && program.id, name));
orig.call(gl, program && program.id, name)
);
wrap("getUniform", orig => (program, location) =>
orig.call(gl, program && program.id, location && location.id));
orig.call(gl, program && program.id, location && location.id)
);
wrap("getUniformLocation", orig => (program, name) =>
new WebGLUniformLocation(orig.call(gl, program && program.id, name)));
new WebGLUniformLocation(orig.call(gl, program && program.id, name))
);
wrap(["uniform1f", "uniform1i"], orig => (loc, x) =>
orig.call(gl, loc && loc.id, x));
orig.call(gl, loc && loc.id, x)
);
wrap(["uniform2f", "uniform2i"], orig => (loc, x, y) =>
orig.call(gl, loc && loc.id, x, y));
orig.call(gl, loc && loc.id, x, y)
);
wrap(["uniform3f", "uniform3i"], orig => (loc, x, y, z) =>
orig.call(gl, loc && loc.id, x, y, z));
orig.call(gl, loc && loc.id, x, y, z)
);
wrap(["uniform4f", "uniform4i"], orig => (loc, x, y, z, w) =>
orig.call(gl, loc && loc.id, x, y, z, w));
wrap(["uniform1fv", "uniform2fv", "uniform3fv", "uniform4fv"], orig => (
loc,
val
) => orig.call(gl, loc && loc.id, new Float32Array(val)));
wrap(["uniform1iv", "uniform2iv", "uniform3iv", "uniform4iv"], orig => (
loc,
val
) => orig.call(gl, loc && loc.id, new Int32Array(val)));
wrap(["uniformMatrix2fv", "uniformMatrix3fv", "uniformMatrix4fv"], orig => (
loc,
transpose,
val
) => orig.call(gl, loc && loc.id, transpose, new Float32Array(val)));
orig.call(gl, loc && loc.id, x, y, z, w)
);
wrap(
["uniform1fv", "uniform2fv", "uniform3fv", "uniform4fv"],
orig => (loc, val) => orig.call(gl, loc && loc.id, new Float32Array(val))
);
wrap(
["uniform1iv", "uniform2iv", "uniform3iv", "uniform4iv"],
orig => (loc, val) => orig.call(gl, loc && loc.id, new Int32Array(val))
);
wrap(
["uniformMatrix2fv", "uniformMatrix3fv", "uniformMatrix4fv"],
orig => (loc, transpose, val) =>
orig.call(gl, loc && loc.id, transpose, new Float32Array(val))
);
wrap(
[
"vertexAttrib1fv",
"vertexAttrib2fv",
"vertexAttrib3fv",
"vertexAttrib4fv"
"vertexAttrib4fv",
],
orig => (index, val) => orig.call(gl, index, new Float32Array(val))
);
Expand Down
Loading

0 comments on commit 0f50010

Please sign in to comment.