removed overly generic begin_frame / end_frame calls

This commit is contained in:
Anthony Pesch 2017-04-18 08:54:18 -04:00
parent 5fae12ddaa
commit c29ae7b6d2
10 changed files with 50 additions and 43 deletions

View File

@ -103,6 +103,11 @@ prof_token_t prof_get_aggregate_token(const char *name) {
return tok;
}
void prof_flip() {
/* flip frame-based profile zones at the end of every frame */
MicroProfileFlip();
}
void prof_update(int64_t now) {
/* update time-based aggregate counters every second */
int64_t next_aggregation = prof.last_aggregation + NS_PER_SEC;
@ -121,11 +126,6 @@ void prof_update(int64_t now) {
}
}
void prof_flip() {
/* flip frame-based profile zones at the end of every frame */
MicroProfileFlip();
}
void prof_counter_set(prof_token_t tok, int64_t count) {
if (prof.aggregate[tok]) {
prof.counters[tok].store(count);

View File

@ -47,10 +47,10 @@ int64_t prof_counter_load(prof_token_t tok);
void prof_counter_add(prof_token_t tok, int64_t count);
void prof_counter_set(prof_token_t tok, int64_t count);
/* called at the end of every frame to aggregate frame-based profile zones */
void prof_flip();
/* called periodically to aggregate time-based aggregate counters */
void prof_update(int64_t now);
/* called at the end of every frame to aggregate frame-based profile zones */
void prof_flip();
#endif

View File

@ -81,9 +81,11 @@ static int emu_launch_gdi(struct emu *emu, const char *path) {
}
static void emu_paint(struct emu *emu) {
r_begin_frame(emu->r);
nk_begin_frame(emu->nk);
mp_begin_frame(emu->mp);
prof_counter_add(COUNTER_frames, 1);
r_clear_viewport(emu->r);
nk_update_input(emu->nk);
/* render the next ta context */
{
@ -163,13 +165,13 @@ static void emu_paint(struct emu *emu) {
}
}
/* update profiler stats */
prof_counter_add(COUNTER_frames, 1);
/* update frame-based profiler stats */
prof_flip();
mp_end_frame(emu->mp);
nk_end_frame(emu->nk);
r_end_frame(emu->r);
mp_render(emu->mp);
nk_render(emu->nk);
r_swap_buffers(emu->r);
}
static void emu_keydown(void *data, int device_index, enum keycode code,

View File

@ -742,8 +742,9 @@ static void tracer_render_list(struct tracer *tracer,
}
static void tracer_paint(struct tracer *tracer) {
r_begin_frame(tracer->r);
nk_begin_frame(tracer->nk);
r_clear_viewport(tracer->r);
nk_update_input(tracer->nk);
/* render ui */
tracer_render_side_menu(tracer);
@ -769,8 +770,9 @@ static void tracer_paint(struct tracer *tracer) {
r_end_surfaces(tracer->r);
}
nk_end_frame(tracer->nk);
r_end_frame(tracer->r);
nk_render(tracer->nk);
r_swap_buffers(tracer->r);
}
static void tracer_keydown(void *data, int device_index, enum keycode code,

View File

@ -233,7 +233,7 @@ static void mp_draw_line(struct microprofile *mp, float *verts, int num_verts,
}
}
void mp_end_frame(struct microprofile *mp) {
void mp_render(struct microprofile *mp) {
s_mp = mp;
/* update draw surfaces */
@ -256,8 +256,6 @@ void mp_end_frame(struct microprofile *mp) {
mp->num_verts = 0;
}
void mp_begin_frame(struct microprofile *mp) {}
void mp_destroy(struct microprofile *mp) {
r_destroy_texture(mp->r, mp->font_texture);

View File

@ -8,7 +8,6 @@ struct window;
struct microprofile *mp_create(struct window *window, struct render_backend *r);
void mp_destroy(struct microprofile *mp);
void mp_begin_frame(struct microprofile *mp);
void mp_end_frame(struct microprofile *mp);
void mp_render(struct microprofile *mp);
#endif

View File

@ -50,7 +50,7 @@ static void nk_mousemove(void *data, int x, int y) {
nk->mousey = y;
}
void nk_end_frame(struct nuklear *nk) {
void nk_render(struct nuklear *nk) {
/* convert draw list into vertex / element buffers */
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct vertex2, xy)},
@ -111,12 +111,12 @@ void nk_end_frame(struct nuklear *nk) {
r_end_surfaces2(nk->r);
r_end_ortho(nk->r);
/* reset mouse wheel state as it won't be reset through any event */
/* reset mouse wheel state at this point as it won't be reset through an
actual input event */
nk->mouse_wheel = 0;
}
void nk_begin_frame(struct nuklear *nk) {
/* update input state for the frame */
void nk_update_input(struct nuklear *nk) {
nk_input_begin(&nk->ctx);
nk_input_motion(&nk->ctx, nk->mousex, nk->mousey);

View File

@ -45,7 +45,7 @@ struct nuklear {
struct nuklear *nk_create(struct window *window, struct render_backend *r);
void nk_destroy(struct nuklear *nk);
void nk_begin_frame(struct nuklear *nk);
void nk_end_frame(struct nuklear *nk);
void nk_update_input(struct nuklear *nk);
void nk_render(struct nuklear *nk);
#endif

View File

@ -688,11 +688,11 @@ void r_begin_ortho(struct render_backend *r) {
glUniformMatrix4fv(r_get_uniform(r, UNIFORM_MVP), 1, GL_FALSE, ortho);
}
void r_end_frame(struct render_backend *r) {
void r_swap_buffers(struct render_backend *r) {
SDL_GL_SwapWindow(r->win->handle);
}
void r_begin_frame(struct render_backend *r) {
void r_clear_viewport(struct render_backend *r) {
r_set_depth_mask(r, 1);
glViewport(0, 0, r->win->width, r->win->height);
@ -700,16 +700,21 @@ void r_begin_frame(struct render_backend *r) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void r_wait(sync_handle_t on) {
GLsync sync = on;
CHECK(glIsSync(sync));
void r_destroy_sync(struct render_backend *r, sync_handle_t handle) {
GLsync sync = handle;
DCHECK(glIsSync(sync));
GLenum res = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, UINT64_MAX);
CHECK(res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED);
glDeleteSync(sync);
}
sync_handle_t r_sync(struct render_backend *r) {
void r_wait_sync(struct render_backend *r, sync_handle_t handle) {
GLsync sync = handle;
DCHECK(glIsSync(sync));
glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
}
sync_handle_t r_insert_sync(struct render_backend *r) {
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glFlush();
return sync;

View File

@ -146,11 +146,12 @@ texture_handle_t r_create_texture(struct render_backend *r,
const uint8_t *buffer);
void r_destroy_texture(struct render_backend *r, texture_handle_t handle);
sync_handle_t r_sync(struct render_backend *r);
void r_wait(sync_handle_t on);
sync_handle_t r_insert_sync(struct render_backend *r);
void r_wait_sync(struct render_backend *r, sync_handle_t handle);
void r_destroy_sync(struct render_backend *r, sync_handle_t handle);
void r_begin_frame(struct render_backend *r);
void r_end_frame(struct render_backend *r);
void r_clear_viewport(struct render_backend *r);
void r_swap_buffers(struct render_backend *r);
void r_begin_ortho(struct render_backend *r);
void r_end_ortho(struct render_backend *r);