Commit f2fc9bf0 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

better example and bugfix

parent 27e53817
...@@ -3,6 +3,7 @@ const { ...@@ -3,6 +3,7 @@ const {
AppRegistry, AppRegistry,
StyleSheet, StyleSheet,
View, View,
Text,
} = React; } = React;
const Video = require("react-native-video").default; const Video = require("react-native-video").default;
const { const {
...@@ -37,20 +38,32 @@ class App extends React.Component { ...@@ -37,20 +38,32 @@ class App extends React.Component {
this.state = { this.state = {
blur: 0, blur: 0,
blurPasses: 2, blurPasses: 2,
hue: 0 hue: 0,
mode: 0
}; };
} }
render () { render () {
const { blur, hue, blurPasses } = this.state; const { blur, hue, blurPasses, mode } = this.state;
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Surface autoRedraw eventsThrough width={width} height={height}> <Surface pixelRatio={1} width={640} height={480} autoRedraw eventsThrough width={width} height={height}>
<Blur passes={blurPasses} factor={blur}> <Blur passes={blurPasses} factor={blur}>
<HueRotate hue={hue}> <HueRotate hue={hue}>
<Video source={{ uri: "video" }} repeat style={styles.video} /> { mode === 0 ?
<Video source={{ uri: "video" }} repeat style={styles.video} /> :
mode === 1 ?
<View style={{ flex: 1, backgroundColor: "#fff", padding: 10 }}>
<Text style={{ fontSize: 80, color: "#F00" }}>Hello</Text>
<Text style={{ fontSize: 60, color: "#00F" }}>World</Text>
</View> :
mode === 2 ?
"http://i.imgur.com/2Go2D7i.jpg"
: null
}
</HueRotate> </HueRotate>
</Blur> </Blur>
</Surface> </Surface>
<Field min={0} max={3} step={1} value={mode} onChange={mode => this.setState({ mode })} name="Content" width={width} />
<Field min={0} max={2*Math.PI} value={hue} onChange={hue => this.setState({ hue })} name="Hue" width={width} /> <Field min={0} max={2*Math.PI} value={hue} onChange={hue => this.setState({ hue })} name="Hue" width={width} />
<Field min={0} max={16} value={blur} onChange={blur => this.setState({ blur })} name="Blur" width={width} /> <Field min={0} max={16} value={blur} onChange={blur => this.setState({ blur })} name="Blur" width={width} />
<Field min={2} max={8} step={1} value={blurPasses} onChange={blurPasses => this.setState({ blurPasses })} name="Blur Passes" width={width} /> <Field min={2} max={8} step={1} value={blurPasses} onChange={blurPasses => this.setState({ blurPasses })} name="Blur Passes" width={width} />
......
...@@ -342,7 +342,7 @@ RCT_NOT_IMPLEMENTED(-init) ...@@ -342,7 +342,7 @@ RCT_NOT_IMPLEMENTED(-init)
imgData = [GLImageData genPixelsWithView:v withPixelRatio:self.contentScaleFactor]; imgData = [GLImageData genPixelsWithView:v withPixelRatio:self.contentScaleFactor];
} }
} }
if (imgData) rasterizedContent[i] = imgData; rasterizedContent[i] = imgData==nil ? [GLImageData empty] : imgData;
} }
_rasterizedContent = rasterizedContent; _rasterizedContent = rasterizedContent;
[self setNeedsDisplay]; [self setNeedsDisplay];
......
...@@ -384,7 +384,7 @@ GLuint compileShader (NSString* shaderName, NSString* shaderString, GLenum shade ...@@ -384,7 +384,7 @@ GLuint compileShader (NSString* shaderName, NSString* shaderString, GLenum shade
[self computeMeta]; [self computeMeta];
pointerLoc = glGetAttribLocation(program, "position"); pointerLoc = glGetAttribLocation(program, "_p");
glGenBuffers(1, &buffer); glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
......
...@@ -77,7 +77,7 @@ withOnCompile:(RCTResponseSenderBlock)onCompile ...@@ -77,7 +77,7 @@ withOnCompile:(RCTResponseSenderBlock)onCompile
_shaders[id] = shader; _shaders[id] = shader;
} }
static NSString* fullViewportVert = @"attribute vec2 position;varying vec2 uv;void main() {gl_Position = vec4(position,0.0,1.0);uv = vec2(0.5, 0.5) * (position+vec2(1.0, 1.0));}"; static NSString* fullViewportVert = @"attribute vec2 _p;varying vec2 uv;void main(){gl_Position = vec4(_p,0.,1.);uv=vec2(.5,.5)*(_p+vec2(1.,1.));}";
NSString* glTypeString (int type) { NSString* glTypeString (int type) {
switch (type) { switch (type) {
......
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