Skip to content

Commit

Permalink
Fix: unbreak compilation on OpenBSD - pt1
Browse files Browse the repository at this point in the history
Mesa in OpenBSD don't show glGetQueryObjectui64v. We use
glXGetProcAddress for obtain the function pointer
  • Loading branch information
yukiteruamano committed Feb 10, 2024
1 parent c8372b7 commit 1cad55f
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/backend/gl/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "backend/backend_common.h"
#include "backend/gl/gl_common.h"

static PFNGLGETQUERYOBJECTUI64VPROC ptrglGetQueryObjectui64v = NULL;

void gl_prepare(backend_t *base, const region_t *reg attr_unused) {
auto gd = (struct gl_data *)base;
glBeginQuery(GL_TIME_ELAPSED, gd->frame_timing[gd->current_frame_timing]);
Expand Down Expand Up @@ -1213,13 +1215,29 @@ bool gl_last_render_time(backend_t *base, struct timespec *ts) {
return false;
}

GLuint64 time;
glGetQueryObjectui64v(gd->frame_timing[gd->current_frame_timing ^ 1],
GL_QUERY_RESULT, &time);
ts->tv_sec = (long)(time / 1000000000);
ts->tv_nsec = (long)(time % 1000000000);
gl_check_err();
return true;
// We need obtain proc pointer for glGetQueryObjectui64v function.
// In OpenBSD this function no appear publicly, glXGetProcAddress resolve the issue.
if(ptrglGetQueryObjectui64v == NULL) {
ptrglGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC)
glXGetProcAddress("glGetQueryObjectui64v");

GLuint64 time;
ptrglGetQueryObjectui64v(gd->frame_timing[gd->current_frame_timing ^ 1],
GL_QUERY_RESULT, &time);
ts->tv_sec = (long)(time / 1000000000);
ts->tv_nsec = (long)(time % 1000000000);
gl_check_err();
}
else {
GLuint64 time;
ptrglGetQueryObjectui64v(gd->frame_timing[gd->current_frame_timing ^ 1],
GL_QUERY_RESULT, &time);
ts->tv_sec = (long)(time / 1000000000);
ts->tv_nsec = (long)(time % 1000000000);
gl_check_err();
}

return true;
}

bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
Expand Down

0 comments on commit 1cad55f

Please sign in to comment.