# DynamicTexture drawImage update

**URL:** <https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412>\
**Category:** Questions\
**Created:** [December 23, 2018, 3:24pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412 "2018-12-23T15:24:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wrath\_014](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@Wrath\_014](https://forum.babylonjs.com/u/Wrath_014)\
**Post date:** [December 23, 2018, 3:24pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/1 "2018-12-23T15:24:10Z")

</div>

Hey,

I’m using DynamicTexture to render a stream of jpeg images with web worker to first handle the incoming data (reassemble the packets since frame size is quite big). I’ve noticed that when displaying in the same time 4 motion jpeg players the FPS is dropping for all players. Is there a better way of doing so other than :  
img.src = buffer\_string;  
img.onload = () =\> {  
textureContext.drawImage(img, 0, 0);  
this.planeTexture.update();  
}

where textureContext = this.planeTexture.getContext();  
and planeTexture is a DynamicTexture object.

I think that updating the texture is a consuming and heavy operation, am I right?

Thanks.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 24, 2018, 3:34am UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/2 "2018-12-24T03:34:50Z")

</div>

Well it is time consuming but how big is the fps drop? Can you run a profile?

---

<div class="post-metadata">

**Author:** ![Wrath\_014](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@Wrath\_014](https://forum.babylonjs.com/u/Wrath_014)\
**Post date:** [December 24, 2018, 7:21am UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/3 "2018-12-24T07:21:40Z")

</div>

I ran a profile and the time it took to update the texture ranges between 3 ms and 13 ms.  
It takes the web worker to handle the packets about 1.5 ms (most of the time it’s less the 1 ms).  
The fps drop is quite fuzzy it ranges from 28 to 45 fps.

Is there a better way of doing it?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 24, 2018, 7:50am UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/4 "2018-12-24T07:50:24Z")

</div>

13ms is clearly too much. As a reference the GUI which used the same tech updates in less than a millisecond

How large are your files?

---

<div class="post-metadata">

**Author:** ![Wrath\_014](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@Wrath\_014](https://forum.babylonjs.com/u/Wrath_014)\
**Post date:** [December 24, 2018, 7:55am UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/5 "2018-12-24T07:55:40Z")

</div>

We use 1MB, 2MB and 4MB cameras, but the backend resize them all to 640x480.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 24, 2018, 3:00pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/6 "2018-12-24T15:00:55Z")

</div>

well then this is definitely too slow  
Can you repro somehow in the PG?

---

<div class="post-metadata">

**Author:** ![Wrath\_014](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@Wrath\_014](https://forum.babylonjs.com/u/Wrath_014)\
**Post date:** [December 25, 2018, 2:26pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/7 "2018-12-25T14:26:04Z")

</div>

I can’t repro the stream, sorry…  
other than that the code is quite simple and it’s in the original post

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 25, 2018, 4:33pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/8 "2018-12-25T16:33:58Z")

</div>

Well so do you repro your issue in the PG? I mean the perf issue?

---

<div class="post-metadata">

**Author:** ![Wrath\_014](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@Wrath\_014](https://forum.babylonjs.com/u/Wrath_014)\
**Post date:** [December 31, 2018, 7:47am UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/9 "2018-12-31T07:47:59Z")

</div>

[https://www.babylonjs-playground.com/#LXZPJK#108](https://www.babylonjs-playground.com/#LXZPJK#108)

sorry it took too long

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [January 8, 2019, 6:54pm UTC](https://forum.babylonjs.com/t/dynamictexture-drawimage-update/412/10 "2019-01-08T18:54:53Z")

</div>

In your example you are reloading the img on every tick so this may not be accurate. You should keep the img because else the decoding process can be long
