gpt4 book ai didi

c++ - Qt3D纹理参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:06:44 42 4
gpt4 key购买 nike

我正在使用 Qt3D (5.11),当我尝试设置要由自定义片段着色器使用的 QParameter 值时遇到断言。这是似乎不起作用的代码部分:

auto entity = new Qt3DRender::QEntity( mRootEntity );
auto material = new Qt3DRender::QMaterial( entity );

// Set up the custom geometry and material for the entity, which works
// fine in tests as long as the fragment shader does not use texture mapping

auto image = new Qt3DRender::QTextureImage( entity );
image->setSource( QString( "qrc:/image.png" ) );

auto texture = new Qt3DRender::QTexture2D( entity );
texture->addTextureImage( image );

material->addParameter( new QParameter( "imageTexture", texture, entity ) );

我只包含了这个问题所需的部分代码:

这是设置简单纹理参数的有效方法吗?如果不是,我缺少什么来设置简单的图像?

请注意,qrc:/image.png 是一个 256x256 图像,我在该项目的其他地方使用过,没有问题。

代码编译正常,但当我运行它时,我得到一个带有以下消息的断言:ASSERT: "texture"in file texture\textureimage.cpp, line 94

我在带有 Qt 5.11 的 Windows 10 上使用 VS2017。

最佳答案

我偶然发现了这个问题。将 QTextureImage 设置为 entity 会导致断言。完全离开父级(有效地将其设置为 nullptr)或将其作为父级为 texture 可解决此问题。

这是一些工作代码:

auto texture = new Qt3DRender::QTexture2D( entity );
auto image = new Qt3DRender::QTextureImage( texture );
image->setSource( QString( "qrc:/image.png" ) );
texture->addTextureImage( image );

material->addParameter( new QParameter( "imageTexture", texture, entity ) );

这可能是一个错误?如果有人知道为什么 QTextureImage 不能安全地作为 entity 的父级,请添加评论。

关于c++ - Qt3D纹理参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54451636/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com