Skip to content

Commit 7c8211b

Browse files
authored
Merge pull request #8857 from eupthere/shader-version-regex
Fix WebGL shader version regex
2 parents 5c31a02 + 38e6203 commit 7c8211b

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/webgl/p5.Shader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Shader {
9999
* @returns {String} The GLSL version used by the shader.
100100
*/
101101
version() {
102-
const match = /#version (.+)$/.exec(this.vertSrc());
102+
const match = /#version (.+)$/m.exec(this.vertSrc());
103103
if (match) {
104104
return match[1];
105105
} else {

test/unit/webgl/p5.Shader.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,29 @@ suite('p5.Shader', function() {
244244
var curShader = myp5._renderer.states.userFillShader;
245245
assert.isTrue(curShader === null);
246246
});
247+
test('version() detects a #version directive', function() {
248+
const shader = myp5.createShader(
249+
`
250+
#version 300 es
251+
precision highp float;
252+
attribute vec3 aPosition;
253+
uniform mat4 uModelViewMatrix;
254+
uniform mat4 uProjectionMatrix;
255+
256+
void main() {
257+
gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
258+
}
259+
`,
260+
`
261+
precision highp float;
262+
263+
void main() {
264+
gl_FragColor = vec4(1.0);
265+
}
266+
`
267+
);
268+
assert.strictEqual(shader.version(), '300 es');
269+
});
247270
suite('Hooks', function() {
248271
let myShader;
249272
beforeEach(function() {

0 commit comments

Comments
 (0)