# Texture with frequent source changes (video, image, canvas, etc)

**URL:** <https://forum.babylonjs.com/t/texture-with-frequent-source-changes-video-image-canvas-etc/26851>\
**Category:** Questions\
**Created:** [January 17, 2022, 6:59pm UTC](https://forum.babylonjs.com/t/texture-with-frequent-source-changes-video-image-canvas-etc/26851 "2022-01-17T18:59:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vandy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vandy/32/3597_2.png) [@Vandy](https://forum.babylonjs.com/u/Vandy)\
**Post date:** [January 17, 2022, 6:59pm UTC](https://forum.babylonjs.com/t/texture-with-frequent-source-changes-video-image-canvas-etc/26851/1 "2022-01-17T18:59:18Z")

</div>

We have some meshes in our project that have frequent source changes (think television screen with the channels changing between images, videos and dynamic canvases). Would there be any performance gain to us writing our own texture class that is a combination of the existing texture classes like VideoTexture, HTMLElementTexture, etc.

We have been studying some of the underlying classes and can see, for example, the video texture when switching from a poster to the video just creates a new texture within the class and updates it in the engine. Not sure the exact under the hood mechanism, but somehow materials must know of this change in texture.

Would this approach to creating a custom texture type that switches between various sources (image, video, canvas, etc) have any advantage over just constantly swapping out the texture on a material to one of the existing texture types?

i.e is there any performance difference between  
myMat.texture = mySpecialNewTextureTypeThatHandlesMultipleSourceTypes

vs

myMat.texture = builtInBabylonTextureTypesButIamChangingThisPropertyOften

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [January 17, 2022, 7:23pm UTC](https://forum.babylonjs.com/t/texture-with-frequent-source-changes-video-image-canvas-etc/26851/2 "2022-01-17T19:23:11Z")

</div>

I believe that the built-in Babylon way to deal with textures would be more performant just because there will be less extra code for the same task.  
There is also [Asset Manager | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/importers/assetManager#textureassettask) which helps to load different types of assets with callbacks `onSuccess` and `onError`.  
Or just create an array and put all textures there, then show/load them on demand (there is may be no need to load a video for videotexture since you can stream it).

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [January 18, 2022, 5:52am UTC](https://forum.babylonjs.com/t/texture-with-frequent-source-changes-video-image-canvas-etc/26851/3 "2022-01-18T05:52:42Z")

</div>

Hey @Vandy!

Maybe it’s worth to look at the new feature for fast material switching introduced in BJS5:

> **[Render pass ids | Babylon.js Documentation](https://doc.babylonjs.com/advanced_topics/renderPasses)**
>
> Learn all about render pass id in Babylon.js.
