1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

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