@@ -36,7 +36,9 @@ package starling.display
36
36
import starling.utils.Color ;
37
37
import starling.utils.MathUtil ;
38
38
import starling.utils.MatrixUtil ;
39
+ import starling.utils.Pool ;
39
40
import starling.utils.SystemUtil ;
41
+ import starling.utils.execute ;
40
42
41
43
use namespace starling_internal;
42
44
@@ -392,8 +394,8 @@ package starling.display
392
394
/** Draws the object into a BitmapData object.
393
395
*
394
396
* <p>This is achieved by drawing the object into the back buffer and then copying the
395
- * pixels of the back buffer into a texture. This also means that the returned bitmap
396
- * data cannot be bigger than the current viewPort .</p>
397
+ * pixels of the back buffer into a texture. Beware: image sizes bigger than the back
398
+ * buffer are only supported in AIR version 25 or higher and NOT in Flash Player .</p>
397
399
*
398
400
* @param out If you pass null, the object will be created for you.
399
401
* If you pass a BitmapData object, it should have the size of the
@@ -412,6 +414,8 @@ package starling.display
412
414
var scaleX : Number = viewPort. width / stageWidth ;
413
415
var scaleY : Number = viewPort. height / stageHeight ;
414
416
var backBufferScale: Number = painter. backBufferScaleFactor;
417
+ var totalScaleX: Number = scaleX * backBufferScale;
418
+ var totalScaleY: Number = scaleY * backBufferScale;
415
419
var projectionX: Number , projectionY: Number ;
416
420
var bounds : Rectangle ;
417
421
@@ -429,33 +433,63 @@ package starling.display
429
433
projectionX = bounds . x ;
430
434
projectionY = bounds . y ;
431
435
432
- out ||= new BitmapData (Math . ceil (bounds . width * scaleX * backBufferScale ),
433
- Math . ceil (bounds . height * scaleY * backBufferScale ));
436
+ out ||= new BitmapData (Math . ceil (bounds . width * totalScaleX ),
437
+ Math . ceil (bounds . height * totalScaleY ));
434
438
}
435
439
436
440
color = Color . multiply(color , alpha ); // premultiply alpha
437
441
438
- painter. clear (color , alpha );
439
442
painter. pushState();
440
443
painter. setupContextDefaults();
441
444
painter. state . renderTarget = null ;
442
445
painter. state . setModelviewMatricesToIdentity();
443
446
painter. setStateTo(transformationMatrix);
444
- painter. state . setProjectionMatrix(projectionX, projectionY,
445
- painter. backBufferWidth / scaleX , painter. backBufferHeight / scaleY ,
446
- stageWidth , stageHeight , stage . cameraPosition);
447
447
448
- if ( _mask ) painter . drawMask( mask , this ) ;
448
+ // Images that are bigger than the current back buffer are drawn in multiple steps.
449
449
450
- if (_filter ) _filter . render(painter);
451
- else render(painter);
450
+ var stepX: Number ;
451
+ var stepY: Number = projectionY;
452
+ var stepWidth: Number = painter. backBufferWidth / scaleX ;
453
+ var stepHeight: Number = painter. backBufferHeight / scaleY ;
454
+ var positionInBitmap: Point = Pool. getPoint(0 , 0 );
455
+ var boundsInBuffer: Rectangle = Pool. getRectangle (0 , 0 ,
456
+ painter. backBufferWidth * backBufferScale,
457
+ painter. backBufferHeight * backBufferScale);
452
458
453
- if (_mask ) painter. eraseMask(mask , this );
459
+ while (positionInBitmap. y < out. height )
460
+ {
461
+ stepX = projectionX;
462
+ positionInBitmap. x = 0 ;
463
+
464
+ while (positionInBitmap. x < out. width )
465
+ {
466
+ painter. clear (color , alpha );
467
+ painter. state . setProjectionMatrix(stepX, stepY, stepWidth, stepHeight,
468
+ stageWidth , stageHeight , stage . cameraPosition);
469
+
470
+ if (_mask ) painter. drawMask(mask , this );
471
+
472
+ if (_filter ) _filter . render(painter);
473
+ else render(painter);
474
+
475
+ if (_mask ) painter. eraseMask(mask , this );
476
+
477
+ painter. finishMeshBatch();
478
+ execute (painter. context. drawToBitmapData, out, boundsInBuffer, positionInBitmap);
479
+
480
+ stepX += stepWidth;
481
+ positionInBitmap. x += stepWidth * totalScaleX;
482
+ }
483
+
484
+ stepY += stepHeight;
485
+ positionInBitmap. y += stepHeight * totalScaleY;
486
+ }
454
487
455
- painter. finishMeshBatch();
456
- painter. context. drawToBitmapData(out);
457
488
painter. popState();
458
489
490
+ Pool. putRectangle(boundsInBuffer);
491
+ Pool. putPoint(positionInBitmap);
492
+
459
493
return out;
460
494
}
461
495
0 commit comments