Allow enabling specific gfx backends via program args
This commit is contained in:
parent
cce494899a
commit
a8fd35cd91
3 changed files with 48 additions and 84 deletions
2
Makefile
2
Makefile
|
@ -491,7 +491,7 @@ PLATFORM_CFLAGS += -DNO_SEGMENTED_MEMORY -DUSE_SYSTEM_MALLOC
|
||||||
# Compiler and linker flags for graphics backend
|
# Compiler and linker flags for graphics backend
|
||||||
ifeq ($(ENABLE_OPENGL),1)
|
ifeq ($(ENABLE_OPENGL),1)
|
||||||
# TODO: right now the opengl and vulkan backends are linked, will seperate later...
|
# TODO: right now the opengl and vulkan backends are linked, will seperate later...
|
||||||
GFX_CFLAGS := -DENABLE_OPENGL -DENABLE_VULKAN
|
GFX_CFLAGS := -DENABLE_OPENGL -DENABLE_VULKAN -DENABLE_GFX_DUMMY
|
||||||
GFX_LDFLAGS :=
|
GFX_LDFLAGS :=
|
||||||
ifeq ($(TARGET_WINDOWS),1)
|
ifeq ($(TARGET_WINDOWS),1)
|
||||||
GFX_CFLAGS += $(shell sdl2-config --cflags) -DGLEW_STATIC
|
GFX_CFLAGS += $(shell sdl2-config --cflags) -DGLEW_STATIC
|
||||||
|
|
|
@ -151,6 +151,10 @@ static void gfx_dummy_renderer_end_frame(void) {
|
||||||
static void gfx_dummy_renderer_finish_render(void) {
|
static void gfx_dummy_renderer_finish_render(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* gfx_dummy_get_name(void) {
|
||||||
|
return "Dummy";
|
||||||
|
}
|
||||||
|
|
||||||
struct GfxWindowManagerAPI gfx_dummy_wm_api = {
|
struct GfxWindowManagerAPI gfx_dummy_wm_api = {
|
||||||
gfx_dummy_wm_init,
|
gfx_dummy_wm_init,
|
||||||
gfx_dummy_wm_set_keyboard_callbacks,
|
gfx_dummy_wm_set_keyboard_callbacks,
|
||||||
|
@ -187,6 +191,7 @@ struct GfxRenderingAPI gfx_dummy_renderer_api = {
|
||||||
gfx_dummy_renderer_on_resize,
|
gfx_dummy_renderer_on_resize,
|
||||||
gfx_dummy_renderer_start_frame,
|
gfx_dummy_renderer_start_frame,
|
||||||
gfx_dummy_renderer_end_frame,
|
gfx_dummy_renderer_end_frame,
|
||||||
gfx_dummy_renderer_finish_render
|
gfx_dummy_renderer_finish_render,
|
||||||
|
gfx_dummy_get_name
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
117
src/pc/pc_main.c
117
src/pc/pc_main.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef TARGET_WEB
|
#ifdef TARGET_WEB
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
|
@ -100,39 +101,6 @@ void produce_one_frame(void) {
|
||||||
gfx_end_frame();
|
gfx_end_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TARGET_WEB
|
|
||||||
static void em_main_loop(void) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static void request_anim_frame(void (*func)(double time)) {
|
|
||||||
EM_ASM(requestAnimationFrame(function(time) {
|
|
||||||
dynCall("vd", $0, [time]);
|
|
||||||
}), func);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_anim_frame(double time) {
|
|
||||||
static double target_time;
|
|
||||||
|
|
||||||
time *= 0.03; // milliseconds to frame count (33.333 ms -> 1)
|
|
||||||
|
|
||||||
if (time >= target_time + 10.0) {
|
|
||||||
// We are lagging 10 frames behind, probably due to coming back after inactivity,
|
|
||||||
// so reset, with a small margin to avoid potential jitter later.
|
|
||||||
target_time = time - 0.010;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
// If refresh rate is 15 Hz or something we might need to generate two frames
|
|
||||||
if (time >= target_time) {
|
|
||||||
produce_one_frame();
|
|
||||||
target_time = target_time + 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
request_anim_frame(on_anim_frame);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void save_config(void) {
|
static void save_config(void) {
|
||||||
configfile_save(CONFIG_FILE);
|
configfile_save(CONFIG_FILE);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +109,7 @@ static void on_fullscreen_changed(bool is_now_fullscreen) {
|
||||||
configFullscreen = is_now_fullscreen;
|
configFullscreen = is_now_fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_func(void) {
|
int main(int argc, char *argv[]) {
|
||||||
#ifdef USE_SYSTEM_MALLOC
|
#ifdef USE_SYSTEM_MALLOC
|
||||||
main_pool_init();
|
main_pool_init();
|
||||||
gGfxAllocOnlyPool = alloc_only_pool_init();
|
gGfxAllocOnlyPool = alloc_only_pool_init();
|
||||||
|
@ -154,35 +122,48 @@ void main_func(void) {
|
||||||
configfile_load(CONFIG_FILE);
|
configfile_load(CONFIG_FILE);
|
||||||
atexit(save_config);
|
atexit(save_config);
|
||||||
|
|
||||||
#ifdef TARGET_WEB
|
int ogl_vulkan_dummy = 0;
|
||||||
emscripten_set_main_loop(em_main_loop, 0, 0);
|
|
||||||
request_anim_frame(on_anim_frame);
|
for(int i = 1; i < argc; i++) {
|
||||||
#endif
|
if(strcmp(argv[i], "-opengl") == 0) {
|
||||||
|
ogl_vulkan_dummy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(argv[i], "-vulkan") == 0) {
|
||||||
|
ogl_vulkan_dummy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(argv[i], "-dummy") == 0) {
|
||||||
|
ogl_vulkan_dummy = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_DX12)
|
|
||||||
rendering_api = &gfx_direct3d12_api;
|
|
||||||
wm_api = &gfx_dxgi_api;
|
|
||||||
#elif defined(ENABLE_DX11)
|
|
||||||
rendering_api = &gfx_direct3d11_api;
|
|
||||||
wm_api = &gfx_dxgi_api;
|
|
||||||
#elif defined(ENABLE_OPENGL)
|
|
||||||
rendering_api = &gfx_vulkan_api;
|
|
||||||
wm_api = &gfx_sdl;
|
wm_api = &gfx_sdl;
|
||||||
#elif defined(ENABLE_GFX_DUMMY)
|
|
||||||
rendering_api = &gfx_dummy_renderer_api;
|
|
||||||
wm_api = &gfx_dummy_wm_api;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gfx_init(wm_api, rendering_api, "Super Mario 64 PC-Port", configFullscreen);
|
switch(ogl_vulkan_dummy) {
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
rendering_api = &gfx_opengl_api;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
rendering_api = &gfx_vulkan_api;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
rendering_api = &gfx_dummy_renderer_api;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gfx_init(wm_api, rendering_api, "Super Mario 64", configFullscreen);
|
||||||
|
|
||||||
wm_api->set_fullscreen_changed_callback(on_fullscreen_changed);
|
wm_api->set_fullscreen_changed_callback(on_fullscreen_changed);
|
||||||
wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up);
|
wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up);
|
||||||
|
|
||||||
#if HAVE_WASAPI
|
|
||||||
if (audio_api == NULL && audio_wasapi.init()) {
|
|
||||||
audio_api = &audio_wasapi;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if HAVE_PULSE_AUDIO
|
#if HAVE_PULSE_AUDIO
|
||||||
if (audio_api == NULL && audio_pulse.init()) {
|
if (audio_api == NULL && audio_pulse.init()) {
|
||||||
audio_api = &audio_pulse;
|
audio_api = &audio_pulse;
|
||||||
|
@ -193,11 +174,7 @@ void main_func(void) {
|
||||||
audio_api = &audio_alsa;
|
audio_api = &audio_alsa;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef TARGET_WEB
|
|
||||||
if (audio_api == NULL && audio_sdl.init()) {
|
|
||||||
audio_api = &audio_sdl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (audio_api == NULL) {
|
if (audio_api == NULL) {
|
||||||
audio_api = &audio_null;
|
audio_api = &audio_null;
|
||||||
}
|
}
|
||||||
|
@ -206,28 +183,10 @@ void main_func(void) {
|
||||||
sound_init();
|
sound_init();
|
||||||
|
|
||||||
thread5_game_loop(NULL);
|
thread5_game_loop(NULL);
|
||||||
#ifdef TARGET_WEB
|
|
||||||
/*for (int i = 0; i < atoi(argv[1]); i++) {
|
|
||||||
game_loop_one_iteration();
|
|
||||||
}*/
|
|
||||||
inited = 1;
|
|
||||||
#else
|
|
||||||
inited = 1;
|
inited = 1;
|
||||||
while (1) {
|
while (1) {
|
||||||
wm_api->main_loop(produce_one_frame);
|
wm_api->main_loop(produce_one_frame);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
#include <windows.h>
|
|
||||||
int WINAPI WinMain(UNUSED HINSTANCE hInstance, UNUSED HINSTANCE hPrevInstance, UNUSED LPSTR pCmdLine, UNUSED int nCmdShow) {
|
|
||||||
main_func();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
int main(UNUSED int argc, UNUSED char *argv[]) {
|
|
||||||
main_func();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue