summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-08-17 15:55:51 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-08-22 16:52:02 +0300
commit547af7475ef0004cbf7542a57e23de62e8590cc3 (patch)
tree5504a40458744ec23ea04c4539fe4e56ba430101
parent6761b325fb18ff31a05177678d8a0ad81c5c0d81 (diff)
downloadqtlocation-mapboxgl-547af7475ef0004cbf7542a57e23de62e8590cc3.tar.gz
[Qt] Implement a Qt headless renderer
Using legacy QGLWidget because we support Qt4.
-rw-r--r--include/mbgl/platform/default/headless_view.hpp9
-rw-r--r--platform/qt/config.cmake9
-rw-r--r--platform/qt/qt.cmake7
-rw-r--r--platform/qt/test/headless_view_qt.cpp106
4 files changed, 121 insertions, 10 deletions
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index e3acc8e379..989c226694 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -1,6 +1,9 @@
#pragma once
-#ifdef __APPLE__
+#if defined(__QT__)
+#define MBGL_USE_QT 1
+class QGLWidget;
+#elif defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IOS
#define MBGL_USE_EAGL 1
@@ -63,6 +66,10 @@ private:
bool extensionsLoaded = false;
bool active = false;
+#if MBGL_USE_QT
+ QGLWidget* glContext = nullptr;
+#endif
+
#if MBGL_USE_CGL
CGLContextObj glContext = nullptr;
#endif
diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake
index 46cc98eb81..f22e4c827b 100644
--- a/platform/qt/config.cmake
+++ b/platform/qt/config.cmake
@@ -40,15 +40,20 @@ macro(mbgl_platform_core)
endif()
endmacro()
-# TODO: Implement a Qt headless view, using offscreen
-# graphics system.
macro(mbgl_platform_test)
target_sources(mbgl-test
PRIVATE test/src/main.cpp
+ PRIVATE platform/qt/test/headless_view_qt.cpp
+ PRIVATE platform/default/headless_display.cpp
+ PRIVATE platform/default/headless_view.cpp
)
set_source_files_properties(
test/src/main.cpp
PROPERTIES COMPILE_FLAGS -DWORK_DIRECTORY="${CMAKE_SOURCE_DIR}"
)
+
+ target_link_libraries(mbgl-test
+ ${MBGL_QT_LIBRARIES}
+ )
endmacro()
diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake
index 9033bcfe37..0122f8922d 100644
--- a/platform/qt/qt.cmake
+++ b/platform/qt/qt.cmake
@@ -29,10 +29,6 @@ set(MBGL_QT_FILES
# Misc
PRIVATE platform/default/log_stderr.cpp
- # Headless headless_view_cgl
- PRIVATE platform/default/headless_display.cpp
- PRIVATE platform/default/headless_view.cpp
-
# Platform integration
PRIVATE platform/qt/src/async_task.cpp
PRIVATE platform/qt/src/async_task_impl.hpp
@@ -77,7 +73,6 @@ endif()
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND MBGL_QT_FILES
PRIVATE platform/darwin/src/nsthread.mm
- PRIVATE platform/darwin/src/headless_view_cgl.cpp
)
list(APPEND MBGL_QT_LIBRARIES
PRIVATE "-framework Foundation"
@@ -86,10 +81,8 @@ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
else()
list(APPEND MBGL_QT_FILES
PRIVATE platform/default/thread.cpp
- PRIVATE platform/default/headless_view_glx.cpp
)
list(APPEND MBGL_QT_LIBRARIES
PRIVATE -lGL
- PRIVATE -lX11
)
endif()
diff --git a/platform/qt/test/headless_view_qt.cpp b/platform/qt/test/headless_view_qt.cpp
new file mode 100644
index 0000000000..03ecb741ab
--- /dev/null
+++ b/platform/qt/test/headless_view_qt.cpp
@@ -0,0 +1,106 @@
+#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/platform/default/headless_view.hpp>
+
+#include <QApplication>
+#include <QGLContext>
+#include <QGLWidget>
+
+#if QT_VERSION >= 0x050000
+#include <QOpenGLContext>
+#endif
+
+namespace mbgl {
+
+gl::glProc HeadlessView::initializeExtension(const char* name) {
+#if QT_VERSION >= 0x050000
+ QOpenGLContext* thisContext = QOpenGLContext::currentContext();
+ return thisContext->getProcAddress(name);
+#else
+ const QGLContext* thisContext = QGLContext::currentContext();
+ return reinterpret_cast<mbgl::gl::glProc>(thisContext->getProcAddress(name));
+#endif
+}
+
+void HeadlessView::createContext() {
+ static const char* argv[] = { "mbgl" };
+ static int argc = 1;
+ static auto* app = new QApplication(argc, const_cast<char**>(argv));
+
+ Q_UNUSED(app);
+
+ glContext = new QGLWidget;
+}
+
+void HeadlessView::destroyContext() {
+ delete glContext;
+}
+
+void HeadlessView::resizeFramebuffer() {
+ const unsigned int w = dimensions[0] * pixelRatio;
+ const unsigned int h = dimensions[1] * pixelRatio;
+
+ // Create depth/stencil buffer
+ MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil));
+ MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil));
+ MBGL_CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h));
+ MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0));
+
+ MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboColor));
+ MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor));
+ MBGL_CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h));
+ MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0));
+
+ MBGL_CHECK_ERROR(glGenFramebuffersEXT(1, &fbo));
+ MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
+
+ MBGL_CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor));
+ MBGL_CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil));
+
+ GLenum status = MBGL_CHECK_ERROR(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
+
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ std::string error("Couldn't create framebuffer: ");
+ switch (status) {
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: (error += "incomplete attachment"); break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: error += "incomplete missing attachment"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: error += "incomplete dimensions"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: error += "incomplete formats"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: error += "incomplete draw buffer"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: error += "incomplete read buffer"; break;
+ case GL_FRAMEBUFFER_UNSUPPORTED: error += "unsupported"; break;
+ default: error += "other"; break;
+ }
+ throw std::runtime_error(error);
+ }
+
+ MBGL_CHECK_ERROR(glViewport(0, 0, w, h));
+}
+
+void HeadlessView::clearBuffers() {
+ MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
+
+ if (fbo) {
+ MBGL_CHECK_ERROR(glDeleteFramebuffersEXT(1, &fbo));
+ fbo = 0;
+ }
+
+ if (fboColor) {
+ MBGL_CHECK_ERROR(glDeleteRenderbuffersEXT(1, &fboColor));
+ fboColor = 0;
+ }
+
+ if (fboDepthStencil) {
+ MBGL_CHECK_ERROR(glDeleteRenderbuffersEXT(1, &fboDepthStencil));
+ fboDepthStencil = 0;
+ }
+}
+
+void HeadlessView::activateContext() {
+ glContext->makeCurrent();
+}
+
+void HeadlessView::deactivateContext() {
+ glContext->doneCurrent();
+}
+
+} // namespace mbgl