diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-03 01:59:24 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-04 18:43:08 +0200 |
commit | e66cc2e583b8a56f1c9ace613c9bf6c1d0643712 (patch) | |
tree | 9e49031a64da303675cc545bc852163d4eb5abeb /platform/default | |
parent | f376827ed21115c43347841e346f908697179fd0 (diff) | |
download | qtlocation-mapboxgl-e66cc2e583b8a56f1c9ace613c9bf6c1d0643712.tar.gz |
[linux] Added OSMesa headless backend
Diffstat (limited to 'platform/default')
-rw-r--r-- | platform/default/headless_backend_osmesa.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/platform/default/headless_backend_osmesa.cpp b/platform/default/headless_backend_osmesa.cpp new file mode 100644 index 0000000000..e0e385fcc6 --- /dev/null +++ b/platform/default/headless_backend_osmesa.cpp @@ -0,0 +1,47 @@ +#include <mbgl/platform/default/headless_backend.hpp> +#include <mbgl/platform/log.hpp> + +namespace mbgl { + +gl::glProc HeadlessBackend::initializeExtension(const char* name) { + return OSMesaGetProcAddress(name); +} + +void HeadlessBackend::createContext() { + if (glContext == nullptr) { +#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 + glContext = OSMesaCreateContextExt(OSMESA_RGBA, 16, 0, 0, nullptr); +#else + glContext = OSMesaCreateContext(OSMESA_RGBA, nullptr); +#endif + if (glContext == nullptr) { + Log::Error(Event::OpenGL, "failed to create OSMesa context"); + } + } + + if (glContext == nullptr) { + throw std::runtime_error("Error creating GL context object."); + } +} + +void HeadlessBackend::destroyContext() { + if (glContext) { + if (glContext != OSMesaGetCurrentContext()) { + activateContext(); + } + OSMesaDestroyContext(glContext); + glContext = nullptr; + } +} + +void HeadlessBackend::activateContext() { + if (!OSMesaMakeCurrent(glContext, &fakeBuffer, GL_UNSIGNED_BYTE, 1, 1)) { + throw std::runtime_error("Switching OpenGL context failed.\n"); + } +} + +void HeadlessBackend::deactivateContext() { + // no-op. +} + +} // namespace mbgl |