Skip to content

Commit

Permalink
Rename RenderData to RenderBackend. RenderSettings struct
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rgb committed May 22, 2019
1 parent 3cf37e5 commit 129792c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 85 deletions.
50 changes: 26 additions & 24 deletions src/milton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,11 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
PROFILE_GRAPH_BEGIN(update);

b32 end_stroke = (input->flags & MiltonInputFlags_END_STROKE);
b32 do_full_redraw = false;

milton->render_settings.do_full_redraw = false;

b32 brush_outline_should_draw = false;
int render_flags = RenderDataFlags_NONE | RenderDataFlags_WITH_BLUR;
int render_flags = RenderBackendFlags_NONE | RenderBackendFlags_WITH_BLUR;

b32 draw_custom_rectangle = false; // Custom rectangle used for new strokes, undo/redo.
Rect custom_rectangle = rect_without_size();
Expand All @@ -1043,25 +1045,25 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
if ( input->flags & MiltonInputFlags_OPEN_FILE ) {
milton_load(milton);
upload_gui(milton);
do_full_redraw = true;
render_flags |= RenderDataFlags_WITH_BLUR;
milton->render_settings.do_full_redraw = true;
render_flags |= RenderBackendFlags_WITH_BLUR;
}

if ( milton->flags & MiltonStateFlags_FULL_REDRAW_REQUESTED ) {
milton->flags &= ~MiltonStateFlags_FULL_REDRAW_REQUESTED;
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
}

i32 now = (i32)SDL_GetTicks();

if ( input->flags & MiltonInputFlags_FULL_REFRESH ) {
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
// GUI might have changed layer effect parameters.
render_flags |= RenderDataFlags_WITH_BLUR;
render_flags |= RenderBackendFlags_WITH_BLUR;
}

if ( input->scale ) {
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;

f32 scale_factor = SCALE_FACTOR;
i32 view_scale_limit = VIEW_SCALE_LIMIT;
Expand All @@ -1082,7 +1084,7 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
// If we are *not* zooming and we are panning, we can copy most of the
// framebuffer
if ( !(input->pan_delta == v2l{}) ) {
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
}
}

Expand All @@ -1105,8 +1107,8 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
push(&milton->canvas->stroke_graveyard, stroke);
push(&milton->canvas->redo_stack, h);

do_full_redraw = true;
render_flags |= RenderDataFlags_WITH_BLUR;
milton->render_settings.do_full_redraw = true;
render_flags |= RenderBackendFlags_WITH_BLUR;

SaveBlockHeader header = {};
header.type = Block_LAYER_CONTENT;
Expand All @@ -1128,8 +1130,8 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
push(&l->strokes, stroke);
push(&milton->canvas->history, h);

do_full_redraw = true;
render_flags |= RenderDataFlags_WITH_BLUR;
milton->render_settings.do_full_redraw = true;
render_flags |= RenderBackendFlags_WITH_BLUR;

SaveBlockHeader header = {};
header.type = Block_LAYER_CONTENT;
Expand Down Expand Up @@ -1189,7 +1191,7 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
milton_stroke_input(milton, input);
if ( prev_num_points == 0 && ws->num_points > 0 ) {
// New stroke. Clear screen without blur.
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
}
}
}
Expand All @@ -1203,12 +1205,12 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
gpu_update_export_rect(milton->render_data, exporter);
}
if ( exporter->state != ExporterState_EMPTY ) {
render_flags |= RenderDataFlags_EXPORTING;
render_flags |= RenderBackendFlags_EXPORTING;
}
milton->gui->flags &= ~(MiltonGuiFlags_SHOWING_PREVIEW);
}
else if ( render_flags & RenderDataFlags_EXPORTING ) {
render_flags &= ~RenderDataFlags_EXPORTING;
else if ( render_flags & RenderBackendFlags_EXPORTING ) {
render_flags &= ~RenderBackendFlags_EXPORTING;
}

if ( (input->flags & MiltonInputFlags_IMGUI_GRABBED_INPUT) ) {
Expand All @@ -1235,9 +1237,9 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
}

if ( milton->gui->visible ) {
render_flags |= RenderDataFlags_GUI_VISIBLE;
render_flags |= RenderBackendFlags_GUI_VISIBLE;
} else {
render_flags &= ~RenderDataFlags_GUI_VISIBLE;
render_flags &= ~RenderBackendFlags_GUI_VISIBLE;
}

if ( milton->current_mode == MiltonMode::EYEDROPPER ) {
Expand Down Expand Up @@ -1316,8 +1318,8 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
clear_stroke_redo(milton);

// Make sure we show blurred layers when finishing a stroke.
render_flags |= RenderDataFlags_WITH_BLUR;
do_full_redraw = true;
render_flags |= RenderBackendFlags_WITH_BLUR;
milton->render_settings.do_full_redraw = true;

// Update save block
SaveBlockHeader header = {};
Expand Down Expand Up @@ -1491,7 +1493,7 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
}

if (milton->current_mode == MiltonMode::PEEK_OUT) {
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
peek_out_tick(milton);
}

Expand All @@ -1505,11 +1507,11 @@ milton_update_and_render(Milton* milton, MiltonInput* input)
ClipFlags clip_flags = ClipFlags_JUST_CLIP;

#if REDRAW_EVERY_FRAME
do_full_redraw = true;
milton->render_settings.do_full_redraw = true;
#endif

// Note: We flip the rectangles. GL is bottom-left by default.
if ( do_full_redraw ) {
if ( milton->render_settings.do_full_redraw ) {
view_width = milton->view->screen_size.w;
view_height = milton->view->screen_size.h;
// Only update GPU data if we are redrawing the full screen. This means
Expand Down
12 changes: 8 additions & 4 deletions src/milton.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct HistoryElement
};

struct MiltonGui;
struct RenderData;
struct RenderBackend;
struct CanvasView;
struct Layer;
struct MiltonPersist;
Expand Down Expand Up @@ -124,6 +124,11 @@ struct PeekOut
i64 low_scale;
};

struct RenderSettings
{
b32 do_full_redraw;
};

struct Milton
{
b32 flags; // See MiltonStateFlags
Expand Down Expand Up @@ -155,8 +160,6 @@ struct Milton
i32 hover_flash_ms; // Set on keyboard shortcut to change brush size.
// Brush hover "flashes" if it is currently hidden to show its current size.

// TODO: I don't know how the system is going to look, so for now putting the render zoom stuff here.
// TODO: peek-out
PeekOut* peek_out;

// Read only
Expand All @@ -168,7 +171,8 @@ struct Milton

SmoothFilter* smooth_filter;

RenderData* render_data; // Hardware Renderer
RenderSettings render_settings;
RenderBackend* render_data;

// Heap
Arena root_arena; // Lives forever
Expand Down
6 changes: 3 additions & 3 deletions src/render_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

// Render Workers:
// We have a bunch of workers running on threads, who wait on a lockless
// queue to take BlockgroupRenderData structures.
// queue to take BlockgroupRenderBackend structures.
// When there is work available, they call blockgroup_render_thread with the
// appropriate parameters.
struct BlockgroupRenderData
struct BlockgroupRenderBackend
{
i32 block_start;
};
Expand All @@ -26,7 +26,7 @@ struct RenderStack

// LIFO work queue
SDL_mutex* mutex;
BlockgroupRenderData blockgroup_render_data[RENDER_STACK_SIZE];
BlockgroupRenderBackend blockgroup_render_data[RENDER_STACK_SIZE];
i32 index;

SDL_sem* work_available;
Expand Down
Loading

0 comments on commit 129792c

Please sign in to comment.