aboutsummaryrefslogtreecommitdiff
path: root/src/backend/gl/gl_common.h
diff options
context:
space:
mode:
authorallusive-dev <[email protected]>2023-10-30 15:12:21 +1100
committerallusive-dev <[email protected]>2023-10-30 15:12:21 +1100
commitac33357e7ce7c474aeaffc92e381020289d767a2 (patch)
tree7f05fa79b3ccd7834f85cc65a07fbd4f8030eb94 /src/backend/gl/gl_common.h
parentCreate FUNDING.yml (diff)
downloadcompfy-1.0.0.tar.xz
compfy-1.0.0.zip
Version 1.01.0.0
Diffstat (limited to 'src/backend/gl/gl_common.h')
-rw-r--r--src/backend/gl/gl_common.h100
1 files changed, 86 insertions, 14 deletions
diff --git a/src/backend/gl/gl_common.h b/src/backend/gl/gl_common.h
index b1d93b0..3a78865 100644
--- a/src/backend/gl/gl_common.h
+++ b/src/backend/gl/gl_common.h
@@ -12,16 +12,40 @@
#define CASESTRRET(s) \
case s: return #s
+struct gl_blur_context;
+
+static inline GLint glGetUniformLocationChecked(GLuint p, const char *name) {
+ auto ret = glGetUniformLocation(p, name);
+ if (ret < 0) {
+ log_info("Failed to get location of uniform '%s'. This is normal when "
+ "using custom shaders.",
+ name);
+ }
+ return ret;
+}
+
+#define bind_uniform(shader, uniform) \
+ (shader)->uniform_##uniform = glGetUniformLocationChecked((shader)->prog, #uniform)
// Program and uniforms for window shader
typedef struct {
+ UT_hash_handle hh;
+ uint32_t id;
GLuint prog;
- GLint unifm_opacity;
- GLint unifm_invert_color;
- GLint unifm_tex;
- GLint unifm_dim;
- GLint unifm_brightness;
- GLint unifm_max_brightness;
+ GLint uniform_opacity;
+ GLint uniform_invert_color;
+ GLint uniform_tex;
+ GLint uniform_dim;
+ GLint uniform_brightness;
+ GLint uniform_max_brightness;
+ GLint uniform_corner_radius;
+ GLint uniform_border_width;
+ GLint uniform_time;
+
+ GLint uniform_mask_tex;
+ GLint uniform_mask_offset;
+ GLint uniform_mask_corner_radius;
+ GLint uniform_mask_inverted;
} gl_win_shader_t;
// Program and uniforms for brightness shader
@@ -29,13 +53,23 @@ typedef struct {
GLuint prog;
} gl_brightness_shader_t;
+typedef struct {
+ GLuint prog;
+ GLint uniform_color;
+} gl_shadow_shader_t;
+
// Program and uniforms for blur shader
typedef struct {
GLuint prog;
- GLint unifm_pixel_norm;
- GLint unifm_opacity;
+ GLint uniform_pixel_norm;
+ GLint uniform_opacity;
GLint texorig_loc;
GLint scale_loc;
+
+ GLint uniform_mask_tex;
+ GLint uniform_mask_offset;
+ GLint uniform_mask_corner_radius;
+ GLint uniform_mask_inverted;
} gl_blur_shader_t;
typedef struct {
@@ -53,6 +87,7 @@ struct gl_texture {
// Textures for auxiliary uses.
GLuint auxiliary_texture[2];
+ gl_win_shader_t *shader;
void *user_data;
};
@@ -60,14 +95,22 @@ struct gl_data {
backend_t base;
// If we are using proprietary NVIDIA driver
bool is_nvidia;
+ // If ARB_robustness extension is present
+ bool has_robustness;
+ // If EXT_EGL_image_storage extension is present
+ bool has_egl_image_storage;
// Height and width of the root window
int height, width;
- gl_win_shader_t win_shader;
+ // Hash-table of window shaders
+ gl_win_shader_t *default_shader;
gl_brightness_shader_t brightness_shader;
gl_fill_shader_t fill_shader;
+ gl_shadow_shader_t shadow_shader;
GLuint back_texture, back_fbo;
GLuint present_prog;
+ GLuint default_mask_texture;
+
/// Called when an gl_texture is decoupled from the texture it refers. Returns
/// the decoupled user_data
void *(*decouple_texture_user_data)(backend_t *base, void *user_data);
@@ -83,16 +126,25 @@ typedef struct session session_t;
#define GL_PROG_MAIN_INIT \
{ .prog = 0, .unifm_opacity = -1, .unifm_invert_color = -1, .unifm_tex = -1, }
+void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst,
+ int extent_height, int texture_height, int root_height,
+ bool y_inverted, GLint *coord, GLuint *indices);
+
GLuint gl_create_shader(GLenum shader_type, const char *shader_str);
GLuint gl_create_program(const GLuint *const shaders, int nshaders);
GLuint gl_create_program_from_str(const char *vert_shader_str, const char *frag_shader_str);
+GLuint gl_create_program_from_strv(const char **vert_shaders, const char **frag_shaders);
+void *gl_create_window_shader(backend_t *backend_data, const char *source);
+void gl_destroy_window_shader(backend_t *backend_data, void *shader);
+uint64_t gl_get_shader_attributes(backend_t *backend_data, void *shader);
+bool gl_set_image_property(backend_t *backend_data, enum image_properties prop,
+ void *image_data, void *args);
/**
* @brief Render a region with texture data.
*/
-void gl_compose(backend_t *, void *ptex,
- int dst_x1, int dst_y1, int dst_x2, int dst_y2,
- const region_t *reg_tgt, const region_t *reg_visible);
+void gl_compose(backend_t *, void *image_data, coord_t image_dst, void *mask,
+ coord_t mask_dst, const region_t *reg_tgt, const region_t *reg_visible);
void gl_resize(struct gl_data *, int width, int height);
@@ -105,19 +157,29 @@ bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
const region_t *reg_op, const region_t *reg_visible, void *arg);
void gl_release_image(backend_t *base, void *image_data);
+void *gl_make_mask(backend_t *base, geometry_t size, const region_t *reg);
void *gl_clone(backend_t *base, const void *image_data, const region_t *reg_visible);
-bool gl_blur(backend_t *base, double opacity, void *, const region_t *reg_blur,
- const region_t *reg_visible);
+bool gl_blur(backend_t *base, double opacity, void *ctx, void *mask, coord_t mask_dst,
+ const region_t *reg_blur, const region_t *reg_visible);
+bool gl_blur_impl(double opacity, struct gl_blur_context *bctx, void *mask,
+ coord_t mask_dst, const region_t *reg_blur,
+ const region_t *reg_visible attr_unused, GLuint source_texture,
+ geometry_t source_size, GLuint target_fbo, GLuint default_mask);
void *gl_create_blur_context(backend_t *base, enum blur_method, void *args);
void gl_destroy_blur_context(backend_t *base, void *ctx);
+struct backend_shadow_context *gl_create_shadow_context(backend_t *base, double radius);
+void gl_destroy_shadow_context(backend_t *base attr_unused, struct backend_shadow_context *ctx);
+void *gl_shadow_from_mask(backend_t *base, void *mask,
+ struct backend_shadow_context *sctx, struct color color);
void gl_get_blur_size(void *blur_context, int *width, int *height);
void gl_fill(backend_t *base, struct color, const region_t *clip);
void gl_present(backend_t *base, const region_t *);
bool gl_read_pixel(backend_t *base, void *image_data, int x, int y, struct color *output);
+enum device_status gl_device_status(backend_t *base);
static inline void gl_delete_texture(GLuint texture) {
glDeleteTextures(1, &texture);
@@ -218,3 +280,13 @@ static inline bool gl_has_extension(const char *ext) {
log_info("Missing GL extension %s.", ext);
return false;
}
+
+static const GLuint vert_coord_loc = 0;
+static const GLuint vert_in_texcoord_loc = 1;
+
+#define GLSL(version, ...) "#version " #version "\n" #__VA_ARGS__
+#define QUOTE(...) #__VA_ARGS__
+
+extern const char vertex_shader[], copy_with_mask_frag[], masking_glsl[], dummy_frag[],
+ fill_frag[], fill_vert[], interpolating_frag[], interpolating_vert[], win_shader_glsl[],
+ win_shader_default[], present_vertex_shader[], shadow_colorization_frag[];