Mercurial > repos > blastem
comparison render_sdl.c @ 2600:251cc75574af
Basic emscripten support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 13 Feb 2025 02:18:30 -0800 |
parents | 35f765c2bc87 |
children | f5603b4ee14d |
comparison
equal
deleted
inserted
replaced
2599:ca8141c2d6ba | 2600:251cc75574af |
---|---|
105 return sync_src < SYNC_VIDEO; | 105 return sync_src < SYNC_VIDEO; |
106 } | 106 } |
107 | 107 |
108 uint8_t render_should_release_on_exit(void) | 108 uint8_t render_should_release_on_exit(void) |
109 { | 109 { |
110 #ifdef __EMSCRIPTEN__ | |
111 return 0; | |
112 #else | |
110 return sync_src != SYNC_AUDIO_THREAD; | 113 return sync_src != SYNC_AUDIO_THREAD; |
114 #endif | |
111 } | 115 } |
112 | 116 |
113 void render_buffer_consumed(audio_source *src) | 117 void render_buffer_consumed(audio_source *src) |
114 { | 118 { |
115 SDL_CondSignal(src->opaque); | 119 SDL_CondSignal(src->opaque); |
1269 windowed_height = height; | 1273 windowed_height = height; |
1270 | 1274 |
1271 SDL_DisplayMode mode; | 1275 SDL_DisplayMode mode; |
1272 //TODO: Explicit multiple monitor support | 1276 //TODO: Explicit multiple monitor support |
1273 SDL_GetCurrentDisplayMode(0, &mode); | 1277 SDL_GetCurrentDisplayMode(0, &mode); |
1278 #ifdef __EMSCRIPTEN__ | |
1279 display_hz = 60; //TODO: FIXME | |
1280 #else | |
1274 display_hz = mode.refresh_rate; | 1281 display_hz = mode.refresh_rate; |
1282 #endif | |
1275 | 1283 |
1276 if (fullscreen) { | 1284 if (fullscreen) { |
1277 //the SDL2 migration guide suggests setting width and height to 0 when using SDL_WINDOW_FULLSCREEN_DESKTOP | 1285 //the SDL2 migration guide suggests setting width and height to 0 when using SDL_WINDOW_FULLSCREEN_DESKTOP |
1278 //but that doesn't seem to work right when using OpenGL, at least on Linux anyway | 1286 //but that doesn't seem to work right when using OpenGL, at least on Linux anyway |
1279 width = mode.w; | 1287 width = mode.w; |
1507 } | 1515 } |
1508 #endif | 1516 #endif |
1509 free(path); | 1517 free(path); |
1510 } | 1518 } |
1511 | 1519 |
1520 #ifndef __EMSCRIPTEN__ | |
1512 void GLAPIENTRY gl_message_callback(GLenum source, GLenum type, GLenum id, GLenum severity, GLsizei length, const GLchar *message, const void *user) | 1521 void GLAPIENTRY gl_message_callback(GLenum source, GLenum type, GLenum id, GLenum severity, GLsizei length, const GLchar *message, const void *user) |
1513 { | 1522 { |
1514 fprintf(stderr, "GL Message: %d, %d, %d - %s\n", source, type, severity, message); | 1523 fprintf(stderr, "GL Message: %d, %d, %d - %s\n", source, type, severity, message); |
1515 } | 1524 } |
1525 #endif | |
1516 | 1526 |
1517 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) | 1527 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) |
1518 { | 1528 { |
1519 uint8_t win_idx = 0xFF; | 1529 uint8_t win_idx = 0xFF; |
1520 for (int i = 0; i < num_extras; i++) | 1530 for (int i = 0; i < num_extras; i++) |
1551 extras[win_idx].height = height; | 1561 extras[win_idx].height = height; |
1552 #ifndef DISABLE_OPENGL | 1562 #ifndef DISABLE_OPENGL |
1553 if (render_gl) { | 1563 if (render_gl) { |
1554 extras[win_idx].gl_context = SDL_GL_CreateContext(extras[win_idx].win); | 1564 extras[win_idx].gl_context = SDL_GL_CreateContext(extras[win_idx].win); |
1555 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); | 1565 SDL_GL_MakeCurrent(extras[win_idx].win, extras[win_idx].gl_context); |
1566 #ifndef __EMSCRIPTEN__ | |
1556 glEnable(GL_DEBUG_OUTPUT); | 1567 glEnable(GL_DEBUG_OUTPUT); |
1557 if (glDebugMessageCallback) { | 1568 if (glDebugMessageCallback) { |
1558 glDebugMessageCallback(gl_message_callback, NULL); | 1569 glDebugMessageCallback(gl_message_callback, NULL); |
1559 } | 1570 } |
1571 #endif | |
1560 glGenTextures(2, extras[win_idx].gl_texture); | 1572 glGenTextures(2, extras[win_idx].gl_texture); |
1561 for (int i = 0; i < 2; i++) | 1573 for (int i = 0; i < 2; i++) |
1562 { | 1574 { |
1563 glBindTexture(GL_TEXTURE_2D, extras[win_idx].gl_texture[i]); | 1575 glBindTexture(GL_TEXTURE_2D, extras[win_idx].gl_texture[i]); |
1564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 1576 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
2254 void render_set_ui_render_fun(ui_render_fun fun) | 2266 void render_set_ui_render_fun(ui_render_fun fun) |
2255 { | 2267 { |
2256 render_ui = fun; | 2268 render_ui = fun; |
2257 } | 2269 } |
2258 | 2270 |
2271 static ui_render_fun frame_presented; | |
2272 void render_set_frame_presented_fun(ui_render_fun fun) | |
2273 { | |
2274 frame_presented = fun; | |
2275 } | |
2276 | |
2259 void render_update_display() | 2277 void render_update_display() |
2260 { | 2278 { |
2261 #ifndef DISABLE_OPENGL | 2279 #ifndef DISABLE_OPENGL |
2262 if (render_gl) { | 2280 if (render_gl) { |
2263 SDL_GL_MakeCurrent(main_window, main_context); | 2281 SDL_GL_MakeCurrent(main_window, main_context); |
2326 #endif | 2344 #endif |
2327 if (!events_processed) { | 2345 if (!events_processed) { |
2328 process_events(); | 2346 process_events(); |
2329 } | 2347 } |
2330 events_processed = 0; | 2348 events_processed = 0; |
2349 if (frame_presented) { | |
2350 frame_presented(); | |
2351 } | |
2331 } | 2352 } |
2332 | 2353 |
2333 uint32_t render_emulated_width() | 2354 uint32_t render_emulated_width() |
2334 { | 2355 { |
2335 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; | 2356 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; |