style: created struct for each shader type

This commit is contained in:
Will McKinnon 2023-04-30 13:03:09 -04:00
parent 06339c325c
commit ace9a222b8
2 changed files with 264 additions and 238 deletions

View file

@ -35,7 +35,70 @@ struct decoration_data {
bool blur; bool blur;
}; };
struct gles2_tex_shader { struct blur_shader {
GLuint program;
GLint proj;
GLint tex;
GLint pos_attrib;
GLint tex_attrib;
GLint radius;
GLint halfpixel;
};
struct box_shadow_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint position;
GLint size;
GLint blur_sigma;
GLint corner_radius;
};
struct corner_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint is_top_left;
GLint is_top_right;
GLint is_bottom_left;
GLint is_bottom_right;
GLint position;
GLint radius;
GLint half_size;
GLint half_thickness;
};
struct quad_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
};
struct rounded_quad_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint size;
GLint position;
GLint radius;
};
struct stencil_mask_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint half_size;
GLint position;
GLint radius;
};
struct tex_shader {
GLuint program; GLuint program;
GLint proj; GLint proj;
GLint tex; GLint tex;
@ -51,26 +114,6 @@ struct gles2_tex_shader {
GLint has_titlebar; GLint has_titlebar;
}; };
struct rounded_quad_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint size;
GLint position;
GLint radius;
};
struct blur_shader {
GLuint program;
GLint proj;
GLint tex;
GLint pos_attrib;
GLint tex_attrib;
GLint radius;
GLint halfpixel;
};
struct fx_renderer { struct fx_renderer {
float projection[9]; float projection[9];
@ -95,64 +138,21 @@ struct fx_renderer {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
} procs; } procs;
// Shaders
struct { struct {
struct { struct box_shadow_shader box_shadow;
GLuint program; struct blur_shader blur1;
GLint proj; struct blur_shader blur2;
GLint color; struct corner_shader corner;
GLint pos_attrib; struct quad_shader quad;
} quad;
struct rounded_quad_shader rounded_quad; struct rounded_quad_shader rounded_quad;
struct rounded_quad_shader rounded_tl_quad; struct rounded_quad_shader rounded_tl_quad;
struct rounded_quad_shader rounded_tr_quad; struct rounded_quad_shader rounded_tr_quad;
struct rounded_quad_shader rounded_bl_quad; struct rounded_quad_shader rounded_bl_quad;
struct rounded_quad_shader rounded_br_quad; struct rounded_quad_shader rounded_br_quad;
struct stencil_mask_shader stencil_mask;
struct { struct tex_shader tex_rgba;
GLuint program; struct tex_shader tex_rgbx;
GLint proj; struct tex_shader tex_ext;
GLint color;
GLint pos_attrib;
GLint half_size;
GLint position;
GLint radius;
} stencil_mask;
struct blur_shader blur1;
struct blur_shader blur2;
struct {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint is_top_left;
GLint is_top_right;
GLint is_bottom_left;
GLint is_bottom_right;
GLint position;
GLint radius;
GLint half_size;
GLint half_thickness;
} corner;
struct {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint position;
GLint size;
GLint blur_sigma;
GLint corner_radius;
} box_shadow;
struct gles2_tex_shader tex_rgba;
struct gles2_tex_shader tex_rgbx;
struct gles2_tex_shader tex_ext;
} shaders; } shaders;
}; };

View file

