opengl: address some clang-tidy issues

This commit is contained in:
Maxim Solovyov 2023-09-15 00:43:15 +03:00
parent c6abb4e270
commit 0cd72bf61a
No known key found for this signature in database
2 changed files with 72 additions and 42 deletions

View File

@ -78,8 +78,9 @@ bool glx_init(session_t *ps, bool need_render) {
}
// Ensure GLX_EXT_texture_from_pixmap exists
if (need_render && !glxext.has_GLX_EXT_texture_from_pixmap)
if (need_render && !glxext.has_GLX_EXT_texture_from_pixmap) {
goto glx_init_end;
}
// Initialize GLX data structure
if (!ps->psglx) {
@ -178,9 +179,10 @@ bool glx_init(session_t *ps, bool need_render) {
// Check GL_ARB_texture_non_power_of_two, requires a GLX context and
// must precede FBConfig fetching
if (need_render)
if (need_render) {
psglx->has_texture_non_power_of_two =
gl_has_extension("GL_ARB_texture_non_power_of_two");
}
// Render preparations
if (need_render) {
@ -200,7 +202,7 @@ bool glx_init(session_t *ps, bool need_render) {
}
// Clear screen
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glXSwapBuffers(ps->c.dpy, get_tgt_window(ps));
}
@ -210,15 +212,17 @@ bool glx_init(session_t *ps, bool need_render) {
glx_init_end:
XFree(pvis);
if (!success)
if (!success) {
glx_destroy(ps);
}
return success;
}
static void glx_free_prog_main(glx_prog_main_t *pprogram) {
if (!pprogram)
if (!pprogram) {
return;
}
if (pprogram->prog) {
glDeleteProgram(pprogram->prog);
pprogram->prog = 0;
@ -232,8 +236,9 @@ static void glx_free_prog_main(glx_prog_main_t *pprogram) {
* Destroy GLX related resources.
*/
void glx_destroy(session_t *ps) {
if (!ps->psglx)
if (!ps->psglx) {
return;
}
// Free all GLX resources of windows
win_stack_foreach_managed(w, &ps->window_stack) {
@ -373,8 +378,9 @@ bool glx_init_blur(session_t *ps) {
double sum = 0.0;
for (int j = 0; j < height; ++j) {
for (int k = 0; k < width; ++k) {
if (height / 2 == j && width / 2 == k)
if (height / 2 == j && width / 2 == k) {
continue;
}
double val = kern->data[j * width + k];
if (val == 0) {
continue;
@ -691,8 +697,9 @@ bool glx_bind_texture(session_t *ps attr_unused, glx_texture_t **pptex, int x, i
*/
bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, int width,
int height, bool repeat, const struct glx_fbconfig_info *fbcfg) {
if (ps->o.backend != BKEND_GLX && ps->o.backend != BKEND_XR_GLX_HYBRID)
if (ps->o.backend != BKEND_GLX && ps->o.backend != BKEND_XR_GLX_HYBRID) {
return true;
}
if (!pixmap) {
log_error("Binding to an empty pixmap %#010x. This can't work.", pixmap);
@ -754,14 +761,15 @@ bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
// pixmap-specific parameters, and this may change in the future
GLenum tex_tgt = 0;
if (GLX_TEXTURE_2D_BIT_EXT & fbcfg->texture_tgts &&
ps->psglx->has_texture_non_power_of_two)
ps->psglx->has_texture_non_power_of_two) {
tex_tgt = GLX_TEXTURE_2D_EXT;
else if (GLX_TEXTURE_RECTANGLE_BIT_EXT & fbcfg->texture_tgts)
} else if (GLX_TEXTURE_RECTANGLE_BIT_EXT & fbcfg->texture_tgts) {
tex_tgt = GLX_TEXTURE_RECTANGLE_EXT;
else if (!(GLX_TEXTURE_2D_BIT_EXT & fbcfg->texture_tgts))
} else if (!(GLX_TEXTURE_2D_BIT_EXT & fbcfg->texture_tgts)) {
tex_tgt = GLX_TEXTURE_RECTANGLE_EXT;
else
} else {
tex_tgt = GLX_TEXTURE_2D_EXT;
}
log_debug("depth %d, tgt %#x, rgba %d", depth, tex_tgt,
(GLX_TEXTURE_FORMAT_RGBA_EXT == fbcfg->texture_fmt));
@ -820,8 +828,9 @@ bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
// The specification requires rebinding whenever the content changes...
// We can't follow this, too slow.
if (need_release)
if (need_release) {
glXReleaseTexImageEXT(ps->c.dpy, ptex->glpixmap, GLX_FRONT_LEFT_EXT);
}
glXBindTexImageEXT(ps->c.dpy, ptex->glpixmap, GLX_FRONT_LEFT_EXT, NULL);
@ -859,14 +868,16 @@ void glx_release_pixmap(session_t *ps, glx_texture_t *ptex) {
*/
void glx_set_clip(session_t *ps, const region_t *reg) {
// Quit if we aren't using stencils
if (ps->o.glx_no_stencil)
if (ps->o.glx_no_stencil) {
return;
}
glDisable(GL_STENCIL_TEST);
glDisable(GL_SCISSOR_TEST);
if (!reg)
if (!reg) {
return;
}
int nrects;
const rect_t *rects = pixman_region32_rectangles((region_t *)reg, &nrects);
@ -914,8 +925,9 @@ bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
// Calculate copy region size
glx_blur_cache_t ibc = {.width = 0, .height = 0};
if (!pbc)
if (!pbc) {
pbc = &ibc;
}
int mdx = dx, mdy = dy, mwidth = width, mheight = height;
// log_trace("%d, %d, %d, %d", mdx, mdy, mwidth, mheight);
@ -942,24 +954,29 @@ bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
*/
GLenum tex_tgt = GL_TEXTURE_RECTANGLE;
if (ps->psglx->has_texture_non_power_of_two)
if (ps->psglx->has_texture_non_power_of_two) {
tex_tgt = GL_TEXTURE_2D;
}
// Free textures if size inconsistency discovered
if (mwidth != pbc->width || mheight != pbc->height)
if (mwidth != pbc->width || mheight != pbc->height) {
free_glx_bc_resize(ps, pbc);
}
// Generate FBO and textures if needed
if (!pbc->textures[0])
if (!pbc->textures[0]) {
pbc->textures[0] = glx_gen_texture(tex_tgt, mwidth, mheight);
}
GLuint tex_scr = pbc->textures[0];
if (more_passes && !pbc->textures[1])
if (more_passes && !pbc->textures[1]) {
pbc->textures[1] = glx_gen_texture(tex_tgt, mwidth, mheight);
}
pbc->width = mwidth;
pbc->height = mheight;
GLuint tex_scr2 = pbc->textures[1];
if (more_passes && !pbc->fbo)
if (more_passes && !pbc->fbo) {
glGenFramebuffers(1, &pbc->fbo);
}
const GLuint fbo = pbc->fbo;
if (!tex_scr || (more_passes && !tex_scr2)) {
@ -987,7 +1004,7 @@ bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
} */
// Texture scaling factor
GLfloat texfac_x = 1.0f, texfac_y = 1.0f;
GLfloat texfac_x = 1.0F, texfac_y = 1.0F;
if (tex_tgt == GL_TEXTURE_2D) {
texfac_x /= (GLfloat)mwidth;
texfac_y /= (GLfloat)mheight;
@ -1020,10 +1037,12 @@ bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
} else {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);
if (have_scissors)
if (have_scissors) {
glEnable(GL_SCISSOR_TEST);
if (have_stencil)
}
if (have_stencil) {
glEnable(GL_STENCIL_TEST);
}
}
// Color negation for testing...
@ -1033,12 +1052,15 @@ bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glUseProgram(ppass->prog);
if (ppass->unifm_offset_x >= 0)
if (ppass->unifm_offset_x >= 0) {
glUniform1f(ppass->unifm_offset_x, texfac_x);
if (ppass->unifm_offset_y >= 0)
}
if (ppass->unifm_offset_y >= 0) {
glUniform1f(ppass->unifm_offset_y, texfac_y);
if (ppass->unifm_factor_center >= 0)
}
if (ppass->unifm_factor_center >= 0) {
glUniform1f(ppass->unifm_factor_center, factor_center);
}
P_PAINTREG_START(crect) {
auto rx = (GLfloat)(crect.x1 - mdx) * texfac_x;
@ -1088,10 +1110,12 @@ glx_blur_dst_end:
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(tex_tgt, 0);
glDisable(tex_tgt);
if (have_scissors)
if (have_scissors) {
glEnable(GL_SCISSOR_TEST);
if (have_stencil)
}
if (have_stencil) {
glEnable(GL_STENCIL_TEST);
}
if (&ibc == pbc) {
free_glx_bc(ps, pbc);
@ -1276,7 +1300,7 @@ bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, int z,
// considering all those mess in color negation and modulation
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0f, 0.0f, 0.0f, factor);
glColor4f(0.0F, 0.0F, 0.0F, factor);
P_PAINTREG_START(crect) {
// XXX what does all of these variables mean?
@ -1292,7 +1316,7 @@ bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, int z,
}
P_PAINTREG_END();
glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
glColor4f(0.0F, 0.0F, 0.0F, 0.0F);
glDisable(GL_BLEND);
gl_check_err();
@ -1412,15 +1436,19 @@ bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx,
glUseProgram(pprogram->prog);
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
if (pprogram->unifm_opacity >= 0)
if (pprogram->unifm_opacity >= 0) {
glUniform1f(pprogram->unifm_opacity, (float)opacity);
if (pprogram->unifm_invert_color >= 0)
}
if (pprogram->unifm_invert_color >= 0) {
glUniform1i(pprogram->unifm_invert_color, neg);
if (pprogram->unifm_tex >= 0)
}
if (pprogram->unifm_tex >= 0) {
glUniform1i(pprogram->unifm_tex, 0);
if (pprogram->unifm_time >= 0)
glUniform1f(pprogram->unifm_time, (float)ts.tv_sec * 1000.0f +
(float)ts.tv_nsec / 1.0e6f);
}
if (pprogram->unifm_time >= 0) {
glUniform1f(pprogram->unifm_time, (float)ts.tv_sec * 1000.0F +
(float)ts.tv_nsec / 1.0e6F);
}
}
// log_trace("Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d", x, y, width, height,
@ -1460,8 +1488,8 @@ bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx,
// Invert Y if needed, this may not work as expected, though. I
// don't have such a FBConfig to test with.
if (!ptex->y_inverted) {
ry = 1.0f - ry;
rye = 1.0f - rye;
ry = 1.0F - ry;
rye = 1.0F - rye;
}
// log_trace("Rect %d: %f, %f, %f, %f -> %d, %d, %d, %d", ri, rx,
@ -1493,7 +1521,7 @@ bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx,
// Cleanup
glBindTexture(ptex->target, 0);
glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
glColor4f(0.0F, 0.0F, 0.0F, 0.0F);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glDisable(GL_BLEND);
glDisable(GL_COLOR_LOGIC_OP);
@ -1506,8 +1534,9 @@ bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx,
glActiveTexture(GL_TEXTURE0);
}
if (has_prog)
if (has_prog) {
glUseProgram(0);
}
gl_check_err();

View File

@ -156,8 +156,9 @@ static inline bool glx_has_context(session_t *ps) {
*/
static inline bool ensure_glx_context(session_t *ps) {
// Create GLX context
if (!glx_has_context(ps))
if (!glx_has_context(ps)) {
glx_init(ps, false);
}
return glx_has_context(ps);
}