1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "textureimage_p.h"
5#include <Qt3DRender/qtextureimage.h>
6#include <Qt3DRender/private/managers_p.h>
7#include <Qt3DRender/private/qabstracttextureimage_p.h>
8
9QT_BEGIN_NAMESPACE
10
11using namespace Qt3DCore;
12
13namespace Qt3DRender {
14namespace Render {
15
16TextureImage::TextureImage()
17 : BackendNode(ReadWrite)
18 , m_dirty(false)
19 , m_layer(0)
20 , m_mipLevel(0)
21 , m_face(QAbstractTexture::CubeMapPositiveX)
22{
23}
24
25TextureImage::~TextureImage()
26{
27}
28
29void TextureImage::cleanup()
30{
31 m_generator.reset();
32 m_dirty = false;
33 m_layer = 0;
34 m_mipLevel = 0;
35 m_face = QAbstractTexture::CubeMapPositiveX;
36}
37
38void TextureImage::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
39{
40 const QAbstractTextureImage *node = qobject_cast<const QAbstractTextureImage *>(object: frontEnd);
41 if (!node)
42 return;
43
44 const bool oldEnabled = isEnabled();
45 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
46 m_dirty |= (oldEnabled != isEnabled());
47
48 if (node->layer() != m_layer) {
49 m_layer = node->layer();
50 m_dirty = true;
51 }
52
53 if (node->mipLevel() != m_mipLevel) {
54 m_mipLevel = node->mipLevel();
55 m_dirty = true;
56 }
57
58 if (node->face() != m_face) {
59 m_face = node->face();
60 m_dirty = true;
61 }
62
63 const QAbstractTextureImagePrivate *d = static_cast<const QAbstractTextureImagePrivate *>(QNodePrivate::get(q: node));
64 if (d->dataGenerator() != m_generator) {
65 m_generator = d->dataGenerator();
66 m_dirty = true;
67 }
68
69 if (m_dirty)
70 markDirty(changes: AbstractRenderer::AllDirty);
71}
72
73void TextureImage::unsetDirty()
74{
75 m_dirty = false;
76}
77
78TextureImageFunctor::TextureImageFunctor(AbstractRenderer *renderer,
79 TextureImageManager *textureImageManager)
80 : m_renderer(renderer)
81 , m_textureImageManager(textureImageManager)
82{
83}
84
85Qt3DCore::QBackendNode *TextureImageFunctor::create(Qt3DCore::QNodeId id) const
86{
87 TextureImage *backend = m_textureImageManager->getOrCreateResource(id);
88 backend->setRenderer(m_renderer);
89 return backend;
90}
91
92Qt3DCore::QBackendNode *TextureImageFunctor::get(Qt3DCore::QNodeId id) const
93{
94 return m_textureImageManager->lookupResource(id);
95}
96
97void TextureImageFunctor::destroy(Qt3DCore::QNodeId id) const
98{
99 m_textureImageManager->releaseResource(id);
100}
101
102} // namespace Render
103} // namespace Qt3DRender
104
105QT_END_NAMESPACE
106

source code of qt3d/src/render/texture/textureimage.cpp