Skip to content

Commit

Permalink
removed width and height parameters from fx_framebuffer_bind()
Browse files Browse the repository at this point in the history
  • Loading branch information
WillPower3309 committed Apr 24, 2023
1 parent b610419 commit 3d1b294
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/sway/desktop/fx_renderer/fx_framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct fx_framebuffer {
GLuint fb;
};

void fx_framebuffer_bind(struct fx_framebuffer *buffer, GLsizei width, GLsizei height);
void fx_framebuffer_bind(struct fx_framebuffer *buffer);

void fx_framebuffer_create(struct fx_framebuffer *buffer, int width, int height, bool bind);

Expand Down
5 changes: 2 additions & 3 deletions sway/desktop/fx_renderer/fx_framebuffer.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "log.h"
#include "sway/desktop/fx_renderer/fx_framebuffer.h"

void fx_framebuffer_bind(struct fx_framebuffer *buffer, GLsizei width, GLsizei height) {
void fx_framebuffer_bind(struct fx_framebuffer *buffer) {
glBindFramebuffer(GL_FRAMEBUFFER, buffer->fb);
glViewport(0, 0, width, height);
}

void fx_framebuffer_create(struct fx_framebuffer *buffer, int width, int height, bool bind) {
Expand Down Expand Up @@ -48,7 +47,7 @@ void fx_framebuffer_create(struct fx_framebuffer *buffer, int width, int height,
// Bind the default framebuffer
glBindTexture(GL_TEXTURE_2D, 0);
if (bind) {
fx_framebuffer_bind(buffer, width, height);
fx_framebuffer_bind(buffer);
}
}

Expand Down
3 changes: 2 additions & 1 deletion sway/desktop/fx_renderer/fx_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void fx_renderer_fini(struct fx_renderer *renderer) {
}

void fx_renderer_begin(struct fx_renderer *renderer, int width, int height) {
glViewport(0, 0, width, height);
renderer->viewport_width = width;
renderer->viewport_height = height;

Expand All @@ -399,7 +400,7 @@ void fx_renderer_begin(struct fx_renderer *renderer, int width, int height) {
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

// Bind to our main framebuffer
fx_framebuffer_bind(&renderer->main_buffer, width, height);
fx_framebuffer_bind(&renderer->main_buffer);
}

void fx_renderer_end(struct fx_renderer *renderer) {
Expand Down
23 changes: 10 additions & 13 deletions sway/desktop/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,15 @@ static void render_texture(struct wlr_output *wlr_output,
}

/* Renders the blur for each damaged rect and swaps the buffer */
void render_blur_segments(struct fx_renderer *renderer, struct sway_output *output,
void render_blur_segments(struct fx_renderer *renderer,
const float matrix[static 9], pixman_region32_t* damage,
struct fx_framebuffer **buffer, struct blur_shader* shader,
const struct wlr_box *box, int blur_radius) {
int width, height;
wlr_output_transformed_resolution(output->wlr_output, &width, &height);

if (*buffer == &renderer->effects_buffer) {
fx_framebuffer_bind(&renderer->effects_buffer_swapped, width, height);
fx_framebuffer_bind(&renderer->effects_buffer_swapped);
} else {
fx_framebuffer_bind(&renderer->effects_buffer, width, height);
fx_framebuffer_bind(&renderer->effects_buffer);
}

if (pixman_region32_not_empty(damage)) {
Expand Down Expand Up @@ -221,7 +219,7 @@ struct fx_framebuffer *get_main_buffer_blur(struct fx_renderer *renderer, struct
struct fx_framebuffer *current_buffer = &renderer->main_buffer;

// Bind to blur framebuffer
fx_framebuffer_bind(&renderer->effects_buffer, monitor_box.width, monitor_box.height);
fx_framebuffer_bind(&renderer->effects_buffer);
glBindTexture(renderer->main_buffer.texture.target, renderer->main_buffer.texture.id);

// damage region will be scaled, make a temp
Expand All @@ -234,29 +232,29 @@ struct fx_framebuffer *get_main_buffer_blur(struct fx_renderer *renderer, struct
int blur_passes = config->blur_params.num_passes;

// First pass
render_blur_segments(renderer, output, gl_matrix, &tempDamage, &current_buffer,
render_blur_segments(renderer, gl_matrix, &tempDamage, &current_buffer,
&renderer->shaders.blur1, box, blur_radius);

// Downscale
for (int i = 1; i < blur_passes; ++i) {
wlr_region_scale(&tempDamage, &damage, 1.0f / (1 << (i + 1)));
render_blur_segments(renderer, output, gl_matrix, &tempDamage, &current_buffer,
render_blur_segments(renderer, gl_matrix, &tempDamage, &current_buffer,
&renderer->shaders.blur1, box, blur_radius);
}

// Upscale
for (int i = blur_passes - 1; i >= 0; --i) {
// when upsampling we make the region twice as big
wlr_region_scale(&tempDamage, &damage, 1.0f / (1 << i));
render_blur_segments(renderer, output, gl_matrix, &tempDamage, &current_buffer,
render_blur_segments(renderer, gl_matrix, &tempDamage, &current_buffer,
&renderer->shaders.blur2, box, blur_radius);
}

pixman_region32_fini(&tempDamage);
pixman_region32_fini(&damage);

// Bind back to the default buffer
fx_framebuffer_bind(&renderer->main_buffer, monitor_box.width, monitor_box.height);
fx_framebuffer_bind(&renderer->main_buffer);

return current_buffer;
}
Expand Down Expand Up @@ -493,7 +491,7 @@ void render_monitor_blur(struct sway_output *output, pixman_region32_t *damage)
fx_renderer_clear(clear_color);
}
render_whole_output(renderer, wlr_output, &fake_damage, &buffer->texture);
fx_framebuffer_bind(&renderer->main_buffer, monitor_box.width, monitor_box.height);
fx_framebuffer_bind(&renderer->main_buffer);

pixman_region32_fini(&fake_damage);

Expand Down Expand Up @@ -1762,7 +1760,6 @@ void output_render(struct sway_output *output, struct timespec *when,
int width, height;
wlr_output_transformed_resolution(wlr_output, &width, &height);


fx_renderer_begin(renderer, width, height);

if (debug.damage == DAMAGE_RERENDER) {
Expand Down Expand Up @@ -1949,7 +1946,7 @@ void output_render(struct sway_output *output, struct timespec *when,

renderer_end:
// Draw the contents of our buffer into the wlr buffer
fx_framebuffer_bind(&renderer->wlr_buffer, width, height);
fx_framebuffer_bind(&renderer->wlr_buffer);
float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f};
if (pixman_region32_not_empty(&extended_damage)) {
int nrects;
Expand Down

0 comments on commit 3d1b294

Please sign in to comment.