Skip to content

Commit 3f24498

Browse files
Merge pull request #9 from rreusser/glsl-success
Get glslify working with ify-loader
2 parents 5d5b0b7 + 9075fd6 commit 3f24498

File tree

8 files changed

+92
-1
lines changed

8 files changed

+92
-1
lines changed

fixtures/glsl/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const glsl = require('glslify')
2+
3+
console.log(glsl`
4+
precision mediump float;
5+
#pragma glslify: ones = require(./ones)
6+
void main () {
7+
gl_FragColor = ones();
8+
}
9+
`)

fixtures/glsl/ones.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vec4 ones () {
2+
return vec4(1);
3+
}
4+
#pragma glslify: export(ones)

fixtures/glsl/output.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
precision mediump float;
3+
#define GLSLIFY 1
4+
#define GLSLIFY 1
5+
vec4 ones () {
6+
return vec4(1);
7+
}
8+
9+
void main () {
10+
gl_FragColor = ones();
11+
}
12+
,

fixtures/glsl/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "fixture",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "../../node_modules/.bin/webpack webpack.config.js"
6+
},
7+
"browserify": {
8+
"transform": [
9+
"glslify"
10+
]
11+
}
12+
}

fixtures/glsl/webpack.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
entry: './index.js',
5+
output: {
6+
path: __dirname,
7+
filename: 'bundle.js'
8+
},
9+
module: {
10+
rules: [{
11+
test: /\.js/,
12+
use: path.join(__dirname, '..', '..')
13+
}]
14+
}
15+
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function loader (source) {
3737

3838
const name = transform[0]
3939
const opts = transform[1] || {}
40+
opts._flags = opts._flags || []
4041

4142
if (typeof name === 'function') {
4243
return next(null, name(filename, opts))

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
},
2121
"devDependencies": {
2222
"brfs": "^1.4.2",
23+
"from2-string": "^1.1.0",
24+
"glslify": "^6.1.0",
2325
"npm-which": "^2.0.0",
2426
"regl": "^1.3.0",
2527
"standard": "^5.4.1",
2628
"tap-spec": "^4.1.1",
2729
"tape": "^4.4.0",
2830
"through2": "^2.0.0",
29-
"webpack": "^2.2.1"
31+
"webpack": "^3.4.0"
3032
},
3133
"scripts": {
3234
"test": "node test.js | tspec",

test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,39 @@ test('error handling', function (t) {
8787
t.equal(code, 2, 'exit code was 2')
8888
})
8989
})
90+
91+
test('glsl-transform', function (t) {
92+
const wpack = which.sync('webpack', { cwd: __dirname })
93+
const output = path.join(__dirname, 'fixtures', 'glsl', 'bundle.js')
94+
const config = path.join(__dirname, 'fixtures', 'glsl', 'webpack.config.js')
95+
const fixture = path.join(__dirname, 'fixtures', 'glsl', 'output.txt')
96+
97+
t.plan(1)
98+
99+
try {
100+
fs.unlinkSync(output)
101+
} catch (e) {}
102+
103+
spawn(wpack, [
104+
'--module-bind', 'js=' + __dirname,
105+
'--config',
106+
config
107+
], {
108+
cwd: path.join(__dirname, 'fixtures', 'glsl'),
109+
stdio: ['pipe', 'pipe', 2]
110+
}).once('exit', function () {
111+
const result = fs.readFileSync(output, { encoding: 'utf8' })
112+
113+
fs.unlinkSync(output)
114+
115+
vm.runInNewContext(result, {
116+
console: {
117+
log: function (shader) {
118+
const expected = fs.readFileSync(fixture, { encoding: 'utf8' })
119+
t.equal(shader + '\n', expected, 'processed brfs from package.json')
120+
}
121+
}
122+
})
123+
})
124+
})
125+

0 commit comments

Comments
 (0)