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:
		| @ -354,6 +354,7 @@ bool gl_blur(backend_t *base, double opacity, const region_t *reg_blur, | |||||||
| 		assert(gd->blur_texture[curr]); | 		assert(gd->blur_texture[curr]); | ||||||
| 		glBindTexture(gd->blur_texture_target, gd->blur_texture[curr]); | 		glBindTexture(gd->blur_texture_target, gd->blur_texture[curr]); | ||||||
|  |  | ||||||
|  | 		glUseProgram(p->prog); | ||||||
| 		if (i < gd->npasses - 1) { | 		if (i < gd->npasses - 1) { | ||||||
| 			// not last pass, draw into framebuffer | 			// not last pass, draw into framebuffer | ||||||
| 			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gd->blur_fbo); | 			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."); | 				log_error("Framebuffer attachment failed."); | ||||||
| 				goto end; | 				goto end; | ||||||
| 			} | 			} | ||||||
|  | 			glUniform1f(p->unifm_opacity, 1.0); | ||||||
| 		} else { | 		} else { | ||||||
| 			// last pass, draw directly into the back buffer | 			// last pass, draw directly into the back buffer | ||||||
| 			glBindFramebuffer(GL_FRAMEBUFFER, 0); | 			glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||||||
| 			glDrawBuffer(GL_BACK); | 			glDrawBuffer(GL_BACK); | ||||||
|  | 			glUniform1f(p->unifm_opacity, opacity); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		glUseProgram(p->prog); |  | ||||||
| 		if (gd->blur_texture_target == GL_TEXTURE_2D) { | 		if (gd->blur_texture_target == GL_TEXTURE_2D) { | ||||||
| 			glUniform1f(p->unifm_offset_x, 1.0 / gd->width); | 			glUniform1f(p->unifm_offset_x, 1.0 / gd->width); | ||||||
| 			glUniform1f(p->unifm_offset_y, 1.0 / gd->height); | 			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 " | 		log_error("Failed to get location of uniform '%s'. compton might not " | ||||||
| 		          "work correctly.", | 		          "work correctly.", | ||||||
| 		          name); | 		          name); | ||||||
| 		return 0; |  | ||||||
| 	} | 	} | ||||||
| 	return ret; | 	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_x; | ||||||
| 		uniform float offset_y; | 		uniform float offset_y; | ||||||
| 		uniform %s tex_scr; | 		uniform %s tex_scr; | ||||||
|  | 		uniform float opacity; | ||||||
| 		out vec4 out_color; | 		out vec4 out_color; | ||||||
| 		void main() { | 		void main() { | ||||||
| 			vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); | 			vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); | ||||||
| 			%s //body of the convolution | 			%s //body of the convolution | ||||||
| 			out_color = sum / float(%.7g); | 			out_color = sum / float(%.7g) * opacity; | ||||||
| 		} | 		} | ||||||
| 	); | 	); | ||||||
| 	static const char *FRAG_SHADER_BLUR_ADD = QUOTE( | 	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"); | 		    glGetUniformLocationChecked(pass->prog, "offset_x"); | ||||||
| 		pass->unifm_offset_y = | 		pass->unifm_offset_y = | ||||||
| 		    glGetUniformLocationChecked(pass->prog, "offset_y"); | 		    glGetUniformLocationChecked(pass->prog, "offset_y"); | ||||||
|  | 		pass->unifm_opacity = | ||||||
|  | 		    glGetUniformLocationChecked(pass->prog, "opacity"); | ||||||
| 	} | 	} | ||||||
| 	free(extension); | 	free(extension); | ||||||
|  |  | ||||||
|  | |||||||
| @ -16,24 +16,18 @@ | |||||||
|  |  | ||||||
| // Program and uniforms for window shader | // Program and uniforms for window shader | ||||||
| typedef struct { | typedef struct { | ||||||
| 	/// GLSL program. |  | ||||||
| 	GLuint prog; | 	GLuint prog; | ||||||
| 	/// Location of uniform "opacity" in window GLSL program. |  | ||||||
| 	GLint unifm_opacity; | 	GLint unifm_opacity; | ||||||
| 	/// Location of uniform "invert_color" in blur GLSL program. |  | ||||||
| 	GLint unifm_invert_color; | 	GLint unifm_invert_color; | ||||||
| 	/// Location of uniform "tex" in window GLSL program. |  | ||||||
| 	GLint unifm_tex; | 	GLint unifm_tex; | ||||||
| } gl_win_shader_t; | } gl_win_shader_t; | ||||||
|  |  | ||||||
| // Program and uniforms for blur shader | // Program and uniforms for blur shader | ||||||
| typedef struct { | typedef struct { | ||||||
| 	/// GLSL program for blur. |  | ||||||
| 	GLuint prog; | 	GLuint prog; | ||||||
| 	/// Location of uniform "offset_x" in blur GLSL program. |  | ||||||
| 	GLint unifm_offset_x; | 	GLint unifm_offset_x; | ||||||
| 	/// Location of uniform "offset_y" in blur GLSL program. |  | ||||||
| 	GLint unifm_offset_y; | 	GLint unifm_offset_y; | ||||||
|  | 	GLint unifm_opacity; | ||||||
| } gl_blur_shader_t; | } gl_blur_shader_t; | ||||||
|  |  | ||||||
| /// @brief Wrapper of a binded GLX texture. | /// @brief Wrapper of a binded GLX texture. | ||||||
| @ -42,6 +36,7 @@ typedef struct gl_texture { | |||||||
| 	int *refcount; | 	int *refcount; | ||||||
| 	GLuint texture; | 	GLuint texture; | ||||||
| 	GLenum target; | 	GLenum target; | ||||||
|  | 	// The size of the backing texture | ||||||
| 	int width, height; | 	int width, height; | ||||||
| 	// The effective size of the texture | 	// The effective size of the texture | ||||||
| 	int ewidth, eheight; | 	int ewidth, eheight; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Yuxuan Shui
					Yuxuan Shui