@@ -8531,6 +8531,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
85318531 w.HTMLGL.context = this;
85328532
85338533 this.createStage(); //Creating stage before showing it
8534+ console.log('context updated position');
85348535 this.updateScrollPosition(); //Initialize scroll position for first time
85358536 this.initListeners();
85368537 this.elementResolver = new w.HTMLGL.GLElementResolver(this);
@@ -8610,6 +8611,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86108611 height = w.innerHeight;
86118612
86128613 this.renderer.resize(width, height);
8614+ this.updateTextures();
86138615 this.stage.changed = true;
86148616 }
86158617
@@ -8624,10 +8626,16 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86248626
86258627 if (this.stage.changed) {
86268628 this.renderer.render(this.stage);
8627- this .stage.changed = false;
8629+ w.HTMLGL .stage.changed = false;
86288630 }
86298631 }
86308632
8633+ p.updateTextures = function () {
8634+ w.HTMLGL.elements.forEach(function(element){
8635+ element.updateTexture();
8636+ });
8637+ }
8638+
86318639 p.onMouseEvent = function (event) {
86328640 var x = event.x || event.pageX,
86338641 y = event.y || event.pageY,
@@ -8638,6 +8646,13 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
86388646 element ? w.HTMLGL.util.emitEvent(element, event) : null;
86398647 }
86408648
8649+ //We would like to rerender if something changed, otherwise stand by
8650+ p.markStageAsChanged = function () {
8651+ if (w.HTMLGL.stage && !w.HTMLGL.stage.changed) {
8652+ w.HTMLGL.stage.changed = true;
8653+ }
8654+ }
8655+
86418656 w.HTMLGL.GLContext = GLContext;
86428657 new GLContext();
86438658})(window);
@@ -8714,14 +8729,17 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87148729 p = Object.create(HTMLElement.prototype);
87158730
87168731 p.createdCallback = function () {
8717- //Check needed
8718- if (this.baseURI.length > 0) {
8732+ //Checking is node created inside of html2canvas virtual window or not. We do not need WebGL there
8733+ var isInsideHtml2Canvas = this.baseURI.length === 0;
8734+
8735+ if (!isInsideHtml2Canvas) {
87198736 w.HTMLGL.elements.push(this);
8737+ //Needed to determine is element WebGL rendered or not
87208738 this.renderer = 'webgl';
87218739 this.transformObject = {};
87228740 this.boundingRect = {};
87238741 this.image = {};
8724- this.sprite = {} ;
8742+ this.sprite = new PIXI.Sprite() ;
87258743 this.texture = {};
87268744 this.halfWidth = 0;
87278745 this.halfHeight = 0;
@@ -8735,13 +8753,16 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87358753 p.init = function () {
87368754 this.updateTexture();
87378755 this.initObservers();
8738- this.patchstyleGLTransform ();
8756+ this.patchStyleGLTransform ();
87398757 }
87408758
8759+ //Updateing bounds, waiting for all images to load and calling rasterization then
87418760 p.updateTexture = function () {
87428761 var self = this;
8762+ self.updateBoundingRect();
87438763
87448764 new HTMLGL.ImagesLoaded(self, function () {
8765+ //Bounds could change during images loading
87458766 self.updateBoundingRect();
87468767 self.image = html2canvas(self, {
87478768 onrendered: self.applyNewTexture,
@@ -8751,22 +8772,27 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87518772 });
87528773 }
87538774
8775+ //Recreating texture from canvas given after calling updateTexture
87548776 p.applyNewTexture = function (textureCanvas) {
87558777 this.image = textureCanvas;
87568778 this.texture = PIXI.Texture.fromCanvas(this.image);
87578779
87588780 if (!this.haveSprite()) {
8759- this.createSprite (this.texture);
8781+ this.initSprite (this.texture);
87608782 } else {
87618783 this.sprite.setTexture(this.texture);
87628784 }
87638785
87648786 this.updatePivot();
87658787 this.updateSpriteTransform();
8766- this.markStageAsChanged();
8788+
8789+ w.HTMLGL.context.markStageAsChanged();
87678790 }
87688791
8792+ //Just updates WebGL representation coordinates and transformation
87698793 p.updateSpriteTransform = function () {
8794+
8795+ //TODO add 3d rotation support
87708796 var translateX = parseFloat(this.transformObject.translateX) || 0,
87718797 translateY = parseFloat(this.transformObject.translateY) || 0,
87728798 scaleX = parseFloat(this.transformObject.scaleX) || 1,
@@ -8780,9 +8806,11 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87808806 this.sprite.scale.y = scaleY;
87818807 this.sprite.rotation = rotate;
87828808 }
8783- this.markStageAsChanged();
8809+
8810+ w.HTMLGL.context.markStageAsChanged();
87848811 }
87858812
8813+ //Getting bounding rect with respect to current scroll position
87868814 p.updateBoundingRect = function () {
87878815 this.boundingRect = {
87888816 left: this.getBoundingClientRect().left,
@@ -8796,16 +8824,18 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87968824 this.boundingRect.top = w.HTMLGL.scrollY + parseFloat(this.boundingRect.top);
87978825 }
87988826
8827+ //Correct pivot needed to rotate element around it`s center
87998828 p.updatePivot = function () {
88008829 this.halfWidth = this.sprite.width / 2;
88018830 this.halfHeight = this.sprite.height / 2;
88028831 this.sprite.pivot.x = this.halfWidth;
88038832 this.sprite.pivot.y = this.halfHeight;
88048833 }
88058834
8806- p.createSprite = function (texture) {
8835+ p.initSprite = function (texture) {
88078836 var self = this;
8808- this.sprite = new PIXI.Sprite(texture);
8837+ //this.sprite = new PIXI.Sprite(texture);
8838+ this.sprite.setTexture(texture);
88098839 w.HTMLGL.document.addChild(this.sprite);
88108840 setTimeout(function () {
88118841 self.hideDOM();
@@ -8835,11 +8865,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88358865 this.observer.observe(this, config);
88368866 }
88378867
8838- p.disconnectObservers = function () {
8839- this.observer.disconnect();
8840- }
8841-
8842- p.patchstyleGLTransform = function () {
8868+ p.patchStyleGLTransform = function () {
88438869 var self = this;
88448870 self.styleGL = {};
88458871
@@ -8882,12 +8908,6 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88828908 return this.sprite.stage;
88838909 }
88848910
8885- p.markStageAsChanged = function () {
8886- if (w.HTMLGL.stage && !w.HTMLGL.stage.changed) {
8887- w.HTMLGL.stage.changed = true;
8888- }
8889- }
8890-
88918911 w.HTMLGL.GLElement = document.registerElement(CUSTOM_ELEMENT_TAG_NAME, {
88928912 prototype: p
88938913 });
0 commit comments