@ -112,8 +112,115 @@ error:
return 0; return 0;
} }
static bool link_tex_program(struct fx_renderer *renderer, static bool link_blur_program(struct blur_shader *shader, const char *shader_program) {
struct gles2_tex_shader *shader, enum fx_tex_shader_source source) { GLuint prog;
shader->program = prog = link_program(shader_program);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->tex = glGetUniformLocation(prog, "tex");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->tex_attrib = glGetAttribLocation(prog, "texcoord");
shader->radius = glGetUniformLocation(prog, "radius");
shader->halfpixel = glGetUniformLocation(prog, "halfpixel");
return true;
}
static bool link_box_shadow_program(struct box_shadow_shader *shader) {
GLuint prog;
shader->program = prog = link_program(box_shadow_frag_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->position = glGetUniformLocation(prog, "position");
shader->size = glGetUniformLocation(prog, "size");
shader->blur_sigma = glGetUniformLocation(prog, "blur_sigma");
shader->corner_radius = glGetUniformLocation(prog, "corner_radius");
return true;
}
static bool link_corner_program(struct corner_shader *shader) {
GLuint prog;
shader->program = prog = link_program(corner_frag_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->position = glGetUniformLocation(prog, "position");
shader->half_size = glGetUniformLocation(prog, "half_size");
shader->half_thickness = glGetUniformLocation(prog, "half_thickness");
shader->radius = glGetUniformLocation(prog, "radius");
shader->is_top_left = glGetUniformLocation(prog, "is_top_left");
shader->is_top_right = glGetUniformLocation(prog, "is_top_right");
shader->is_bottom_left = glGetUniformLocation(prog, "is_bottom_left");
shader->is_bottom_right = glGetUniformLocation(prog, "is_bottom_right");
return true;
}
static bool link_quad_program(struct quad_shader *shader) {
GLuint prog;
shader->program = prog = link_program(quad_frag_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
return true;
}
static bool link_rounded_quad_program(struct rounded_quad_shader *shader,
enum fx_rounded_quad_shader_source source) {
GLchar quad_src[2048];
snprintf(quad_src, sizeof(quad_src),
"#define SOURCE %d\n%s", source, quad_round_frag_src);
GLuint prog;
shader->program = prog = link_program(quad_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->size = glGetUniformLocation(prog, "size");
shader->position = glGetUniformLocation(prog, "position");
shader->radius = glGetUniformLocation(prog, "radius");
return true;
}
static bool link_stencil_mask_program(struct stencil_mask_shader *shader) {
GLuint prog;
shader->program = prog = link_program(stencil_mask_frag_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->position = glGetUniformLocation(prog, "position");
shader->half_size = glGetUniformLocation(prog, "half_size");
shader->radius = glGetUniformLocation(prog, "radius");
return true;
}
static bool link_tex_program(struct tex_shader *shader,
enum fx_tex_shader_source source) {
GLchar frag_src[2048]; GLchar frag_src[2048];
snprintf(frag_src, sizeof(frag_src), snprintf(frag_src, sizeof(frag_src),
"#define SOURCE %d\n%s", source, tex_frag_src); "#define SOURCE %d\n%s", source, tex_frag_src);
@ -140,28 +247,6 @@ static bool link_tex_program(struct fx_renderer *renderer,
return true; return true;
} }
static bool link_rounded_quad_program(struct fx_renderer *renderer,
struct rounded_quad_shader *shader, enum fx_rounded_quad_shader_source source) {
GLchar quad_src[2048];
snprintf(quad_src, sizeof(quad_src),
"#define SOURCE %d\n%s", source, quad_round_frag_src);
GLuint prog;
shader->program = prog = link_program(quad_src);
if (!shader->program) {
return false;
}
shader->proj = glGetUniformLocation(prog, "proj");
shader->color = glGetUniformLocation(prog, "color");
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->size = glGetUniformLocation(prog, "size");
shader->position = glGetUniformLocation(prog, "position");
shader->radius = glGetUniformLocation(prog, "radius");
return true;
}
static bool check_gl_ext(const char *exts, const char *ext) { static bool check_gl_ext(const char *exts, const char *ext) {
size_t extlen = strlen(ext); size_t extlen = strlen(ext);
const char *end = exts + strlen(exts); const char *end = exts + strlen(exts);
@ -232,127 +317,61 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) {
"glEGLImageTargetTexture2DOES"); "glEGLImageTargetTexture2DOES");
} }
// init shaders // blur shaders
GLuint prog; if (!link_blur_program(&renderer->shaders.blur1, blur1_frag_src)) {
goto error;
// quad fragment shader }
prog = link_program(quad_frag_src); if (!link_blur_program(&renderer->shaders.blur2, blur2_frag_src)) {
renderer->shaders.quad.program = prog; goto error;
if (!renderer->shaders.quad.program) { }
// box shadow shader
if (!link_box_shadow_program(&renderer->shaders.box_shadow)) {
goto error;
}
// corner border shader
if (!link_corner_program(&renderer->shaders.corner)) {
goto error;
}
// quad fragment shader
if (!link_quad_program(&renderer->shaders.quad)) {
goto error; goto error;
} }
renderer->shaders.quad.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.quad.color = glGetUniformLocation(prog, "color");
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
// rounded quad fragment shaders // rounded quad fragment shaders
if (!link_rounded_quad_program(renderer, &renderer->shaders.rounded_quad, if (!link_rounded_quad_program(&renderer->shaders.rounded_quad,
SHADER_SOURCE_QUAD_ROUND)) { SHADER_SOURCE_QUAD_ROUND)) {
goto error; goto error;
} }
if (!link_rounded_quad_program(renderer, &renderer->shaders.rounded_tl_quad, if (!link_rounded_quad_program(&renderer->shaders.rounded_tl_quad,
SHADER_SOURCE_QUAD_ROUND_TOP_LEFT)) { SHADER_SOURCE_QUAD_ROUND_TOP_LEFT)) {
goto error; goto error;
} }
if (!link_rounded_quad_program(renderer, &renderer->shaders.rounded_tr_quad, if (!link_rounded_quad_program(&renderer->shaders.rounded_tr_quad,
SHADER_SOURCE_QUAD_ROUND_TOP_RIGHT)) { SHADER_SOURCE_QUAD_ROUND_TOP_RIGHT)) {
goto error; goto error;
} }
if (!link_rounded_quad_program(renderer, &renderer->shaders.rounded_bl_quad, if (!link_rounded_quad_program(&renderer->shaders.rounded_bl_quad,
SHADER_SOURCE_QUAD_ROUND_BOTTOM_LEFT)) { SHADER_SOURCE_QUAD_ROUND_BOTTOM_LEFT)) {
goto error; goto error;
} }
if (!link_rounded_quad_program(renderer, &renderer->shaders.rounded_br_quad, if (!link_rounded_quad_program(&renderer->shaders.rounded_br_quad,
SHADER_SOURCE_QUAD_ROUND_BOTTOM_RIGHT)) { SHADER_SOURCE_QUAD_ROUND_BOTTOM_RIGHT)) {
goto error; goto error;
} }
// Border corner shader
prog = link_program(corner_frag_src);
renderer->shaders.corner.program = prog;
if (!renderer->shaders.corner.program) {
goto error;
}
renderer->shaders.corner.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.corner.color = glGetUniformLocation(prog, "color");
renderer->shaders.corner.pos_attrib = glGetAttribLocation(prog, "pos");
renderer->shaders.corner.is_top_left = glGetUniformLocation(prog, "is_top_left");
renderer->shaders.corner.is_top_right = glGetUniformLocation(prog, "is_top_right");
renderer->shaders.corner.is_bottom_left = glGetUniformLocation(prog, "is_bottom_left");
renderer->shaders.corner.is_bottom_right = glGetUniformLocation(prog, "is_bottom_right");
renderer->shaders.corner.position = glGetUniformLocation(prog, "position");
renderer->shaders.corner.radius = glGetUniformLocation(prog, "radius");
renderer->shaders.corner.half_size = glGetUniformLocation(prog, "half_size");
renderer->shaders.corner.half_thickness = glGetUniformLocation(prog, "half_thickness");
// box shadow shader
prog = link_program(box_shadow_frag_src);
renderer->shaders.box_shadow.program = prog;
if (!renderer->shaders.box_shadow.program) {
goto error;
}
renderer->shaders.box_shadow.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.box_shadow.color = glGetUniformLocation(prog, "color");
renderer->shaders.box_shadow.pos_attrib = glGetAttribLocation(prog, "pos");
renderer->shaders.box_shadow.position = glGetUniformLocation(prog, "position");
renderer->shaders.box_shadow.size = glGetUniformLocation(prog, "size");
renderer->shaders.box_shadow.blur_sigma = glGetUniformLocation(prog, "blur_sigma");
renderer->shaders.box_shadow.corner_radius = glGetUniformLocation(prog, "corner_radius");
// stencil mask shader // stencil mask shader
prog = link_program(stencil_mask_frag_src); if (!link_stencil_mask_program(&renderer->shaders.stencil_mask)) {
renderer->shaders.stencil_mask.program = prog;
if (!renderer->shaders.stencil_mask.program) {
goto error; goto error;
} }
renderer->shaders.stencil_mask.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.stencil_mask.color = glGetUniformLocation(prog, "color");
renderer->shaders.stencil_mask.pos_attrib = glGetAttribLocation(prog, "pos");
renderer->shaders.stencil_mask.position = glGetUniformLocation(prog, "position");
renderer->shaders.stencil_mask.radius = glGetUniformLocation(prog, "radius");
renderer->shaders.stencil_mask.half_size = glGetUniformLocation(prog, "half_size");
// Blur 1
prog = link_program(blur1_frag_src);
renderer->shaders.blur1.program = prog;
if (!renderer->shaders.blur1.program) {
goto error;
}
renderer->shaders.blur1.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.blur1.tex = glGetUniformLocation(prog, "tex");
renderer->shaders.blur1.pos_attrib = glGetAttribLocation(prog, "pos");
renderer->shaders.blur1.tex_attrib = glGetAttribLocation(prog, "texcoord");
renderer->shaders.blur1.radius = glGetUniformLocation(prog, "radius");
renderer->shaders.blur1.halfpixel = glGetUniformLocation(prog, "halfpixel");
// Blur 2
prog = link_program(blur2_frag_src);
renderer->shaders.blur2.program = prog;
if (!renderer->shaders.blur2.program) {
goto error;
}
renderer->shaders.blur2.proj = glGetUniformLocation(prog, "proj");
renderer->shaders.blur2.tex = glGetUniformLocation(prog, "tex");
renderer->shaders.blur2.pos_attrib = glGetAttribLocation(prog, "pos");
renderer->shaders.blur2.tex_attrib = glGetAttribLocation(prog, "texcoord");
renderer->shaders.blur2.radius = glGetUniformLocation(prog, "radius");
renderer->shaders.blur2.halfpixel = glGetUniformLocation(prog, "halfpixel");
// fragment shaders // fragment shaders
if (!link_tex_program(renderer, &renderer->shaders.tex_rgba, if (!link_tex_program(&renderer->shaders.tex_rgba, SHADER_SOURCE_TEXTURE_RGBA)) {
SHADER_SOURCE_TEXTURE_RGBA)) {
goto error; goto error;
} }
if (!link_tex_program(renderer, &renderer->shaders.tex_rgbx, if (!link_tex_program(&renderer->shaders.tex_rgbx, SHADER_SOURCE_TEXTURE_RGBX)) {
SHADER_SOURCE_TEXTURE_RGBX)) {
goto error; goto error;
} }
if (!link_tex_program(renderer, &renderer->shaders.tex_ext, if (!link_tex_program(&renderer->shaders.tex_ext, SHADER_SOURCE_TEXTURE_EXTERNAL)) {
SHADER_SOURCE_TEXTURE_EXTERNAL)) {
goto error; goto error;
} }
if (!eglMakeCurrent(wlr_egl_get_display(egl), if (!eglMakeCurrent(wlr_egl_get_display(egl),
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not unset current EGL"); sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not unset current EGL");
@ -363,17 +382,17 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) {
return renderer; return renderer;
error: error:
glDeleteProgram(renderer->shaders.quad.program);
glDeleteProgram(renderer->shaders.rounded_quad.program);
glDeleteProgram(renderer->shaders.rounded_tl_quad.program);
glDeleteProgram(renderer->shaders.rounded_tr_quad.program);
glDeleteProgram(renderer->shaders.rounded_bl_quad.program);
glDeleteProgram(renderer->shaders.rounded_br_quad.program);
glDeleteProgram(renderer->shaders.corner.program);
glDeleteProgram(renderer->shaders.stencil_mask.program);
glDeleteProgram(renderer->shaders.box_shadow.program);
glDeleteProgram(renderer->shaders.blur1.program); glDeleteProgram(renderer->shaders.blur1.program);
glDeleteProgram(renderer->shaders.blur2.program); glDeleteProgram(renderer->shaders.blur2.program);
glDeleteProgram(renderer->shaders.box_shadow.program);
glDeleteProgram(renderer->shaders.corner.program);
glDeleteProgram(renderer->shaders.quad.program);
glDeleteProgram(renderer->shaders.rounded_quad.program);
glDeleteProgram(renderer->shaders.rounded_bl_quad.program);
glDeleteProgram(renderer->shaders.rounded_br_quad.program);
glDeleteProgram(renderer->shaders.rounded_tl_quad.program);
glDeleteProgram(renderer->shaders.rounded_tr_quad.program);
glDeleteProgram(renderer->shaders.stencil_mask.program);
glDeleteProgram(renderer->shaders.tex_rgba.program); glDeleteProgram(renderer->shaders.tex_rgba.program);
glDeleteProgram(renderer->shaders.tex_rgbx.program); glDeleteProgram(renderer->shaders.tex_rgbx.program);
glDeleteProgram(renderer->shaders.tex_ext.program); glDeleteProgram(renderer->shaders.tex_ext.program);
@ -453,7 +472,7 @@ bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer, struct fx_te
const struct wlr_fbox *src_box, const struct wlr_box *dst_box, const float matrix[static 9], const struct wlr_fbox *src_box, const struct wlr_box *dst_box, const float matrix[static 9],
struct decoration_data deco_data) { struct decoration_data deco_data) {
struct gles2_tex_shader *shader = NULL; struct tex_shader *shader = NULL;
switch (fx_texture->target) { switch (fx_texture->target) {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
@ -576,19 +595,20 @@ void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *box,
glEnable(GL_BLEND); glEnable(GL_BLEND);
} }
glUseProgram(renderer->shaders.quad.program); struct quad_shader shader = renderer->shaders.quad;
glUseProgram(shader.program);
glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, gl_matrix); glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
glUniform4f(renderer->shaders.quad.color, color[0], color[1], color[2], color[3]); glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
glVertexAttribPointer(renderer->shaders.quad.pos_attrib, 2, GL_FLOAT, GL_FALSE, glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
0, verts); 0, verts);
glEnableVertexAttribArray(renderer->shaders.quad.pos_attrib); glEnableVertexAttribArray(shader.pos_attrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib); glDisableVertexAttribArray(shader.pos_attrib);
} }
void fx_render_rounded_rect(struct fx_renderer *renderer, const struct wlr_box *box, void fx_render_rounded_rect(struct fx_renderer *renderer, const struct wlr_box *box,
@ -674,29 +694,31 @@ void fx_render_border_corner(struct fx_renderer *renderer, const struct wlr_box
glEnable(GL_BLEND); glEnable(GL_BLEND);
} }
glUseProgram(renderer->shaders.corner.program); struct corner_shader shader = renderer->shaders.corner;
glUniformMatrix3fv(renderer->shaders.corner.proj, 1, GL_FALSE, gl_matrix); glUseProgram(shader.program);
glUniform4f(renderer->shaders.corner.color, color[0], color[1], color[2], color[3]);
glUniform1f(renderer->shaders.corner.is_top_left, corner_location == TOP_LEFT); glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
glUniform1f(renderer->shaders.corner.is_top_right, corner_location == TOP_RIGHT); glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
glUniform1f(renderer->shaders.corner.is_bottom_left, corner_location == BOTTOM_LEFT);
glUniform1f(renderer->shaders.corner.is_bottom_right, corner_location == BOTTOM_RIGHT);
glUniform2f(renderer->shaders.corner.position, box->x, box->y); glUniform1f(shader.is_top_left, corner_location == TOP_LEFT);
glUniform1f(renderer->shaders.corner.radius, radius); glUniform1f(shader.is_top_right, corner_location == TOP_RIGHT);
glUniform2f(renderer->shaders.corner.half_size, box->width / 2.0, box->height / 2.0); glUniform1f(shader.is_bottom_left, corner_location == BOTTOM_LEFT);
glUniform1f(renderer->shaders.corner.half_thickness, border_thickness / 2.0); glUniform1f(shader.is_bottom_right, corner_location == BOTTOM_RIGHT);
glVertexAttribPointer(renderer->shaders.corner.pos_attrib, 2, GL_FLOAT, GL_FALSE, glUniform2f(shader.position, box->x, box->y);
glUniform1f(shader.radius, radius);
glUniform2f(shader.half_size, box->width / 2.0, box->height / 2.0);
glUniform1f(shader.half_thickness, border_thickness / 2.0);
glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
0, verts); 0, verts);
glEnableVertexAttribArray(renderer->shaders.corner.pos_attrib); glEnableVertexAttribArray(shader.pos_attrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(renderer->shaders.corner.pos_attrib); glDisableVertexAttribArray(shader.pos_attrib);
} }
void fx_render_stencil_mask(struct fx_renderer *renderer, const struct wlr_box *box, void fx_render_stencil_mask(struct fx_renderer *renderer, const struct wlr_box *box,
@ -717,28 +739,30 @@ void fx_render_stencil_mask(struct fx_renderer *renderer, const struct wlr_box *
glEnable(GL_BLEND); glEnable(GL_BLEND);
glUseProgram(renderer->shaders.stencil_mask.program); struct stencil_mask_shader shader = renderer->shaders.stencil_mask;
glUniformMatrix3fv(renderer->shaders.stencil_mask.proj, 1, GL_FALSE, gl_matrix); glUseProgram(shader.program);
glUniform2f(renderer->shaders.stencil_mask.half_size, box->width * 0.5, box->height * 0.5); glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
glUniform2f(renderer->shaders.stencil_mask.position, box->x, box->y);
glUniform1f(renderer->shaders.stencil_mask.radius, corner_radius);
glVertexAttribPointer(renderer->shaders.stencil_mask.pos_attrib, 2, GL_FLOAT, GL_FALSE, glUniform2f(shader.half_size, box->width * 0.5, box->height * 0.5);
glUniform2f(shader.position, box->x, box->y);
glUniform1f(shader.radius, corner_radius);
glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
0, verts); 0, verts);
glEnableVertexAttribArray(renderer->shaders.stencil_mask.pos_attrib); glEnableVertexAttribArray(shader.pos_attrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(renderer->shaders.stencil_mask.pos_attrib); glDisableVertexAttribArray(shader.pos_attrib);
} }
// TODO: alpha input arg? // TODO: alpha input arg?
void fx_render_box_shadow(struct fx_renderer *renderer, const struct wlr_box *box, void fx_render_box_shadow(struct fx_renderer *renderer, const struct wlr_box *box,
const float color[static 4], const float matrix [static 9], int corner_radius, const float color[static 4], const float matrix[static 9], int corner_radius,
float blur_sigma) { float blur_sigma) {
if (box->width == 0 || box->height == 0) { if (box->width == 0 || box->height == 0) {
return; return;
@ -783,24 +807,26 @@ void fx_render_box_shadow(struct fx_renderer *renderer, const struct wlr_box *bo
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(renderer->shaders.box_shadow.program); struct box_shadow_shader shader = renderer->shaders.box_shadow;
glUniformMatrix3fv(renderer->shaders.box_shadow.proj, 1, GL_FALSE, gl_matrix); glUseProgram(shader.program);
glUniform4f(renderer->shaders.box_shadow.color, color[0], color[1], color[2], color[3]);
glUniform1f(renderer->shaders.box_shadow.blur_sigma, blur_sigma);
glUniform1f(renderer->shaders.box_shadow.corner_radius, corner_radius);
glUniform2f(renderer->shaders.box_shadow.size, box->width, box->height); glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
glUniform2f(renderer->shaders.box_shadow.position, box->x, box->y); glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
glUniform1f(shader.blur_sigma, blur_sigma);
glUniform1f(shader.corner_radius, corner_radius);
glVertexAttribPointer(renderer->shaders.box_shadow.pos_attrib, 2, GL_FLOAT, GL_FALSE, glUniform2f(shader.size, box->width, box->height);
glUniform2f(shader.position, box->x, box->y);
glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
0, verts); 0, verts);
glEnableVertexAttribArray(renderer->shaders.box_shadow.pos_attrib); glEnableVertexAttribArray(shader.pos_attrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(renderer->shaders.box_shadow.pos_attrib); glDisableVertexAttribArray(shader.pos_attrib);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);