new glx: handle blur with opacity
Now blur can fade out smoothly Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
34254ff86e
commit
a72fb0c755
@ -354,6 +354,7 @@ bool gl_blur(backend_t *base, double opacity, const region_t *reg_blur,
|
||||
assert(gd->blur_texture[curr]);
|
||||
glBindTexture(gd->blur_texture_target, gd->blur_texture[curr]);
|
||||
|
||||
glUseProgram(p->prog);
|
||||
if (i < gd->npasses - 1) {
|
||||
// not last pass, draw into framebuffer
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gd->blur_fbo);
|
||||
@ -366,13 +367,14 @@ bool gl_blur(backend_t *base, double opacity, const region_t *reg_blur,
|
||||
log_error("Framebuffer attachment failed.");
|
||||
goto end;
|
||||
}
|
||||
glUniform1f(p->unifm_opacity, 1.0);
|
||||
} else {
|
||||
// last pass, draw directly into the back buffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glDrawBuffer(GL_BACK);
|
||||
glUniform1f(p->unifm_opacity, opacity);
|
||||
}
|
||||
|
||||
glUseProgram(p->prog);
|
||||
if (gd->blur_texture_target == GL_TEXTURE_2D) {
|
||||
glUniform1f(p->unifm_offset_x, 1.0 / gd->width);
|
||||
glUniform1f(p->unifm_offset_y, 1.0 / gd->height);
|
||||
@ -457,7 +459,6 @@ static GLuint glGetUniformLocationChecked(GLuint p, const char *name) {
|
||||
log_error("Failed to get location of uniform '%s'. compton might not "
|
||||
"work correctly.",
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -543,11 +544,12 @@ static bool gl_init_blur(struct gl_data *gd, conv *const *const kernels) {
|
||||
uniform float offset_x;
|
||||
uniform float offset_y;
|
||||
uniform %s tex_scr;
|
||||
uniform float opacity;
|
||||
out vec4 out_color;
|
||||
void main() {
|
||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
%s //body of the convolution
|
||||
out_color = sum / float(%.7g);
|
||||
out_color = sum / float(%.7g) * opacity;
|
||||
}
|
||||
);
|
||||
static const char *FRAG_SHADER_BLUR_ADD = QUOTE(
|
||||
@ -620,6 +622,8 @@ static bool gl_init_blur(struct gl_data *gd, conv *const *const kernels) {
|
||||
glGetUniformLocationChecked(pass->prog, "offset_x");
|
||||
pass->unifm_offset_y =
|
||||
glGetUniformLocationChecked(pass->prog, "offset_y");
|
||||
pass->unifm_opacity =
|
||||
glGetUniformLocationChecked(pass->prog, "opacity");
|
||||
}
|
||||
free(extension);
|
||||
|
||||
|
@ -16,24 +16,18 @@
|
||||
|
||||
// Program and uniforms for window shader
|
||||
typedef struct {
|
||||
/// GLSL program.
|
||||
GLuint prog;
|
||||
/// Location of uniform "opacity" in window GLSL program.
|
||||
GLint unifm_opacity;
|
||||
/// Location of uniform "invert_color" in blur GLSL program.
|
||||
GLint unifm_invert_color;
|
||||
/// Location of uniform "tex" in window GLSL program.
|
||||
GLint unifm_tex;
|
||||
} gl_win_shader_t;
|
||||
|
||||
// Program and uniforms for blur shader
|
||||
typedef struct {
|
||||
/// GLSL program for blur.
|
||||
GLuint prog;
|
||||
/// Location of uniform "offset_x" in blur GLSL program.
|
||||
GLint unifm_offset_x;
|
||||
/// Location of uniform "offset_y" in blur GLSL program.
|
||||
GLint unifm_offset_y;
|
||||
GLint unifm_opacity;
|
||||
} gl_blur_shader_t;
|
||||
|
||||
/// @brief Wrapper of a binded GLX texture.
|
||||
@ -42,6 +36,7 @@ typedef struct gl_texture {
|
||||
int *refcount;
|
||||
GLuint texture;
|
||||
GLenum target;
|
||||
// The size of the backing texture
|
||||
int width, height;
|
||||
// The effective size of the texture
|
||||
int ewidth, eheight;
|
||||
|
Loading…
Reference in New Issue
Block a user