Convert printf_errf/dbgf in opengl.c

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-20 16:50:11 +00:00
parent 22669889eb
commit 3966491846
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 90 additions and 104 deletions

View File

@ -3752,8 +3752,10 @@ session_init(session_t *ps_old, int argc, char **argv) {
init_overlay(ps);
// Initialize filters, must be preceded by OpenGL context creation
if (!init_render(ps))
if (!init_render(ps)) {
log_fatal("Failed to initialize the backend");
exit(1);
}
if (ps->o.print_diagnostics) {
print_diagnostics(ps);

View File

@ -74,9 +74,11 @@ glx_update_fbconfig_bydepth(session_t *ps, int depth, glx_fbconfig_t *pfbcfg) {
// Compare new FBConfig with current one
if (glx_cmp_fbconfig(ps, ps->psglx->fbconfigs[depth], pfbcfg) < 0) {
#ifdef DEBUG_GLX
printf_dbgf("(%d): %#x overrides %#x, target %#x.\n", depth, (unsigned) pfbcfg->cfg, (ps->psglx->fbconfigs[depth] ? (unsigned) ps->psglx->fbconfigs[depth]->cfg: 0), pfbcfg->texture_tgts);
#endif
log_trace("(depth %d): %p overrides %p, target %#x.", depth,
pfbcfg->cfg,
ps->psglx->fbconfigs[depth] ? ps->psglx->fbconfigs[depth]->cfg:
0,
pfbcfg->texture_tgts);
if (!ps->psglx->fbconfigs[depth]) {
ps->psglx->fbconfigs[depth] = cmalloc(glx_fbconfig_t);
}
@ -113,11 +115,11 @@ glx_update_fbconfig(session_t *ps) {
if (Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BUFFER_SIZE, &depth)
|| Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_ALPHA_SIZE, &depth_alpha)) {
printf_errf("(): Failed to retrieve buffer size and alpha size of FBConfig %d.", id);
log_error("Failed to retrieve buffer size and alpha size of FBConfig %d.", id);
continue;
}
if (Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BIND_TO_TEXTURE_TARGETS_EXT, &fbinfo.texture_tgts)) {
printf_errf("(): Failed to retrieve BIND_TO_TEXTURE_TARGETS_EXT of FBConfig %d.", id);
log_error("Failed to retrieve BIND_TO_TEXTURE_TARGETS_EXT of FBConfig %d.", id);
continue;
}
@ -126,7 +128,7 @@ glx_update_fbconfig(session_t *ps) {
XVisualInfo *pvi = glXGetVisualFromFBConfig(ps->dpy, *pcur);
if (!pvi) {
// On nvidia-drivers-325.08 this happens slightly too often...
// printf_errf("(): Failed to retrieve X Visual of FBConfig %d.", id);
// log_error("Failed to retrieve X Visual of FBConfig %d.", id);
continue;
}
visualdepth = pvi->depth;
@ -163,19 +165,16 @@ glx_update_fbconfig(session_t *ps) {
// Sanity checks
if (!ps->psglx->fbconfigs[ps->depth]) {
printf_errf("(): No FBConfig found for default depth %d.", ps->depth);
log_error("No FBConfig found for default depth %d.", ps->depth);
return false;
}
if (!ps->psglx->fbconfigs[32]) {
printf_errf("(): No FBConfig found for depth 32. Expect crazy things.");
log_error("No FBConfig found for depth 32. Expect crazy things.");
}
#ifdef DEBUG_GLX
printf_dbgf("(): %d-bit: %#3x, 32-bit: %#3x\n",
ps->depth, (int) ps->psglx->fbconfigs[ps->depth]->cfg,
(int) ps->psglx->fbconfigs[32]->cfg);
#endif
log_trace("%d-bit: %p, 32-bit: %p", ps->depth, ps->psglx->fbconfigs[ps->depth]->cfg,
ps->psglx->fbconfigs[32]->cfg);
return true;
}
@ -208,8 +207,8 @@ static void
glx_debug_msg_callback(GLenum source, GLenum type,
GLuint id, GLenum severity, GLsizei length, const GLchar *message,
GLvoid *userParam) {
printf_dbgf("(): source 0x%04X, type 0x%04X, id %u, severity 0x%0X, \"%s\"\n",
source, type, id, severity, message);
log_trace("source 0x%04X, type 0x%04X, id %u, severity 0x%0X, \"%s\"",
source, type, id, severity, message);
}
#endif
@ -226,7 +225,7 @@ glx_init(session_t *ps, bool need_render) {
if (glXQueryExtension(ps->dpy, &ps->glx_event, &ps->glx_error))
ps->glx_exists = true;
else {
printf_errf("(): No GLX extension.");
log_error("No GLX extension.");
goto glx_init_end;
}
}
@ -234,7 +233,7 @@ glx_init(session_t *ps, bool need_render) {
// Get XVisualInfo
pvis = get_visualinfo_from_visual(ps, ps->vis);
if (!pvis) {
printf_errf("(): Failed to acquire XVisualInfo for current visual.");
log_error("Failed to acquire XVisualInfo for current visual.");
goto glx_init_end;
}
@ -242,13 +241,13 @@ glx_init(session_t *ps, bool need_render) {
if (need_render) {
int value = 0;
if (Success != glXGetConfig(ps->dpy, pvis, GLX_USE_GL, &value) || !value) {
printf_errf("(): Root visual is not a GL visual.");
log_error("Root visual is not a GL visual.");
goto glx_init_end;
}
if (Success != glXGetConfig(ps->dpy, pvis, GLX_DOUBLEBUFFER, &value)
|| !value) {
printf_errf("(): Root visual is not a double buffered GL visual.");
log_error("Root visual is not a double buffered GL visual.");
goto glx_init_end;
}
}
@ -281,8 +280,7 @@ glx_init(session_t *ps, bool need_render) {
{
GLXFBConfig fbconfig = get_fbconfig_from_visualinfo(ps, pvis);
if (!fbconfig) {
printf_errf("(): Failed to get GLXFBConfig for root visual %#lx.",
pvis->visualid);
log_error("Failed to get GLXFBConfig for root visual %#lx.", pvis->visualid);
goto glx_init_end;
}
@ -290,7 +288,7 @@ glx_init(session_t *ps, bool need_render) {
(f_glXCreateContextAttribsARB)
glXGetProcAddress((const GLubyte *) "glXCreateContextAttribsARB");
if (!p_glXCreateContextAttribsARB) {
printf_errf("(): Failed to get glXCreateContextAttribsARB().");
log_error("Failed to get glXCreateContextAttribsARB().");
goto glx_init_end;
}
@ -304,13 +302,13 @@ glx_init(session_t *ps, bool need_render) {
#endif
if (!psglx->context) {
printf_errf("(): Failed to get GLX context.");
log_error("Failed to get GLX context.");
goto glx_init_end;
}
// Attach GLX context
if (!glXMakeCurrent(ps->dpy, get_tgt_window(ps), psglx->context)) {
printf_errf("(): Failed to attach GLX context.");
log_error("Failed to attach GLX context.");
goto glx_init_end;
}
@ -320,7 +318,7 @@ glx_init(session_t *ps, bool need_render) {
(f_DebugMessageCallback)
glXGetProcAddress((const GLubyte *) "glDebugMessageCallback");
if (!p_DebugMessageCallback) {
printf_errf("(): Failed to get glDebugMessageCallback(0.");
log_error("Failed to get glDebugMessageCallback(0.");
goto glx_init_end;
}
p_DebugMessageCallback(glx_debug_msg_callback, ps);
@ -336,7 +334,7 @@ glx_init(session_t *ps, bool need_render) {
GLint val = 0;
glGetIntegerv(GL_STENCIL_BITS, &val);
if (!val) {
printf_errf("(): Target window doesn't have stencil buffer.");
log_error("Target window doesn't have stencil buffer.");
goto glx_init_end;
}
}
@ -361,7 +359,7 @@ glx_init(session_t *ps, bool need_render) {
psglx->glXReleaseTexImageProc = (f_ReleaseTexImageEXT)
glXGetProcAddress((const GLubyte *) "glXReleaseTexImageEXT");
if (!psglx->glXBindTexImageProc || !psglx->glXReleaseTexImageProc) {
printf_errf("(): Failed to acquire glXBindTexImageEXT() / glXReleaseTexImageEXT().");
log_error("Failed to acquire glXBindTexImageEXT() / glXReleaseTexImageEXT().");
goto glx_init_end;
}
}
@ -468,12 +466,12 @@ glx_reinit(session_t *ps, bool need_render) {
glx_destroy(ps);
if (!glx_init(ps, need_render)) {
printf_errf("(): Failed to initialize GLX.");
log_error("Failed to initialize GLX.");
return false;
}
if (!vsync_init(ps)) {
printf_errf("(): Failed to initialize VSync.");
log_error("Failed to initialize VSync.");
return false;
}
@ -508,8 +506,8 @@ glx_init_blur(session_t *ps) {
GLuint fbo = 0;
glGenFramebuffers(1, &fbo);
if (!fbo) {
printf_errf("(): Failed to generate Framebuffer. Cannot do "
"multi-pass blur with GLX backend.");
log_error("Failed to generate Framebuffer. Cannot do multi-pass blur with GLX"
" backend.");
return false;
}
glDeleteFramebuffers(1, &fbo);
@ -572,42 +570,41 @@ glx_init_blur(session_t *ps) {
strlen(FRAG_SHADER_BLUR_SUFFIX) +
strlen(texture_func) + 12 + 1;
char *shader_str = ccalloc(len, char);
{
char *pc = shader_str;
sprintf(pc, FRAG_SHADER_BLUR_PREFIX, extension, sampler_type);
pc += strlen(pc);
assert(strlen(shader_str) < len);
char *pc = shader_str;
sprintf(pc, FRAG_SHADER_BLUR_PREFIX, extension, sampler_type);
pc += strlen(pc);
assert(strlen(shader_str) < len);
double sum = 0.0;
for (int j = 0; j < hei; ++j) {
for (int k = 0; k < wid; ++k) {
if (hei / 2 == j && wid / 2 == k)
continue;
double val = XFIXED_TO_DOUBLE(kern[2 + j * wid + k]);
if (0.0 == val)
continue;
sum += val;
sprintf(pc, shader_add, val, texture_func, k - wid / 2, j - hei / 2);
pc += strlen(pc);
assert(strlen(shader_str) < len);
}
double sum = 0.0;
for (int j = 0; j < hei; ++j) {
for (int k = 0; k < wid; ++k) {
if (hei / 2 == j && wid / 2 == k)
continue;
double val = XFIXED_TO_DOUBLE(kern[2 + j * wid + k]);
if (0.0 == val)
continue;
sum += val;
sprintf(pc, shader_add, val, texture_func, k - wid / 2, j - hei / 2);
pc += strlen(pc);
assert(strlen(shader_str) < len);
}
sprintf(pc, FRAG_SHADER_BLUR_SUFFIX, texture_func, sum);
assert(strlen(shader_str) < len);
}
sprintf(pc, FRAG_SHADER_BLUR_SUFFIX, texture_func, sum);
assert(strlen(shader_str) < len);
ppass->frag_shader = glx_create_shader(GL_FRAGMENT_SHADER, shader_str);
free(shader_str);
}
if (!ppass->frag_shader) {
printf_errf("(): Failed to create fragment shader %d.", i);
log_error("Failed to create fragment shader %d.", i);
return false;
}
// Build program
ppass->prog = glx_create_program(&ppass->frag_shader, 1);
if (!ppass->prog) {
printf_errf("(): Failed to create GLSL program.");
log_error("Failed to create GLSL program.");
return false;
}
@ -615,7 +612,7 @@ glx_init_blur(session_t *ps) {
#define P_GET_UNIFM_LOC(name, target) { \
ppass->target = glGetUniformLocation(ppass->prog, name); \
if (ppass->target < 0) { \
printf_errf("(): Failed to get location of %d-th uniform '" name "'. Might be troublesome.", i); \
log_error("Failed to get location of %d-th uniform '" name "'. Might be troublesome.", i); \
} \
}
@ -652,7 +649,7 @@ glx_load_prog_main(session_t *ps,
// Build program
pprogram->prog = glx_create_program_from_str(vshader_str, fshader_str);
if (!pprogram->prog) {
printf_errf("(): Failed to create GLSL program.");
log_error("Failed to create GLSL program.");
return false;
}
@ -660,7 +657,7 @@ glx_load_prog_main(session_t *ps,
#define P_GET_UNIFM_LOC(name, target) { \
pprogram->target = glGetUniformLocation(pprogram->prog, name); \
if (pprogram->target < 0) { \
printf_errf("(): Failed to get location of uniform '" name "'. Might be troublesome."); \
log_error("Failed to get location of uniform '" name "'. Might be troublesome."); \
} \
}
P_GET_UNIFM_LOC("opacity", unifm_opacity);
@ -683,7 +680,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
return true;
if (!pixmap) {
printf_errf("(%#010x): Binding to an empty pixmap. This can't work.", pixmap);
log_error("Binding to an empty pixmap %#010x. This can't work.", pixmap);
return false;
}
@ -725,19 +722,19 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
unsigned rbdwid = 0;
if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry,
&width, &height, &rbdwid, &depth)) {
printf_errf("(%#010x): Failed to query Pixmap info.", pixmap);
log_error("Failed to query info of pixmap %#010x.", pixmap);
return false;
}
if (depth > OPENGL_MAX_DEPTH) {
printf_errf("(%d): Requested depth higher than %d.", depth,
OPENGL_MAX_DEPTH);
log_error("Requested depth %d higher than %d.", depth,
OPENGL_MAX_DEPTH);
return false;
}
}
const glx_fbconfig_t *pcfg = ps->psglx->fbconfigs[depth];
if (!pcfg) {
printf_errf("(%d): Couldn't find FBConfig with requested depth.", depth);
log_error("Couldn't find FBConfig with requested depth %d.", depth);
return false;
}
@ -755,10 +752,8 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
else
tex_tgt = GLX_TEXTURE_2D_EXT;
#ifdef DEBUG_GLX
printf_dbgf("(): depth %d, tgt %#x, rgba %d\n", depth, tex_tgt,
(GLX_TEXTURE_FORMAT_RGBA_EXT == pcfg->texture_fmt));
#endif
log_debug("depth %d, tgt %#x, rgba %d", depth, tex_tgt,
(GLX_TEXTURE_FORMAT_RGBA_EXT == pcfg->texture_fmt));
GLint attrs[] = {
GLX_TEXTURE_FORMAT_EXT,
@ -778,7 +773,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
ptex->y_inverted = pcfg->y_inverted;
}
if (!ptex->glpixmap) {
printf_errf("(): Failed to allocate GLX pixmap.");
log_error("Failed to allocate GLX pixmap.");
return false;
}
@ -802,7 +797,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
ptex->texture = texture;
}
if (!ptex->texture) {
printf_errf("(): Failed to allocate texture.");
log_error("Failed to allocate texture.");
return false;
}
@ -998,9 +993,7 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
pbc = &ibc;
int mdx = dx, mdy = dy, mwidth = width, mheight = height;
#ifdef DEBUG_GLX
printf_dbgf("(): %d, %d, %d, %d\n", mdx, mdy, mwidth, mheight);
#endif
//log_trace("%d, %d, %d, %d", mdx, mdy, mwidth, mheight);
/*
if (ps->o.resize_damage > 0) {
@ -1045,11 +1038,11 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
const GLuint fbo = pbc->fbo;
if (!tex_scr || (more_passes && !tex_scr2)) {
printf_errf("(): Failed to allocate texture.");
log_error("Failed to allocate texture.");
goto glx_blur_dst_end;
}
if (more_passes && !fbo) {
printf_errf("(): Failed to allocate framebuffer.");
log_error("Failed to allocate framebuffer.");
goto glx_blur_dst_end;
}
@ -1099,7 +1092,7 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
glDrawBuffers(1, DRAWBUFS);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER)
!= GL_FRAMEBUFFER_COMPLETE) {
printf_errf("(): Framebuffer attachment failed.");
log_error("Framebuffer attachment failed.");
goto glx_blur_dst_end;
}
}
@ -1142,9 +1135,8 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
GLfloat rdxe = rdx + (crect.x2 - crect.x1);
GLfloat rdye = rdy - (crect.y2 - crect.y1);
#ifdef DEBUG_GLX
printf_dbgf("(): %f, %f, %f, %f -> %f, %f, %f, %f\n", rx, ry, rxe, rye, rdx, rdy, rdxe, rdye);
#endif
//log_trace("%f, %f, %f, %f -> %f, %f, %f, %f", rx, ry, rxe, rye, rdx,
// rdy, rdxe, rdye);
glTexCoord2f(rx, ry);
glVertex3f(rdx, rdy, z);
@ -1235,7 +1227,7 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
const region_t *reg_tgt, const glx_prog_main_t *pprogram
) {
if (!ptex || !ptex->texture) {
printf_errf("(): Missing texture.");
log_error("Missing texture.");
return false;
}
@ -1349,9 +1341,8 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
glUniform1i(pprogram->unifm_tex, 0);
}
#ifdef DEBUG_GLX
printf_dbgf("(): Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d\n", x, y, width, height, dx, dy, ptex->width, ptex->height, z);
#endif
//log_trace("Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d", x, y, width, height,
// dx, dy, ptex->width, ptex->height, z);
// Bind texture
glBindTexture(ptex->target, ptex->texture);
@ -1389,9 +1380,8 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
rye = 1.0 - rye;
}
#ifdef DEBUG_GLX
printf_dbgf("(): Rect %d: %f, %f, %f, %f -> %d, %d, %d, %d\n", ri, rx, ry, rxe, rye, rdx, rdy, rdxe, rdye);
#endif
//log_trace("Rect %d: %f, %f, %f, %f -> %d, %d, %d, %d", ri, rx, ry, rxe, rye,
// rdx, rdy, rdxe, rdye);
#define P_TEXCOORD(cx, cy) { \
if (dual_texture) { \
@ -1465,15 +1455,12 @@ glx_take_screenshot(session_t *ps, int *out_length) {
GLuint
glx_create_shader(GLenum shader_type, const char *shader_str) {
#ifdef DEBUG_GLX_GLSL
printf("glx_create_shader(): ===\n%s\n===\n", shader_str);
fflush(stdout);
#endif
log_trace("glx_create_shader(): ===\n%s\n===", shader_str);
bool success = false;
GLuint shader = glCreateShader(shader_type);
if (!shader) {
printf_errf("(): Failed to create shader with type %#x.", shader_type);
log_error("Failed to create shader with type %#x.", shader_type);
goto glx_create_shader_end;
}
glShaderSource(shader, 1, &shader_str, NULL);
@ -1489,8 +1476,7 @@ glx_create_shader(GLenum shader_type, const char *shader_str) {
if (log_len) {
char log[log_len + 1];
glGetShaderInfoLog(shader, log_len, NULL, log);
printf_errf("(): Failed to compile shader with type %d: %s",
shader_type, log);
log_error("Failed to compile shader with type %d: %s", shader_type, log);
}
goto glx_create_shader_end;
}
@ -1512,7 +1498,7 @@ glx_create_program(const GLuint * const shaders, int nshaders) {
bool success = false;
GLuint program = glCreateProgram();
if (!program) {
printf_errf("(): Failed to create program.");
log_error("Failed to create program.");
goto glx_create_program_end;
}
@ -1530,7 +1516,7 @@ glx_create_program(const GLuint * const shaders, int nshaders) {
if (log_len) {
char log[log_len + 1];
glGetProgramInfoLog(program, log_len, NULL, log);
printf_errf("(): Failed to link program: %s", log);
log_error("Failed to link program: %s", log);
}
goto glx_create_program_end;
}
@ -1565,17 +1551,15 @@ glx_create_program_from_str(const char *vert_shader_str,
if (frag_shader_str)
frag_shader = glx_create_shader(GL_FRAGMENT_SHADER, frag_shader_str);
{
GLuint shaders[2];
unsigned int count = 0;
if (vert_shader)
shaders[count++] = vert_shader;
if (frag_shader)
shaders[count++] = frag_shader;
assert(count <= sizeof(shaders) / sizeof(shaders[0]));
if (count)
prog = glx_create_program(shaders, count);
}
GLuint shaders[2];
unsigned int count = 0;
if (vert_shader)
shaders[count++] = vert_shader;
if (frag_shader)
shaders[count++] = frag_shader;
assert(count <= sizeof(shaders) / sizeof(shaders[0]));
if (count)
prog = glx_create_program(shaders, count);
if (vert_shader)
glDeleteShader(vert_shader);