Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.2
-
None
Description
Two Textures with the same file as their source create one native texture resource under the hood. This is good, especially when considering examples like the following where the Texture objects have some different settings (here, the mappingMode and the flipU) that require using separate Texture objects, instead of referencing the same one from the materials. In the example, background.jpg is loaded only once and there is only one native texture object created with the native graphics API, even though there are two QQuick3DTextures.
Model { source: "InvertedSphere.mesh" scale: Qt.vector3d(4000, 4000, 4000) eulerRotation.y: 90 materials: PrincipledMaterial { lighting: PrincipledMaterial.NoLighting baseColorMap: Texture { flipU: true source: "background.jpg" } } } Model { source: "#Cube" scale: Qt.vector3d(3, 3, 3) eulerRotation: Qt.vector3d(30, 30, 0) materials: PrincipledMaterial { specularReflectionMap: Texture { source: "background.jpg" mappingMode: Texture.Environment } } }
Now try doing the same with a Qt Quick scene as the texture content:
Item { id: quickScene visible: false width: 1024 height: 1024 ... } Model { source: "InvertedSphere.mesh" scale: Qt.vector3d(4000, 4000, 4000) eulerRotation.y: 90 materials: PrincipledMaterial { lighting: PrincipledMaterial.NoLighting baseColorMap: Texture { flipU: true sourceItem: quickScene } } } Model { source: "#Cube" scale: Qt.vector3d(3, 3, 3) eulerRotation: Qt.vector3d(30, 30, 0) materials: PrincipledMaterial { specularReflectionMap: Texture { sourceItem: quickScene mappingMode: Texture.Environment } } }
The only difference in the two Models is the usage of sourceItem instead of source. This leads to creating two native texture objects under the hood, and renders the Qt Quick scene twice. This is as expected, based on the implementation (QQuick3DTexture ensures there is a QSGTexture for the 2D content, independently from any other QQuick3DTexture), but is not ideal both from performance and resource usage perspective.
Compare with Qt Quick and ShaderEffect: there ShaderEffectSource serves as a middleman of some sort, i.e. two ShaderEffects can use the same ShaderEffectSource as their source, where the ShaderEffectSource is the object that references an Item in its sourceItem property, creates a QSGLayer when necessary, takes care of updating the content etc. In Quick3D there is no such component in the middle, which gives us a more straightforward API, but it is more complicated internally to be fully optimal.