move render backend, nuklear and microprofile objects out of window

This commit is contained in:
Anthony Pesch 2017-04-11 18:04:31 -04:00
parent 4c30c2b4e5
commit 0c02b2e1bf
8 changed files with 247 additions and 233 deletions

View File

@ -14,8 +14,10 @@
#include "hw/sh4/sh4.h"
#include "sys/thread.h"
#include "sys/time.h"
#include "ui/microprofile.h"
#include "ui/nuklear.h"
#include "ui/window.h"
#include "video/render_backend.h"
DEFINE_AGGREGATE_COUNTER(frames);
@ -27,6 +29,12 @@ struct emu {
struct dreamcast *dc;
volatile int running;
int debug_menu;
struct render_backend *rb;
struct microprofile *mp;
struct nuklear *nk;
/* render state */
struct tr *tr;
struct render_context rc;
@ -72,45 +80,96 @@ static int emu_launch_gdi(struct emu *emu, const char *path) {
return 1;
}
static void emu_paint(void *data) {
struct emu *emu = data;
static void emu_paint(struct emu *emu) {
rb_begin_frame(emu->rb);
nk_begin_frame(emu->nk);
mp_begin_frame(emu->mp);
/* wait for the next ta context */
struct render_context *rc = &emu->rc;
struct tile_ctx *pending_ctx = NULL;
/* render the next ta context */
{
struct render_context *rc = &emu->rc;
struct tile_ctx *pending_ctx = NULL;
while (emu->running) {
if (ta_lock_pending_context(emu->dc->ta, &pending_ctx, 1000)) {
tr_parse_context(emu->tr, pending_ctx, rc);
ta_unlock_pending_context(emu->dc->ta);
break;
while (emu->running) {
if (ta_lock_pending_context(emu->dc->ta, &pending_ctx, 1000)) {
tr_parse_context(emu->tr, pending_ctx, rc);
ta_unlock_pending_context(emu->dc->ta);
break;
}
}
tr_render_context(emu->tr, rc);
}
/* render debug menus */
{
if (emu->debug_menu) {
struct nk_context *ctx = &emu->nk->ctx;
struct nk_rect bounds = {0.0f, 0.0f, (float)emu->window->width,
DEBUG_MENU_HEIGHT};
nk_style_default(ctx);
ctx->style.window.border = 0.0f;
ctx->style.window.menu_border = 0.0f;
ctx->style.window.spacing = nk_vec2(0.0f, 0.0f);
ctx->style.window.padding = nk_vec2(0.0f, 0.0f);
if (nk_begin(ctx, "debug menu", bounds, NK_WINDOW_NO_SCROLLBAR)) {
nk_menubar_begin(ctx);
nk_layout_row_begin(ctx, NK_STATIC, DEBUG_MENU_HEIGHT,
MAX_WINDOW_LISTENERS + 2);
/* add our own debug menu */
nk_layout_row_push(ctx, 30.0f);
if (nk_menu_begin_label(ctx, "EMU", NK_TEXT_LEFT,
nk_vec2(140.0f, 200.0f))) {
nk_layout_row_dynamic(ctx, DEBUG_MENU_HEIGHT, 1);
int fullscreen = emu->window->fullscreen;
if (nk_checkbox_label(ctx, "fullscreen", &fullscreen)) {
win_set_fullscreen(emu->window, fullscreen);
}
nk_menu_end(ctx);
}
/* add each devices's debug menu */
dc_debug_menu(emu->dc, ctx);
/* fill up remaining space with status */
char status[128];
int frames = (int)prof_counter_load(COUNTER_frames);
int ta_renders = (int)prof_counter_load(COUNTER_ta_renders);
int pvr_vblanks = (int)prof_counter_load(COUNTER_pvr_vblanks);
int sh4_instrs =
(int)(prof_counter_load(COUNTER_sh4_instrs) / 1000000.0f);
int arm7_instrs =
(int)(prof_counter_load(COUNTER_arm7_instrs) / 1000000.0f);
snprintf(status, sizeof(status),
"FPS %3d RPS %3d VBS %3d SH4 %4d ARM %d", frames, ta_renders,
pvr_vblanks, sh4_instrs, arm7_instrs);
nk_layout_row_push(ctx, (float)emu->window->width -
ctx->current->layout->row.item_offset);
nk_label(ctx, status, NK_TEXT_RIGHT);
nk_layout_row_end(ctx);
nk_menubar_end(ctx);
}
nk_end(ctx);
}
}
tr_render_context(emu->tr, rc);
/* update profiler stats */
prof_counter_add(COUNTER_frames, 1);
prof_flip();
}
static void emu_debug_menu(void *data, struct nk_context *ctx) {
struct emu *emu = data;
/* set status string */
char status[128];
int frames = (int)prof_counter_load(COUNTER_frames);
int ta_renders = (int)prof_counter_load(COUNTER_ta_renders);
int pvr_vblanks = (int)prof_counter_load(COUNTER_pvr_vblanks);
int sh4_instrs = (int)(prof_counter_load(COUNTER_sh4_instrs) / 1000000.0f);
int arm7_instrs = (int)(prof_counter_load(COUNTER_arm7_instrs) / 1000000.0f);
snprintf(status, sizeof(status), "%3d FPS %3d RPS %3d VBS %4d SH4 %d ARM",
frames, ta_renders, pvr_vblanks, sh4_instrs, arm7_instrs);
win_set_status(emu->window, status);
dc_debug_menu(emu->dc, ctx);
mp_end_frame(emu->mp);
nk_end_frame(emu->nk);
rb_end_frame(emu->rb);
}
static void emu_keydown(void *data, int device_index, enum keycode code,
@ -119,7 +178,7 @@ static void emu_keydown(void *data, int device_index, enum keycode code,
if (code == K_F1) {
if (value > 0) {
win_enable_debug_menu(emu->window, !emu->window->debug_menu);
emu->debug_menu = emu->debug_menu ? 0 : 1;
}
return;
}
@ -200,7 +259,7 @@ void emu_run(struct emu *emu, const char *path) {
}
/* create tile renderer */
emu->tr = tr_create(emu->window->rb, ta_texture_provider(emu->dc->ta));
emu->tr = tr_create(emu->rb, ta_texture_provider(emu->dc->ta));
/* load gdi / bin if specified */
if (path) {
@ -234,6 +293,7 @@ void emu_run(struct emu *emu, const char *path) {
while (emu->running) {
win_pump_events(emu->window);
emu_paint(emu);
}
/* wait for the core thread to exit */
@ -245,10 +305,25 @@ void emu_destroy(struct emu *emu) {
if (emu->tr) {
tr_destroy(emu->tr);
}
if (emu->dc) {
dc_destroy(emu->dc);
}
if (emu->nk) {
nk_destroy(emu->nk);
}
if (emu->mp) {
mp_destroy(emu->mp);
}
if (emu->rb) {
rb_destroy(emu->rb);
}
win_remove_listener(emu->window, &emu->listener);
free(emu);
}
@ -256,13 +331,39 @@ struct emu *emu_create(struct window *window) {
struct emu *emu = calloc(1, sizeof(struct emu));
emu->window = window;
/* add window input listeners */
emu->listener = (struct window_listener){
emu, &emu_paint, &emu_debug_menu, &emu_joy_add, &emu_joy_remove,
&emu_keydown, NULL, &emu_close, {0}};
emu, NULL, &emu_joy_add, &emu_joy_remove,
&emu_keydown, NULL, &emu_close, {0}};
win_add_listener(emu->window, &emu->listener);
/* enable debug menu by default */
win_enable_debug_menu(emu->window, 1);
/* setup render backend */
emu->rb = rb_create(emu->window);
if (!emu->rb) {
LOG_WARNING("Render backend creation failed");
emu_destroy(emu);
return NULL;
}
/* setup microprofile */
emu->mp = mp_create(emu->window, emu->rb);
if (!emu->mp) {
LOG_WARNING("MicroProfile creation failed");
emu_destroy(emu);
return NULL;
}
/* setup nuklear */
emu->nk = nk_create(emu->window, emu->rb);
if (!emu->nk) {
LOG_WARNING("Nuklear creation failed");
emu_destroy(emu);
return NULL;
}
/* debug menu enabled by default */
emu->debug_menu = 1;
return emu;
}

View File

@ -66,10 +66,11 @@ struct tracer_texture_entry {
struct tracer {
struct window *window;
struct render_backend *rb;
struct nuklear *nk;
struct tr *tr;
struct window_listener listener;
struct texture_provider provider;
struct render_backend *rb;
struct tr *tr;
/* ui state */
int running;
@ -284,7 +285,7 @@ static void tracer_reset_context(struct tracer *tracer) {
static const float SCRUBBER_WINDOW_HEIGHT = 20.0f;
static void tracer_render_scrubber_menu(struct tracer *tracer) {
struct nk_context *ctx = &tracer->window->nk->ctx;
struct nk_context *ctx = &tracer->nk->ctx;
nk_style_default(ctx);
@ -320,7 +321,7 @@ static void tracer_render_scrubber_menu(struct tracer *tracer) {
static void tracer_param_tooltip(struct tracer *tracer,
struct render_param *rp) {
struct nk_context *ctx = &tracer->window->nk->ctx;
struct nk_context *ctx = &tracer->nk->ctx;
if (nk_tooltip_begin(ctx, 300.0f)) {
nk_layout_row_dynamic(ctx, ctx->style.font->height, 1);
@ -569,7 +570,7 @@ static void tracer_param_tooltip(struct tracer *tracer,
}
static void tracer_render_side_menu(struct tracer *tracer) {
struct nk_context *ctx = &tracer->window->nk->ctx;
struct nk_context *ctx = &tracer->nk->ctx;
/* transparent menu backgrounds / selectables */
@ -740,41 +741,43 @@ static void tracer_render_list(struct tracer *tracer,
}
}
static void tracer_paint(void *data) {
struct tracer *tracer = data;
static void tracer_paint(struct tracer *tracer) {
rb_begin_frame(tracer->rb);
nk_begin_frame(tracer->nk);
/* render ui */
tracer_render_side_menu(tracer);
tracer_render_scrubber_menu(tracer);
/* render context up to the surface of the currently selected param */
struct render_context *rc = &tracer->rc;
int stopped = 0;
int end = -1;
{
struct render_context *rc = &tracer->rc;
int stopped = 0;
int end = -1;
if (tracer->current_param >= 0) {
struct render_param *rp = &rc->params[tracer->current_param];
end = rp->last_surf;
if (tracer->current_param >= 0) {
struct render_param *rp = &rc->params[tracer->current_param];
end = rp->last_surf;
}
rb_begin_surfaces(tracer->rb, rc->projection, rc->verts, rc->num_verts);
tracer_render_list(tracer, rc, TA_LIST_OPAQUE, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_PUNCH_THROUGH, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_TRANSLUCENT, end, &stopped);
rb_end_surfaces(tracer->rb);
}
rb_begin_surfaces(tracer->rb, rc->projection, rc->verts, rc->num_verts);
tracer_render_list(tracer, rc, TA_LIST_OPAQUE, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_PUNCH_THROUGH, end, &stopped);
tracer_render_list(tracer, rc, TA_LIST_TRANSLUCENT, end, &stopped);
rb_end_surfaces(tracer->rb);
nk_end_frame(tracer->nk);
rb_end_frame(tracer->rb);
}
static void tracer_keydown(void *data, int device_index, enum keycode code,
int16_t value) {
struct tracer *tracer = data;
if (code == K_F1) {
if (value > 0) {
win_enable_debug_menu(tracer->window, !tracer->window->debug_menu);
}
} else if (code == K_LEFT && value > 0) {
if (code == K_LEFT && value > 0) {
tracer_prev_context(tracer);
} else if (code == K_RIGHT && value > 0) {
tracer_next_context(tracer);
@ -818,6 +821,7 @@ void tracer_run(struct tracer *tracer, const char *path) {
while (tracer->running) {
win_pump_events(tracer->window);
tracer_paint(tracer);
}
}
@ -825,8 +829,21 @@ void tracer_destroy(struct tracer *tracer) {
if (tracer->trace) {
trace_destroy(tracer->trace);
}
if (tracer->tr) {
tr_destroy(tracer->tr);
}
if (tracer->nk) {
nk_destroy(tracer->nk);
}
if (tracer->rb) {
rb_destroy(tracer->rb);
}
win_remove_listener(tracer->window, &tracer->listener);
tr_destroy(tracer->tr);
free(tracer);
}
@ -837,16 +854,33 @@ struct tracer *tracer_create(struct window *window) {
struct tracer *tracer = calloc(1, sizeof(struct tracer));
tracer->window = window;
/* add window input listeners */
tracer->listener = (struct window_listener){
tracer, &tracer_paint, NULL, NULL, NULL,
&tracer_keydown, NULL, &tracer_close, {0}};
tracer, NULL, NULL, NULL, &tracer_keydown, NULL, &tracer_close, {0}};
win_add_listener(tracer->window, &tracer->listener);
/* setup render backend */
tracer->rb = rb_create(tracer->window);
if (!tracer->rb) {
LOG_WARNING("Render backend creation failed");
tracer_destroy(tracer);
return NULL;
}
/* setup nuklear */
tracer->nk = nk_create(tracer->window, tracer->rb);
if (!tracer->nk) {
LOG_WARNING("Nuklear creation failed");
tracer_destroy(tracer);
return NULL;
}
/* setup tile renderer */
tracer->provider =
(struct texture_provider){tracer, &tracer_texture_provider_find_texture};
tracer->rb = window->rb;
tracer->tr = tr_create(tracer->rb, &tracer->provider);
win_add_listener(tracer->window, &tracer->listener);
/* add all textures to free list */
for (int i = 0, n = array_size(tracer->textures); i < n; i++) {
struct tracer_texture_entry *entry = &tracer->textures[i];

View File

@ -26,6 +26,7 @@ static const int MAX_2D_SURFACES = 256;
struct microprofile {
struct window *window;
struct render_backend *rb;
struct window_listener listener;
texture_handle_t font_texture;
struct surface2d surfs[MAX_2D_SURFACES];
@ -240,18 +241,16 @@ void mp_end_frame(struct microprofile *mp) {
MicroProfileDraw(mp->window->width, mp->window->height);
/* render the surfaces */
struct render_backend *rb = mp->window->rb;
rb_begin_ortho(rb);
rb_begin_surfaces2d(rb, mp->verts, mp->num_verts, nullptr, 0);
rb_begin_ortho(mp->rb);
rb_begin_surfaces2d(mp->rb, mp->verts, mp->num_verts, nullptr, 0);
for (int i = 0; i < mp->num_surfs; i++) {
struct surface2d *surf = &mp->surfs[i];
rb_draw_surface2d(rb, surf);
rb_draw_surface2d(mp->rb, surf);
}
rb_end_surfaces2d(rb);
rb_end_ortho(rb);
rb_end_surfaces2d(mp->rb);
rb_end_ortho(mp->rb);
/* reset surfaces */
mp->num_surfs = 0;
@ -261,26 +260,25 @@ void mp_end_frame(struct microprofile *mp) {
void mp_begin_frame(struct microprofile *mp) {}
void mp_destroy(struct microprofile *mp) {
rb_destroy_texture(mp->window->rb, mp->font_texture);
rb_destroy_texture(mp->rb, mp->font_texture);
win_remove_listener(mp->window, &mp->listener);
free(mp);
}
struct microprofile *mp_create(struct window *window) {
struct microprofile *mp_create(struct window *window,
struct render_backend *rb) {
struct microprofile *mp = reinterpret_cast<struct microprofile *>(
calloc(1, sizeof(struct microprofile)));
mp->window = window;
mp->listener = {mp, NULL, NULL, NULL, NULL,
&mp_keydown, &mp_mousemove, NULL, {}};
mp->rb = rb;
/* add input event listeners */
mp->listener = {mp, NULL, NULL, NULL, &mp_keydown, &mp_mousemove, NULL, {}};
win_add_listener(mp->window, &mp->listener);
/* init microprofile */
struct render_backend *rb = mp->window->rb;
/* register and enable cpu and gpu groups by default */
uint16_t cpu_group = MicroProfileGetGroup("cpu", MicroProfileTokenTypeCpu);
g_MicroProfile.nActiveGroupWanted |= 1ll << cpu_group;
@ -295,9 +293,10 @@ struct microprofile *mp_create(struct window *window) {
g_MicroProfile.nAggregateFlip = 120;
/* register the font texture */
mp->font_texture = rb_create_texture(
rb, PXL_RGBA, FILTER_NEAREST, WRAP_CLAMP_TO_EDGE, WRAP_CLAMP_TO_EDGE, 0,
FONT_WIDTH, FONT_HEIGHT, reinterpret_cast<const uint8_t *>(s_font_data));
mp->font_texture =
rb_create_texture(mp->rb, PXL_RGBA, FILTER_NEAREST, WRAP_CLAMP_TO_EDGE,
WRAP_CLAMP_TO_EDGE, 0, FONT_WIDTH, FONT_HEIGHT,
reinterpret_cast<const uint8_t *>(s_font_data));
return mp;
}

View File

@ -2,9 +2,11 @@
#define MICROPROFILE_IMPL_H
struct microprofile;
struct render_backend;
struct window;
struct microprofile *mp_create(struct window *window);
struct microprofile *mp_create(struct window *window,
struct render_backend *rb);
void mp_destroy(struct microprofile *mp);
void mp_begin_frame(struct microprofile *mp);

View File

@ -51,8 +51,6 @@ static void nk_mousemove(void *data, int x, int y) {
}
void nk_end_frame(struct nuklear *nk) {
struct render_backend *rb = nk->window->rb;
/* 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 vertex2d, xy)},
@ -77,8 +75,8 @@ void nk_end_frame(struct nuklear *nk) {
nk_convert(&nk->ctx, &nk->cmds, &vbuf, &ebuf, &config);
/* bind buffers */
rb_begin_ortho(rb);
rb_begin_surfaces2d(rb, nk->vertices, nk->ctx.draw_list.vertex_count,
rb_begin_ortho(nk->rb);
rb_begin_surfaces2d(nk->rb, nk->vertices, nk->ctx.draw_list.vertex_count,
nk->elements, nk->ctx.draw_list.element_count);
/* pass each draw command off to the render backend */
@ -105,14 +103,14 @@ void nk_end_frame(struct nuklear *nk) {
surf.first_vert = offset;
surf.num_verts = cmd->elem_count;
rb_draw_surface2d(rb, &surf);
rb_draw_surface2d(nk->rb, &surf);
offset += cmd->elem_count;
}
nk_clear(&nk->ctx);
rb_end_surfaces2d(rb);
rb_end_ortho(rb);
rb_end_surfaces2d(nk->rb);
rb_end_ortho(nk->rb);
/* reset mouse wheel state as it won't be reset through any event */
nk->mouse_wheel = 0;
@ -139,19 +137,22 @@ void nk_destroy(struct nuklear *nk) {
nk_font_atlas_clear(&nk->atlas);
nk_free(&nk->ctx);
rb_destroy_texture(nk->window->rb, nk->font_texture);
rb_destroy_texture(nk->rb, nk->font_texture);
win_remove_listener(nk->window, &nk->listener);
free(nk);
}
struct nuklear *nk_create(struct window *window) {
struct nuklear *nk_create(struct window *window, struct render_backend *rb) {
struct nuklear *nk = calloc(1, sizeof(struct nuklear));
nk->window = window;
nk->listener = (struct window_listener){
nk, NULL, NULL, NULL, NULL, &nk_keydown, &nk_mousemove, NULL, {0}};
nk->window = window;
nk->rb = rb;
/* add input event listeners */
nk->listener = (struct window_listener){
nk, NULL, NULL, NULL, &nk_keydown, &nk_mousemove, NULL, {0}};
win_add_listener(nk->window, &nk->listener);
/* create default font texture */
@ -162,7 +163,7 @@ struct nuklear *nk_create(struct window *window) {
const void *font_data = nk_font_atlas_bake(
&nk->atlas, &font_width, &font_height, NK_FONT_ATLAS_RGBA32);
nk->font_texture =
rb_create_texture(nk->window->rb, PXL_RGBA, FILTER_BILINEAR, WRAP_REPEAT,
rb_create_texture(nk->rb, PXL_RGBA, FILTER_BILINEAR, WRAP_REPEAT,
WRAP_REPEAT, 0, font_width, font_height, font_data);
nk_font_atlas_end(&nk->atlas, nk_handle_id((int)nk->font_texture), &nk->null);

View File

@ -16,8 +16,11 @@
#define NK_MAX_VERTICES 16384
#define NK_MAX_ELEMENTS (NK_MAX_VERTICES * 4)
struct render_backend;
struct nuklear {
struct window *window;
struct render_backend *rb;
struct window_listener listener;
struct nk_context ctx;
@ -39,7 +42,7 @@ struct nuklear {
int shift[2];
};
struct nuklear *nk_create(struct window *window);
struct nuklear *nk_create(struct window *window, struct render_backend *rb);
void nk_destroy(struct nuklear *nk);
void nk_begin_frame(struct nuklear *nk);

View File

@ -5,9 +5,6 @@
#include "ui/window.h"
#include "core/assert.h"
#include "core/list.h"
#include "ui/microprofile.h"
#include "ui/nuklear.h"
#include "video/render_backend.h"
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
@ -81,82 +78,6 @@ static int win_device_index(struct window *win, SDL_JoystickID which) {
return 0;
}
static void win_set_fullscreen(struct window *win, int fullscreen) {
win->fullscreen = fullscreen;
SDL_SetWindowFullscreen(win->handle, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
}
static void win_debug_menu(struct window *win) {
if (!win->debug_menu) {
return;
}
struct nk_context *ctx = &win->nk->ctx;
struct nk_rect bounds = {0.0f, 0.0f, (float)win->width, DEBUG_MENU_HEIGHT};
nk_style_default(ctx);
ctx->style.window.border = 0.0f;
ctx->style.window.menu_border = 0.0f;
ctx->style.window.spacing = nk_vec2(0.0f, 0.0f);
ctx->style.window.padding = nk_vec2(0.0f, 0.0f);
if (nk_begin(ctx, "debug menu", bounds, NK_WINDOW_NO_SCROLLBAR)) {
nk_menubar_begin(ctx);
nk_layout_row_begin(ctx, NK_STATIC, DEBUG_MENU_HEIGHT,
MAX_WINDOW_LISTENERS + 2);
/* add our own debug menu */
nk_layout_row_push(ctx, 50.0f);
if (nk_menu_begin_label(ctx, "WINDOW", NK_TEXT_LEFT,
nk_vec2(140.0f, 200.0f))) {
nk_layout_row_dynamic(ctx, DEBUG_MENU_HEIGHT, 1);
int fullscreen = win->fullscreen;
if (nk_checkbox_label(ctx, "fullscreen", &fullscreen)) {
win_set_fullscreen(win, fullscreen);
}
nk_menu_end(ctx);
}
/* add each listener's debug menu */
list_for_each_entry(listener, &win->listeners, struct window_listener, it) {
if (listener->debug_menu) {
listener->debug_menu(listener->data, ctx);
}
}
/* fill up remaining space with status */
nk_layout_row_push(
ctx, (float)win->width - ctx->current->layout->row.item_offset);
nk_label(ctx, win->status, NK_TEXT_RIGHT);
nk_layout_row_end(ctx);
nk_menubar_end(ctx);
}
nk_end(ctx);
}
static void win_handle_paint(struct window *win) {
rb_begin_frame(win->rb);
nk_begin_frame(win->nk);
mp_begin_frame(win->mp);
list_for_each_entry(listener, &win->listeners, struct window_listener, it) {
if (listener->paint) {
listener->paint(listener->data);
}
}
win_debug_menu(win);
mp_end_frame(win->mp);
nk_end_frame(win->nk);
rb_end_frame(win->rb);
}
static void win_handle_keydown(struct window *win, int device_index,
enum keycode code, int16_t value) {
list_for_each_entry(listener, &win->listeners, struct window_listener, it) {
@ -888,19 +809,14 @@ static void win_pump_sdl(struct window *win) {
}
}
void win_enable_debug_menu(struct window *win, int active) {
win->debug_menu = active;
}
void win_set_status(struct window *win, const char *status) {
strncpy(win->status, status, sizeof(win->status));
}
void win_pump_events(struct window *win) {
win_pump_sdl(win);
}
/* trigger a paint event after draining all other window-related events */
win_handle_paint(win);
void win_set_fullscreen(struct window *win, int fullscreen) {
win->fullscreen = fullscreen;
SDL_SetWindowFullscreen(win->handle, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
}
void win_remove_listener(struct window *win, struct window_listener *listener) {
@ -946,18 +862,6 @@ glcontext_t win_gl_create_context(struct window *win) {
}
void win_destroy(struct window *win) {
if (win->mp) {
mp_destroy(win->mp);
}
if (win->nk) {
nk_destroy(win->nk);
}
if (win->rb) {
rb_destroy(win->rb);
}
if (win->handle) {
SDL_DestroyWindow(win->handle);
}
@ -996,29 +900,5 @@ struct window *win_create() {
return NULL;
}
/* setup video backend */
win->rb = rb_create(win);
if (!win->rb) {
LOG_WARNING("Render backend creation failed");
win_destroy(win);
return NULL;
}
/* setup nuklear */
win->nk = nk_create(win);
if (!win->nk) {
LOG_WARNING("Nuklear creation failed");
win_destroy(win);
return NULL;
}
/* setup microprofile */
win->mp = mp_create(win);
if (!win->mp) {
LOG_WARNING("MicroProfile creation failed");
win_destroy(win);
return NULL;
}
return win;
}

View File

@ -31,7 +31,6 @@ typedef void *glcontext_t;
struct window_listener {
void *data;
void (*paint)(void *data);
void (*debug_menu)(void *data, struct nk_context *ctx);
void (*joy_add)(void *data, int joystick_index);
void (*joy_remove)(void *data, int joystick_index);
void (*keydown)(void *data, int device_index, enum keycode code,
@ -44,15 +43,11 @@ struct window_listener {
struct window {
/* public */
struct SDL_Window *handle;
struct render_backend *rb;
struct nuklear *nk;
struct microprofile *mp;
/* read only */
int width;
int height;
int fullscreen;
int debug_menu;
/* private state */
struct list listeners;
@ -71,9 +66,8 @@ void win_gl_destroy_context(struct window *win, glcontext_t ctx);
void win_add_listener(struct window *win, struct window_listener *listener);
void win_remove_listener(struct window *win, struct window_listener *listener);
void win_set_fullscreen(struct window *win, int fullscreen);
void win_pump_events(struct window *win);
void win_set_status(struct window *win, const char *status);
void win_enable_debug_menu(struct window *win, int active);
#endif