[Interest] Creating Custom QSGTexture
Mike Krus
mike.krus at kdab.com
Thu Sep 11 15:11:46 CEST 2025
Thanks, think I may have explained it wrong though.
I don’t have a native texture to use. I have some data I want to use in a shader via a texture.
I need to create a QSGTexture type object but there doesn’t seem to be any existing API to
do that beyond createTextureFromImage().
I presume I’d need to derive and use RHI itself to create an RHI texture but was hoping to
find an example which that in the context of the scene graph, especially when it comes to
the creation of the RHI texture and the uploading/updating of the data.
Mike
> On 11 Sep 2025, at 13:44, Allan Sandfeld Jensen <kde at carewolf.com> wrote:
>
> On Thursday, 11 September 2025 12:28:52 Central European Summer Time Mike Krus
> via Interest wrote:
>> Hi
>>
>> I’m porting a project from Qt5/OpenGL SceneGraph code to new Qt6/RHI
>>
>> I have a custom item with a scene graph which creates a custom shader and a
>> custom texture from some application data (not an image).
>>
>> In Qt5, I have Texture class derived from QSGTexture which create the
>> underlying OpenGL buffers for the textures and handles to data, binding,
>> etc.
>>
>> In Qt6, the same classes exists but the custom Texture class needs to create
>> RHI based texture objects, with the appropriate format, copy the data into
>> it, etc. But I have not been able to find some relevant code to do that.
>> All the code I found in QtDeclarative itself either use
>> QQuickWindow::createTextureFromImage() or a QSGTextureProvider.
>>
>> There some example which create custom RHI textures, but not in the context
>> of the scene graph (using RHI directly in QQuickRHIItem for example).
>>
>> Any ideas how this can be done?
>>
> The way we do in Qt WebEngine now, is using QNativeInterface. For instance
> from OpenGL texture
> QNativeInterface::QSGOpenGLTexture::fromNative(texture, win, size, texOpts);
> or from Metal texture
> QNativeInterface::QSGMetalTexture::fromNative(texture, win, size, texOpts);
> or from Vulkan texture
> QNativeInterface::QSGVulkanTexture::fromNative(importedImage,
> importedImageCreateInfo.initialLayout, win, size, texOpts);
>
> Best regards
> Allan
—
Mike Krus | mike.krus at kdab.com | Senior Software Engineer & Teamlead
KDAB (UK) Ltd., a KDAB Group company
Tel: UK Office +44 1625 809908 Mobile +44 7833 491941
KDAB - Trusted Software Excellence
More information about the Interest
mailing list