Skip to content

Commit d757f79

Browse files
committed
Live previews of BOS shaders
1 parent c0c40d9 commit d757f79

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

cfg/dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ config.module.loaders.push({
3838
loader: 'babel-loader',
3939
include: [].concat(
4040
config.additionalPaths,
41-
[ path.join(__dirname, '/../src') ]
41+
[ path.join(__dirname, '/../src') ],
42+
[ path.join(__dirname, '/../node_modules/glslCanvas') ]
4243
)
4344
});
4445

src/containers/ArtworkDetailContainer.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ class ArtworkDetailContainer extends Component {
3535
}
3636

3737
componentWillReceiveProps(nextProps) {
38-
console.log('nextProps', nextProps);
3938
this.setState({
4039
thumb_url: nextProps.singleArtwork && nextProps.singleArtwork.thumb_url || noThumbImg
4140
});
4241
}
4342

43+
componentDidUpdate() {
44+
if (this.canvas && !this.glslCanvas) {
45+
this.glslCanvas = new GlslCanvas(this.canvas);
46+
}
47+
}
48+
4449
_formatDisplayName(format) {
4550
switch (format) {
4651
case 'openframe-glslviewer':
@@ -50,6 +55,23 @@ class ArtworkDetailContainer extends Component {
5055
}
5156
}
5257

58+
_getPreviewElement() {
59+
const url = this.props.singleArtwork.url;
60+
const re = /thebookofshaders\.com/i;
61+
const bos = url.match(re);
62+
if (bos) {
63+
return (<canvas
64+
ref={(canvas) => { this.canvas = canvas; }}
65+
className="artwork-detail__canvas"
66+
data-fragment-url={url}
67+
width="1000"
68+
height="1000"></canvas>);
69+
70+
} else {
71+
return (<img className="artwork-detail__img" src={this.state.thumb_url} onError={::this._imageError} />);
72+
}
73+
}
74+
5375
_handlePushClick(e) {
5476
e.preventDefault();
5577
let {params, actions, isAuthenticated} = this.props;
@@ -111,7 +133,9 @@ class ArtworkDetailContainer extends Component {
111133
<div className="artwork-detail__author">by {singleArtwork.author_name}</div>
112134
</div>
113135

114-
<img className="artwork-detail__img" src={this.state.thumb_url} onError={::this._imageError} />
136+
{
137+
::this._getPreviewElement(this.state.thumb_url)
138+
}
115139

116140
<div className="artwork-detail__info">
117141

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import FeatureFlagsContainer from './containers/FeatureFlagsContainer';
2121
import VerifiedEmailContainer from './containers/VerifiedEmailContainer';
2222
import ResetPasswordContainer from './containers/ResetPasswordContainer';
2323

24+
import GlslCanvas from '../node_modules/glslCanvas/src/GlslCanvas.js';
25+
2426
require('./images/touch-icon-iphone.png');
2527
require('./images/touch-icon-ipad.png');
2628
require('./images/touch-icon-iphone-retina.png');

src/styles/artwork/ArtworkDetail.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
margin: 20px 0;
4242
}
4343

44+
&__canvas {
45+
width: 100%;
46+
margin: 20px 0;
47+
border: none;
48+
}
49+
4450
&__label {
4551
font-size: 14px;
4652
color: #aaa;

0 commit comments

Comments
 (0)