jwwalker wrote: ↑Sun Jan 16, 2022 4:41 am
(Hmm, now that I look at that again, maybe I should try setting the number of mipmaps before the scheduleTransitionTo call.)
Yes, that's exactly the reason setNumMipmaps complained. It needs to be done while the texture is (still) OnStorage
jwwalker wrote: ↑Sun Jan 16, 2022 4:41 am
There could be many textures loaded this way, some coming from data within 3D object files, and some coming from image files (e.g. JPEG) on disk. New textures can be loaded at unpredictable times, not just when the program starts but certainly not every frame. I would imagine that mipmaps for a texture should be generated soon after that texture is loaded.
OK. The reason I asked frequency is because to call _autogenerateMipmaps you need TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps flags (see _autogenerateMipmaps docs).
This has a performance cost, but it's ok if you plan on calling _autogenerateMipmaps often (e.g. every frame).
For regular textures (i.e. uploaded once, read all the time afterwards) the recommended path is to create a temporary 2nd texture, call _autogenerateMipmaps there; and then copy the data to the original texture and destroy the temporary 2nd texture (this is what the
filter does).
Now you have 4 possible solutions:
1. Do it yourself, _autogenerateMipmaps on the same texture. Best for textures that will be changing often. What you're doing now, but the texture needs TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps. You're already very close.
2. Do it yourself, _autogenerateMipmaps on a temporary texture. See GenerateHwMipmaps::_executeSerial for example code
3. Let Ogre do it via a ResourceLoadingListener registered in ResourceGroupManager and overriding ResourceLoadingListener::grouplessResourceExists grouplessResourceLoading and grouplessResourceOpened. That way Ogre can load it asynchronously but instead of a file, the data is sourced from the listener. This allows you for async streaming.
You'll have to create the texture NOT as manual texture; but rather pretending the texture is a regular one coming from a file (i.e. AutomaticBatching, Type2D), and using filenames to identify them in the listener.
4. Let Ogre do it, pretend you're loading a regular texture from file; but when you call scheduleTransitionTo, you provide your own Image instead of nullptr. eg. see AreaApproxLightsGameState::createAreaMask
Take note that if D3D11 device is lost (and Vulkan too, but Vulkan currently isn't handling it) automatic recovery won't be possible except for Option 3.
You can still listen for device lost events and manually recover though.