c++ - 将 Qt 代码从 createTextureFromId 更新为 createTextureFromNativeObject
问题描述
我有一段代码如下所示:
// Before the scene graph starts to render, we update to the pending texture
void prepareNode()
{
m_Lock.lock();
int newId = m_ID;
QSize size = m_Size;
m_ID = 0;
m_Lock.unlock();
if (newId)
{
delete m_Texture;
// note: include QQuickWindow::TextureHasAlphaChannel if the rendered content
// has alpha.
m_Texture = m_Window->createTextureFromId(newId, size);
setTexture(m_Texture);
markDirty(DirtyMaterial);
// This will notify the rendering thread that the texture is now being rendered
// and it can start rendering to the other one.
Q_EMIT textureInUse();
}
}
现在将 Qt 更新到 5.15,函数 createTextureFromId 不再受支持,应替换为 createTextureFromNativeObject。
但是,我无法在 Qt 方面找到有关如何从纹理 ID 获取 QTNativeObject 的任何有用文档。(我对Qt的理解低于基础)
注意:更改布局和父函数是一个很大的开销。该函数被称为
connect(m_QMLWindow->m_RenderThread, &QMLRenderThread::textureReady, node, &TextureNode::newTexture,
Qt::DirectConnection);
我想应该有一种简单的方法来遍历createTextureFromNativeObject?
解决方案
你可以试试:
QQuickWindow::CreateTextureOptions texOpts;
if (hasAlphaChannel)
texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel);
m_Texture = m_Window->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture, &newId, 0, size, texOpts);
推荐阅读
- ruby-on-rails - 使用 mongoid 更新布尔数据
- ios - 手动引入数据(iOS 数据库)
- couchbase - 与 4.5 相比,5.1 版中的 cbtransfer 到 csv 不同
- sql - SQL Server 中存储过程和触发器的执行
- r - Shiny App中的SliderInput和SelectInput不起作用
- python-3.x - 在 BST python 中删除节点
- typescript - 使用动态键和 T 数组通用键入哈希图
- php - 如果输入文件为空 php,如何设置默认的 none.png 图像
- wpf - 构建 WPF 仪表控件
- javascript - 在Javascript中对范围内的每个元素求和