mirror of https://github.com/qt/qt3d.git
Properly update properties from Backend to Frontend textures
Taking into account we have texture sharing in the backend, we can only update frontend texture properties once we have created the shared backend texture. Code was adjusted to retrieve these properties when creating the GLTexture. Such changes are stored and sent on the next run loop from a job where they are distributed to all referenced frontend Texture. The status property handling has also been updated to send status changes to all shared textures instead of just the texture whose data generator is used to gather the data. A manual test checking texture property updates, sharing and remote url sharing has also been added. Change-Id: I8ed2449fe57c9d7337580b0f7561f974cbd5006d Task-number: QTBUG-65775 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
parent
0b10ab797f
commit
85f8e910fa
|
|
@ -87,7 +87,7 @@ bool ResourceAccessor::accessResource(ResourceType type, Qt3DCore::QNodeId nodeI
|
|||
|
||||
glTex->setExternalRenderingEnabled(true);
|
||||
QOpenGLTexture **glTextureHandle = reinterpret_cast<QOpenGLTexture **>(handle);
|
||||
*glTextureHandle = glTex->getOrCreateGLTexture();
|
||||
*glTextureHandle = glTex->getGLTexture();
|
||||
*lock = glTex->externalRenderingLock();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ namespace JobTypes {
|
|||
ProximityFiltering,
|
||||
SyncFilterEntityByLayer,
|
||||
SyncMaterialGatherer,
|
||||
UpdateLayerEntity
|
||||
UpdateLayerEntity,
|
||||
SendTextureChangesToFrontend
|
||||
};
|
||||
|
||||
} // JobTypes
|
||||
|
|
|
|||
|
|
@ -863,7 +863,7 @@ void SubmissionContext::bindFrameBufferAttachmentHelper(GLuint fboId, const Atta
|
|||
for (const Attachment &attachment : attachments_) {
|
||||
GLTexture *rTex = glTextureManager->lookupResource(attachment.m_textureUuid);
|
||||
if (!m_glHelper->frameBufferNeedsRenderBuffer(attachment)) {
|
||||
QOpenGLTexture *glTex = rTex ? rTex->getOrCreateGLTexture() : nullptr;
|
||||
QOpenGLTexture *glTex = rTex ? rTex->getGLTexture() : nullptr;
|
||||
if (glTex != nullptr) {
|
||||
// The texture can not be rendered simultaniously by another renderer
|
||||
Q_ASSERT(!rTex->isExternalRenderingEnabled());
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ Renderer::Renderer(QRenderAspect::RenderType type)
|
|||
, m_bufferGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyBuffers(); }, JobTypes::DirtyBufferGathering))
|
||||
, m_vaoGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForAbandonedVaos(); }, JobTypes::DirtyVaoGathering))
|
||||
, m_textureGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyTextures(); }, JobTypes::DirtyTextureGathering))
|
||||
, m_sendTextureChangesToFrontendJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { sendTextureChangesToFrontend(); }, JobTypes::SendTextureChangesToFrontend))
|
||||
, m_introspectShaderJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { reloadDirtyShaders(); }, JobTypes::DirtyShaderGathering))
|
||||
, m_syncTextureLoadingJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([] {}, JobTypes::SyncTextureLoading))
|
||||
, m_ownedContext(false)
|
||||
|
|
@ -1170,6 +1171,28 @@ void Renderer::reloadDirtyShaders()
|
|||
}
|
||||
}
|
||||
|
||||
// Executed in a job
|
||||
void Renderer::sendTextureChangesToFrontend()
|
||||
{
|
||||
const QVector<QPair<TextureProperties, Qt3DCore::QNodeIdVector>> updateTextureProperties = std::move(m_updatedTextureProperties);
|
||||
for (const auto &pair : updateTextureProperties) {
|
||||
// Prepare change notification
|
||||
|
||||
const Qt3DCore::QNodeIdVector targetIds = pair.second;
|
||||
for (const Qt3DCore::QNodeId targetId: targetIds) {
|
||||
// Lookup texture
|
||||
Texture *t = m_nodesManager->textureManager()->lookupResource(targetId);
|
||||
|
||||
// Texture might have been deleted between previous and current frame
|
||||
if (t == nullptr)
|
||||
continue;
|
||||
|
||||
// Send change and update backend
|
||||
t->updatePropertiesAndNotify(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render Thread (or QtQuick RenderThread when using Scene3D)
|
||||
// Scene3D: When using Scene3D rendering, we can't assume that when
|
||||
// updateGLResources is called, the resource handles points to still existing
|
||||
|
|
@ -1230,7 +1253,7 @@ void Renderer::updateGLResources()
|
|||
if (texture == nullptr)
|
||||
continue;
|
||||
|
||||
// Update texture properties
|
||||
// Create or Update GLTexture
|
||||
updateTexture(texture);
|
||||
}
|
||||
// We want to upload textures data at this point as the SubmissionThread and
|
||||
|
|
@ -1240,8 +1263,16 @@ void Renderer::updateGLResources()
|
|||
GLTextureManager *glTextureManager = m_nodesManager->glTextureManager();
|
||||
const QVector<GLTexture *> glTextures = glTextureManager->activeResources();
|
||||
// Upload texture data
|
||||
for (GLTexture *glTexture : glTextures)
|
||||
glTexture->getOrCreateGLTexture();
|
||||
for (GLTexture *glTexture : glTextures) {
|
||||
const GLTexture::TextureUpdateInfo info = glTexture->createOrUpdateGLTexture();
|
||||
|
||||
// GLTexture creation provides us width/height/format ... information
|
||||
// for textures which had not initially specified these information (TargetAutomatic...)
|
||||
// Gather these information and store them to be distributed by a change next frame
|
||||
const QNodeIdVector referenceTextureIds = glTextureManager->referencedTextureIds(glTexture);
|
||||
// Store properties and referenceTextureIds
|
||||
m_updatedTextureProperties.push_back({info.properties, referenceTextureIds});
|
||||
}
|
||||
}
|
||||
}
|
||||
// When Textures are cleaned up, their id is saved so that they can be
|
||||
|
|
@ -1664,6 +1695,9 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
|
|||
renderBinJobs.push_back(m_sendRenderCaptureJob);
|
||||
}
|
||||
|
||||
// Do we need to notify any texture about property changes?
|
||||
if (m_updatedTextureProperties.size() > 0)
|
||||
renderBinJobs.push_back(m_sendTextureChangesToFrontendJob);
|
||||
|
||||
renderBinJobs.push_back(m_sendBufferCaptureJob);
|
||||
renderBinJobs.append(bufferJobs);
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@
|
|||
#include <Qt3DRender/private/updateskinningpalettejob_p.h>
|
||||
#include <Qt3DRender/private/updateentitylayersjob_p.h>
|
||||
#include <Qt3DRender/private/renderercache_p.h>
|
||||
#include <Qt3DRender/private/texture_p.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QMatrix4x4>
|
||||
|
|
@ -216,6 +217,7 @@ public:
|
|||
inline IntrospectShadersJobPtr introspectShadersJob() const { return m_introspectShaderJob; }
|
||||
inline Qt3DCore::QAspectJobPtr bufferGathererJob() const { return m_bufferGathererJob; }
|
||||
inline Qt3DCore::QAspectJobPtr textureGathererJob() const { return m_textureGathererJob; }
|
||||
inline Qt3DCore::QAspectJobPtr sendTextureChangesToFrontendJob() const { return m_sendTextureChangesToFrontendJob; }
|
||||
inline UpdateEntityLayersJobPtr updateEntityLayersJob() const { return m_updateEntityLayersJob; }
|
||||
|
||||
Qt3DCore::QAbstractFrameAdvanceService *frameAdvanceService() const override;
|
||||
|
|
@ -370,6 +372,7 @@ private:
|
|||
GenericLambdaJobPtr<std::function<void ()>> m_bufferGathererJob;
|
||||
GenericLambdaJobPtr<std::function<void ()>> m_vaoGathererJob;
|
||||
GenericLambdaJobPtr<std::function<void ()>> m_textureGathererJob;
|
||||
GenericLambdaJobPtr<std::function<void ()>> m_sendTextureChangesToFrontendJob;
|
||||
IntrospectShadersJobPtr m_introspectShaderJob;
|
||||
|
||||
SynchronizerJobPtr m_syncTextureLoadingJob;
|
||||
|
|
@ -379,6 +382,7 @@ private:
|
|||
void lookForDownloadableBuffers();
|
||||
void lookForDirtyTextures();
|
||||
void reloadDirtyShaders();
|
||||
void sendTextureChangesToFrontend();
|
||||
|
||||
QMutex m_abandonedVaosMutex;
|
||||
QVector<HVao> m_abandonedVaos;
|
||||
|
|
@ -387,6 +391,7 @@ private:
|
|||
QVector<HBuffer> m_downloadableBuffers;
|
||||
QVector<HShader> m_dirtyShaders;
|
||||
QVector<HTexture> m_dirtyTextures;
|
||||
QVector<QPair<TextureProperties, Qt3DCore::QNodeIdVector>> m_updatedTextureProperties;
|
||||
|
||||
bool m_ownedContext;
|
||||
|
||||
|
|
|
|||
|
|
@ -105,10 +105,13 @@ void GLTexture::destroyGLTexture()
|
|||
destroyResources();
|
||||
}
|
||||
|
||||
QOpenGLTexture* GLTexture::getOrCreateGLTexture()
|
||||
GLTexture::TextureUpdateInfo GLTexture::createOrUpdateGLTexture()
|
||||
{
|
||||
QMutexLocker locker(&m_textureMutex);
|
||||
bool needUpload = false;
|
||||
TextureUpdateInfo textureInfo;
|
||||
|
||||
m_properties.status = QAbstractTexture::Error;
|
||||
|
||||
// on the first invocation in the render thread, make sure to
|
||||
// evaluate the texture data generator output
|
||||
|
|
@ -140,7 +143,8 @@ QOpenGLTexture* GLTexture::getOrCreateGLTexture()
|
|||
needUpload = true;
|
||||
} else {
|
||||
qWarning() << "[Qt3DRender::GLTexture] No QTextureData generated from Texture Generator yet. Texture will be invalid for this frame";
|
||||
return nullptr;
|
||||
textureInfo.properties.status = QAbstractTexture::Loading;
|
||||
return textureInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,8 +192,10 @@ QOpenGLTexture* GLTexture::getOrCreateGLTexture()
|
|||
}
|
||||
|
||||
// don't try to create the texture if the format was not set
|
||||
if (m_properties.format == QAbstractTexture::Automatic)
|
||||
return nullptr;
|
||||
if (m_properties.format == QAbstractTexture::Automatic) {
|
||||
textureInfo.properties.status = QAbstractTexture::Error;
|
||||
return textureInfo;
|
||||
}
|
||||
|
||||
// if the properties changed, we need to re-allocate the texture
|
||||
if (testDirtyFlag(Properties)) {
|
||||
|
|
@ -197,15 +203,24 @@ QOpenGLTexture* GLTexture::getOrCreateGLTexture()
|
|||
m_gl = nullptr;
|
||||
}
|
||||
|
||||
|
||||
if (!m_gl) {
|
||||
m_gl = buildGLTexture();
|
||||
if (!m_gl)
|
||||
return nullptr;
|
||||
if (!m_gl) {
|
||||
textureInfo.properties.status = QAbstractTexture::Error;
|
||||
return textureInfo;
|
||||
}
|
||||
|
||||
m_gl->allocateStorage();
|
||||
if (!m_gl->isStorageAllocated()) {
|
||||
return nullptr;
|
||||
textureInfo.properties.status = QAbstractTexture::Error;
|
||||
return textureInfo;
|
||||
}
|
||||
}
|
||||
m_properties.status = QAbstractTexture::Ready;
|
||||
|
||||
textureInfo.properties = m_properties;
|
||||
textureInfo.texture = m_gl;
|
||||
|
||||
// need to (re-)upload texture data?
|
||||
if (needUpload) {
|
||||
|
|
@ -223,7 +238,7 @@ QOpenGLTexture* GLTexture::getOrCreateGLTexture()
|
|||
setDirtyFlag(Properties, false);
|
||||
setDirtyFlag(Parameters, false);
|
||||
|
||||
return m_gl;
|
||||
return textureInfo;
|
||||
}
|
||||
|
||||
RenderBuffer *GLTexture::getOrCreateRenderBuffer()
|
||||
|
|
@ -442,7 +457,7 @@ void GLTexture::uploadGLTextureData()
|
|||
}
|
||||
|
||||
// Upload all QTexImageData references by the TextureImages
|
||||
for (int i = 0; i < m_images.size(); i++) {
|
||||
for (int i = 0; i < std::min(m_images.size(), m_imageData.size()); i++) {
|
||||
const QTextureImageDataPtr &imgData = m_imageData.at(i);
|
||||
// Here the bytes in the QTextureImageData contain data for a single
|
||||
// layer, face or mip level, unlike the QTextureGenerator case where
|
||||
|
|
|
|||
|
|
@ -140,7 +140,13 @@ public:
|
|||
* If the texture properties or parameters have changed, these changes
|
||||
* will be applied to the resulting OpenGL texture.
|
||||
*/
|
||||
QOpenGLTexture* getOrCreateGLTexture();
|
||||
struct TextureUpdateInfo
|
||||
{
|
||||
QOpenGLTexture *texture = nullptr;
|
||||
TextureProperties properties;
|
||||
};
|
||||
|
||||
TextureUpdateInfo createOrUpdateGLTexture();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
|
|
|||
|
|
@ -117,24 +117,8 @@ void Texture::cleanup()
|
|||
m_textureImageIds.clear();
|
||||
|
||||
// set default values
|
||||
m_properties.width = 1;
|
||||
m_properties.height = 1;
|
||||
m_properties.depth = 1;
|
||||
m_properties.layers = 1;
|
||||
m_properties.mipLevels = 1;
|
||||
m_properties.samples = 1;
|
||||
m_properties.generateMipMaps = false;
|
||||
m_properties.format = QAbstractTexture::RGBA8_UNorm;
|
||||
m_properties.target = QAbstractTexture::Target2D;
|
||||
|
||||
m_parameters.magnificationFilter = QAbstractTexture::Nearest;
|
||||
m_parameters.minificationFilter = QAbstractTexture::Nearest;
|
||||
m_parameters.wrapModeX = QTextureWrapMode::ClampToEdge;
|
||||
m_parameters.wrapModeY = QTextureWrapMode::ClampToEdge;
|
||||
m_parameters.wrapModeZ = QTextureWrapMode::ClampToEdge;
|
||||
m_parameters.maximumAnisotropy = 1.0f;
|
||||
m_parameters.comparisonFunction = QAbstractTexture::CompareLessEqual;
|
||||
m_parameters.comparisonMode = QAbstractTexture::CompareNone;
|
||||
m_properties = {};
|
||||
m_parameters = {};
|
||||
|
||||
m_dirty = NotDirty;
|
||||
}
|
||||
|
|
@ -229,73 +213,6 @@ void Texture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
|
|||
BackendNode::sceneChangeEvent(e);
|
||||
}
|
||||
|
||||
void Texture::notifyStatus(QAbstractTexture::Status status)
|
||||
{
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("status");
|
||||
change->setValue(status);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
void Texture::updateFromData(QTextureDataPtr data)
|
||||
{
|
||||
if (data->width() != m_properties.width) {
|
||||
m_properties.width = data->width();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("width");
|
||||
change->setValue(data->width());
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (data->height() != m_properties.height) {
|
||||
m_properties.height = data->height();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("height");
|
||||
change->setValue(data->height());
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (data->depth() != m_properties.depth) {
|
||||
m_properties.depth = data->depth();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("depth");
|
||||
change->setValue(data->depth());
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (data->layers() != m_properties.layers) {
|
||||
m_properties.layers = data->layers();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("layers");
|
||||
change->setValue(data->layers());
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (data->format() != m_properties.format) {
|
||||
m_properties.format = data->format();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("format");
|
||||
change->setValue(data->format());
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (data->target() != m_properties.target) {
|
||||
// TODO frontend property is actually constant
|
||||
m_properties.target = data->target();
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("target");
|
||||
change->setValue(data->target());
|
||||
notifyObservers(change);
|
||||
}
|
||||
}
|
||||
|
||||
// Called by sceneChangeEvent or TextureDownloadRequest (both in AspectThread context)
|
||||
void Texture::setDataGenerator(const QTextureGeneratorPtr &generator)
|
||||
{
|
||||
|
|
@ -303,6 +220,72 @@ void Texture::setDataGenerator(const QTextureGeneratorPtr &generator)
|
|||
addDirtyFlag(DirtyDataGenerator);
|
||||
}
|
||||
|
||||
// Called by sendTextureChangesToFrontendJob once GLTexture and sharing
|
||||
// has been performed
|
||||
void Texture::updatePropertiesAndNotify(const TextureProperties &properties)
|
||||
{
|
||||
// If we are Dirty, some property has changed and the properties we have
|
||||
// received are potentially already outdated
|
||||
if (m_dirty != NotDirty)
|
||||
return;
|
||||
|
||||
// Note we don't update target has it is constant for frontend nodes
|
||||
|
||||
if (properties.width != m_properties.width) {
|
||||
m_properties.width = properties.width;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("width");
|
||||
change->setValue(properties.width);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (properties.height != m_properties.height) {
|
||||
m_properties.height = properties.height;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("height");
|
||||
change->setValue(properties.height);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (properties.depth != m_properties.depth) {
|
||||
m_properties.depth = properties.depth;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("depth");
|
||||
change->setValue(properties.depth);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (properties.layers != m_properties.layers) {
|
||||
m_properties.layers = properties.layers;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("layers");
|
||||
change->setValue(properties.layers);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (properties.format != m_properties.format) {
|
||||
m_properties.format = properties.format;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("format");
|
||||
change->setValue(properties.format);
|
||||
notifyObservers(change);
|
||||
}
|
||||
|
||||
if (properties.status != m_properties.status) {
|
||||
m_properties.status = properties.status;
|
||||
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
|
||||
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
|
||||
change->setPropertyName("status");
|
||||
change->setValue(properties.status);
|
||||
notifyObservers(change);
|
||||
}
|
||||
}
|
||||
|
||||
bool Texture::isValid(TextureImageManager *manager) const
|
||||
{
|
||||
for (const QNodeId id : m_textureImageIds) {
|
||||
|
|
|
|||
|
|
@ -86,12 +86,13 @@ struct TextureProperties
|
|||
QAbstractTexture::Target target = QAbstractTexture::Target2D;
|
||||
QAbstractTexture::TextureFormat format = QAbstractTexture::RGBA8_UNorm;
|
||||
bool generateMipMaps = false;
|
||||
QAbstractTexture::Status status = QAbstractTexture::None;
|
||||
|
||||
bool operator==(const TextureProperties &o) const {
|
||||
return (width == o.width) && (height == o.height) && (depth == o.depth)
|
||||
&& (layers == o.layers) && (mipLevels == o.mipLevels) && (target == o.target)
|
||||
&& (format == o.format) && (generateMipMaps == o.generateMipMaps)
|
||||
&& (samples == o.samples);
|
||||
&& (samples == o.samples) && (status == o.status);
|
||||
}
|
||||
inline bool operator!=(const TextureProperties &o) const { return !(*this == o); }
|
||||
};
|
||||
|
|
@ -155,9 +156,8 @@ public:
|
|||
inline const Qt3DCore::QNodeIdVector textureImageIds() const { return m_textureImageIds; }
|
||||
inline const QTextureGeneratorPtr& dataGenerator() const { return m_dataFunctor; }
|
||||
|
||||
void notifyStatus(QAbstractTexture::Status status);
|
||||
void updateFromData(QTextureDataPtr data);
|
||||
void setDataGenerator(const QTextureGeneratorPtr &generator);
|
||||
void updatePropertiesAndNotify(const TextureProperties &propreties);
|
||||
bool isValid(TextureImageManager *manager) const;
|
||||
private:
|
||||
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ SUBDIRS += \
|
|||
rendercapture-qml-fbo \
|
||||
blitframebuffer-qml \
|
||||
raycasting-qml \
|
||||
shared_texture_image
|
||||
shared_texture_image \
|
||||
texture_property_updates
|
||||
|
||||
qtHaveModule(widgets): {
|
||||
SUBDIRS += \
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
|
|
@ -0,0 +1,102 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QQuickView>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlContext>
|
||||
#include <Qt3DRender/QAbstractTexture>
|
||||
|
||||
template<typename Obj>
|
||||
QHash<int, QString> enumToNameMap(const char *enumName)
|
||||
{
|
||||
const QMetaObject metaObj = Obj::staticMetaObject;
|
||||
const int indexOfEnum = metaObj.indexOfEnumerator(enumName);
|
||||
const QMetaEnum metaEnum = metaObj.enumerator(indexOfEnum);
|
||||
const int keysCount = metaEnum.keyCount();
|
||||
|
||||
QHash<int, QString> v;
|
||||
v.reserve(keysCount);
|
||||
for (int i = 0; i < keysCount; ++i)
|
||||
v[metaEnum.value(i)] = metaEnum.key(i);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
class EnumNameMapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_INVOKABLE QString statusName(int v) const { return m_statusMap.value(v); }
|
||||
Q_INVOKABLE QString formatName(int v) const { return m_formatMap.value(v); }
|
||||
Q_INVOKABLE QString targetName(int v) const { return m_targetMap.value(v); }
|
||||
|
||||
private:
|
||||
const QHash<int, QString> m_statusMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Status");
|
||||
const QHash<int, QString> m_formatMap = enumToNameMap<Qt3DRender::QAbstractTexture>("TextureFormat");
|
||||
const QHash<int, QString> m_targetMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Target");
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
QQuickView view;
|
||||
|
||||
QQmlContext *ctx =view.rootContext();
|
||||
EnumNameMapper mapper;
|
||||
ctx->setContextProperty(QStringLiteral("nameMapper"), &mapper);
|
||||
|
||||
view.setSource(QUrl("qrc:/main.qml"));
|
||||
view.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "main.moc"
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt3D module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.2 as QQ2
|
||||
import QtQuick.Scene3D 2.0
|
||||
import Qt3D.Core 2.0
|
||||
import Qt3D.Render 2.0
|
||||
import Qt3D.Input 2.0
|
||||
import Qt3D.Extras 2.0
|
||||
|
||||
QQ2.Item {
|
||||
id: root
|
||||
width: 1280
|
||||
height: 720
|
||||
|
||||
property int i: 0
|
||||
readonly property var sources: ["https://codereview.qt-project.org/gitweb?p=qt/qt3d.git;a=blob_plain;hb=refs/heads/dev;f=examples/qt3d/planets-qml/images/solarsystemscope/earthmap2k.jpg", "qrc:/image.jpg", "qrc:/image2.jpg", "qrc:/wrongpath.jpg"]
|
||||
readonly property url textureSource: sources[i]
|
||||
|
||||
QQ2.Timer {
|
||||
interval: 3000
|
||||
repeat: true
|
||||
running: true
|
||||
onTriggered: i = (i + 1) % sources.length
|
||||
}
|
||||
|
||||
Scene3D {
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
|
||||
aspects: ["input", "logic"]
|
||||
|
||||
Entity {
|
||||
id: sceneRoot
|
||||
|
||||
readonly property var textureModel: [texture1, texture2, texture3, texture4]
|
||||
|
||||
readonly property Texture texture1: TextureLoader {
|
||||
source: textureSource
|
||||
}
|
||||
|
||||
readonly property Texture texture2: TextureLoader {
|
||||
source: textureSource
|
||||
}
|
||||
|
||||
readonly property Texture texture3: Texture2D {
|
||||
textureImages: TextureImage {
|
||||
source: textureSource
|
||||
}
|
||||
}
|
||||
|
||||
readonly property Texture texture4: Texture2D {
|
||||
textureImages: TextureImage {
|
||||
source: textureSource
|
||||
}
|
||||
}
|
||||
|
||||
Camera {
|
||||
id: camera
|
||||
projectionType: CameraLens.PerspectiveProjection
|
||||
fieldOfView: 45
|
||||
aspectRatio: 16/9
|
||||
nearPlane : 0.1
|
||||
farPlane : 1000.0
|
||||
position: Qt.vector3d( 0.0, 20.0, -40.0 )
|
||||
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
|
||||
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
|
||||
}
|
||||
|
||||
OrbitCameraController {
|
||||
camera: camera
|
||||
}
|
||||
|
||||
components: [
|
||||
RenderSettings {
|
||||
activeFrameGraph: ForwardRenderer {
|
||||
clearColor: Qt.rgba(0, 0.5, 1, 1)
|
||||
camera: camera
|
||||
}
|
||||
},
|
||||
// Event Source will be set by the Qt3DQuickWindow
|
||||
InputSettings { }
|
||||
]
|
||||
|
||||
CuboidMesh { id: mesh }
|
||||
|
||||
NodeInstantiator {
|
||||
id: instantiator
|
||||
model: sceneRoot.textureModel
|
||||
|
||||
Entity {
|
||||
readonly property Transform transform: Transform {
|
||||
readonly property real angle: model.index / instantiator.count * Math.PI * 2
|
||||
translation: Qt.vector3d(Math.cos(angle) * 10, 0, Math.sin(angle) * 10)
|
||||
scale: 10
|
||||
}
|
||||
|
||||
readonly property DiffuseMapMaterial material: DiffuseMapMaterial {
|
||||
diffuse: model.modelData
|
||||
}
|
||||
components: [ mesh, material, transform ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QQ2.Text {
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
bottom: parent.bottom
|
||||
}
|
||||
font.pointSize: 20
|
||||
text: "Source (" + (i + 1) + " of " + sources.length + "): " + textureSource
|
||||
}
|
||||
|
||||
QQ2.ListView {
|
||||
anchors {
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
}
|
||||
readonly property var targets: []
|
||||
readonly property var status: []
|
||||
|
||||
spacing: 30
|
||||
model: sceneRoot.textureModel
|
||||
width: parent.width / 4
|
||||
delegate: QQ2.Grid {
|
||||
spacing: 10
|
||||
columns: 2
|
||||
QQ2.Text { text: "Target: " + nameMapper.targetName(model.modelData.target) }
|
||||
QQ2.Text { text: "Format: " + nameMapper.formatName(model.modelData.format.toString()) }
|
||||
QQ2.Text { text: "Width: " + model.modelData.width }
|
||||
QQ2.Text { text: "Height: " + model.modelData.height }
|
||||
QQ2.Text { text: "Depth: " + model.modelData.depth}
|
||||
QQ2.Text { text: "Layers: " + model.modelData.layers}
|
||||
QQ2.Text { text: "Status: " + nameMapper.statusName(model.modelData.status.toString()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
QT += 3dcore 3drender 3dinput 3dquick 3dlogic qml quick 3dquickextras
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
|
||||
OTHER_FILES += \
|
||||
main.qml
|
||||
|
||||
RESOURCES += \
|
||||
texture_property_updates.qrc
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>image.jpg</file>
|
||||
<file>image2.jpg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Loading…
Reference in New Issue