[core] separate Backend from View for headless rendering
This commit is contained in:
@@ -1,54 +1,14 @@
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
gl::glProc HeadlessView::initializeExtension(const char* name) {
|
||||
return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name));
|
||||
}
|
||||
|
||||
void HeadlessView::createContext() {
|
||||
xDisplay = display->xDisplay;
|
||||
fbConfigs = display->fbConfigs;
|
||||
|
||||
if (!glContext) {
|
||||
// Try to create a legacy context
|
||||
glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True);
|
||||
if (glContext) {
|
||||
if (!glXIsDirect(xDisplay, glContext)) {
|
||||
Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context");
|
||||
glXDestroyContext(xDisplay, glContext);
|
||||
glContext = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (glContext == nullptr) {
|
||||
throw std::runtime_error("Error creating GL context object.");
|
||||
}
|
||||
|
||||
// Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to
|
||||
// activate the context.
|
||||
int pbufferAttributes[] = {
|
||||
GLX_PBUFFER_WIDTH, 8,
|
||||
GLX_PBUFFER_HEIGHT, 8,
|
||||
None
|
||||
};
|
||||
glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes);
|
||||
}
|
||||
|
||||
void HeadlessView::destroyContext() {
|
||||
if (glxPbuffer) {
|
||||
glXDestroyPbuffer(xDisplay, glxPbuffer);
|
||||
glxPbuffer = 0;
|
||||
}
|
||||
|
||||
glXDestroyContext(xDisplay, glContext);
|
||||
void HeadlessView::bindFramebuffer() {
|
||||
assert(fbo);
|
||||
MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
|
||||
}
|
||||
|
||||
void HeadlessView::resizeFramebuffer() {
|
||||
@@ -93,8 +53,6 @@ void HeadlessView::resizeFramebuffer() {
|
||||
}
|
||||
|
||||
void HeadlessView::clearBuffers() {
|
||||
assert(active);
|
||||
|
||||
MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
|
||||
|
||||
if (fbo) {
|
||||
@@ -113,16 +71,4 @@ void HeadlessView::clearBuffers() {
|
||||
}
|
||||
}
|
||||
|
||||
void HeadlessView::activateContext() {
|
||||
if (!glXMakeContextCurrent(xDisplay, glxPbuffer, glxPbuffer, glContext)) {
|
||||
throw std::runtime_error("Switching OpenGL context failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void HeadlessView::deactivateContext() {
|
||||
if (!glXMakeContextCurrent(xDisplay, 0, 0, nullptr)) {
|
||||
throw std::runtime_error("Removing OpenGL context failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user