@@ -12,6 +12,7 @@ import {
12
12
createContext2 ,
13
13
checkColor ,
14
14
itWebGL ,
15
+ fnWithCallbackToPromise ,
15
16
} from '../webgl.js' ;
16
17
17
18
class MsgCapturer {
@@ -105,9 +106,9 @@ describe('program tests', () => {
105
106
assertTruthy ( msgCapturer . hasMsgs ( ) ) ;
106
107
} ) ;
107
108
108
- itWebGL ( 'works async with callback' , function ( done ) {
109
+ itWebGL ( 'works async with callback' , async function ( ) {
109
110
const { gl} = createContext ( ) ;
110
- const programInfo = twgl . createProgramInfo ( gl , [
111
+ const programInfo = await fnWithCallbackToPromise ( twgl . createProgramInfo ) ( gl , [
111
112
`void main() {gl_Position = vec4(0); }` ,
112
113
`precision mediump float;
113
114
uniform vec4 u_foo;
@@ -122,16 +123,16 @@ describe('program tests', () => {
122
123
assertTruthy ( gl . getProgramParameter ( programInfo . program , gl . LINK_STATUS ) ) ;
123
124
gl . useProgram ( programInfo . program ) ;
124
125
gl . drawArrays ( gl . TRIANGLES , 0 , 3 ) ;
125
- done ( ) ;
126
+ assertNoWebGLError ( gl ) ;
126
127
} ,
127
128
} ) ;
128
129
assertFalsy ( programInfo ) ;
129
130
} ) ;
130
131
131
- itWebGL ( 'works async with callback with bad shader' , function ( done ) {
132
+ itWebGL ( 'works async with callback with bad shader' , async function ( ) {
132
133
const { gl} = createContext ( ) ;
133
134
const msgs = [ ] ;
134
- const programInfo = twgl . createProgramInfo ( gl , [
135
+ const programInfo = await fnWithCallbackToPromise ( twgl . createProgramInfo ) ( gl , [
135
136
`void main() {gl_Position = vec4(0); }` ,
136
137
`precision mediump float;
137
138
uniform vec4 u_foo;
@@ -146,16 +147,15 @@ describe('program tests', () => {
146
147
assertTruthy ( err ) ;
147
148
assertFalsy ( programInfo ) ;
148
149
assertTruthy ( msgs . length > 0 ) ;
149
- done ( ) ;
150
150
} ,
151
151
} ) ;
152
152
assertFalsy ( programInfo ) ;
153
153
} ) ;
154
154
155
- itWebGL ( 'works async with callback missing shader' , function ( done ) {
155
+ itWebGL ( 'works async with callback missing shader' , async function ( ) {
156
156
const { gl} = createContext ( ) ;
157
157
const msgs = [ ] ;
158
- const programInfo = twgl . createProgramInfo ( gl , [
158
+ const programInfo = await fnWithCallbackToPromise ( twgl . createProgramInfo ) ( gl , [
159
159
`void main() {gl_Position = vec4(0); }` ,
160
160
] , {
161
161
errorCallback ( msg ) {
@@ -165,7 +165,6 @@ describe('program tests', () => {
165
165
assertTruthy ( err ) ;
166
166
assertFalsy ( programInfo ) ;
167
167
assertTruthy ( msgs . length > 0 ) ;
168
- done ( ) ;
169
168
} ,
170
169
} ) ;
171
170
assertFalsy ( programInfo ) ;
@@ -364,9 +363,28 @@ describe('program tests', () => {
364
363
assertFalsy ( msgCapturer . hasMsgs ( ) ) ;
365
364
} ) ;
366
365
367
- itWebGL ( 'compiles program async with callback ' , function ( done ) {
366
+ itWebGL ( 'does not delete existing shaders ' , ( ) => {
368
367
const { gl} = createContext ( ) ;
369
- const program = twgl . createProgram ( gl , [
368
+ const msgCapturer = new MsgCapturer ( ) ;
369
+ const vs = gl . createShader ( gl . VERTEX_SHADER ) ;
370
+ gl . shaderSource ( vs , `void main() { gl_Position = vec4(0); }` ) ;
371
+ gl . compileShader ( vs ) ;
372
+ const fsBad = `precision mediump float; void main() { gl_FragColorS = vec4(0); }` ;
373
+ const programBad = twgl . createProgram ( gl , [ vs , fsBad ] , {
374
+ errorCallback : ( ) => { } ,
375
+ } ) ;
376
+ assertFalsy ( programBad ) ;
377
+ const fsGood = `precision mediump float; void main() { gl_FragColor = vec4(0); }` ;
378
+ const programGood = twgl . createProgram ( gl , [ vs , fsGood ] , {
379
+ errorCallback : msgCapturer . cb ,
380
+ } ) ;
381
+ assertTruthy ( programGood instanceof WebGLProgram ) ;
382
+ assertFalsy ( msgCapturer . hasMsgs ( ) ) ;
383
+ } ) ;
384
+
385
+ itWebGL ( 'compiles program async with callback' , async function ( ) {
386
+ const { gl} = createContext ( ) ;
387
+ const program = await fnWithCallbackToPromise ( twgl . createProgram ) ( gl , [
370
388
`void main() { gl_Position = vec4(0); }` ,
371
389
`precision mediump float; void main() { gl_FragColor = vec4(0); }` ,
372
390
] , {
@@ -377,16 +395,15 @@ describe('program tests', () => {
377
395
gl . useProgram ( program ) ;
378
396
gl . drawArrays ( gl . TRIANGLES , 0 , 3 ) ;
379
397
assertEqual ( gl . getError ( ) , gl . NONE ) ;
380
- done ( ) ;
381
398
} ,
382
399
} ) ;
383
400
assertFalsy ( program ) ; // nothing is returned if callback
384
401
} ) ;
385
402
386
- itWebGL ( 'compiles program async with callback with error' , function ( done ) {
403
+ itWebGL ( 'compiles program async with callback with error' , async function ( ) {
387
404
const { gl} = createContext ( ) ;
388
405
const msgs = [ ] ;
389
- const program = twgl . createProgram ( gl , [
406
+ const program = await fnWithCallbackToPromise ( twgl . createProgram ) ( gl , [
390
407
`void main() { gl_Position = vec4(0); }` ,
391
408
`precision mediump float; void main() { gl_Frag Color = vec4(0); }` ,
392
409
] , {
@@ -397,7 +414,6 @@ describe('program tests', () => {
397
414
assertTruthy ( err ) ;
398
415
assertFalsy ( program ) ;
399
416
assertTruthy ( msgs . length > 0 ) ;
400
- done ( ) ;
401
417
} ,
402
418
} ) ;
403
419
assertFalsy ( program ) ; // nothing is returned if callback
@@ -1017,9 +1033,9 @@ describe('program tests', () => {
1017
1033
assertTruthy ( msgCapturer . hasMsgs ( ) ) ;
1018
1034
} ) ;
1019
1035
1020
- itWebGL ( 'compiles program async with callback' , function ( done ) {
1036
+ itWebGL ( 'compiles program async with callback' , async function ( ) {
1021
1037
const { gl} = createContext ( ) ;
1022
- const program = twgl . createProgramFromScripts ( gl , addShaderScripts ( [
1038
+ const program = await fnWithCallbackToPromise ( twgl . createProgramFromScripts ) ( gl , addShaderScripts ( [
1023
1039
`void main() { gl_Position = vec4(0); }` ,
1024
1040
`precision mediump float; void main() { gl_FragColor = vec4(0); }` ,
1025
1041
] ) , {
@@ -1030,16 +1046,15 @@ describe('program tests', () => {
1030
1046
gl . useProgram ( program ) ;
1031
1047
gl . drawArrays ( gl . TRIANGLES , 0 , 3 ) ;
1032
1048
assertEqual ( gl . getError ( ) , gl . NONE ) ;
1033
- done ( ) ;
1034
1049
} ,
1035
1050
} ) ;
1036
1051
assertFalsy ( program ) ; // nothing is returned if callback
1037
1052
} ) ;
1038
1053
1039
- itWebGL ( 'compiles program async with callback with error' , function ( done ) {
1054
+ itWebGL ( 'compiles program async with callback with error' , async function ( ) {
1040
1055
const { gl} = createContext ( ) ;
1041
1056
const msgs = [ ] ;
1042
- const program = twgl . createProgramFromScripts ( gl , addShaderScripts ( [
1057
+ const program = await fnWithCallbackToPromise ( twgl . createProgramFromScripts ) ( gl , addShaderScripts ( [
1043
1058
`void main() { gl_Position = vec4(0); }` ,
1044
1059
`precision mediump float; void main() { gl_Frag Color = vec4(0); }` ,
1045
1060
] ) , {
@@ -1050,16 +1065,15 @@ describe('program tests', () => {
1050
1065
assertTruthy ( err ) ;
1051
1066
assertFalsy ( program ) ;
1052
1067
assertTruthy ( msgs . length > 0 ) ;
1053
- done ( ) ;
1054
1068
} ,
1055
1069
} ) ;
1056
1070
assertFalsy ( program ) ; // nothing is returned if callback
1057
1071
} ) ;
1058
1072
1059
- itWebGL ( 'compiles program async with callback with bad ids' , function ( done ) {
1073
+ itWebGL ( 'compiles program async with callback with bad ids' , async function ( ) {
1060
1074
const { gl} = createContext ( ) ;
1061
1075
const msgs = [ ] ;
1062
- const program = twgl . createProgramFromScripts ( gl , addShaderScripts ( [
1076
+ const program = await fnWithCallbackToPromise ( twgl . createProgramFromScripts ) ( gl , addShaderScripts ( [
1063
1077
`idThatDoesNotExist` ,
1064
1078
] ) , {
1065
1079
errorCallback ( msg ) {
@@ -1069,7 +1083,6 @@ describe('program tests', () => {
1069
1083
assertTruthy ( err ) ;
1070
1084
assertFalsy ( program ) ;
1071
1085
assertTruthy ( msgs . length > 0 ) ;
1072
- done ( ) ;
1073
1086
} ,
1074
1087
} ) ;
1075
1088
assertFalsy ( program ) ; // nothing is returned if callback
@@ -1117,9 +1130,9 @@ describe('program tests', () => {
1117
1130
assertTruthy ( msgCapturer . hasMsgs ( ) ) ;
1118
1131
} ) ;
1119
1132
1120
- itWebGL ( 'compiles program async with callback' , function ( done ) {
1133
+ itWebGL ( 'compiles program async with callback' , async function ( ) {
1121
1134
const { gl} = createContext ( ) ;
1122
- const program = twgl . createProgramFromSources ( gl , [
1135
+ const program = await fnWithCallbackToPromise ( twgl . createProgramFromSources ) ( gl , [
1123
1136
`void main() { gl_Position = vec4(0); }` ,
1124
1137
`precision mediump float; void main() { gl_FragColor = vec4(0); }` ,
1125
1138
] , {
@@ -1130,16 +1143,15 @@ describe('program tests', () => {
1130
1143
gl . useProgram ( program ) ;
1131
1144
gl . drawArrays ( gl . TRIANGLES , 0 , 3 ) ;
1132
1145
assertEqual ( gl . getError ( ) , gl . NONE ) ;
1133
- done ( ) ;
1134
1146
} ,
1135
1147
} ) ;
1136
1148
assertFalsy ( program ) ; // nothing is returned if callback
1137
1149
} ) ;
1138
1150
1139
- itWebGL ( 'compiles program async with callback with error' , function ( done ) {
1151
+ itWebGL ( 'compiles program async with callback with error' , async function ( ) {
1140
1152
const { gl} = createContext ( ) ;
1141
1153
const msgs = [ ] ;
1142
- const program = twgl . createProgramFromSources ( gl , [
1154
+ const program = await fnWithCallbackToPromise ( twgl . createProgramFromSources ) ( gl , [
1143
1155
`void main() { gl_Position = vec4(0); }` ,
1144
1156
`precision mediump float; void main() { gl_Frag Color = vec4(0); }` ,
1145
1157
] , {
@@ -1150,7 +1162,6 @@ describe('program tests', () => {
1150
1162
assertTruthy ( err ) ;
1151
1163
assertFalsy ( program ) ;
1152
1164
assertTruthy ( msgs . length > 0 ) ;
1153
- done ( ) ;
1154
1165
} ,
1155
1166
} ) ;
1156
1167
assertFalsy ( program ) ; // nothing is returned if callback
0 commit comments