Replies: 3 comments 2 replies
-
Hey @cswkim, I'm gonna try to answer all your questions, but first you may want to understand a few things about WebGL textures and how curtainsjs handles them. Uploading textures to the GPU using The library caches every image texture under the hood. This means that every time you use I know that @kekkorider has been dealing with a fair amount of textures when working on this website: https://rupert-rothschildvignerons.com/gallery So, with that in mind, I'll try to answer your questions:
I hope this has been helpful. Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hey @cswkim, When using a SPA such as React/Vue/Svelte or any custom AJAX navigation, you should instanciate your curtains object once on initial page load and most of the time you should keep it running as long as your web app is opened. Whenever a texture image source is loaded, the texture is added to the cache (if not already in there). The cache isn't cleared until you destroy your curtains instance, which means it's living the whole time your app is up. That way if you ever recreate a plane that uses an already uploaded image (like when navigating back to a page that first contained the plane), the texture will be taken from the cache instead of recreated from scratch. This is a huge performance boost. So yeah, you could potentially clog your GPU memory when creating hundreds of textures. But once again, this is not something you should be doing with WebGL, whatever the library used. As for your third question, you could try to implement this algorithm, but I'm pretty sure that uploading images to the GPU at runtime like that will impact the performances. If you want to permanently delete a texture (ie remove it from the cache and delete the GL texture), you could use curtainsjs/src/core/Texture.js Lines 1226 to 1269 in bab814c Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hey @cswkim , I don't know exactly how the GPU memory is handled. There's the Chrome devtools frame rendering tool: stats.js can also be of some help: https://github.com/mrdoob/stats.js/ Cheers, |
Beta Was this translation helpful? Give feedback.
-
I'm extremely new to the WebGL world so hopefully I can try to explain my scenario well enough to elicit some advice. The basic gist of the site is a very long carousel, where at most you see one image/texture at a time. Then there are previous and next buttons that will run a GL transition to the previous or next image. I don't want any lag/delay in transition during carousel change. What I'm noticing is that on Android browsers and Chrome for macOS, the transitions run very well. However, on iOS devices (iPhone and iPad) and Safari for macOS, there is often an unpleasant effect during transition where the screen goes black for a brief moment. I'm guessing this is due to the texture not being "ready" before the plane starts to render the transition? So if you went from imageX to imageY, you often see that black screen, however if you then went back to imageX from imageY, the transition runs smooth. Is that because the textures have been properly uploaded to the GPU?
All examples I've seen use just a handful of images and can preload the textures easily. But what if you have potentially hundreds of images? You can't preload them all at once, but maybe every time you move to a new image, you preload the previous and next ones ahead of time?
My questions:
Do I need to remove all Planes from the Curtains object and then create a new one for every image change?
If I keep the same Plane object for the entire carousel, I shouldn't use
addTexture
orcreateTexture
, but rather have 2 fixed texture objects with my sampler names (uTextureFrom
anduTextureTo
) and usesetSource()
? ButsetSource
needs the images to already be loaded into the Plane?Should I keep track of every texture I preloaded using
TextureLoader
, so I have a giant array of all these "loose" textures? Then for every image change I check this global array to see if a texture has already been preloaded to the GPU with the matching image source and if so, use that loose texture in acreateTexture
call?How long does a texture "live" in the GPU? Will it be a problem if you are navigating through this long carousel and loading all these textures into the GPU? How does curtains behind the scenes keep track of textures in the planes and what has been sent to the GPU? When do the textures get removed from the GPU?
Can you actually preload let's say 200 textures? I'm assuming this would be a bad idea. An image could be anywhere from ~100KB - ~500KB. For my device I checked
<myCurtainsObject>.gl.getParameter(<myCurtainsObject>.gl.MAX_TEXTURE_IMAGE_UNITS)
and it returned 16. But is that value the maximum number of textures drawn to the canvas at a time?I suppose the closest example I encountered was the ajax navigation with plane removal.
Beta Was this translation helpful? Give feedback.
All reactions