-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from gre/more-advanced-loop
Introduces Uniform.backbufferFrom(node)
- Loading branch information
Showing
14 changed files
with
491 additions
and
224 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//@flow | ||
import React, { Component } from "react"; | ||
import { NearestCopy, LinearCopy, Uniform } from "gl-react"; | ||
import { Surface } from "gl-react-dom"; | ||
import { BlurXY } from "../blurxy"; | ||
import { images } from "./meta"; | ||
import timeLoop from "../../HOC/timeLoop"; | ||
|
||
const ContinuousBlur = timeLoop(BlurXY); | ||
|
||
export default class Example extends Component { | ||
state = { | ||
buffering: false | ||
}; | ||
componentWillReceiveProps({ image, refreshId }: *) { | ||
if (image !== this.props.image || refreshId !== this.props.refreshId) { | ||
this.setState({ buffering: false }); // start again with the image | ||
} | ||
} | ||
onDraw = () => { | ||
if (!this.state.buffering) { | ||
// after a first draw without buffering, enable it back | ||
this.setState({ buffering: true }); | ||
} | ||
}; | ||
getMainBuffer = () => { | ||
const { main } = this.refs; | ||
return main ? Uniform.backbufferFrom(main.getNodeRef()) : null; | ||
}; | ||
render() { | ||
const { image, factor } = this.props; | ||
const { buffering } = this.state; | ||
return ( | ||
<Surface width={400} height={300} preload={images}> | ||
<NearestCopy> | ||
<LinearCopy backbuffering ref="main" onDraw={this.onDraw}> | ||
<ContinuousBlur factor={factor}> | ||
{!buffering ? image : this.getMainBuffer} | ||
</ContinuousBlur> | ||
</LinearCopy> | ||
</NearestCopy> | ||
</Surface> | ||
); | ||
} | ||
static defaultProps = { | ||
image: require("./1.jpg"), | ||
factor: 0, | ||
refreshId: 0 | ||
}; | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/cookbook/src/examples/blurfeedback/index.source.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports=`//@flow | ||
import React, { Component } from "react"; | ||
import { NearestCopy, LinearCopy, Uniform } from "gl-react"; | ||
import { Surface } from "gl-react-dom"; | ||
import { BlurXY } from "../blurxy"; | ||
import { images } from "./meta"; | ||
import timeLoop from "../../HOC/timeLoop"; | ||
const ContinuousBlur = timeLoop(BlurXY); | ||
export default class Example extends Component { | ||
state = { | ||
buffering: false | ||
}; | ||
componentWillReceiveProps({ image, refreshId }: *) { | ||
if (image !== this.props.image || refreshId !== this.props.refreshId) { | ||
this.setState({ buffering: false }); // start again with the image | ||
} | ||
} | ||
onDraw = () => { | ||
if (!this.state.buffering) { | ||
// after a first draw without buffering, enable it back | ||
this.setState({ buffering: true }); | ||
} | ||
}; | ||
getMainBuffer = () => { | ||
const { main } = this.refs; | ||
return main ? Uniform.backbufferFrom(main.getNodeRef()) : null; | ||
}; | ||
render() { | ||
const { image, factor } = this.props; | ||
const { buffering } = this.state; | ||
return ( | ||
<Surface width={400} height={300} preload={images}> | ||
<NearestCopy> | ||
<LinearCopy backbuffering ref="main" onDraw={this.onDraw}> | ||
<ContinuousBlur factor={factor}> | ||
{!buffering ? image : this.getMainBuffer} | ||
</ContinuousBlur> | ||
</LinearCopy> | ||
</NearestCopy> | ||
</Surface> | ||
); | ||
} | ||
static defaultProps = { | ||
image: require("./1.jpg"), | ||
factor: 0, | ||
refreshId: 0 | ||
}; | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import markdown from "../../markdown"; | ||
import ImagesPicker from "../../toolbox/ImagesPicker"; | ||
import makeFloatSlider from "../../toolbox/makeFloatSlider"; | ||
|
||
export const images = [ | ||
require("./1.jpg"), | ||
require("./2.jpg"), | ||
require("./3.jpg") | ||
]; | ||
|
||
export const toolbox = [ | ||
{ | ||
prop: "factor", | ||
title: "Blur", | ||
Editor: makeFloatSlider(0, 8, 0.2) | ||
}, | ||
{ | ||
prop: "image", | ||
title: "Image", | ||
Editor: ImagesPicker, | ||
style: { width: 400 }, | ||
imageStyle: { maxWidth: 56, maxHeight: 56, marginBottom: 16 }, | ||
images | ||
}, | ||
{ | ||
prop: "refreshId", | ||
title: "", | ||
Editor: ({ onChange, value }) => | ||
<button | ||
style={{ fontSize: "1.4em", lineHeight: "1.4em" }} | ||
onClick={() => onChange(value + 1)} | ||
> | ||
REFRESH | ||
</button> | ||
} | ||
]; | ||
|
||
export const title = "Blur feedback"; | ||
|
||
export const desc = markdown` | ||
buffering the result of a blur back to the source | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ blurmap | |
blurmapmouse | ||
blurmapdyn | ||
blurimgtitle | ||
blurfeedback | ||
gol | ||
golglider | ||
golrot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.