Skip to content

Commit

Permalink
blur wip - draw whole screen
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rgb committed Apr 28, 2017
1 parent f9f321b commit 9713b64
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
6 changes: 4 additions & 2 deletions src/blur.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -124,4 +126,3 @@ void free_layers(Layer* root);

i64 count_strokes(Layer* root);
i64 count_clipped_strokes(Layer* root, i32 num_workers);

1 change: 0 additions & 1 deletion src/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/hardware_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 16 additions & 17 deletions src/milton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}


Expand All @@ -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.

}
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9713b64

Please sign in to comment.