+
-
+
-
- this.refs.gameCanvas }}
- />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
this.refs.laser }}
+ shader={shaders.laser}
+ uniforms={{ t: () => this.refs.gameCanvas }}
/>
-
-
+
-
-
- {() => this.refs.glare}
-
-
-
-
-
-
-
-
- {() => this.refs.laser
- //FIXME this should be glare instead.
- //but i think there is a bug in gl-react!
- }
+
+
+
+
+
+
+
-
-
+
+
+
+
+ this.refs.laser }}
+ />
+
+
+
+
+
+ {() => this.refs.glare}
+
+
+
+
+
+
+
+
+ {() => this.refs.laser
+ //FIXME this should be glare instead.
+ //but i think there is a bug in gl-react!
+ }
+
+
+
+
+
+
+
+
+
-
this.refs.laser,
+ R: () => this.refs.persistence,
+ B: () => this.refs.glareBlurred,
+ L: () => this.refs.glareCursor,
+ E: () => this.refs.player,
+ s,
+ F,
+ k
}}
/>
-
+
- this.refs.laser,
- R: () => this.refs.persistence,
- B: () => this.refs.glareBlurred,
- L: () => this.refs.glareCursor,
- E: () => this.refs.player,
- s,
- F,
- k
- }} />
-
+
-
-
-
-
+
+
+
-
);
}
_: any;
- componentDidMount () {
- this._ = gameBuild(
- this.refs.container,
- this.refs.gameCanvas,
- () => this.forceUpdate()
+ componentDidMount() {
+ this._ = gameBuild(this.refs.container, this.refs.gameCanvas, () =>
+ this.forceUpdate()
);
}
componentWillUnmount() {
@@ -334,6 +345,6 @@ export default class Example extends Component {
sendAsteroid = () => window._behindAsteroids_send();
static defaultProps = {
- showCanvas: false,
+ showCanvas: false
};
}
diff --git a/packages/cookbook/src/examples/behindasteroids/index.source.js b/packages/cookbook/src/examples/behindasteroids/index.source.js
index c72e263..e73a0cf 100644
--- a/packages/cookbook/src/examples/behindasteroids/index.source.js
+++ b/packages/cookbook/src/examples/behindasteroids/index.source.js
@@ -1,6 +1,6 @@
module.exports=`//@flow
import React, { Component } from "react";
-import { Shaders, Node, GLSL, Bus, Backbuffer } from "gl-react";
+import { Shaders, Node, GLSL, Bus, Uniform } from "gl-react";
import { Surface } from "gl-react-dom";
import gameBuild from "./build";
@@ -118,7 +118,6 @@ void main() {
1.0);
}
\`
-
},
player: {
frag: GLSL\`
@@ -213,118 +212,130 @@ void main() {
}
});
-const Blur1D =
- ({ dim, dir, children: t }) =>
-
;
+const Blur1D = ({ dim, dir, children: t }) => (
+
+);
export default class Example extends Component {
- render () {
- const {showCanvas} = this.props;
- const {pt,pl,ex,J,P,s,F,k,S,W,H} =
- // HACK to just render the game
- this._ ? this._.getWebGLParams() :
-({ pt: 0, pl: 0, ex: 0, J: 0, P: 0, s: 0, F: 0, k: [0,0], W: 2, H: 2, S: 0 });
- const dim = [ W, H ];
+ render() {
+ const { showCanvas } = this.props;
+ const { pt, pl, ex, J, P, s, F, k, S, W, H } =
+ // HACK to just render the game
+ this._
+ ? this._.getWebGLParams()
+ : {
+ pt: 0,
+ pl: 0,
+ ex: 0,
+ J: 0,
+ P: 0,
+ s: 0,
+ F: 0,
+ k: [0, 0],
+ W: 2,
+ H: 2,
+ S: 0
+ };
+ const dim = [W, H];
return (
-
+
-
+
-
- this.refs.gameCanvas }}
- />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
this.refs.laser }}
+ shader={shaders.laser}
+ uniforms={{ t: () => this.refs.gameCanvas }}
/>
-
-
+
-
-
- {() => this.refs.glare}
-
-
-
-
-
-
-
-
- {() => this.refs.laser
- //FIXME this should be glare instead.
- //but i think there is a bug in gl-react!
- }
+
+
+
+
+
+
+
-
-
+
+
+
+
+ this.refs.laser }}
+ />
+
+
+
+
+
+ {() => this.refs.glare}
+
+
+
+
+
+
+
+
+ {() => this.refs.laser
+ //FIXME this should be glare instead.
+ //but i think there is a bug in gl-react!
+ }
+
+
+
+
+
+
+
+
+
-
this.refs.laser,
+ R: () => this.refs.persistence,
+ B: () => this.refs.glareBlurred,
+ L: () => this.refs.glareCursor,
+ E: () => this.refs.player,
+ s,
+ F,
+ k
}}
/>
-
+
- this.refs.laser,
- R: () => this.refs.persistence,
- B: () => this.refs.glareBlurred,
- L: () => this.refs.glareCursor,
- E: () => this.refs.player,
- s,
- F,
- k
- }} />
-
+
-
-
-
-
+
+
+
-
);
}
_: any;
- componentDidMount () {
- this._ = gameBuild(
- this.refs.container,
- this.refs.gameCanvas,
- () => this.forceUpdate()
+ componentDidMount() {
+ this._ = gameBuild(this.refs.container, this.refs.gameCanvas, () =>
+ this.forceUpdate()
);
}
componentWillUnmount() {
@@ -334,7 +345,7 @@ export default class Example extends Component {
sendAsteroid = () => window._behindAsteroids_send();
static defaultProps = {
- showCanvas: false,
+ showCanvas: false
};
}
`
diff --git a/packages/cookbook/src/examples/blurimgtitle/index.source.js b/packages/cookbook/src/examples/blurimgtitle/index.source.js
index 4ff8240..6d20293 100644
--- a/packages/cookbook/src/examples/blurimgtitle/index.source.js
+++ b/packages/cookbook/src/examples/blurimgtitle/index.source.js
@@ -1,11 +1,12 @@
module.exports=`//@flow
-import React, { PureComponent, Component, PropTypes } from "react";
+import React, { PureComponent, Component } from "react";
+import PropTypes from "prop-types";
import { Shaders, Node, GLSL, Bus, LinearCopy, connectSize } from "gl-react";
import { Surface } from "gl-react-dom";
import JSON2D from "react-json2d";
-import {Blur1D} from "../blurxy";
-import {Blur} from "../blurmulti";
-import {BlurV} from "../blurmap";
+import { Blur1D } from "../blurxy";
+import { Blur } from "../blurmulti";
+import { BlurV } from "../blurmap";
const shaders = Shaders.create({
ImageTitle: {
@@ -42,54 +43,60 @@ gl_FragColor = vec4(
vec3(smoothstep(1.0, threshold, texture2D(t, uv).r)),
1.0);
}\`
- },
+ }
});
-const AveragePixels = ({ children, quality }) =>
-
+const AveragePixels = ({ children, quality }) => (
+
+ resolution={[1, quality]}
+ direction={[0.1, 0]}
+ >
{children}
- ;
+
+);
-const TitleBlurMap = ({ children: title, threshold }) =>
+const TitleBlurMap = ({ children: title, threshold }) => (
{title}
+ )
}}
width={64}
height={64}
- />;
+ />
+);
class Title extends PureComponent {
- render () {
+ render() {
const { children, width, height } = this.props;
- return {{
- size: [ width, height ],
- background: "#fff",
- draws: [
- {
- "font": "bold 78px Didot,Georgia,serif",
- "fillStyle": "#000",
- "textBaseline": "top",
- "textAlign": "center"
- },
- [ "fillText", children, width/2, 10, 84 ],
- ]
- }};
+ return (
+
+
+ {{
+ size: [width, height],
+ background: "#fff",
+ draws: [
+ {
+ font: "bold 78px Didot,Georgia,serif",
+ fillStyle: "#000",
+ textBaseline: "top",
+ textAlign: "center"
+ },
+ ["fillText", children, width / 2, 10, 84]
+ ]
+ }}
+
+
+ );
}
}
@@ -99,50 +106,48 @@ class ImageTitleC extends Component {
height: PropTypes.number.isRequired,
children: PropTypes.any.isRequired,
text: PropTypes.string.isRequired,
- colorThreshold: PropTypes.number.isRequired,
+ colorThreshold: PropTypes.number.isRequired
};
render() {
const { width, height, children: img, text, colorThreshold } = this.props;
return (
- this.refs.imgBlurred,
- title:() => this.refs.title,
- imgTone:() => this.refs.imgTone,
- blurMap:() => this.refs.blurMap,
- }}>
+ this.refs.imgBlurred,
+ title: () => this.refs.title,
+ imgTone: () => this.refs.imgTone,
+ blurMap: () => this.refs.blurMap
+ }}
+ >
-
-
- {text}
-
-
+
+
+ {text}
+
+
-
-
- {() => this.refs.title}
-
-
+
+
+ {() => this.refs.title}
+
+
-
-
- {img}
-
-
+
+
+ {img}
+
+
-
- this.refs.blurMap}
- factor={4}
- passes={4}>
- {img}
-
-
+
+ this.refs.blurMap} factor={4} passes={4}>
+ {img}
+
+
-
+
);
}
}
@@ -152,18 +157,18 @@ export default class Example extends Component {
render() {
const { title, colorThreshold, image } = this.props;
return (
-
-
- {image}
-
-
+
+
+ {image}
+
+
);
}
static defaultProps = {
title: "Hello\\nSan Francisco\\n☻",
colorThreshold: 0.6,
- image: require("./sf-6.jpg"),
+ image: require("./sf-6.jpg")
};
}
`
diff --git a/packages/cookbook/src/examples/glsledit/meta.js b/packages/cookbook/src/examples/glsledit/meta.js
index 85e9fd6..c2d81c3 100755
--- a/packages/cookbook/src/examples/glsledit/meta.js
+++ b/packages/cookbook/src/examples/glsledit/meta.js
@@ -1,11 +1,11 @@
-
-export const title = "GLSL live editor";
-
import "./glsledit.css";
import makeTextArea from "../../toolbox/makeTextArea";
+export const title = "GLSL live editor";
+
export const toolbox = [
- { prop: "frag",
+ {
+ prop: "frag",
Editor: makeTextArea({
height: 400,
padding: 10,
@@ -16,6 +16,7 @@ export const toolbox = [
color: "#ABB2BF",
fontSize: 10,
lineHeight: 1.5,
- fontFamily: "Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace",
- }) }
+ fontFamily: "Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace"
+ })
+ }
];
diff --git a/packages/cookbook/src/examples/gol/index.js b/packages/cookbook/src/examples/gol/index.js
index 93a5cd0..0d57bc0 100755
--- a/packages/cookbook/src/examples/gol/index.js
+++ b/packages/cookbook/src/examples/gol/index.js
@@ -1,12 +1,12 @@
//@flow
import React from "react";
-import {Backbuffer,Shaders,Node,GLSL,NearestCopy} from "gl-react";
+import { Uniform, Shaders, Node, GLSL, NearestCopy } from "gl-react";
import { Surface } from "gl-react-dom";
import timeLoop from "../../HOC/timeLoop";
export const shaders = Shaders.create({
InitGameOfLife: {
-// returns white or black randomly
+ // returns white or black randomly
frag: GLSL`
precision highp float;
// i
@@ -20,7 +20,7 @@ void main() {
}`
},
GameOfLife: {
-// implement Game Of Life.
+ // implement Game Of Life.
frag: GLSL`
precision highp float;
varying vec2 uv;
@@ -48,36 +48,37 @@ const refreshEveryTicks = 20;
export const GameOfLife = ({ tick }) => {
// Changing size is "destructive" and will reset the Game of Life state
- const size = 16 * (1+Math.floor(tick/refreshEveryTicks));
+ const size = 16 * (1 + Math.floor(tick / refreshEveryTicks));
// However, we can conditionally change shader/uniforms,
// React reconciliation will preserve the same instance,
// and our Game of Life state will get preserved!
- return tick%refreshEveryTicks===0
- ? to draw in sync each componentDidUpdate time
- />
- : ;
+ return tick % refreshEveryTicks === 0
+ ? to draw in sync each componentDidUpdate time
+ />
+ : ;
};
const GameOfLifeLoop = timeLoop(GameOfLife, { refreshRate: 20 });
-export default () =>
+export default () => (
+);
diff --git a/packages/cookbook/src/examples/gol/index.source.js b/packages/cookbook/src/examples/gol/index.source.js
index f6bc3ce..b3f5a03 100644
--- a/packages/cookbook/src/examples/gol/index.source.js
+++ b/packages/cookbook/src/examples/gol/index.source.js
@@ -1,12 +1,12 @@
module.exports=`//@flow
import React from "react";
-import {Backbuffer,Shaders,Node,GLSL,NearestCopy} from "gl-react";
+import { Uniform, Shaders, Node, GLSL, NearestCopy } from "gl-react";
import { Surface } from "gl-react-dom";
import timeLoop from "../../HOC/timeLoop";
export const shaders = Shaders.create({
InitGameOfLife: {
-// returns white or black randomly
+ // returns white or black randomly
frag: GLSL\`
precision highp float;
// i
@@ -20,7 +20,7 @@ void main() {
}\`
},
GameOfLife: {
-// implement Game Of Life.
+ // implement Game Of Life.
frag: GLSL\`
precision highp float;
varying vec2 uv;
@@ -48,37 +48,38 @@ const refreshEveryTicks = 20;
export const GameOfLife = ({ tick }) => {
// Changing size is "destructive" and will reset the Game of Life state
- const size = 16 * (1+Math.floor(tick/refreshEveryTicks));
+ const size = 16 * (1 + Math.floor(tick / refreshEveryTicks));
// However, we can conditionally change shader/uniforms,
// React reconciliation will preserve the same instance,
// and our Game of Life state will get preserved!
- return tick%refreshEveryTicks===0
- ? to draw in sync each componentDidUpdate time
- />
- : ;
+ return tick % refreshEveryTicks === 0
+ ? to draw in sync each componentDidUpdate time
+ />
+ : ;
};
const GameOfLifeLoop = timeLoop(GameOfLife, { refreshRate: 20 });
-export default () =>
+export default () => (
+);
`
diff --git a/packages/cookbook/src/examples/golglider/index.js b/packages/cookbook/src/examples/golglider/index.js
index f8b2104..e2cd305 100755
--- a/packages/cookbook/src/examples/golglider/index.js
+++ b/packages/cookbook/src/examples/golglider/index.js
@@ -1,23 +1,27 @@
//@flow
import React, { Component } from "react";
-import { Backbuffer, Node, NearestCopy } from "gl-react";
+import { Uniform, Node, NearestCopy } from "gl-react";
import { Surface } from "gl-react-dom";
-import {shaders} from "../gol";
+import { shaders } from "../gol";
import timeLoop from "../../HOC/timeLoop";
import gliderGunImage from "./glider-gun-64.png";
-const GameOfLifeLoop = timeLoop(({ tick, size }) =>
- , { refreshRate: 20 });
+const GameOfLifeLoop = timeLoop(
+ ({ tick, size }) => (
+
+ ),
+ { refreshRate: 20 }
+);
export default class Example extends Component {
render() {
@@ -25,9 +29,11 @@ export default class Example extends Component {
+ ]}
+ >
diff --git a/packages/cookbook/src/examples/golglider/index.source.js b/packages/cookbook/src/examples/golglider/index.source.js
index cfb6e1c..bdc80d3 100644
--- a/packages/cookbook/src/examples/golglider/index.source.js
+++ b/packages/cookbook/src/examples/golglider/index.source.js
@@ -1,23 +1,27 @@
module.exports=`//@flow
import React, { Component } from "react";
-import { Backbuffer, Node, NearestCopy } from "gl-react";
+import { Uniform, Node, NearestCopy } from "gl-react";
import { Surface } from "gl-react-dom";
-import {shaders} from "../gol";
+import { shaders } from "../gol";
import timeLoop from "../../HOC/timeLoop";
import gliderGunImage from "./glider-gun-64.png";
-const GameOfLifeLoop = timeLoop(({ tick, size }) =>
- , { refreshRate: 20 });
+const GameOfLifeLoop = timeLoop(
+ ({ tick, size }) => (
+
+ ),
+ { refreshRate: 20 }
+);
export default class Example extends Component {
render() {
@@ -25,9 +29,11 @@ export default class Example extends Component {
+ ]}
+ >
diff --git a/packages/cookbook/src/examples/golglider/meta.js b/packages/cookbook/src/examples/golglider/meta.js
index 044312f..68d620a 100755
--- a/packages/cookbook/src/examples/golglider/meta.js
+++ b/packages/cookbook/src/examples/golglider/meta.js
@@ -1,18 +1,21 @@
import React from "react";
import markdown from "../../markdown";
-export const title = "GameOfLife is initialized with a glider texture";
import gliderGun64png from "./glider-gun-64.png";
+
+export const title = "GameOfLife is initialized with a glider texture";
export const desc = markdown`
**Game of Life** init with an image!
`;
export const descAfter = markdown`
Initial image state inspired from [wikipedia](https://en.wikipedia.org/wiki/Conway's_Game_of_Life).
${
}
-${
-
-}
+${(
+
+
+
+)}
`;
diff --git a/packages/cookbook/src/examples/golwebcam/index.js b/packages/cookbook/src/examples/golwebcam/index.js
index a814490..f9f4878 100755
--- a/packages/cookbook/src/examples/golwebcam/index.js
+++ b/packages/cookbook/src/examples/golwebcam/index.js
@@ -1,6 +1,6 @@
//@flow
import React, { Component } from "react";
-import { Bus, Backbuffer, Node, Shaders, GLSL } from "gl-react";
+import { Bus, Uniform, Node, Shaders, GLSL } from "gl-react";
import { Surface } from "gl-react-dom";
import { Video } from "../video";
import { WebCamSource } from "../webcam";
@@ -13,22 +13,34 @@ const extraShaders = Shaders.create({
precision highp float;
varying vec2 uv;
uniform sampler2D gol, webcam;
+uniform float webcamRatio;
void main () {
- vec3 webcamC = texture2D(webcam, uv).rgb;
- gl_FragColor = vec4(
- vec3(1.0) * texture2D(gol, uv).r +
- webcamC * mix(step(0.5, webcamC.r), 0.9, 0.2),
- 1.0);
+ vec2 aspect = vec2(max(1.0, 1.0/webcamRatio), max(1.0, webcamRatio));
+ vec2 p = uv * aspect + (1.0 - aspect) / 2.0;
+ if (0.0>p.x||1.0p.y||1.0
;
const GameOfLife = ({ size, reset, resetTexture }) =>
@@ -39,8 +51,8 @@ const GameOfLife = ({ size, reset, resetTexture }) =>
backbuffering
sync
uniforms={{
- t: reset ? resetTexture : Backbuffer,
- size,
+ t: reset ? resetTexture : Uniform.Backbuffer,
+ size
}}
/>;
@@ -53,34 +65,37 @@ export default class Example extends Component {
render() {
const { reset, size } = this.state;
return (
-
+
+
+ {redraw =>
+ }
+
- { redraw =>
-
- }
-
- this.refs.webcam}
- />
- }
- webcam={() => this.refs.webcam}
- />
-
+ this.refs.webcam}
+ />
+ }
+ webcam={() => this.refs.webcam}
+ />
+
);
}
onMouseDown = () =>
- this.setState({ reset: true, size: Math.floor(10 + 200*Math.random()*Math.random()) });
- onMouseUp = () =>
- this.setState({ reset: false });
+ this.setState({
+ reset: true,
+ size: Math.floor(10 + 200 * Math.random() * Math.random())
+ });
+ onMouseUp = () => this.setState({ reset: false });
}
diff --git a/packages/cookbook/src/examples/golwebcam/index.source.js b/packages/cookbook/src/examples/golwebcam/index.source.js
index 1fd0b60..cf57043 100644
--- a/packages/cookbook/src/examples/golwebcam/index.source.js
+++ b/packages/cookbook/src/examples/golwebcam/index.source.js
@@ -1,6 +1,6 @@
module.exports=`//@flow
import React, { Component } from "react";
-import { Bus, Backbuffer, Node, Shaders, GLSL } from "gl-react";
+import { Bus, Uniform, Node, Shaders, GLSL } from "gl-react";
import { Surface } from "gl-react-dom";
import { Video } from "../video";
import { WebCamSource } from "../webcam";
@@ -13,22 +13,34 @@ const extraShaders = Shaders.create({
precision highp float;
varying vec2 uv;
uniform sampler2D gol, webcam;
+uniform float webcamRatio;
void main () {
- vec3 webcamC = texture2D(webcam, uv).rgb;
- gl_FragColor = vec4(
- vec3(1.0) * texture2D(gol, uv).r +
- webcamC * mix(step(0.5, webcamC.r), 0.9, 0.2),
- 1.0);
+ vec2 aspect = vec2(max(1.0, 1.0/webcamRatio), max(1.0, webcamRatio));
+ vec2 p = uv * aspect + (1.0 - aspect) / 2.0;
+ if (0.0>p.x||1.0p.y||1.0
;
const GameOfLife = ({ size, reset, resetTexture }) =>
@@ -39,8 +51,8 @@ const GameOfLife = ({ size, reset, resetTexture }) =>
backbuffering
sync
uniforms={{
- t: reset ? resetTexture : Backbuffer,
- size,
+ t: reset ? resetTexture : Uniform.Backbuffer,
+ size
}}
/>;
@@ -53,35 +65,38 @@ export default class Example extends Component {
render() {
const { reset, size } = this.state;
return (
-
+
+
+ {redraw =>
+ }
+
- { redraw =>
-
- }
-
- this.refs.webcam}
- />
- }
- webcam={() => this.refs.webcam}
- />
-
+ this.refs.webcam}
+ />
+ }
+ webcam={() => this.refs.webcam}
+ />
+
);
}
onMouseDown = () =>
- this.setState({ reset: true, size: Math.floor(10 + 200*Math.random()*Math.random()) });
- onMouseUp = () =>
- this.setState({ reset: false });
+ this.setState({
+ reset: true,
+ size: Math.floor(10 + 200 * Math.random() * Math.random())
+ });
+ onMouseUp = () => this.setState({ reset: false });
}
`
diff --git a/packages/cookbook/src/examples/golwebcam/meta.js b/packages/cookbook/src/examples/golwebcam/meta.js
index 2001514..b4d80a5 100755
--- a/packages/cookbook/src/examples/golwebcam/meta.js
+++ b/packages/cookbook/src/examples/golwebcam/meta.js
@@ -1,3 +1,3 @@
export const title = "WebCam stream + Game Of Life!";
-export const desc =
-`Click to reset Game Of Life (random size)`;
+export const desc = `Click to reset Game Of Life (random size)`;
+export const descAfter = `See also usage of Uniform.textureSizeRatio`;
diff --git a/packages/cookbook/src/examples/ibex/index.js b/packages/cookbook/src/examples/ibex/index.js
index efec9c7..37e4de5 100755
--- a/packages/cookbook/src/examples/ibex/index.js
+++ b/packages/cookbook/src/examples/ibex/index.js
@@ -7,7 +7,7 @@
//@flow
import React, { Component } from "react";
-import { Shaders, Node, GLSL, Backbuffer } from "gl-react";
+import { Shaders, Node, GLSL, Uniform } from "gl-react";
import { Surface } from "gl-react-dom";
import ndarray from "ndarray";
import timeLoop from "../../HOC/timeLoop";
@@ -339,7 +339,7 @@ void main () {
class IBEXLogic extends Component {
state = {
- seed: Math.random(),
+ seed: Math.random()
};
shouldComponentUpdate({ tick }) {
return tick !== this.props.tick;
@@ -351,61 +351,58 @@ class IBEXLogic extends Component {
initialState,
forestGrowFactor,
waterFactor,
- fireFactor,
+ fireFactor
} = this.props;
const { seed } = this.state;
- let draw=false, drawPosition=[0,0], drawRadius=0, drawElement=0;
+ let draw = false, drawPosition = [0, 0], drawRadius = 0, drawElement = 0;
let w = Math.random() < waterFactor, f = Math.random() < fireFactor;
if (w && f) {
if (Math.random() * waterFactor - Math.random() * fireFactor > 0) {
f = false;
- }
- else {
+ } else {
w = false;
}
}
if (w) {
draw = true;
- drawPosition=[
- size[0]*Math.random(),
- size[1]*(0.8 + 0.2 * Math.random()),
+ drawPosition = [
+ size[0] * Math.random(),
+ size[1] * (0.8 + 0.2 * Math.random())
];
drawRadius = 4;
drawElement = 3;
console.log(drawElement, drawPosition, drawPosition);
- }
- else if (f) {
+ } else if (f) {
draw = true;
- drawPosition=[
- size[0]*Math.random(),
- 0,
- ];
+ drawPosition = [size[0] * Math.random(), 0];
drawRadius = 4;
drawElement = 2;
console.log(drawElement, drawPosition, drawPosition);
}
- return ;
+ return (
+
+ );
}
}
@@ -416,86 +413,89 @@ var colors = [
[0.40, 0.75, 0.90], // 3: water
[0.60, 0.00, 0.00], // 4: volcano (fire spawner)
[0.30, 0.60, 0.70], // 5: source (water spawner)
- [0.15, 0.20, 0.27], // 6: wind left
- [0.07, 0.12, 0.19], // 7: wind right
- [0.20, 0.60, 0.20] // 8: grass (forest)
+ [0.15, 0.20, 0.27], // 6: wind left
+ [0.07, 0.12, 0.19], // 7: wind right
+ [0.20, 0.60, 0.20] // 8: grass (forest)
];
-const IBEXRender = ({ size, children: state }) =>
+const IBEXRender = ({ size, children: state }) => (
;
+ />
+);
-const Game = timeLoop(class extends Component {
- state = {
- tick: 0,
- lastTickTime: this.props.time,
- };
+const Game = timeLoop(
+ class extends Component {
+ state = {
+ tick: 0,
+ lastTickTime: this.props.time
+ };
- componentWillReceiveProps({ time, speed }) {
- this.setState(({ tick, lastTickTime }) => {
- const delta = 1000/speed;
- if (time-lastTickTime > delta) {
- return {
- tick: tick + 1,
- lastTickTime: lastTickTime + delta,
- };
- }
- });
+ componentWillReceiveProps({ time, speed }) {
+ this.setState(({ tick, lastTickTime }) => {
+ const delta = 1000 / speed;
+ if (time - lastTickTime > delta) {
+ return {
+ tick: tick + 1,
+ lastTickTime: lastTickTime + delta
+ };
+ }
+ });
+ }
+
+ render() {
+ const {
+ size,
+ initialState,
+ forestGrowFactor,
+ waterFactor,
+ fireFactor
+ } = this.props;
+ const { tick } = this.state;
+ return (
+
+
+
+ );
+ }
}
-
- render() {
- const {
- size,
- initialState,
- forestGrowFactor,
- waterFactor,
- fireFactor
- } = this.props;
- const {
- tick,
- } = this.state;
- return
-
- ;
- }
-});
+);
// This should be implemented in a shader (it's a cellular automaton too)
// but it's how it was done in the game
-function generate (startX: number, worldSize: [number,number]) {
+function generate(startX: number, worldSize: [number, number]) {
var worldPixelRawBuf = new Uint8Array(worldSize[0] * worldSize[1] * 4);
var worldPixelBuf = new Uint8Array(worldSize[0] * worldSize[1]);
var waterInGeneration = 0;
var volcanoInGeneration = 0;
var w = worldSize[0], h = worldSize[1];
- function step (a, b, x) {
- return Math.max(0, Math.min((x-a) / (b-a), 1));
+ function step(a, b, x) {
+ return Math.max(0, Math.min((x - a) / (b - a), 1));
}
- function affectColor (buf, i, c) {
+ function affectColor(buf, i, c) {
buf[i] = ~~(256 * c / 9);
- buf[i+3] = 1;
+ buf[i + 3] = 1;
}
- function get (b, x, y) {
+ function get(b, x, y) {
if (x >= 0 && x < w && y >= 0 && y < h) {
return b[x + y * w];
}
return y > 50 ? 1 : 0;
}
- function set (b, x, y, e) {
+ function set(b, x, y, e) {
if (x >= 0 && x < w && y >= 0 && y < h) {
b[x + y * w] = e;
}
@@ -505,9 +505,9 @@ function generate (startX: number, worldSize: [number,number]) {
for (x = startX; x < worldSize[0]; ++x) {
for (y = 0; y < worldSize[1]; ++y) {
e = +(Math.random() >
- 0.22
- + 0.3 * (step(0, 20, y)
- + step(worldSize[1]-20, worldSize[1] - 2, y)));
+ 0.22 +
+ 0.3 *
+ (step(0, 20, y) + step(worldSize[1] - 20, worldSize[1] - 2, y)));
set(worldPixelBuf, x, y, e);
}
}
@@ -519,17 +519,25 @@ function generate (startX: number, worldSize: [number,number]) {
var me = get(cur, x, y);
var sum =
0.1 * me +
- (0.9 + 0.1 * Math.random()) * (get(cur, x-1, y-1)?1:0) +
- (0.9 + 0.1 * Math.random()) * (get(cur, x, y-1)?1:0) +
- (0.9 + 0.1 * Math.random()) * (get(cur, x+1, y-1)?1:0) +
- (1.4 + 0.2 * Math.random()) * (get(cur, x-1, y)?1:0) +
- (1.1 + 0.2 * Math.random()) * (get(cur, x+1, y)?1:0) +
- (1.6 - 0.1 * Math.random()) * (get(cur, x-1, y+1)?1:0) +
- (1.2 - 0.2 * Math.random()) * (get(cur, x, y+1)?1:0) +
- (1.0 - 0.1 * Math.random()) * (get(cur, x+1, y+1?1:0));
- let e = +(sum <= 6 + (Math.random()-0.5) * (1-k/K));
- if (e && sum >= 6 - Math.random() * waterInGeneration + 4 * step(110, 0, y)) e = 5;
- if (e && sum >= 6 - Math.random() * volcanoInGeneration + 6 * step(20, 60, y)) e = 4;
+ (0.9 + 0.1 * Math.random()) * (get(cur, x - 1, y - 1) ? 1 : 0) +
+ (0.9 + 0.1 * Math.random()) * (get(cur, x, y - 1) ? 1 : 0) +
+ (0.9 + 0.1 * Math.random()) * (get(cur, x + 1, y - 1) ? 1 : 0) +
+ (1.4 + 0.2 * Math.random()) * (get(cur, x - 1, y) ? 1 : 0) +
+ (1.1 + 0.2 * Math.random()) * (get(cur, x + 1, y) ? 1 : 0) +
+ (1.6 - 0.1 * Math.random()) * (get(cur, x - 1, y + 1) ? 1 : 0) +
+ (1.2 - 0.2 * Math.random()) * (get(cur, x, y + 1) ? 1 : 0) +
+ (1.0 - 0.1 * Math.random()) * get(cur, x + 1, y + 1 ? 1 : 0);
+ let e = +(sum <= 6 + (Math.random() - 0.5) * (1 - k / K));
+ if (
+ e &&
+ sum >= 6 - Math.random() * waterInGeneration + 4 * step(110, 0, y)
+ )
+ e = 5;
+ if (
+ e &&
+ sum >= 6 - Math.random() * volcanoInGeneration + 6 * step(20, 60, y)
+ )
+ e = 4;
set(swp, x, y, e);
}
}
@@ -541,14 +549,16 @@ function generate (startX: number, worldSize: [number,number]) {
for (i = 0; i < worldPixelBuf.length; ++i) {
affectColor(worldPixelRawBuf, 4 * i, worldPixelBuf[i]);
}
- return ndarray(worldPixelRawBuf, [ worldSize[0], worldSize[1], 4]).transpose(1, 0, 2).step(1, -1, 1);
+ return ndarray(worldPixelRawBuf, [worldSize[0], worldSize[1], 4])
+ .transpose(1, 0, 2)
+ .step(1, -1, 1);
}
-const size = [200,200];
+const size = [200, 200];
export default class Example extends Component {
state = {
- initialState: generate(0, size),
+ initialState: generate(0, size)
};
render() {
const { forestGrowFactor, fireFactor, waterFactor, speed } = this.props;
@@ -571,11 +581,10 @@ export default class Example extends Component {
speed: 60,
forestGrowFactor: 1,
fireFactor: 0,
- waterFactor: 0,
+ waterFactor: 0
};
}
-
/**
* Game Rule Interactions.
*
diff --git a/packages/cookbook/src/examples/ibex/index.source.js b/packages/cookbook/src/examples/ibex/index.source.js
index 773b6da..5c78968 100644
--- a/packages/cookbook/src/examples/ibex/index.source.js
+++ b/packages/cookbook/src/examples/ibex/index.source.js
@@ -7,7 +7,7 @@ module.exports=`/**
//@flow
import React, { Component } from "react";
-import { Shaders, Node, GLSL, Backbuffer } from "gl-react";
+import { Shaders, Node, GLSL, Uniform } from "gl-react";
import { Surface } from "gl-react-dom";
import ndarray from "ndarray";
import timeLoop from "../../HOC/timeLoop";
@@ -339,7 +339,7 @@ void main () {
class IBEXLogic extends Component {
state = {
- seed: Math.random(),
+ seed: Math.random()
};
shouldComponentUpdate({ tick }) {
return tick !== this.props.tick;
@@ -351,61 +351,58 @@ class IBEXLogic extends Component {
initialState,
forestGrowFactor,
waterFactor,
- fireFactor,
+ fireFactor
} = this.props;
const { seed } = this.state;
- let draw=false, drawPosition=[0,0], drawRadius=0, drawElement=0;
+ let draw = false, drawPosition = [0, 0], drawRadius = 0, drawElement = 0;
let w = Math.random() < waterFactor, f = Math.random() < fireFactor;
if (w && f) {
if (Math.random() * waterFactor - Math.random() * fireFactor > 0) {
f = false;
- }
- else {
+ } else {
w = false;
}
}
if (w) {
draw = true;
- drawPosition=[
- size[0]*Math.random(),
- size[1]*(0.8 + 0.2 * Math.random()),
+ drawPosition = [
+ size[0] * Math.random(),
+ size[1] * (0.8 + 0.2 * Math.random())
];
drawRadius = 4;
drawElement = 3;
console.log(drawElement, drawPosition, drawPosition);
- }
- else if (f) {
+ } else if (f) {
draw = true;
- drawPosition=[
- size[0]*Math.random(),
- 0,
- ];
+ drawPosition = [size[0] * Math.random(), 0];
drawRadius = 4;
drawElement = 2;
console.log(drawElement, drawPosition, drawPosition);
}
- return ;
+ return (
+
+ );
}
}
@@ -416,86 +413,89 @@ var colors = [
[0.40, 0.75, 0.90], // 3: water
[0.60, 0.00, 0.00], // 4: volcano (fire spawner)
[0.30, 0.60, 0.70], // 5: source (water spawner)
- [0.15, 0.20, 0.27], // 6: wind left
- [0.07, 0.12, 0.19], // 7: wind right
- [0.20, 0.60, 0.20] // 8: grass (forest)
+ [0.15, 0.20, 0.27], // 6: wind left
+ [0.07, 0.12, 0.19], // 7: wind right
+ [0.20, 0.60, 0.20] // 8: grass (forest)
];
-const IBEXRender = ({ size, children: state }) =>
+const IBEXRender = ({ size, children: state }) => (
;
+ />
+);
-const Game = timeLoop(class extends Component {
- state = {
- tick: 0,
- lastTickTime: this.props.time,
- };
+const Game = timeLoop(
+ class extends Component {
+ state = {
+ tick: 0,
+ lastTickTime: this.props.time
+ };
- componentWillReceiveProps({ time, speed }) {
- this.setState(({ tick, lastTickTime }) => {
- const delta = 1000/speed;
- if (time-lastTickTime > delta) {
- return {
- tick: tick + 1,
- lastTickTime: lastTickTime + delta,
- };
- }
- });
+ componentWillReceiveProps({ time, speed }) {
+ this.setState(({ tick, lastTickTime }) => {
+ const delta = 1000 / speed;
+ if (time - lastTickTime > delta) {
+ return {
+ tick: tick + 1,
+ lastTickTime: lastTickTime + delta
+ };
+ }
+ });
+ }
+
+ render() {
+ const {
+ size,
+ initialState,
+ forestGrowFactor,
+ waterFactor,
+ fireFactor
+ } = this.props;
+ const { tick } = this.state;
+ return (
+
+
+
+ );
+ }
}
-
- render() {
- const {
- size,
- initialState,
- forestGrowFactor,
- waterFactor,
- fireFactor
- } = this.props;
- const {
- tick,
- } = this.state;
- return
-
- ;
- }
-});
+);
// This should be implemented in a shader (it's a cellular automaton too)
// but it's how it was done in the game
-function generate (startX: number, worldSize: [number,number]) {
+function generate(startX: number, worldSize: [number, number]) {
var worldPixelRawBuf = new Uint8Array(worldSize[0] * worldSize[1] * 4);
var worldPixelBuf = new Uint8Array(worldSize[0] * worldSize[1]);
var waterInGeneration = 0;
var volcanoInGeneration = 0;
var w = worldSize[0], h = worldSize[1];
- function step (a, b, x) {
- return Math.max(0, Math.min((x-a) / (b-a), 1));
+ function step(a, b, x) {
+ return Math.max(0, Math.min((x - a) / (b - a), 1));
}
- function affectColor (buf, i, c) {
+ function affectColor(buf, i, c) {
buf[i] = ~~(256 * c / 9);
- buf[i+3] = 1;
+ buf[i + 3] = 1;
}
- function get (b, x, y) {
+ function get(b, x, y) {
if (x >= 0 && x < w && y >= 0 && y < h) {
return b[x + y * w];
}
return y > 50 ? 1 : 0;
}
- function set (b, x, y, e) {
+ function set(b, x, y, e) {
if (x >= 0 && x < w && y >= 0 && y < h) {
b[x + y * w] = e;
}
@@ -505,9 +505,9 @@ function generate (startX: number, worldSize: [number,number]) {
for (x = startX; x < worldSize[0]; ++x) {
for (y = 0; y < worldSize[1]; ++y) {
e = +(Math.random() >
- 0.22
- + 0.3 * (step(0, 20, y)
- + step(worldSize[1]-20, worldSize[1] - 2, y)));
+ 0.22 +
+ 0.3 *
+ (step(0, 20, y) + step(worldSize[1] - 20, worldSize[1] - 2, y)));
set(worldPixelBuf, x, y, e);
}
}
@@ -519,17 +519,25 @@ function generate (startX: number, worldSize: [number,number]) {
var me = get(cur, x, y);
var sum =
0.1 * me +
- (0.9 + 0.1 * Math.random()) * (get(cur, x-1, y-1)?1:0) +
- (0.9 + 0.1 * Math.random()) * (get(cur, x, y-1)?1:0) +
- (0.9 + 0.1 * Math.random()) * (get(cur, x+1, y-1)?1:0) +
- (1.4 + 0.2 * Math.random()) * (get(cur, x-1, y)?1:0) +
- (1.1 + 0.2 * Math.random()) * (get(cur, x+1, y)?1:0) +
- (1.6 - 0.1 * Math.random()) * (get(cur, x-1, y+1)?1:0) +
- (1.2 - 0.2 * Math.random()) * (get(cur, x, y+1)?1:0) +
- (1.0 - 0.1 * Math.random()) * (get(cur, x+1, y+1?1:0));
- let e = +(sum <= 6 + (Math.random()-0.5) * (1-k/K));
- if (e && sum >= 6 - Math.random() * waterInGeneration + 4 * step(110, 0, y)) e = 5;
- if (e && sum >= 6 - Math.random() * volcanoInGeneration + 6 * step(20, 60, y)) e = 4;
+ (0.9 + 0.1 * Math.random()) * (get(cur, x - 1, y - 1) ? 1 : 0) +
+ (0.9 + 0.1 * Math.random()) * (get(cur, x, y - 1) ? 1 : 0) +
+ (0.9 + 0.1 * Math.random()) * (get(cur, x + 1, y - 1) ? 1 : 0) +
+ (1.4 + 0.2 * Math.random()) * (get(cur, x - 1, y) ? 1 : 0) +
+ (1.1 + 0.2 * Math.random()) * (get(cur, x + 1, y) ? 1 : 0) +
+ (1.6 - 0.1 * Math.random()) * (get(cur, x - 1, y + 1) ? 1 : 0) +
+ (1.2 - 0.2 * Math.random()) * (get(cur, x, y + 1) ? 1 : 0) +
+ (1.0 - 0.1 * Math.random()) * get(cur, x + 1, y + 1 ? 1 : 0);
+ let e = +(sum <= 6 + (Math.random() - 0.5) * (1 - k / K));
+ if (
+ e &&
+ sum >= 6 - Math.random() * waterInGeneration + 4 * step(110, 0, y)
+ )
+ e = 5;
+ if (
+ e &&
+ sum >= 6 - Math.random() * volcanoInGeneration + 6 * step(20, 60, y)
+ )
+ e = 4;
set(swp, x, y, e);
}
}
@@ -541,14 +549,16 @@ function generate (startX: number, worldSize: [number,number]) {
for (i = 0; i < worldPixelBuf.length; ++i) {
affectColor(worldPixelRawBuf, 4 * i, worldPixelBuf[i]);
}
- return ndarray(worldPixelRawBuf, [ worldSize[0], worldSize[1], 4]).transpose(1, 0, 2).step(1, -1, 1);
+ return ndarray(worldPixelRawBuf, [worldSize[0], worldSize[1], 4])
+ .transpose(1, 0, 2)
+ .step(1, -1, 1);
}
-const size = [200,200];
+const size = [200, 200];
export default class Example extends Component {
state = {
- initialState: generate(0, size),
+ initialState: generate(0, size)
};
render() {
const { forestGrowFactor, fireFactor, waterFactor, speed } = this.props;
@@ -571,11 +581,10 @@ export default class Example extends Component {
speed: 60,
forestGrowFactor: 1,
fireFactor: 0,
- waterFactor: 0,
+ waterFactor: 0
};
}
-
/**
* Game Rule Interactions.
*
diff --git a/packages/cookbook/src/examples/webcampersistence/index.js b/packages/cookbook/src/examples/webcampersistence/index.js
index e999ad1..12009f3 100755
--- a/packages/cookbook/src/examples/webcampersistence/index.js
+++ b/packages/cookbook/src/examples/webcampersistence/index.js
@@ -1,6 +1,6 @@
//@flow
import React, { Component } from "react";
-import { Backbuffer, LinearCopy, Node, Shaders, GLSL } from "gl-react";
+import { Uniform, LinearCopy, Node, Shaders, GLSL } from "gl-react";
import { Surface } from "gl-react-dom";
import { Video } from "../video";
import { WebCamSource } from "../webcam";
@@ -18,32 +18,36 @@ void main () {
texture2D(back, uv+vec2(0.0, 0.005)),
persistence
).rgb, 1.0);
-}` }
+}`
+ }
});
-const Persistence = ({ children: t, persistence }) =>
+const Persistence = ({ children: t, persistence }) => (
;
+ uniforms={{ t, back: Uniform.Backbuffer, persistence }}
+ />
+);
export default class Example extends Component {
render() {
- const {persistence} = this.props;
+ const { persistence } = this.props;
return (
- { redraw =>
-
- }
+
+ {redraw => (
+
+ )}
+
);
}
static defaultProps = {
- persistence: 0.8,
+ persistence: 0.8
};
}
diff --git a/packages/cookbook/src/examples/webcampersistence/index.source.js b/packages/cookbook/src/examples/webcampersistence/index.source.js
index 19693dc..d77c43d 100644
--- a/packages/cookbook/src/examples/webcampersistence/index.source.js
+++ b/packages/cookbook/src/examples/webcampersistence/index.source.js
@@ -1,6 +1,6 @@
module.exports=`//@flow
import React, { Component } from "react";
-import { Backbuffer, LinearCopy, Node, Shaders, GLSL } from "gl-react";
+import { Uniform, LinearCopy, Node, Shaders, GLSL } from "gl-react";
import { Surface } from "gl-react-dom";
import { Video } from "../video";
import { WebCamSource } from "../webcam";
@@ -18,33 +18,37 @@ void main () {
texture2D(back, uv+vec2(0.0, 0.005)),
persistence
).rgb, 1.0);
-}\` }
+}\`
+ }
});
-const Persistence = ({ children: t, persistence }) =>
+const Persistence = ({ children: t, persistence }) => (
;
+ uniforms={{ t, back: Uniform.Backbuffer, persistence }}
+ />
+);
export default class Example extends Component {
render() {
- const {persistence} = this.props;
+ const { persistence } = this.props;
return (
- { redraw =>
-
- }
+
+ {redraw => (
+
+ )}
+
);
}
static defaultProps = {
- persistence: 0.8,
+ persistence: 0.8
};
}
`
diff --git a/packages/gl-react-dom/src/CanvasTextureLoader.js b/packages/gl-react-dom/src/CanvasTextureLoader.js
index 125480d..130e952 100755
--- a/packages/gl-react-dom/src/CanvasTextureLoader.js
+++ b/packages/gl-react-dom/src/CanvasTextureLoader.js
@@ -1,9 +1,11 @@
//@flow
import { TextureLoaderRawObject } from "gl-react";
-export default class CanvasTextureLoader extends TextureLoaderRawObject<
- HTMLCanvasElement
-> {
+export default class CanvasTextureLoader
+ extends TextureLoaderRawObject {
canLoad(input: any) {
return input instanceof HTMLCanvasElement;
}
+ mapInputSize(canvas: HTMLCanvasElement) {
+ return [canvas.width, canvas.height];
+ }
}
diff --git a/packages/gl-react-dom/src/ImageTextureLoader.js b/packages/gl-react-dom/src/ImageTextureLoader.js
index 1a99b5d..710f161 100755
--- a/packages/gl-react-dom/src/ImageTextureLoader.js
+++ b/packages/gl-react-dom/src/ImageTextureLoader.js
@@ -69,4 +69,10 @@ export default class ImageTextureLoader extends TextureLoader {
get(input: string) {
return this.textures[input];
}
+ getSize(input: string) {
+ const img = this.get(input);
+ if (img) {
+ return [img.width, img.height];
+ }
+ }
}
diff --git a/packages/gl-react-dom/src/VideoTextureLoader.js b/packages/gl-react-dom/src/VideoTextureLoader.js
index 8680690..dcdc9a0 100755
--- a/packages/gl-react-dom/src/VideoTextureLoader.js
+++ b/packages/gl-react-dom/src/VideoTextureLoader.js
@@ -1,9 +1,8 @@
//@flow
import { TextureLoaderRawObject } from "gl-react";
-export default class VideoTextureLoader extends TextureLoaderRawObject<
- HTMLVideoElement
-> {
+export default class VideoTextureLoader
+ extends TextureLoaderRawObject {
canLoad(input: any) {
return input instanceof HTMLVideoElement;
}
@@ -11,4 +10,7 @@ export default class VideoTextureLoader extends TextureLoaderRawObject<
if (video.videoWidth === 0) return null;
return video;
}
+ mapInputSize(video: HTMLVideoElement) {
+ return [video.videoWidth, video.videoHeight];
+ }
}
diff --git a/packages/gl-react-expo/src/ExponentGLObjectTextureLoader.js b/packages/gl-react-expo/src/ExponentGLObjectTextureLoader.js
index 64e95e3..4c16aae 100644
--- a/packages/gl-react-expo/src/ExponentGLObjectTextureLoader.js
+++ b/packages/gl-react-expo/src/ExponentGLObjectTextureLoader.js
@@ -8,9 +8,8 @@ function hash(obj) {
return JSON.stringify(obj); // FIXME ikr XD
}
-export default class ExponentGLObjectTextureLoader extends TextureLoader<
- Object
-> {
+export default class ExponentGLObjectTextureLoader
+ extends TextureLoader;
const inst = create(renderForSize(1, 1));
const surface = inst.getInstance();
inst.update(renderForSize(20, 20));
@@ -639,7 +639,9 @@ test("bus example 1", () => {
- {() => this.refs.bus}
+
+ {() => this.refs.bus}
+
);
}
@@ -676,9 +678,13 @@ test("bus example 2", () => {
- {() => this.refs.bus1}
+
+ {() => this.refs.bus1}
+
- {() => this.refs.bus2}
+
+ {() => this.refs.bus2}
+
);
}
@@ -721,7 +727,9 @@ test("bus example 3", () => {
- {() => this.refs.bus}
+
+ {() => this.refs.bus}
+
);
}
@@ -998,13 +1006,12 @@ test("a surface can be captured and resized", () => {
}`
}
});
- const render = (w, h) => (
+ const render = (w, h) =>
-
- );
+ ;
const inst = create(render(2, 2));
const surface = inst.getInstance();
expectToBeCloseToColorArray(
@@ -1032,7 +1039,7 @@ test("a node can be captured and resized", () => {
}
});
let node;
- const render = (w, h) => (
+ const render = (w, h) =>
{
height={h}
/>
-
- );
+ ;
const inst = create(render(2, 2));
const surface = inst.getInstance();
invariant(node, "node is defined");
@@ -1094,12 +1100,11 @@ test("Uniform children redraw=>el function", () => {
>
- {redraw => (
+ {redraw =>
(updatingTexture = ref)}
redraw={redraw}
- />
- )}
+ />}
@@ -1184,15 +1189,14 @@ test("Bus redraw=>el function", () => {
webglContextAttributes={{ preserveDrawingBuffer: true }}
>
- {redraw => (
+ {redraw =>
(updatingTexture = ref)}
redraw={redraw}
- />
- )}
+ />}
@@ -1233,7 +1237,7 @@ test("many Surface updates don't result of many redraws", () => {
});
const visitor = new CountersVisitor();
- const wrap = children => (
+ const wrap = children =>
{
webglContextAttributes={{ preserveDrawingBuffer: true }}
>
{children}
-
- );
- const JustBlue = ({ blue }) => (
-
- );
+ ;
+ const JustBlue = ({ blue }) =>
+ ;
const inst = create(wrap());
const surface = inst.getInstance();
@@ -1285,7 +1287,7 @@ test("many Surface flush() don't result of extra redraws", () => {
});
const visitor = new CountersVisitor();
- const wrap = children => (
+ const wrap = children =>
{
webglContextAttributes={{ preserveDrawingBuffer: true }}
>
{children}
-
- );
- const JustBlue = ({ blue }) => (
-
- );
+ ;
+ const JustBlue = ({ blue }) =>
+ ;
const inst = create(wrap());
const surface = inst.getInstance();
@@ -1334,15 +1334,16 @@ test("GL Components that implement shouldComponentUpdate shortcut Surface redraw
const visitor = new CountersVisitor();
Visitors.add(visitor);
- const wrap = children => (
+ const wrap = children =>
- {children}
-
- );
+
+ {children}
+
+ ;
class JustBlue extends React.PureComponent {
render() {
const { blue } = this.props;
@@ -1583,7 +1584,7 @@ test("Node `backbuffering`", () => {
}`
}
});
- const render = t => (
+ const render = t =>
{
-
- );
+ ;
const inst = create(render(red2x2)); // init with red
const surface = inst.getInstance();
expectToBeCloseToColorArray(
@@ -1608,20 +1608,20 @@ test("Node `backbuffering`", () => {
surface.capture(0, 0, 1, 1).data,
new Uint8Array([0, 255, 0, 255])
);
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
surface.flush();
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
new Uint8Array([0, 0, 255, 255])
);
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
surface.flush();
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
new Uint8Array([255, 0, 0, 255])
);
- inst.update(render(Backbuffer));
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
surface.flush();
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
@@ -1644,7 +1644,7 @@ test("Node `backbuffering` in `sync`", () => {
}`
}
});
- const render = t => (
+ const render = t =>
{
/>
-
- );
+ ;
const inst = create(render(red2x2)); // init with red
const surface = inst.getInstance();
// since node was drawn once, there were a first shift.
@@ -1669,18 +1668,18 @@ test("Node `backbuffering` in `sync`", () => {
surface.capture(0, 0, 1, 1).data,
new Uint8Array([0, 255, 0, 255])
);
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
new Uint8Array([0, 0, 255, 255])
);
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
new Uint8Array([255, 0, 0, 255])
);
- inst.update(render(Backbuffer));
- inst.update(render(Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
+ inst.update(render(Uniform.Backbuffer));
expectToBeCloseToColorArray(
surface.capture(0, 0, 1, 1).data,
new Uint8Array([0, 0, 255, 255])
@@ -1864,7 +1863,10 @@ test("can be extended with addTextureLoaderClass", async () => {
}
});
- const loader = createOneTextureLoader(gl => createNDArrayTexture(gl, red2x2));
+ const loader = createOneTextureLoader(
+ gl => createNDArrayTexture(gl, red2x2),
+ [2, 2]
+ );
TextureLoaders.add(loader.Loader);
const inst = create(
{
let onLoadCounter = 0;
const visitor = new CountersVisitor();
- const loader = createOneTextureLoader(gl => createNDArrayTexture(gl, red2x2));
+ const loader = createOneTextureLoader(
+ gl => createNDArrayTexture(gl, red2x2),
+ [2, 2]
+ );
TextureLoaders.add(loader.Loader);
const el = (
{
TextureLoaders.remove(loader.Loader);
});
+test("Uniform.textureSizeRatio allows to send the ratio of a texture in uniform", async () => {
+ const shaders = Shaders.create({
+ contain: {
+ frag: GLSL`
+ precision highp float;
+ varying vec2 uv;
+ uniform sampler2D t;
+ uniform float tRatio;
+ void main() {
+ vec2 p = uv * vec2(max(1.0, 1.0/tRatio), max(1.0, tRatio)); // "contain" the texture to preserve ratio (without center alignment)
+ gl_FragColor =
+ step(0.0, p.x) * step(p.x, 1.0) * // returns 1.0 if x is in [0,1] otherwise 0.0
+ step(0.0, p.y) * step(p.y, 1.0) * // returns 1.0 if y is in [0,1] otherwise 0.0
+ texture2D(t, p);
+ }`
+ }
+ });
+ const loader = createOneTextureLoader(
+ gl => createNDArrayTexture(gl, yellow3x2),
+ [3, 2]
+ );
+ TextureLoaders.add(loader.Loader);
+ const el = (
+
+
+
+ );
+ const inst = create(el);
+ const surface = inst.getInstance();
+ await loader.resolve();
+ surface.flush();
+ expectToBeCloseToColorArray(
+ surface.capture(0, 0, 1, 1).data,
+ new Uint8Array([255, 255, 0, 255])
+ );
+ expectToBeCloseToColorArray(
+ surface.capture(0, 32, 1, 1).data,
+ new Uint8Array([255, 255, 0, 255])
+ );
+ expectToBeCloseToColorArray(
+ surface.capture(0, 63, 1, 1).data,
+ new Uint8Array([0, 0, 0, 0])
+ );
+ inst.unmount();
+ TextureLoaders.remove(loader.Loader);
+});
+
test("Surface `preload` that fails will trigger onLoadError", async () => {
const shaders = Shaders.create({
helloTexture: {
@@ -1962,7 +2024,10 @@ test("Surface `preload` that fails will trigger onLoadError", async () => {
let onLoadCounter = 0;
let onLoadErrorCounter = 0;
- const loader = createOneTextureLoader(gl => createNDArrayTexture(gl, red2x2));
+ const loader = createOneTextureLoader(
+ gl => createNDArrayTexture(gl, red2x2),
+ [2, 2]
+ );
TextureLoaders.add(loader.Loader);
const el = (
{
test("handle context lost nicely", () => {
let surface;
- let contextLost = 0, contextRestored = 0;
+ let contextLost = 0,
+ contextRestored = 0;
class Example extends React.Component {
render() {
return (
@@ -2212,15 +2278,14 @@ void main() {
}
}
- const wrap = children => (
+ const wrap = children =>
{children}
-
- );
+ ;
const inst = create(wrap());
const surface = inst.getInstance();
@@ -2281,7 +2346,12 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
expect(Shaders.get(shaders.helloTexture2)).toBeDefined();
const oldConsole = console;
- let groupEnd = 0, log = 0, warn = 0, error = 0, group = 0, groupCollapsed = 0;
+ let groupEnd = 0,
+ log = 0,
+ warn = 0,
+ error = 0,
+ group = 0,
+ groupCollapsed = 0;
console = {
...oldConsole,
@@ -2296,11 +2366,12 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
let justBlueNode;
const visitor = new VisitorLogger();
- const wrap = children => (
+ const wrap = children =>
- {children}
-
- );
+
+ {children}
+
+ ;
class JustBlue extends React.PureComponent {
render() {
@@ -2334,15 +2405,14 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
);
}
}
- const MissingOrInvalidUniforms = () => (
+ const MissingOrInvalidUniforms = () =>
{
justBlueNode = ref;
}}
shader={shaders.justBlue}
uniforms={{ nope: [1, 2] }}
- />
- );
+ />;
class TreeWithZombiesDontBreak extends React.Component {
render() {
@@ -2434,7 +2504,13 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
justBlueNode.flush();
justBlueNode.redraw();
justBlueNode.flush();
- inst.update(wrap());
+ inst.update(
+ wrap(
+
+
+
+ )
+ );
surface.flush();
inst.update(wrap());
surface.flush();
@@ -2540,7 +2616,12 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
expect(warn).toBeGreaterThan(0);
warn = 0;
inst.update(
- wrap()
+ wrap(
+
+ )
);
surface.flush();
expect(warn).toBeGreaterThan(0);
@@ -2561,7 +2642,9 @@ test("VisitorLogger + bunch of funky extreme tests", () => {
- {() => this.refs.bus}
+
+ {() => this.refs.bus}
+
);
}
diff --git a/packages/tests/flow/correct.js b/packages/tests/flow/correct.js
index 5b629b3..25d7bcc 100755
--- a/packages/tests/flow/correct.js
+++ b/packages/tests/flow/correct.js
@@ -9,18 +9,16 @@ import {
Visitor,
TextureLoader,
TextureLoaders,
- Backbuffer,
+ Uniform,
Bus,
VisitorLogger,
- connectSize,
+ connectSize
} from "gl-react";
-import {
- Surface,
-} from "gl-react-headless";
+import { Surface } from "gl-react-headless";
const shaders = Shaders.create({
a: {
- frag: GLSL`...`,
+ frag: GLSL`...`
},
b: {
frag: "..."
@@ -31,7 +29,7 @@ class A extends React.Component {
surface: ?Surface;
node: ?Node;
doThings() {
- const {surface, node} = this;
+ const { surface, node } = this;
if (surface && node) {
surface.redraw();
node.redraw();
@@ -43,56 +41,58 @@ class A extends React.Component {
}
render() {
return (
- this.surface=ref} width={100} height={200}>
-
-
-
-
-
-
-
- this.node=ref}
- width={1}
- height={1}
- shader={shaders.a}
- backbuffering
- uniformsOptions={{
- foo: { interpolation: "nearest" },
- b: { interpolation: "linear" },
- }}
- uniforms={{
- foo: () => this.refs.foo,
- bar: () => this.refs.bar,
- b: Backbuffer,
- }}
- />
-
-
+ (this.surface = ref)} width={100} height={200}>
+
+
+
+
+
+
+
+ (this.node = ref)}
+ width={1}
+ height={1}
+ shader={shaders.a}
+ backbuffering
+ uniformsOptions={{
+ foo: { interpolation: "nearest" },
+ b: { interpolation: "linear" }
+ }}
+ uniforms={{
+ foo: () => this.refs.foo,
+ bar: () => this.refs.bar,
+ b: Uniform.Backbuffer,
+ bs: Uniform.textureSize(""),
+ br: Uniform.textureSizeRatio("")
+ }}
+ />
+
+
);
}
}
const N = connectSize(({ width, height }) =>
-);
+
+);
const B = () =>
-
-;
+ ;
diff --git a/packages/tests/flow/incorrect.js b/packages/tests/flow/incorrect.js
index 80da9c7..36ee68e 100755
--- a/packages/tests/flow/incorrect.js
+++ b/packages/tests/flow/incorrect.js
@@ -12,11 +12,9 @@ import {
Backbuffer,
Bus,
VisitorLogger,
- connectSize,
+ connectSize
} from "gl-react";
-import {
- Surface,
-} from "gl-react-headless";
+import { Surface } from "gl-react-headless";
;
;
@@ -32,18 +30,18 @@ import {
const shaders = Shaders.create({
valid: {
- frag: GLSL`...`,
+ frag: GLSL`...`
},
a: null,
b: {},
- c: { frag: true },
+ c: { frag: true }
});
class A extends React.Component {
surface: ?Surface;
node: ?Node;
doThings() {
- const {surface, node} = this;
+ const { surface, node } = this;
if (surface && node) {
surface.nope();
node.nope();
@@ -51,17 +49,14 @@ class A extends React.Component {
}
render() {
return (
- this.surface=ref} notexists>
-
-
-
-
-
-
-
+ (this.surface = ref)} notexists>
+
+
+
+
+
+
+
);
}
}
@@ -69,19 +64,19 @@ class A extends React.Component {
connectSize();
const N = connectSize(() =>
-// these are all wrong props
-
+ // these are all wrong props
+
);
diff --git a/packages/tests/flow/snapshot.txt b/packages/tests/flow/snapshot.txt
index 3a064eb..ceca529 100644
--- a/packages/tests/flow/snapshot.txt
+++ b/packages/tests/flow/snapshot.txt
@@ -1,25 +1,25 @@
-../all.test.js:2496
+../all.test.js:2572
v----
-2496: }}
-2500: />
+2572: }}
+2576: />
-^ props of React element `Node`
-2498: uniformsOptions={{ t: { interpolation: "nope" } }}
+2574: uniformsOptions={{ t: { interpolation: "nope" } }}
^^^^^^ string. This type is incompatible with
65: interpolation: Interpolation,
^^^^^^^^^^^^^ string enum. See: ../node_modules/gl-react/lib/Node.js.flow:65
-../all.test.js:2508
+../all.test.js:2584
v----
-2508: }}
-2512: />
+2584: }}
+2588: />
-^ props of React element `Node`
-2510: uniformsOptions={{ t: { wrap: "nope" } }}
+2586: uniformsOptions={{ t: { wrap: "nope" } }}
^^^^^^ string. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: tuple type | WrapMode. See: ../node_modules/gl-react/lib/Node.js.flow:66
@@ -27,7 +27,7 @@
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^^^^^^^^^^^^^ tuple type. See: ../node_modules/gl-react/lib/Node.js.flow:66
Error:
- 2510: uniformsOptions={{ t: { wrap: "nope" } }}
+ 2586: uniformsOptions={{ t: { wrap: "nope" } }}
^^^^^^ string. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^^^^^^^^^^^^^ tuple type. See: ../node_modules/gl-react/lib/Node.js.flow:66
@@ -35,20 +35,20 @@
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^ WrapMode. See: ../node_modules/gl-react/lib/Node.js.flow:66
Error:
- 2510: uniformsOptions={{ t: { wrap: "nope" } }}
+ 2586: uniformsOptions={{ t: { wrap: "nope" } }}
^^^^^^ string. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^ string enum. See: ../node_modules/gl-react/lib/Node.js.flow:66
-../all.test.js:2520
+../all.test.js:2596
v----
-2520: }}
-2524: />
+2596: }}
+2600: />
-^ props of React element `Node`
-2522: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
+2598: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
^^^^^^^^^^^^^^^^ array literal. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: tuple type | WrapMode. See: ../node_modules/gl-react/lib/Node.js.flow:66
@@ -56,7 +56,7 @@
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^^^^^^^^^^^^^ tuple type. See: ../node_modules/gl-react/lib/Node.js.flow:66
Error:
- 2522: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
+ 2598: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
^^^^^^ string. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^ string enum. See: ../node_modules/gl-react/lib/Node.js.flow:66
@@ -64,611 +64,373 @@
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^ WrapMode. See: ../node_modules/gl-react/lib/Node.js.flow:66
Error:
- 2522: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
+ 2598: uniformsOptions={{ t: { wrap: ["nope", "nope"] } }}
^^^^^^^^^^^^^^^^ array literal. This type is incompatible with
66: wrap: [WrapMode, WrapMode] | WrapMode
^^^^^^^^ string enum. See: ../node_modules/gl-react/lib/Node.js.flow:66
-../all.test.js:2532
+../all.test.js:2608
v----
-2532: }}
-2536: />
+2608: }}
+2612: />
-^ props of React element `Node`
-2533: blendFunc="nope"
+2609: blendFunc="nope"
^^^^^^ string. Inexact type is incompatible with exact type
177: blendFunc: BlendFuncSrcDst,
^^^^^^^^^^^^^^^ exact type: object type. See: ../node_modules/gl-react/lib/Node.js.flow:177
-incorrect.js:21
- 21: ;
+incorrect.js:19
+ 19: ;
^^^^^^^^ React element `Node`
-380: props: Props;
- ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:380
- 21: ;
+393: props: Props;
+ ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:393
+ 19: ;
^^^^^^^^ props of React element `Node`
-incorrect.js:27
- 27: ;
+incorrect.js:25
+ 25: ;
^^^^^^^^^^^^^ React element `Node`
- 27: ;
+ 25: ;
^^^^^^^^^^^^^ property `nope`. Property not found in
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
-incorrect.js:27
- 27: ;
+incorrect.js:25
+ 25: ;
^^^^^^^^^^^^^ React element `Node`
-380: props: Props;
- ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:380
- 27: ;
+393: props: Props;
+ ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:393
+ 25: ;
^^^^^^^^^^^^^ props of React element `Node`
-incorrect.js:29
- 29: ;
+incorrect.js:27
+ 27: ;
^^^^^^^^^^^^^^^^^^^ React element `LinearCopy`
- 29: ;
+ 27: ;
^^^^^^^^^^^^^^^^^^^ property `nope`. Property not found in
15: props: Props;
^^^^^ object type. See: ../node_modules/gl-react/lib/LinearCopy.js.flow:15
-incorrect.js:30
- 30: ;
+incorrect.js:28
+ 28: ;
^^^^^^^^^^^^^^^^^^^^ React element `NearestCopy`
- 30: ;
+ 28: ;
^^^^^^^^^^^^^^^^^^^^ property `nope`. Property not found in
15: props: Props;
^^^^^ object type. See: ../node_modules/gl-react/lib/NearestCopy.js.flow:15
-incorrect.js:31
- 31: ;
+incorrect.js:29
+ 29: ;
^^^^^^^^^^^^ React element `Bus`
- 31: ;
+ 29: ;
^^^^^^^^^^^^ property `nope`. Property not found in
45: export default class Bus extends Component<{ index: number }, Props, void> {
^^^^^ object type. See: ../node_modules/gl-react/lib/Bus.js.flow:45
-incorrect.js:33
+incorrect.js:31
v---------------
- 33: const shaders = Shaders.create({
- 34: valid: {
- 35: frag: GLSL`...`,
+ 31: const shaders = Shaders.create({
+ 32: valid: {
+ 33: frag: GLSL`...`
...:
- 40: });
+ 38: });
-^ call of method `create`
- 37: a: null,
+ 35: a: null,
^^^^ null. Inexact type is incompatible with exact type
45: [key: string]: ShaderDefinition
^^^^^^^^^^^^^^^^ exact type: object type. See: ../node_modules/gl-react/lib/Shaders.js.flow:45
-incorrect.js:33
+incorrect.js:31
v---------------
- 33: const shaders = Shaders.create({
- 34: valid: {
- 35: frag: GLSL`...`,
+ 31: const shaders = Shaders.create({
+ 32: valid: {
+ 33: frag: GLSL`...`
...:
- 40: });
+ 38: });
-^ call of method `create`
45: [key: string]: ShaderDefinition
^^^^^^^^^^^^^^^^ property `frag`. Property not found in. See: ../node_modules/gl-react/lib/Shaders.js.flow:45
- 38: b: {},
+ 36: b: {},
^^ object literal
-incorrect.js:39
- 39: c: { frag: true },
+incorrect.js:37
+ 37: c: { frag: true }
^^^^^^^^^^^^^^ object literal. This type is incompatible with
45: [key: string]: ShaderDefinition
^^^^^^^^^^^^^^^^ object type. See: ../node_modules/gl-react/lib/Shaders.js.flow:45
Property `frag` is incompatible:
- 39: c: { frag: true },
+ 37: c: { frag: true }
^^^^ boolean. This type is incompatible with
16: frag: GLSLCode
^^^^^^^^ string. See: ../node_modules/gl-react/lib/Shaders.js.flow:16
-incorrect.js:48
- 48: surface.nope();
+incorrect.js:46
+ 46: surface.nope();
^^^^ property `nope`. Property not found in
- 48: surface.nope();
+ 46: surface.nope();
^^^^^^^ ISurface
-incorrect.js:49
- 49: node.nope();
+incorrect.js:47
+ 47: node.nope();
^^^^ property `nope`. Property not found in
- 49: node.nope();
+ 47: node.nope();
^^^^ Node
-incorrect.js:55
- 55:
- ^^^^^^^^^^^^^^^^^^^^^^^ React element `Bus`
- 55:
- ^^^^^^^^^^^^^^^^^^^^^^^ property `notexists`. Property not found in
+incorrect.js:53
+ 53:
+ ^^^^^^^^^^^^^^^^^^^^^^^ React element `Bus`
+ 53:
+ ^^^^^^^^^^^^^^^^^^^^^^^ property `notexists`. Property not found in
45: export default class Bus extends Component<{ index: number }, Props, void> {
^^^^^ object type. See: ../node_modules/gl-react/lib/Bus.js.flow:45
-incorrect.js:56
- 56:
- ^^^^^^^^ React element `Node`
-380: props: Props;
- ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:380
- 56:
- ^^^^^^^^ props of React element `Node`
+incorrect.js:54
+ 54:
+ ^^^^^^^^ React element `Node`
+393: props: Props;
+ ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:393
+ 54:
+ ^^^^^^^^ props of React element `Node`
-incorrect.js:58
- 58:
- ^^^^^^^^^^^^^^^^^^^^^^ React element `LinearCopy`
- 58:
- ^^^^^^^^^^^^^^^^^^^^^^ property `notexists`. Property not found in
+incorrect.js:56
+ 56:
+ ^^^^^^^^^^^^^^^^^^^^^^ React element `LinearCopy`
+ 56:
+ ^^^^^^^^^^^^^^^^^^^^^^ property `notexists`. Property not found in
15: props: Props;
^^^^^ object type. See: ../node_modules/gl-react/lib/LinearCopy.js.flow:15
-incorrect.js:59
- v----
- 59:
- -^ React element `Node`
- v----
- 59:
- -^ property `notexists`. Property not found in
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+incorrect.js:57
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `Node`
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ property `notexists`. Property not found in
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
-incorrect.js:59
- v----
- 59:
- -^ React element `Node`
- v----
- 59:
- -^ property `shaders`. Property not found in
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+incorrect.js:57
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `Node`
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ property `shaders`. Property not found in
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
-incorrect.js:59
- v----
- 59:
- -^ React element `Node`
-380: props: Props;
- ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:380
- v----
- 59:
- -^ props of React element `Node`
+incorrect.js:57
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `Node`
+393: props: Props;
+ ^^^^^ property `shader`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:393
+ 57:
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ props of React element `Node`
-incorrect.js:69
- 69: connectSize();
+incorrect.js:64
+ 64: connectSize();
^^^^^^^^^^^^^ function call
- 69: connectSize();
+ 64: connectSize();
^^^^^^^^^^^^^ undefined (too few arguments, expected default/rest parameters). This type is incompatible with
- 20: GLComponent: ReactClass<*> | ((props: any) => React.Element<*>)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: type application of identifier `ReactClass` | function type. See: ../node_modules/gl-react/lib/connectSize.js.flow:20
- Member 1:
- 20: GLComponent: ReactClass<*> | ((props: any) => React.Element<*>)
- ^^^^^^^^^^^^^ type application of identifier `ReactClass`. See: ../node_modules/gl-react/lib/connectSize.js.flow:20
- Error:
- 69: connectSize();
- ^^^^^^^^^^^^^ undefined (too few arguments, expected default/rest parameters). This type is incompatible with
- 20: GLComponent: ReactClass<*> | ((props: any) => React.Element<*>)
- ^^^^^^^^^^^^^ class type: C. See: ../node_modules/gl-react/lib/connectSize.js.flow:20
- Member 2:
- 20: GLComponent: ReactClass<*> | ((props: any) => React.Element<*>)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: ../node_modules/gl-react/lib/connectSize.js.flow:20
- Error:
- 69: connectSize();
- ^^^^^^^^^^^^^ undefined (too few arguments, expected default/rest parameters). This type is incompatible with
- 20: GLComponent: ReactClass<*> | ((props: any) => React.Element<*>)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See: ../node_modules/gl-react/lib/connectSize.js.flow:20
+ 19: const connectSize = (GLComponent: ReactClass<*>) =>
+ ^^^^^^^^^^^^^ class type: C. See: ../node_modules/gl-react/lib/connectSize.js.flow:19
-incorrect.js:73
- v----
- 73:
- -^ React element `Node`
- v----
- 73:
+ -^ React element `Node`
+ v----
+ 68:
- -^ property `preload`. Property not found in
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+ 81: />
+ -^ property `preload`. Property not found in
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
-incorrect.js:73
- v----
- 73:
- -^ React element `Node`
- v----
- 73:
+ -^ React element `Node`
+ v----
+ 68:
- -^ property `visitor`. Property not found in
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+ 81: />
+ -^ property `visitor`. Property not found in
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
-incorrect.js:73
- v----
- 73:
- -^ React element `Node`
- 85: shader={false}
- ^^^^^ boolean. This type is incompatible with
+ 81: />
+ -^ React element `Node`
+ 80: shader={false}
+ ^^^^^ boolean. This type is incompatible with
160: shader: ShaderIdentifier | ShaderDefinition,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: ShaderIdentifier | ShaderDefinition. See: ../node_modules/gl-react/lib/Node.js.flow:160
Member 1:
160: shader: ShaderIdentifier | ShaderDefinition,
^^^^^^^^^^^^^^^^ ShaderIdentifier. See: ../node_modules/gl-react/lib/Node.js.flow:160
Error:
- 85: shader={false}
- ^^^^^ boolean. This type is incompatible with
+ 80: shader={false}
+ ^^^^^ boolean. This type is incompatible with
160: shader: ShaderIdentifier | ShaderDefinition,
^^^^^^^^^^^^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:160
Member 2:
160: shader: ShaderIdentifier | ShaderDefinition,
^^^^^^^^^^^^^^^^ ShaderDefinition. See: ../node_modules/gl-react/lib/Node.js.flow:160
Error:
- 85: shader={false}
- ^^^^^ boolean. Inexact type is incompatible with exact type
+ 80: shader={false}
+ ^^^^^ boolean. Inexact type is incompatible with exact type
160: shader: ShaderIdentifier | ShaderDefinition,
^^^^^^^^^^^^^^^^ exact type: object type. See: ../node_modules/gl-react/lib/Node.js.flow:160
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`. This type is incompatible with
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+ 81: />
+ -^ props of React element `Node`. This type is incompatible with
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
Property `height` is incompatible:
- 77: height={false}
- ^^^^^ boolean. This type is incompatible with
+ 72: height={false}
+ ^^^^^ boolean. This type is incompatible with
165: height?: number,
^^^^^^ number. See: ../node_modules/gl-react/lib/Node.js.flow:165
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`. This type is incompatible with
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+ 81: />
+ -^ props of React element `Node`. This type is incompatible with
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
Property `sync` is incompatible:
- 74: sync={1}
- ^ number. This type is incompatible with
+ 69: sync={1}
+ ^ number. This type is incompatible with
163: sync?: boolean,
^^^^^^^ boolean. See: ../node_modules/gl-react/lib/Node.js.flow:163
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`. This type is incompatible with
-380: props: Props;
- ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:380
+ 81: />
+ -^ props of React element `Node`. This type is incompatible with
+393: props: Props;
+ ^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:393
Property `width` is incompatible:
- 76: width={false}
- ^^^^^ boolean. This type is incompatible with
+ 71: width={false}
+ ^^^^^ boolean. This type is incompatible with
164: width?: number,
^^^^^^ number. See: ../node_modules/gl-react/lib/Node.js.flow:164
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`
- 75: clear={42}
- ^^ number. Inexact type is incompatible with exact type
+ 81: />
+ -^ props of React element `Node`
+ 70: clear={42}
+ ^^ number. Inexact type is incompatible with exact type
178: clear: ?Clear
^^^^^ exact type: object type. See: ../node_modules/gl-react/lib/Node.js.flow:178
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`
- v
- 78: blendFunc={{
- 79: src: "nope",
- 80: interpolation: "interpolation_nope",
- 81: wrap: "wrap_nope",
- 82: }}
- ^ property `interpolation`. Property not found in
+ 81: />
+ -^ props of React element `Node`
+ v
+ 73: blendFunc={{
+ 74: src: "nope",
+ 75: interpolation: "interpolation_nope",
+ 76: wrap: "wrap_nope"
+ 77: }}
+ ^ property `interpolation`. Property not found in
177: blendFunc: BlendFuncSrcDst,
^^^^^^^^^^^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:177
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`
- v
- 78: blendFunc={{
- 79: src: "nope",
- 80: interpolation: "interpolation_nope",
- 81: wrap: "wrap_nope",
- 82: }}
- ^ property `wrap`. Property not found in
+ 81: />
+ -^ props of React element `Node`
+ v
+ 73: blendFunc={{
+ 74: src: "nope",
+ 75: interpolation: "interpolation_nope",
+ 76: wrap: "wrap_nope"
+ 77: }}
+ ^ property `wrap`. Property not found in
177: blendFunc: BlendFuncSrcDst,
^^^^^^^^^^^^^^^ object type. See: ../node_modules/gl-react/lib/Node.js.flow:177
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`
- 79: src: "nope",
- ^^^^^^ property `nope`. Property not found in
+ 81: />
+ -^ props of React element `Node`
+ 74: src: "nope",
+ ^^^^^^ property `nope`. Property not found in
95: src: BlendFunc,
^^^^^^^^^ object literal. See: ../node_modules/gl-react/lib/Node.js.flow:95
-incorrect.js:73
- v----
- 73:
- -^ props of React element `Node`
+ 81: />
+ -^ props of React element `Node`
177: blendFunc: BlendFuncSrcDst,
^^^^^^^^^^^^^^^ property `dst`. Property not found in. See: ../node_modules/gl-react/lib/Node.js.flow:177
- v
- 78: blendFunc={{
- 79: src: "nope",
- 80: interpolation: "interpolation_nope",
- 81: wrap: "wrap_nope",
- 82: }}
- ^ object literal
+ v
+ 73: blendFunc={{
+ 74: src: "nope",
+ 75: interpolation: "interpolation_nope",
+ 76: wrap: "wrap_nope"
+ 77: }}
+ ^ object literal
-../node_modules/gl-react/lib/Node.js.flow:431
-431: this.context.glParent._addGLNodeChild(this);
- ^^^^ unused function argument
- 672: _addGLNodeChild() {}
- ^^^^^^^^^^^^^^^^^^^^ function expects no arguments
-
-../node_modules/gl-react/lib/Node.js.flow:443
-443: this.context.glParent._removeGLNodeChild(this);
- ^^^^ unused function argument
- v---------------------
- 123: _removeGLNodeChild() {
- 124: this.glNode = null;
- 125: }
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/Bus.js.flow:123
-
-../node_modules/gl-react/lib/Node.js.flow:443
-443: this.context.glParent._removeGLNodeChild(this);
- ^^^^ unused function argument
- 673: _removeGLNodeChild() {}
- ^^^^^^^^^^^^^^^^^^^^^^^ function expects no arguments
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:25
- 25: log(surface.getGLName() + " _context acquired_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:25
- 25: log(surface.getGLName() + " _context acquired_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:27
- 27: log(surface.getGLName() + " _context lost_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:27
- 27: log(surface.getGLName() + " _context lost_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:35
- 35: log("_size_ `" + width + "`x`" + height + "`");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:35
- 35: log("_size_ `" + width + "`x`" + height + "`");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:51
- v-----------------
- 51: node.getGLName() +
- 52: " redraw _skipped_: " +
- 53: (!node.context.glSurface.gl
- 54: ? "no gl context available!"
- 55: : !node._needsRedraw ? "no need to redraw" : "")
- -----------------------------------------------^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:51
- v-----------------
- 51: node.getGLName() +
- 52: " redraw _skipped_: " +
- 53: (!node.context.glSurface.gl
- 54: ? "no gl context available!"
- 55: : !node._needsRedraw ? "no need to redraw" : "")
- -----------------------------------------------^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:86
- v-----------
- 86: "_size_ `" +
- 87: w +
- 88: "`x`" +
-...:
- 96: "`"
- --^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:86
- v-----------
- 86: "_size_ `" +
- 87: w +
- 88: "`x`" +
-...:
- 96: "`"
- --^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:98
- 98: log("_" + preparedUniforms.length + " uniforms:_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:98
- 98: log("_" + preparedUniforms.length + " uniforms:_");
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:113
- v------------------------------
-113: `${spaces}*${type === "UNKNOWN"
-114: ? "[c='color:red']UNKNOWN[c]"
-115: : type}* _${key}_ = ${values}`,
- -----------------------------^ unused function argument
- v-----------
- 25: log = function() {
- 26: var args;
- 27: args = [];
- ...:
- 36: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:25
-
-../node_modules/gl-react/lib/VisitorLogger.js.flow:113
- v------------------------------
-113: `${spaces}*${type === "UNKNOWN"
-114: ? "[c='color:red']UNKNOWN[c]"
-115: : type}* _${key}_ = ${values}`,
- -----------------------------^ unused function argument
- v-----------
- 38: _log = function() {
- 39: return Function.prototype.apply.call(
- 40: console.log,
- ...:
- 44: };
- ^ function expects no arguments. See: ../node_modules/gl-react/lib/helpers/log.js.flow:38
+../utils.js:42
+ 42: expect(actual).toBeInstanceOf(Uint8Array);
+ ^^^^^^ identifier `expect`. Could not resolve name
-... 24 more errors (only 50 out of 74 errors displayed)
-To see all errors, re-run Flow with --show-all-errors
+Found 34 errors
diff --git a/packages/tests/utils.js b/packages/tests/utils.js
index 0a94c6b..a7e2416 100755
--- a/packages/tests/utils.js
+++ b/packages/tests/utils.js
@@ -249,8 +249,40 @@ export const yellow3x3 = ndarray(
]),
[3, 3, 4]
);
+export const yellow3x2 = ndarray(
+ new Uint8Array([
+ 255,
+ 255,
+ 0,
+ 255,
+ 255,
+ 255,
+ 0,
+ 255,
+ 255,
+ 255,
+ 0,
+ 255,
+ 255,
+ 255,
+ 0,
+ 255,
+ 255,
+ 255,
+ 0,
+ 255,
+ 255,
+ 255,
+ 0,
+ 255
+ ]),
+ [3, 2, 4]
+);
-export function createOneTextureLoader(makeTexture: (gl: any) => WebGLTexture) {
+export function createOneTextureLoader(
+ makeTexture: (gl: any) => WebGLTexture,
+ size: [number, number]
+) {
const textureId = Symbol("one-texture");
const counters = {
constructor: 0,
@@ -287,6 +319,9 @@ export function createOneTextureLoader(makeTexture: (gl: any) => WebGLTexture) {
++counters.get;
return this.texture;
}
+ getSize() {
+ return size;
+ }
load() {
++counters.load;
const promise = d.promise.then(() => {
@@ -332,6 +367,9 @@ class FakeTextureLoader extends TextureLoader {
canLoad(input: any) {
return input instanceof FakeTexture;
}
+ getSize(ft: FakeTexture) {
+ return [ft.width, ft.height];
+ }
get(ft: FakeTexture) {
const array = ft.getPixels();
if (array) {