@@ -231,6 +231,76 @@ suite('p5.RendererGL', function() {
231231 } ) ;
232232 } ) ;
233233
234+ suite ( 'GL Renderer clear()' , function ( ) {
235+ var pg ;
236+ var pixel ;
237+ test ( 'webgl graphics background draws into webgl canvas' , function ( done ) {
238+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
239+ myp5 . background ( 0 , 255 , 255 , 255 ) ;
240+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
241+ pg . background ( 0 ) ;
242+ myp5 . image ( pg , - myp5 . width / 2 , - myp5 . height / 2 ) ;
243+ pixel = myp5 . get ( 0 , 0 ) ;
244+ assert . deepEqual ( pixel , [ 0 , 0 , 0 , 255 ] ) ;
245+ done ( ) ;
246+ } ) ;
247+
248+ test ( 'transparent GL graphics with GL canvas' , function ( done ) {
249+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
250+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
251+ myp5 . background ( 0 , 255 , 255 ) ;
252+ pg . clear ( ) ;
253+ myp5 . image ( pg , - myp5 . width / 2 , - myp5 . height / 2 ) ;
254+ pixel = myp5 . get ( 0 , 0 ) ;
255+ assert . deepEqual ( pixel , [ 0 , 255 , 255 , 255 ] ) ;
256+ done ( ) ;
257+ } ) ;
258+
259+ test ( 'semi-transparent GL graphics with GL canvas' , function ( done ) {
260+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
261+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
262+ myp5 . background ( 0 , 255 , 255 ) ;
263+ pg . background ( 100 , 100 , 100 , 100 ) ;
264+ myp5 . image ( pg , - myp5 . width / 2 , - myp5 . height / 2 ) ;
265+ pixel = myp5 . get ( 0 , 0 ) ;
266+ assert . deepEqual ( pixel , [ 39 , 194 , 194 , 194 ] ) ;
267+ done ( ) ;
268+ } ) ;
269+
270+ test ( 'webgl graphics background draws into 2D canvas' , function ( done ) {
271+ myp5 . createCanvas ( 50 , 50 ) ;
272+ myp5 . background ( 0 , 255 , 255 , 255 ) ;
273+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
274+ pg . background ( 0 ) ;
275+ myp5 . image ( pg , 0 , 0 ) ;
276+ pixel = myp5 . get ( 0 , 0 ) ;
277+ assert . deepEqual ( pixel , [ 0 , 0 , 0 , 255 ] ) ;
278+ done ( ) ;
279+ } ) ;
280+
281+ test ( 'transparent GL graphics with 2D canvas' , function ( done ) {
282+ myp5 . createCanvas ( 50 , 50 ) ;
283+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
284+ myp5 . background ( 0 , 255 , 255 ) ;
285+ pg . clear ( ) ;
286+ myp5 . image ( pg , 0 , 0 ) ;
287+ pixel = myp5 . get ( 0 , 0 ) ;
288+ assert . deepEqual ( pixel , [ 0 , 255 , 255 , 255 ] ) ;
289+ done ( ) ;
290+ } ) ;
291+
292+ test ( 'semi-transparent GL graphics with 2D canvas' , function ( done ) {
293+ myp5 . createCanvas ( 50 , 50 ) ;
294+ pg = myp5 . createGraphics ( 25 , 50 , myp5 . WEBGL ) ;
295+ myp5 . background ( 0 , 255 , 255 ) ;
296+ pg . background ( 100 , 100 , 100 , 100 ) ;
297+ myp5 . image ( pg , 0 , 0 ) ;
298+ pixel = myp5 . get ( 0 , 0 ) ;
299+ assert . deepEqual ( pixel , [ 39 , 194 , 194 , 255 ] ) ;
300+ done ( ) ;
301+ } ) ;
302+ } ) ;
303+
234304 suite ( 'blendMode()' , function ( ) {
235305 var testBlend = function ( mode , intended ) {
236306 myp5 . blendMode ( mode ) ;
@@ -274,8 +344,8 @@ suite('p5.RendererGL', function() {
274344 test ( 'blendModes change pixel colors as expected' , function ( done ) {
275345 myp5 . createCanvas ( 10 , 10 , myp5 . WEBGL ) ;
276346 myp5 . noStroke ( ) ;
277- assert . deepEqual ( [ 133 , 69 , 191 , 255 ] , mixAndReturn ( myp5 . ADD , 255 ) ) ;
278- assert . deepEqual ( [ 0 , 0 , 255 , 255 ] , mixAndReturn ( myp5 . REPLACE , 255 ) ) ;
347+ assert . deepEqual ( [ 133 , 69 , 191 , 158 ] , mixAndReturn ( myp5 . ADD , 255 ) ) ;
348+ assert . deepEqual ( [ 0 , 0 , 255 , 122 ] , mixAndReturn ( myp5 . REPLACE , 255 ) ) ;
279349 assert . deepEqual ( [ 133 , 255 , 133 , 255 ] , mixAndReturn ( myp5 . SUBTRACT , 255 ) ) ;
280350 assert . deepEqual ( [ 255 , 0 , 255 , 255 ] , mixAndReturn ( myp5 . SCREEN , 0 ) ) ;
281351 assert . deepEqual ( [ 0 , 255 , 0 , 255 ] , mixAndReturn ( myp5 . EXCLUSION , 255 ) ) ;
0 commit comments