Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5#include "qsgmapboxglnode.h"
6#include "qgeomapmapboxgl.h"
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{
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
33{
34 const QSize& minSize = size.expandedTo(minTextureSize);
35 const QSize fbSize = minSize * pixelRatio;
36 m_map->resize(minSize);
37
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));
57}
58
60{
61 QOpenGLFunctions *f = window->openglContext()->functions();
62 f->glViewport(0, 0, m_fbo->width(), m_fbo->height());
63
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();
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
105{
106 // QMapboxGL assumes we've prepared the viewport prior to render().
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
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
131
void copyrightsChanged(const QString &copyrightsHtml)
void sgNodeChanged()
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
\inmodule QtCore\reentrant
Definition qpoint.h:217
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
Definition qrect.h:484
StateFlags changedStates() const override
When the underlying rendering API is OpenGL, this function should return a mask where each bit repres...
void render(const RenderState *state) override
This function is called by the renderer and should paint this node with directly invoking commands in...
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
@ DirtyMaterial
Definition qsgnode.h:75
@ DirtyGeometry
Definition qsgnode.h:74
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setHasAlphaChannel(bool alpha)
The QSGRenderNode class represents a set of custom rendering commands targeting the graphics API that...
The QSGSimpleTextureNode class is provided for convenience to easily draw textured content using the ...
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode mode)
Sets the method used to generate texture coordinates to mode.
void setRect(const QRectF &rect)
Sets the target rect of this texture node to r.
void setFiltering(QSGTexture::Filtering filtering)
Sets the filtering to be used for this texture node to filtering.
void setTexture(QSGTexture *texture)
Sets the texture of this texture node to texture.
QSGTexture * texture() const
Returns the texture for this texture node.
void setOwnsTexture(bool owns)
Sets whether the node takes ownership of the texture to owns.
\inmodule QtCore
Definition qsize.h:25
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:192
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
uint alignment
else opt state
[0]
typedef GLint(GL_APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXEXTPROC)(GLuint program
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
static const QSize minTextureSize
double qreal
Definition qtypes.h:187
QSettings settings("MySoft", "Star Runner")
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]