mirror of
https://github.com/gre/gl-react.git
synced 2026-01-25 16:43:36 +00:00
Update Component.md
This commit is contained in:
parent
ab7677f53a
commit
adf86f73d5
@ -13,12 +13,28 @@ class MyEffect extends GL.Component {
|
||||
`GL.Component` allows to **compose** effects:
|
||||
it tells the `gl-react-core` algorithm to "unfold" the `render()` looking for a `GL.View` to merge with.
|
||||
|
||||
> Technically, this is not required to extend `GL.Component` (you can still use `React.Component`),
|
||||
but this is generally a good idea (you always want to make a component "composable").
|
||||
> Although it is technically not required to extend `GL.Component` (you can still use `React.Component`),
|
||||
this is generally a good idea because you always want to make a component "composable".
|
||||
|
||||
## Composing effects
|
||||
|
||||
Once you have defined your component that inject children, you can then compose it with another.
|
||||
Effects component can be implemented as follow:
|
||||
|
||||
```js
|
||||
// Assuming we have defined a shaders.myEffect, where the frag have:
|
||||
// a `tex` sampler2D uniform
|
||||
// a `someParam` uniform
|
||||
class MyEffect extends GL.Component {
|
||||
render () {
|
||||
const { width, height, children, someParam } = this.props;
|
||||
return <GL.View shader={shaders.myEffect} width={width} height={height} uniforms={{ someParam }}>
|
||||
<GL.Target uniform="tex">{children}</GL.Target>
|
||||
</GL.View>;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Once you have defined effect components that inject `children` (let's say `Blur` and `Negative`), you can compose them together.
|
||||
|
||||
**Example:**
|
||||
|
||||
@ -30,7 +46,7 @@ Once you have defined your component that inject children, you can then compose
|
||||
</Blur>
|
||||
```
|
||||
|
||||
and you can make generic component out of it:
|
||||
and define another generic component out of it:
|
||||
|
||||
```js
|
||||
class BlurNegative extends GL.Component {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user