Created
September 1, 2018 16:38
-
-
Save kevzettler/922b8c1670a3deac52db57099fc68ab6 to your computer and use it in GitHub Desktop.
React-regl resource interfaces
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
//The following examples demonstrate the current and potential interfaces for rendering a texture | |
//1 Current external resource initilization | |
// Needs a reference to the `regl` object to create `regl.texture` | |
// results in some weird handshake where `Regl` component needs to initialize and pass `regl` object around | |
class ThreeDThing extends React.Component{ | |
constructor(){ | |
super(props) | |
this.state.reglRef = null | |
} | |
reglInitHandler(regl){ | |
this.setState({ | |
reglRef: regl | |
}); | |
} | |
render(){ | |
return ( | |
<Regl onReglInit={this.reglInitHandler}> | |
{this.state.reglRef ? | |
<Draw | |
vert={...} | |
frag={...} | |
attributes={...} | |
uniform={ | |
tex: this.state.reglRef.texture({ | |
data: ..., | |
mag: 'linear', | |
min: 'linear' | |
}) | |
} | |
/> | |
: null} | |
</Regl> | |
); | |
} | |
} | |
// 2 potentiel interface in which react-regl infers the resource creation from passed pops | |
// `tex` is passed props that "look like a texture" and `Regl` component initializes `regl.texture` internally | |
const derp = () => { | |
return ( | |
<Regl> | |
<Draw | |
vert={...} | |
frag={...} | |
attributes={...} | |
uniform={ | |
tex: { | |
data: ..., | |
mag: 'linear', | |
min: 'linear' | |
} | |
} | |
/> | |
</Regl> | |
); | |
} | |
//3 potentiel interface in which react-regl infers resource creation from child components | |
const derp = () => { | |
return ( | |
<Regl> | |
<Draw | |
vert={...} | |
frag={...} | |
attributes={...}> | |
<Uniform id="text"> | |
<Texture | |
data={...} | |
mag: "linear", | |
min: "linear", | |
/> | |
</Uniform> | |
</Draw> | |
</Regl> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment