diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-06 13:04:59 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-08 18:02:38 +0200 |
commit | 297c303e88416274d3d2c14b5f6abf1c850c3cf8 (patch) | |
tree | 7be5fb4768733727423871d8329a9a94ea1bd214 /platform/darwin/src/headless_display_cgl.cpp | |
parent | 5a828cb80fb69f88840d3085b79c9e756bf0e66d (diff) | |
download | qtlocation-mapboxgl-297c303e88416274d3d2c14b5f6abf1c850c3cf8.tar.gz |
[core] Refactor HeadlessDisplay
Diffstat (limited to 'platform/darwin/src/headless_display_cgl.cpp')
-rw-r--r-- | platform/darwin/src/headless_display_cgl.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/platform/darwin/src/headless_display_cgl.cpp b/platform/darwin/src/headless_display_cgl.cpp new file mode 100644 index 0000000000..e2907a80c9 --- /dev/null +++ b/platform/darwin/src/headless_display_cgl.cpp @@ -0,0 +1,52 @@ +#include <mbgl/platform/default/headless_display.hpp> + +#include <OpenGL/OpenGL.h> + +#include <stdexcept> +#include <string> + +namespace mbgl { + +class HeadlessDisplay::Impl { +public: + Impl(); + ~Impl(); + CGLPixelFormatObj pixelFormat = nullptr; +}; + +HeadlessDisplay::Impl::Impl() { + // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported + // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension. + CGLPixelFormatAttribute attributes[] = { + kCGLPFAOpenGLProfile, + static_cast<CGLPixelFormatAttribute>(kCGLOGLPVersion_Legacy), + static_cast<CGLPixelFormatAttribute>(0) + }; + + GLint num; + CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Error choosing pixel format:") + CGLErrorString(error) + "\n"); + } + if (num <= 0) { + throw std::runtime_error("No pixel formats found."); + } +} + +HeadlessDisplay::Impl::~Impl() { + CGLDestroyPixelFormat(pixelFormat); +} + +template <> +CGLPixelFormatObj HeadlessDisplay::attribute() const { + return impl->pixelFormat; +} + +HeadlessDisplay::HeadlessDisplay() + : impl(std::make_unique<Impl>()) { +} + +HeadlessDisplay::~HeadlessDisplay() { +} + +} // namespace mbgl |