Fix tests when using GL 3.0+ context
This commit is contained in:
@@ -59,6 +59,7 @@ private:
|
||||
GLuint fbo = 0;
|
||||
GLuint fbo_depth_stencil = 0;
|
||||
GLuint fbo_color = 0;
|
||||
bool using_gl_3_or_newer = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ void GLFWView::initialize(mbgl::Map *map_) {
|
||||
glfwSetKeyCallback(window, key);
|
||||
|
||||
|
||||
const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
|
||||
const std::string extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
|
||||
{
|
||||
using namespace mbgl;
|
||||
|
||||
@@ -79,8 +79,8 @@ void GLFWView::initialize(mbgl::Map *map_) {
|
||||
gl::DebugMessageCallback = (gl::PFNGLDEBUGMESSAGECALLBACKPROC)glfwGetProcAddress("glDebugMessageCallback");
|
||||
gl::GetDebugMessageLog = (gl::PFNGLGETDEBUGMESSAGELOGPROC)glfwGetProcAddress("glGetDebugMessageLog");
|
||||
gl::GetPointerv = (gl::PFNGLGETPOINTERVPROC)glfwGetProcAddress("glGetPointerv");
|
||||
gl::PushDebugGroup = (gl::PFNGLPUSHDEBUGGROUPPROC)glfwGetProcAddress("glPushDebugGroup");
|
||||
gl::PopDebugGroup = (gl::PFNGLPOPDEBUGGROUPPROC)glfwGetProcAddress("glPopDebugGroup");
|
||||
//gl::PushDebugGroup = (gl::PFNGLPUSHDEBUGGROUPPROC)glfwGetProcAddress("glPushDebugGroup");
|
||||
//gl::PopDebugGroup = (gl::PFNGLPOPDEBUGGROUPPROC)glfwGetProcAddress("glPopDebugGroup");
|
||||
gl::ObjectLabel = (gl::PFNGLOBJECTLABELPROC)glfwGetProcAddress("glObjectLabel");
|
||||
gl::GetObjectLabel = (gl::PFNGLGETOBJECTLABELPROC)glfwGetProcAddress("glGetObjectLabel");
|
||||
gl::ObjectPtrLabel = (gl::PFNGLOBJECTPTRLABELPROC)glfwGetProcAddress("glObjectPtrLabel");
|
||||
|
||||
@@ -49,7 +49,23 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
|
||||
|
||||
void HeadlessView::loadExtensions() {
|
||||
make_active();
|
||||
const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
|
||||
|
||||
std::string extensions;
|
||||
if (using_gl_3_or_newer) {
|
||||
#ifdef GL_VERSION_3_0
|
||||
GLuint num_extensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, reinterpret_cast<GLint *>(&num_extensions));
|
||||
for (GLuint i = 0; i < num_extensions; i++) {
|
||||
extensions.append(reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)));
|
||||
extensions.append(" ");
|
||||
}
|
||||
#else
|
||||
throw std::runtime_error("Using GL 3.0+ context with out correct headers.\n");
|
||||
#endif
|
||||
} else {
|
||||
extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
|
||||
}
|
||||
|
||||
|
||||
#ifdef MBGL_USE_CGL
|
||||
if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
|
||||
@@ -90,7 +106,7 @@ static const core_profile_version core_profile_versions[] = {
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
|
||||
GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig, bool& using_gl_3_or_newer) {
|
||||
static bool context_creation_failed = false;
|
||||
GLXContext ctx = 0;
|
||||
|
||||
@@ -103,7 +119,8 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
|
||||
});
|
||||
|
||||
// Try to create core profiles from the highest known version on down.
|
||||
for (int i = 0; !ctx && core_profile_versions[i].major; i++) {
|
||||
int i = 0;
|
||||
for (; !ctx && core_profile_versions[i].major; i++) {
|
||||
context_creation_failed = false;
|
||||
const int context_flags[] = {
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major,
|
||||
@@ -116,6 +133,10 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
|
||||
}
|
||||
}
|
||||
|
||||
if (core_profile_versions[i].major >= 3) {
|
||||
using_gl_3_or_newer = true;
|
||||
}
|
||||
|
||||
// Restore the old error handler.
|
||||
XSetErrorHandler(previous_error_handler);
|
||||
return ctx;
|
||||
@@ -149,11 +170,11 @@ void HeadlessView::createContext() {
|
||||
#ifdef GLX_ARB_create_context
|
||||
if (glXCreateContextAttribsARB) {
|
||||
// Try to create a core profile context.
|
||||
gl_context = createCoreProfile(x_display, fb_configs[0]);
|
||||
gl_context = createCoreProfile(x_display, fb_configs[0], using_gl_3_or_newer);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!gl_context) {
|
||||
if (gl_context == 0) {
|
||||
// Try to create a legacy context
|
||||
gl_context = glXCreateNewContext(x_display, fb_configs[0], GLX_RGBA_TYPE, 0, True);
|
||||
if (gl_context) {
|
||||
@@ -331,4 +352,3 @@ void HeadlessView::make_inactive() {
|
||||
void HeadlessView::swap() {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ void Painter::setup() {
|
||||
// Enable GL debugging
|
||||
if ((gl::DebugMessageControl != nullptr) && (gl::DebugMessageCallback != nullptr)) {
|
||||
// This will enable all messages including performance hints
|
||||
gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
//gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
|
||||
// This will only enable high and medium severity messages
|
||||
//gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE);
|
||||
//gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE);
|
||||
gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE);
|
||||
gl::DebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE);
|
||||
|
||||
gl::DebugMessageCallback(gl::debug_callback, nullptr);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo
|
||||
GLint logLength;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
GLchar *log = reinterpret_cast<GLchar *>(malloc(logLength));
|
||||
glGetProgramInfoLog(program, logLength, &logLength, log);
|
||||
Log::Error(Event::Shader, "Program failed to link: %s", log);
|
||||
free(log);
|
||||
@@ -69,7 +69,7 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo
|
||||
GLint logLength;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
GLchar *log = reinterpret_cast<GLchar *>(malloc(logLength));
|
||||
glGetProgramInfoLog(program, logLength, &logLength, log);
|
||||
Log::Error(Event::Shader, "Program failed to validate: %s", log);
|
||||
free(log);
|
||||
@@ -110,7 +110,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) {
|
||||
GLint logLength;
|
||||
glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
GLchar *log = reinterpret_cast<GLchar *>(malloc(logLength));
|
||||
glGetShaderInfoLog(*shader, logLength, &logLength, log);
|
||||
Log::Error(Event::Shader, "Shader failed to compile: %s", log);
|
||||
free(log);
|
||||
|
||||
Reference in New Issue
Block a user