diff --git a/src/blur.f.glsl b/src/blur.f.glsl index 12717fe6..5922340f 100644 --- a/src/blur.f.glsl +++ b/src/blur.f.glsl @@ -18,11 +18,13 @@ main() if ( u_kernel_size > 1 ) { if ( u_direction == 0 ) { for ( int y = -u_kernel_size+1; y < u_kernel_size; y+=2 ) { - out_color += texture(u_canvas, (screen_point+vec2(0.0,y-0.5)) / u_screen_size); + vec2 coord = (screen_point+vec2(0.0,y-0.5)) / u_screen_size; + out_color += texture(u_canvas, coord); } } else { for ( int x = -u_kernel_size+1; x < u_kernel_size; x+=2 ) { - out_color += texture(u_canvas, (screen_point+vec2(x-0.5,0.0)) / u_screen_size); + vec2 coord = (screen_point+vec2(x-0.5,0.0)) / u_screen_size; + out_color += texture(u_canvas, coord); } } out_color /= u_kernel_size; diff --git a/src/canvas.cc b/src/canvas.cc index 75958ab9..740ac922 100644 --- a/src/canvas.cc +++ b/src/canvas.cc @@ -143,6 +143,20 @@ layer_push_stroke(Layer* layer, Stroke stroke) return peek(&layer->strokes); } +b32 +layer_has_blur_effect(Layer* layer) +{ + b32 result = false; + for ( LayerEffect* e = layer->effects; e != NULL; e = e->next ) { + if ( e->enabled && e->type == LayerEffectType_BLUR ) { + result = true; + break; + } + } + return result; +} + + void layer_toggle_visibility(Layer* layer) { diff --git a/src/canvas.h b/src/canvas.h index fd391810..ac2201d5 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -114,6 +114,8 @@ Layer* layer_get_by_id(Layer* root_layer, i32 id); void layer_toggle_visibility(Layer* layer); +b32 layer_has_blur_effect(Layer* layer); + Stroke* layer_push_stroke(Layer* layer, Stroke stroke); typedef struct MiltonState MiltonState; @@ -124,4 +126,3 @@ void free_layers(Layer* root); i64 count_strokes(Layer* root); i64 count_clipped_strokes(Layer* root, i32 num_workers); - diff --git a/src/gui.cc b/src/gui.cc index 0d41552d..f1832a5c 100644 --- a/src/gui.cc +++ b/src/gui.cc @@ -98,7 +98,6 @@ milton_imgui_tick(MiltonInput* input, PlatformState* platform_state, MiltonStat ImGui::PushStyleColor(ImGuiCol_CheckMark, color_slider); ++color_stack; - // Menu ---- int menu_style_stack = 0; // TODO: translate diff --git a/src/hardware_renderer.cc b/src/hardware_renderer.cc index 5fa87bea..e12ef780 100644 --- a/src/hardware_renderer.cc +++ b/src/hardware_renderer.cc @@ -44,7 +44,7 @@ struct RenderData GLuint exporter_program; GLuint texture_fill_program; GLuint postproc_program; - GLuint blur_average_program; + GLuint blur_program; #if MILTON_DEBUG GLuint simple_program; #endif @@ -503,12 +503,12 @@ gpu_init(RenderData* render_data, CanvasView* view, ColorPicker* picker) gl_set_uniform_i(render_data->postproc_program, "u_canvas", 0); } { - render_data->blur_average_program = glCreateProgram(); + render_data->blur_program = glCreateProgram(); GLuint objs[2] = {}; objs[0] = gl_compile_shader(g_simple_v, GL_VERTEX_SHADER); objs[1] = gl_compile_shader(g_blur_f, GL_FRAGMENT_SHADER); - gl_link_program(render_data->blur_average_program, objs, array_count(objs)); - gl_set_uniform_i(render_data->blur_average_program, "u_canvas", 0); + gl_link_program(render_data->blur_program, objs, array_count(objs)); + gl_set_uniform_i(render_data->blur_program, "u_canvas", 0); } #if MILTON_DEBUG { // Simple program @@ -718,7 +718,7 @@ set_screen_size(RenderData* render_data, float* fscreen) render_data->exporter_program, render_data->picker_program, render_data->postproc_program, - render_data->blur_average_program, + render_data->blur_program, }; for ( u64 pi = 0; pi < array_count(programs); ++pi ) { gl_set_uniform_vec2(programs[pi], "u_screen_size", 1, fscreen); @@ -1023,10 +1023,6 @@ gpu_clip_strokes_and_update(Arena* arena, layer_element.flags |= RenderElementFlags_LAYER; Rect screen_bounds; - screen_bounds.left = 0; - screen_bounds.right = render_data->width; - screen_bounds.top = render_data->height; - screen_bounds.bottom = 0; screen_bounds.left = x; screen_bounds.right = x + w; @@ -1085,7 +1081,7 @@ gpu_clip_strokes_and_update(Arena* arena, gpu_cook_stroke(arena, render_data, s); push(clip_array, s->render_element); } - else if ( is_outside && ( flags & ClipFlags_UPDATE_GPU_DATA ) ) { + else if ( false && is_outside && ( flags & ClipFlags_UPDATE_GPU_DATA ) ) { // If it is far away, delete. i32 distance = MLT_ABS(bounds.left - x + bounds.top - y); const i32 min_number_of_screens = 4; @@ -1159,11 +1155,11 @@ enum BoxFilterPass static void box_filter_pass(RenderData* render_data, int kernel_size, int direction) { - glUseProgram(render_data->blur_average_program); - gl_set_uniform_i(render_data->blur_average_program, "u_kernel_size", kernel_size); - GLint t_loc = glGetAttribLocation(render_data->blur_average_program, "a_position"); + glUseProgram(render_data->blur_program); + gl_set_uniform_i(render_data->blur_program, "u_kernel_size", kernel_size); + GLint t_loc = glGetAttribLocation(render_data->blur_program, "a_position"); if ( t_loc >= 0 ) { - gl_set_uniform_i(render_data->blur_average_program, "u_direction", direction); + gl_set_uniform_i(render_data->blur_program, "u_direction", direction); { glBindBuffer(GL_ARRAY_BUFFER, render_data->vbo_screen_quad); glEnableVertexAttribArray((GLuint)t_loc); @@ -1185,6 +1181,7 @@ gpu_render_canvas(RenderData* render_data, i32 view_x, i32 view_y, i32 w = view_width; i32 h = view_height; glScissor(x, y, w, h); + glClearDepth(0.0f); GLCHK(glBindFramebufferEXT(GL_FRAMEBUFFER, render_data->fbo)); @@ -1241,6 +1238,7 @@ gpu_render_canvas(RenderData* render_data, i32 view_x, i32 view_y, RenderElement* re = &clip_array->data[i]; if ( re->flags & RenderElementFlags_LAYER ) { + // Layer render element. // The current framebuffer's color attachment is layer_texture. @@ -1334,6 +1332,8 @@ gpu_render_canvas(RenderData* render_data, i32 view_x, i32 view_y, glEnable(GL_BLEND); } + // glScissor(x, y, w, h); + } // If this element is not a layer, then it is a stroke. else { diff --git a/src/milton.cc b/src/milton.cc index ee3234b4..eafb3e24 100644 --- a/src/milton.cc +++ b/src/milton.cc @@ -1349,16 +1349,6 @@ milton_update_and_render(MiltonState* milton_state, MiltonInput* input) } else if ( is_user_drawing(milton_state) ) { milton_state->working_stroke.bounding_rect = bounding_box_for_stroke(&milton_state->working_stroke); - for ( LayerEffect* e = milton_state->canvas->working_layer->effects; e != NULL; e = e->next ) { - switch ( e->type ) { - case LayerEffectType_BLUR: { - CanvasView* view = milton_state->view; - milton_state->working_stroke.bounding_rect = - rect_enlarge(milton_state->working_stroke.bounding_rect, - 2*(i32)(e->blur.kernel_size*(double)e->blur.original_scale/(double)view->scale)); - } break; - } - } } @@ -1385,7 +1375,6 @@ milton_update_and_render(MiltonState* milton_state, MiltonInput* input) milton_update_brushes(milton_state); // If we are drawing, end the current stroke so that it // doesn't change from eraser to brush or vice versa. - } } } @@ -1517,17 +1506,27 @@ milton_update_and_render(MiltonState* milton_state, MiltonInput* input) view_width = custom_rectangle.right - custom_rectangle.left; view_height = custom_rectangle.bottom - custom_rectangle.top; VALIDATE_RECT(custom_rectangle); + + view_x = 0; + view_y = 0; + view_width = milton_state->view->screen_size.w; + view_height = milton_state->view->screen_size.h; } else if ( milton_state->working_stroke.num_points > 0 ) { - Rect bounds = milton_state->working_stroke.bounding_rect; - bounds.top_left = canvas_to_raster(milton_state->view, bounds.top_left); + Rect bounds = milton_state->working_stroke.bounding_rect; + bounds.top_left = canvas_to_raster(milton_state->view, bounds.top_left); bounds.bot_right = canvas_to_raster(milton_state->view, bounds.bot_right); - view_x = bounds.left; - view_y = bounds.top; - // view_y = milton_state->view->screen_size.h - bounds.bottom; - view_width = bounds.right - bounds.left; + view_x = bounds.left; + view_y = bounds.top; + + view_width = bounds.right - bounds.left; view_height = bounds.bottom - bounds.top; + + view_x = 0; + view_y = 0; + view_width = milton_state->view->screen_size.w; + view_height = milton_state->view->screen_size.h; } PROFILE_GRAPH_BEGIN(clipping);