代码之家  ›  专栏  ›  技术社区  ›  Naaff

Qt3D纹理参数

  •  2
  • Naaff  · 技术社区  · 7 年前

    我正在使用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

    代码编译得很好,但是当我运行它时,我得到一个断言,其中包含以下消息: ASSERT: "texture" in file texture\textureimage.cpp, line 94

    我在Windows10上使用VS2017和Qt5.11。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Naaff    7 年前

    我偶然发现了这个问题。养育 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 ) );
    

    这可能是个虫子?如果有人知道为什么 QTexture图像 实体 ,请添加评论。