Commit 7265b3b2 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

ntroducing GL.createComponent(props => glView, {...staticFields})

parent 9811ebb7
...@@ -24,7 +24,7 @@ void main( void ) { ...@@ -24,7 +24,7 @@ void main( void ) {
} }
}); });
class Banner extends GL.Component { class Banner extends React.Component {
render () { render () {
const { width, height, time } = this.props; const { width, height, time } = this.props;
return <GL.View return <GL.View
......
...@@ -37,7 +37,7 @@ void main() { ...@@ -37,7 +37,7 @@ void main() {
} }
}); });
class Intro extends GL.Component { class Intro extends React.Component {
render () { render () {
const { time, fps, width, height } = this.props; const { time, fps, width, height } = this.props;
return <GL.View return <GL.View
......
const React = require("react-native"); const React = require("react-native");
const GL = require("gl-react-native"); const GL = require("gl-react-native");
class Transition extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, shader, progress, from, to, uniforms }) => {
const { width, height, shader, progress, from, to, uniforms } = this.props;
const scale = React.PixelRatio.get(); const scale = React.PixelRatio.get();
return <GL.View return <GL.View
preload preload
...@@ -19,7 +18,5 @@ class Transition extends GL.Component { ...@@ -19,7 +18,5 @@ class Transition extends GL.Component {
resolution: [ width * scale, height * scale ] resolution: [ width * scale, height * scale ]
}} }}
/>; />;
} },
} { displayName: "Transition" });
module.exports = Transition;
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
}); });
class Vignette extends GL.Component { class Vignette extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
this.onResponderMove = this.onResponderMove.bind(this); this.onResponderMove = this.onResponderMove.bind(this);
......
...@@ -2,15 +2,12 @@ const React = require("react-native"); ...@@ -2,15 +2,12 @@ const React = require("react-native");
const GL = require("gl-react-native"); const GL = require("gl-react-native");
const Blur1D = require("./Blur1D"); const Blur1D = require("./Blur1D");
class Blur extends GL.Component { module.exports = GL.createComponent(({ width, height, factor, children }) =>
render () { <Blur1D width={width} height={height} direction={[ factor, 0 ]}>
const { width, height, factor, children, ...rest } = this.props;
return <Blur1D {...rest} width={width} height={height} direction={[ factor, 0 ]}>
<Blur1D width={width} height={height} direction={[ 0, factor ]}> <Blur1D width={width} height={height} direction={[ 0, factor ]}>
{children} {children}
</Blur1D> </Blur1D>
</Blur1D>; </Blur1D>
} , {
} displayName: "Blur"
});
module.exports = Blur;
...@@ -33,21 +33,18 @@ void main () { ...@@ -33,21 +33,18 @@ void main () {
} }
}); });
class Blur1D extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, direction, children }) =>
const { width, height, direction, children: t, ...rest } = this.props; <GL.View
return <GL.View
{...rest}
shader={shaders.blur1D} shader={shaders.blur1D}
width={width} width={width}
height={height} height={height}
uniforms={{ uniforms={{
direction, direction,
resolution: [ width, height ], resolution: [ width, height ]
t }}>
}} <GL.Uniform name="t">{children}</GL.Uniform>
/>; </GL.View>
} , {
} displayName: "Blur1D"
});
module.exports = Blur1D;
...@@ -14,15 +14,11 @@ void main () { // This function is called FOR EACH PIXEL ...@@ -14,15 +14,11 @@ void main () { // This function is called FOR EACH PIXEL
} }
}); });
class HelloGL extends React.Component { module.exports = GL.createComponent(({ width, height }) =>
render () { <GL.View
const { width, height } = this.props;
return <GL.View
shader={shaders.helloGL} shader={shaders.helloGL}
width={width} width={width}
height={height} height={height}
/>; />,
} { displayName: "HelloGL" }
} );
module.exports = HelloGL;
...@@ -24,17 +24,12 @@ void main() { ...@@ -24,17 +24,12 @@ void main() {
} }
}); });
class HueRotate extends GL.Component { module.exports = GL.createComponent(
render () { ({ hue, children, ...rest }) =>
const { width, height, hue, children: tex, ...rest } = this.props; <GL.View
return <GL.View
{...rest} {...rest}
shader={shaders.hueRotate} shader={shaders.hueRotate}
width={width} uniforms={{ hue }}>
height={height} <GL.Uniform name="tex">{children}</GL.Uniform>
uniforms={{ hue, tex }} </GL.View>
/>; , { displayName: "HueRotate" });
}
}
module.exports = HueRotate;
...@@ -32,17 +32,16 @@ void main () { ...@@ -32,17 +32,16 @@ void main () {
} }
}); });
class PieProgress extends React.Component { module.exports = GL.createComponent(
render () { ({
const {
width, width,
height, height,
progress, progress,
colorInside, colorInside,
colorOutside, colorOutside,
radius radius
} = this.props; }) =>
return <GL.View <GL.View
width={width} width={width}
height={height} height={height}
shader={shaders.pieProgress} shader={shaders.pieProgress}
...@@ -54,13 +53,12 @@ class PieProgress extends React.Component { ...@@ -54,13 +53,12 @@ class PieProgress extends React.Component {
colorOutside, colorOutside,
radius radius
}} }}
/>; />,
} {
} displayName: "PieProgress",
PieProgress.defaultProps = { defaultProps: {
colorInside: [0, 0, 0, 0], colorInside: [0, 0, 0, 0],
colorOutside: [0, 0, 0, 0.5], colorOutside: [0, 0, 0, 0.5],
radius: 0.4 radius: 0.4
}; }
});
module.exports = PieProgress;
...@@ -19,16 +19,11 @@ void main () { ...@@ -19,16 +19,11 @@ void main () {
} }
}); });
class Saturation extends React.Component { module.exports = GL.createComponent(
render () { ({ factor, image, ...rest }) =>
const { width, height, factor, image } = this.props; <GL.View
return <GL.View {...rest}
shader={shaders.saturation} shader={shaders.saturation}
width={width}
height={height}
uniforms={{ factor, image }} uniforms={{ factor, image }}
/>; />,
} { displayName: "Saturation" });
}
module.exports = Saturation;
...@@ -19,9 +19,8 @@ void main () { ...@@ -19,9 +19,8 @@ void main () {
} }
}); });
class Add extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, children }) => {
const { width, height, children } = this.props;
if (!children || children.length !== 2) throw new Error("You must provide 2 children to Add"); if (!children || children.length !== 2) throw new Error("You must provide 2 children to Add");
const [t1, t2] = children; const [t1, t2] = children;
return <GL.View return <GL.View
...@@ -30,7 +29,4 @@ class Add extends GL.Component { ...@@ -30,7 +29,4 @@ class Add extends GL.Component {
height={height} height={height}
uniforms={{ t1, t2 }} uniforms={{ t1, t2 }}
/>; />;
} }, { displayName: "Add" });
}
module.exports = Add;
...@@ -26,28 +26,25 @@ function directionForPass (p, factor, total) { ...@@ -26,28 +26,25 @@ function directionForPass (p, factor, total) {
- Powerful blur: - Powerful blur:
<Blur factor={20} passes={6} width={w} height={h}>{url}</Blur> <Blur factor={20} passes={6} width={w} height={h}>{url}</Blur>
*/ */
class Blur extends GL.Component {
render () { module.exports = GL.createComponent(
const { width, height, factor, children, passes } = this.props; ({ width, height, factor, children, passes }) => {
const rec = p => p <= 0 ? children : const rec = p => p <= 0 ? children :
<Blur1D width={width} height={height} direction={directionForPass(p, factor, passes)}> <Blur1D width={width} height={height} direction={directionForPass(p, factor, passes)}>
{rec(p-1)} {rec(p-1)}
</Blur1D>; </Blur1D>;
return rec(passes);
return rec(passes || 0); },
} {
} displayName: "Blur",
defaultProps: {
Blur.defaultProps = {
passes: 2 passes: 2
}; },
propTypes: {
Blur.propTypes = {
width: PropTypes.number, width: PropTypes.number,
height: PropTypes.number, height: PropTypes.number,
factor: PropTypes.number.isRequired, factor: PropTypes.number.isRequired,
children: PropTypes.any.isRequired, children: PropTypes.any.isRequired,
passes: PropTypes.number passes: PropTypes.number
}; }
});
module.exports = Blur;
...@@ -32,10 +32,9 @@ void main () { ...@@ -32,10 +32,9 @@ void main () {
} }
}); });
class Blur1D extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, direction, children }) =>
const { width, height, direction, children } = this.props; <GL.View
return <GL.View
shader={shaders.blur1D} shader={shaders.blur1D}
width={width} width={width}
height={height} height={height}
...@@ -44,15 +43,7 @@ class Blur1D extends GL.Component { ...@@ -44,15 +43,7 @@ class Blur1D extends GL.Component {
resolution: [ width, height ] resolution: [ width, height ]
}}> }}>
<GL.Uniform name="t">{children}</GL.Uniform> <GL.Uniform name="t">{children}</GL.Uniform>
</GL.View>; </GL.View>
} , {
} displayName: "Blur1D"
});
Blur1D.propTypes = {
width: PropTypes.number,
height: PropTypes.number,
direction: PropTypes.array.isRequired,
children: PropTypes.any.isRequired
};
module.exports = Blur1D;
...@@ -21,17 +21,14 @@ void main () { ...@@ -21,17 +21,14 @@ void main () {
} }
}); });
class Copy extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, children: t, last, ...rest }) =>
const { width, height, children: t, last, ...rest } = this.props; <GL.View
return <GL.View
{...rest} {...rest}
shader={shaders.Copy} shader={shaders.Copy}
width={width} width={width}
height={height} height={height}
uniforms={{ t, preventAlphaMult: !last }} uniforms={{ t, preventAlphaMult: !last }}
/>; />,
} { displayName: "Copy" }
} );
module.exports = Copy;
...@@ -22,9 +22,8 @@ void main () { ...@@ -22,9 +22,8 @@ void main () {
} }
}); });
class Display2 extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, children, vertical, ...rest }) => {
const { width, height, children, vertical, ...rest } = this.props;
if (!children || children.length !== 2) throw new Error("You must provide 2 children to Display2"); if (!children || children.length !== 2) throw new Error("You must provide 2 children to Display2");
let [t1, t2] = children; let [t1, t2] = children;
if (vertical) [t1,t2]=[t2,t1]; // just because webgl y's is reversed if (vertical) [t1,t2]=[t2,t1]; // just because webgl y's is reversed
...@@ -33,14 +32,11 @@ class Display2 extends GL.Component { ...@@ -33,14 +32,11 @@ class Display2 extends GL.Component {
shader={shaders.display2} shader={shaders.display2}
width={width} width={width}
height={height} height={height}
uniforms={{ t1, t2, vertical }} uniforms={{ t1, t2, vertical: !!vertical }}
debug={true} debug={true}
/>; />;
},
{
displayName: "Display2"
} }
} );
Display2.defaultProps = {
vertical: false
};
module.exports = Display2;
...@@ -14,15 +14,12 @@ void main () { // This function is called FOR EACH PIXEL ...@@ -14,15 +14,12 @@ void main () { // This function is called FOR EACH PIXEL
} }
}); });
class HelloGL extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height }) =>
const { width, height } = this.props; <GL.View
return <GL.View
shader={shaders.helloGL} shader={shaders.helloGL}
width={width} width={width}
height={height} height={height}
/>; />,
} { displayName: "HelloGL" }
} );
module.exports = HelloGL;
...@@ -19,9 +19,8 @@ void main () { ...@@ -19,9 +19,8 @@ void main () {
} }
}); });
class Layer extends GL.Component { module.exports = GL.createComponent(
render () { ({ children, ...rest }) => {
const { children, ...rest } = this.props;
if (!children || children.length !== 2) throw new Error("You must provide 2 children to Layer"); if (!children || children.length !== 2) throw new Error("You must provide 2 children to Layer");
const [t1, t2] = children; const [t1, t2] = children;
return <GL.View return <GL.View
...@@ -29,7 +28,8 @@ class Layer extends GL.Component { ...@@ -29,7 +28,8 @@ class Layer extends GL.Component {
shader={shaders.layer} shader={shaders.layer}
uniforms={{ t1, t2 }} uniforms={{ t1, t2 }}
/>; />;
},
{
displayName: "Layer"
} }
} );
module.exports = Layer;
...@@ -19,9 +19,8 @@ void main () { ...@@ -19,9 +19,8 @@ void main () {
} }
}); });
class Multiply extends GL.Component { module.exports = GL.createComponent(
render () { ({ width, height, children }) => {
const { width, height, children } = this.props;
if (!children || children.length !== 2) throw new Error("You must provide 2 children to Multiply"); if (!children || children.length !== 2) throw new Error("You must provide 2 children to Multiply");
const [t1, t2] = children; const [t1, t2] = children;
return <GL.View return <GL.View
...@@ -30,7 +29,5 @@ class Multiply extends GL.Component { ...@@ -30,7 +29,5 @@ class Multiply extends GL.Component {
height={height} height={height}
uniforms={{ t1, t2 }} uniforms={{ t1, t2 }}
/>; />;
} },
} { displayName: "Multiply" });
module.exports = Multiply;
const React = require("react-native");
const GL = require("gl-react-native");
const shaders = GL.Shaders.create({
Premultiply: {
frag: `
precision highp float;
varying vec2 uv;
uniform sampler2D t;
void main () {
vec4 c = texture2D(t, uv);
c.rgb *= c.a;
gl_FragColor = c;
}
`
}
});
class Premultiply extends GL.Component {
render () {
const { children: t, ...rest } = this.props;
return <GL.View
{...rest}
opaque={false}
shader={shaders.Premultiply}
uniforms={{ t }}
/>;
}
}
module.exports = Premultiply;
...@@ -16,16 +16,12 @@ void main () { ...@@ -16,16 +16,12 @@ void main () {
} }
}); });
class TransparentNonPremultiplied extends GL.Component { module.exports = GL.createComponent(
render () { ({ children: t, ...rest }) =>
const { children: t, ...rest } = this.props; <GL.View
return <GL.View
{...rest} {...rest}
opaque={false} opaque={false}
shader={shaders.TransparentNonPremultiplied} shader={shaders.TransparentNonPremultiplied}
uniforms={{ t }} uniforms={{ t }}
/>; />,
} { displayName: "TransparentNonPremultiplied" });
}
module.exports = TransparentNonPremultiplied;
for ex in */; do for ex in */; do
cd $ex; cd $ex;
rm -rf node_modules; #rm -rf node_modules;
npm i; #npm i;
npm i gl-react-native;
react-native bundle --minify; react-native bundle --minify;
cd ..; cd ..;
done; done;
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
"react-native": ">=0.9.0 <0.13.0" "react-native": ">=0.9.0 <0.13.0"
}, },
"dependencies": { "dependencies": {
"invariant": "2.1.0", "invariant": "2.1.1",
"react-native": ">=0.9.0 <0.13.0", "react-native": ">=0.9.0 <0.13.0",
"gl-react-core": "1.1.x" "gl-react-core": "1.2.x"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^1.3.1", "eslint": "^1.3.1",
......
const React = require("react-native");
const {createComponentDeprecated} = require("gl-react-core");
module.exports = createComponentDeprecated(React);
...@@ -2,7 +2,6 @@ const {createView} = require("gl-react-core"); ...@@ -2,7 +2,6 @@ const {createView} = require("gl-react-core");
const React = require("react-native"); const React = require("react-native");
const Shaders = require("./Shaders"); const Shaders = require("./Shaders");
const Uniform = require("./Uniform"); const Uniform = require("./Uniform");
const Component = require("./Component");
const { const {
requireNativeComponent, requireNativeComponent,
...@@ -46,7 +45,7 @@ const renderVcontainer = function ({ style, width, height }, contents, renderer) ...@@ -46,7 +45,7 @@ const renderVcontainer = function ({ style, width, height }, contents, renderer)
</View>; </View>;
}; };
const GLView = createView(React, Shaders, Uniform, Component, renderVcontainer, renderVcontent, renderVGL); const GLView = createView(React, Shaders, Uniform, renderVcontainer, renderVcontent, renderVGL);
GLView.prototype.setNativeProps = function (props) { GLView.prototype.setNativeProps = function (props) {
this.refs.native.setNativeProps(props); this.refs.native.setNativeProps(props);
......
const React = require("react-native"); const React = require("react-native");
const View = require("./View");
const {createComponent} = require("gl-react-core"); const {createComponent} = require("gl-react-core");
module.exports = createComponent(React); module.exports = createComponent(React, View);
const Shaders = require("./Shaders"); const Shaders = require("./Shaders");
const View = require("./View"); const View = require("./View");
const Uniform = require("./Uniform"); const Uniform = require("./Uniform");
const Component = require("./Component"); const Component = require("./ComponentDeprecated");
const createComponent = require("./createComponent");
module.exports = { module.exports = {
Shaders, Shaders,
View, View,
Uniform, Uniform,
Component Component,
createComponent
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment