Skip to content

Commit 8e3447f

Browse files
committed
fix createProgram for getting passed WebGLShaders
1 parent e962455 commit 8e3447f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/programs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ function createProgramNoCheck(gl, shaders, programOptions) {
727727
shader = gl.createShader(type);
728728
gl.shaderSource(shader, prepShaderSource(src).shaderSource);
729729
gl.compileShader(shader);
730-
gl.attachShader(program, shader);
731730
}
731+
gl.attachShader(program, shader);
732732
}
733733

734734
Object.entries(attribLocations).forEach(([attrib, loc]) => gl.bindAttribLocation(program, loc, attrib));

test/tests/program-tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,22 @@ describe('program tests', () => {
348348
assertTruthy(msgCapturer.hasMsgs());
349349
});
350350

351+
itWebGL('succeeds with good existing shaders', () => {
352+
const {gl} = createContext();
353+
const msgCapturer = new MsgCapturer();
354+
const vs = gl.createShader(gl.VERTEX_SHADER);
355+
gl.shaderSource(vs, `void main() { gl_Position = vec4(0); }`);
356+
gl.compileShader(vs);
357+
const fs = gl.createShader(gl.FRAGMENT_SHADER);
358+
gl.shaderSource(fs, `precision mediump float; void main() { gl_FragColor = vec4(0); }`);
359+
gl.compileShader(fs);
360+
const program = twgl.createProgram(gl, [vs, fs], {
361+
errorCallback: msgCapturer.cb,
362+
});
363+
assertTruthy(program instanceof WebGLProgram);
364+
assertFalsy(msgCapturer.hasMsgs());
365+
});
366+
351367
itWebGL('compiles program async with callback', function(done) {
352368
const {gl} = createContext();
353369
const program = twgl.createProgram(gl, [

0 commit comments

Comments
 (0)