Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgmapboxglnode.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2017 Mapbox, Inc.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
7
8#if __has_include(<QtQuick/private/qsgplaintexture_p.h>)
9#include <QtQuick/private/qsgplaintexture_p.h>
10#endif
11
12#include <QtGui/QOpenGLContext>
13#include <QtGui/QOpenGLFunctions>
14
15// QSGMapboxGLTextureNode
16
17static const QSize minTextureSize = QSize(64, 64);
18
19QSGMapboxGLTextureNode::QSGMapboxGLTextureNode(const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio, QGeoMapMapboxGL *geoMap)
21{
22 setTextureCoordinatesTransform(QSGSimpleTextureNode::MirrorVertically);
23 setFiltering(QSGTexture::Linear);
24
25 m_map.reset(new QMapboxGL(nullptr, settings, size.expandedTo(minTextureSize), pixelRatio));
26
27 QObject::connect(m_map.data(), &QMapboxGL::needsRendering, geoMap, &QGeoMap::sgNodeChanged);
28 QObject::connect(m_map.data(), &QMapboxGL::copyrightsChanged, geoMap,
29 static_cast<void (QGeoMap::*)(const QString &)>(&QGeoMapMapboxGL::copyrightsChanged));
30}
31
32void QSGMapboxGLTextureNode::resize(const QSize &size, qreal pixelRatio)
33{
34 const QSize& minSize = size.expandedTo(minTextureSize);
35 const QSize fbSize = minSize * pixelRatio;
36 m_map->resize(minSize);
37
38 m_fbo.reset(new QOpenGLFramebufferObject(fbSize, QOpenGLFramebufferObject::CombinedDepthStencil));
39 m_map->setFramebufferObject(m_fbo->handle(), fbSize);
40
41 QSGPlainTexture *fboTexture = static_cast<QSGPlainTexture *>(texture());
42 if (!fboTexture) {
43 fboTexture = new QSGPlainTexture;
44 fboTexture->setHasAlphaChannel(true);
45 }
46
47 fboTexture->setTextureId(m_fbo->texture());
48 fboTexture->setTextureSize(fbSize);
49
50 if (!texture()) {
51 setTexture(fboTexture);
52 setOwnsTexture(true);
53 }
54
55 setRect(QRectF(QPointF(), minSize));
56 markDirty(QSGNode::DirtyGeometry);
57}
58
59void QSGMapboxGLTextureNode::render(QQuickWindow *window)
60{
61 QOpenGLFunctions *f = window->openglContext()->functions();
62 f->glViewport(0, 0, m_fbo->width(), m_fbo->height());
63
64 GLint alignment;
65 f->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
66
67 m_fbo->bind();
68
69 f->glClearColor(0.f, 0.f, 0.f, 0.f);
70 f->glColorMask(true, true, true, true);
71 f->glClear(GL_COLOR_BUFFER_BIT);
72
73 m_map->render();
74 m_fbo->release();
75
76 // QTBUG-62861
77 f->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
78
79 window->resetOpenGLState();
80 markDirty(QSGNode::DirtyMaterial);
81}
82
84{
85 return m_map.data();
86}
87
88// QSGMapboxGLRenderNode
89
90QSGMapboxGLRenderNode::QSGMapboxGLRenderNode(const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio, QGeoMapMapboxGL *geoMap)
92{
93 m_map.reset(new QMapboxGL(nullptr, settings, size, pixelRatio));
94 QObject::connect(m_map.data(), &QMapboxGL::needsRendering, geoMap, &QGeoMap::sgNodeChanged);
95 QObject::connect(m_map.data(), &QMapboxGL::copyrightsChanged, geoMap,
96 static_cast<void (QGeoMap::*)(const QString &)>(&QGeoMapMapboxGL::copyrightsChanged));
97}
98
100{
101 return m_map.data();
102}
103
104void QSGMapboxGLRenderNode::render(const RenderState *state)
105{
106 // QMapboxGL assumes we've prepared the viewport prior to render().
107 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
108 f->glViewport(state->scissorRect().x(), state->scissorRect().y(), state->scissorRect().width(), state->scissorRect().height());
109 f->glScissor(state->scissorRect().x(), state->scissorRect().y(), state->scissorRect().width(), state->scissorRect().height());
110 f->glEnable(GL_SCISSOR_TEST);
111
112 GLint alignment;
113 f->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
114
115 m_map->render();
116
117 // QTBUG-62861
118 f->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
119}
120
122{
123 return QSGRenderNode::DepthState
124 | QSGRenderNode::StencilState
125 | QSGRenderNode::ScissorState
126 | QSGRenderNode::ColorState
127 | QSGRenderNode::BlendState
128 | QSGRenderNode::ViewportState
129 | QSGRenderNode::RenderTargetState;
130}
StateFlags changedStates() const override
This function should return a mask where each bit represents graphics states changed by the \l render...
void render(const RenderState *state) override
This function is called by the renderer and should paint this node with directly invoking commands vi...
QMapboxGL * map() const
QSGMapboxGLRenderNode(const QMapboxGLSettings &, const QSize &, qreal pixelRatio, QGeoMapMapboxGL *geoMap)
void render(QQuickWindow *)
QSGMapboxGLTextureNode(const QMapboxGLSettings &, const QSize &, qreal pixelRatio, QGeoMapMapboxGL *geoMap)
void resize(const QSize &size, qreal pixelRatio)
QMapboxGL * map() const
#define __has_include(x)
static const QSize minTextureSize