diff --git a/src/fbo.c b/src/fbo.c index 37f98596..e004ba6a 100644 --- a/src/fbo.c +++ b/src/fbo.c @@ -9,7 +9,8 @@ #include "global.h" static float sanitize_scale(float scale) { - return ftopow2(clamp(scale, 0.25, 4.0)); + // return ftopow2(clamp(scale, 0.25, 4.0)); + return max(0.1, scale); } void init_fbo(FBO *fbo, float scale) { @@ -49,6 +50,12 @@ void init_fbo(FBO *fbo, float scale) { } void reinit_fbo(FBO *fbo, float scale) { + if(!fbo->scale) { + // fbo was never initialized + init_fbo(fbo, scale); + return; + } + if(fbo->scale != sanitize_scale(scale)) { delete_fbo(fbo); init_fbo(fbo, scale); @@ -78,6 +85,5 @@ void draw_fbo_viewport(FBO *fbo) { glViewport(0, 0, fbo->scale*SCREEN_W, fbo->scale*SCREEN_H); set_ortho(); - draw_fbo(fbo); } diff --git a/src/menu/options.c b/src/menu/options.c index 48055afc..0b3f4415 100644 --- a/src/menu/options.c +++ b/src/menu/options.c @@ -367,11 +367,11 @@ void options_sub_video(MenuData *parent, void *arg) { add_menu_separator(m); add_menu_entry(m, "Stage viewport quality", do_nothing, - b = bind_quality(CONFIG_FG_QUALITY) + b = bind_scale(CONFIG_FG_QUALITY, 0.1, 1.0, 0.05) ); add_menu_entry(m, "Stage background quality", do_nothing, - b = bind_quality(CONFIG_BG_QUALITY) + b = bind_scale(CONFIG_BG_QUALITY, 0.1, 1.0, 0.05) ); b->dependence = bind_bgquality_dependence; add_menu_entry(m, "Text quality", do_nothing, diff --git a/src/resource/resource.c b/src/resource/resource.c index 9b9f44a9..be0fe195 100644 --- a/src/resource/resource.c +++ b/src/resource/resource.c @@ -386,16 +386,7 @@ const char* resource_util_filename(const char *path) { return path; } -static void fbo_quality_callback(ConfigIndex idx, ConfigValue v) { - FBO *fbos = idx == CONFIG_FG_QUALITY ? resources.fbo.fg : resources.fbo.bg; - reinit_fbo(fbos+0, v.f); - reinit_fbo(fbos+1, v.f); - config_set_float(idx, fbos->scale); -} - void load_resources(void) { - static bool callbacks_set_up = false; - init_fonts(config_get_float(CONFIG_TEXT_QUALITY)); if(glext.draw_instanced) { @@ -404,21 +395,7 @@ void load_resources(void) { menu_preload(); - float fgq = config_get_float(CONFIG_FG_QUALITY); - float bgq = config_get_float(CONFIG_BG_QUALITY); - - init_fbo(&resources.fbo.bg[0], bgq); - init_fbo(&resources.fbo.bg[1], bgq); - init_fbo(&resources.fbo.fg[0], fgq); - init_fbo(&resources.fbo.fg[1], fgq); - resources.stage_postprocess = postprocess_load("shader/postprocess.conf"); - - if(!callbacks_set_up) { - config_set_callback(CONFIG_FG_QUALITY, fbo_quality_callback); - config_set_callback(CONFIG_BG_QUALITY, fbo_quality_callback); - callbacks_set_up = true; - } } void free_resources(bool all) { diff --git a/src/stage.c b/src/stage.c index 145b09f3..7735b0fb 100644 --- a/src/stage.c +++ b/src/stage.c @@ -559,7 +559,7 @@ void stage_loop(StageInfo *stage) { while(global.game_over <= 0) { if(global.game_over != GAMEOVER_TRANSITIONING) { if((!global.boss || boss_is_fleeing(global.boss)) && !global.dialog) { - stage->procs->event(); + // stage->procs->event(); } if(stage->type == STAGE_SPELL && !global.boss && global.game_over != GAMEOVER_RESTART) { diff --git a/src/stages/stage1.c b/src/stages/stage1.c index 9d354496..2bfe87b9 100644 --- a/src/stages/stage1.c +++ b/src/stages/stage1.c @@ -108,11 +108,12 @@ void stage1_fog(int fbonum) { glUseProgram(shader->prog); glUniform1i(uniloc(shader, "tex"), 0); glUniform1i(uniloc(shader, "depth"), 1); - glUniform4f(uniloc(shader, "fog_color"),0.8, 0.8, 0.8, 1.0); - glUniform1f(uniloc(shader, "start"),0.0); - glUniform1f(uniloc(shader, "end"),.8); - glUniform1f(uniloc(shader, "exponent"),3.0); - glUniform1f(uniloc(shader, "sphereness"),.2); + glUniform4f(uniloc(shader, "fog_color"), 0.8, 0.8, 0.8, 1.0); + glUniform1f(uniloc(shader, "start"), 0.0); + glUniform1f(uniloc(shader, "end"), 0.8); + glUniform1f(uniloc(shader, "exponent"), 3.0); + glUniform1f(uniloc(shader, "sphereness"), 0.2); + glUniform1f(uniloc(shader, "sphereness_ofs"), 0.3); glActiveTexture(GL_TEXTURE0 + 1); glBindTexture(GL_TEXTURE_2D, resources.fbo.bg[fbonum].depth); glActiveTexture(GL_TEXTURE0); diff --git a/src/video.c b/src/video.c index ed094c7b..cf644ecb 100644 --- a/src/video.c +++ b/src/video.c @@ -54,10 +54,10 @@ void video_set_viewport(void) { float h = video.current.height; float r = w / h; - if(r > VIEWPORT_ASPECT_RATIO) { - w = h * VIEWPORT_ASPECT_RATIO; - } else if(r < VIEWPORT_ASPECT_RATIO) { - h = w / VIEWPORT_ASPECT_RATIO; + if(r > VIDEO_ASPECT_RATIO) { + w = h * VIDEO_ASPECT_RATIO; + } else if(r < VIDEO_ASPECT_RATIO) { + h = w / VIDEO_ASPECT_RATIO; } glClear(GL_COLOR_BUFFER_BIT); @@ -152,6 +152,27 @@ static void video_init_gl(void) { glClear(GL_COLOR_BUFFER_BIT); } +static void video_update_quality(void) { + float q; + float r = (float)video.current.width / video.current.height; + + if(r >= VIDEO_ASPECT_RATIO) { + q = (float)video.current.height / SCREEN_H; + } else { + q = (float)video.current.width / SCREEN_W; + } + + float fg = q * config_get_float(CONFIG_FG_QUALITY); + float bg = q * config_get_float(CONFIG_BG_QUALITY); + + log_debug("q:%f, fg:%f, bg:%f", q, fg, bg); + + reinit_fbo(&resources.fbo.bg[0], bg); + reinit_fbo(&resources.fbo.bg[1], bg); + reinit_fbo(&resources.fbo.fg[0], fg); + reinit_fbo(&resources.fbo.fg[1], fg); +} + static void _video_setmode(int w, int h, uint32_t flags, bool fallback) { if(!libgl_loaded) { load_gl_library(); @@ -194,6 +215,7 @@ static void _video_setmode(int w, int h, uint32_t flags, bool fallback) { video.real.width = video.current.width; video.real.height = video.current.height; video_set_viewport(); + video_update_quality(); return; } @@ -323,6 +345,7 @@ void video_resize(int w, int h) { video.current.width = w; video.current.height = h; video_set_viewport(); + video_update_quality(); } static void video_cfg_fullscreen_callback(ConfigIndex idx, ConfigValue v) { @@ -340,11 +363,17 @@ static void video_cfg_resizable_callback(ConfigIndex idx, ConfigValue v) { SDL_SetWindowResizable(video.window, config_set_int(idx, v.i)); } +static void video_quality_callback(ConfigIndex idx, ConfigValue v) { + config_set_float(idx, v.f); + video_update_quality(); +} + void video_init(void) { int i, s; bool fullscreen_available = false; memset(&video, 0, sizeof(video)); + memset(&resources.fbo, 0, sizeof(resources.fbo)); // First, register all resolutions that are available in fullscreen @@ -384,6 +413,8 @@ void video_init(void) { config_set_callback(CONFIG_FULLSCREEN, video_cfg_fullscreen_callback); config_set_callback(CONFIG_VSYNC, video_cfg_vsync_callback); config_set_callback(CONFIG_VID_RESIZABLE, video_cfg_resizable_callback); + config_set_callback(CONFIG_FG_QUALITY, video_quality_callback); + config_set_callback(CONFIG_BG_QUALITY, video_quality_callback); log_info("Video subsystem initialized"); } diff --git a/src/video.h b/src/video.h index 5e96fc9a..ec89535c 100644 --- a/src/video.h +++ b/src/video.h @@ -10,7 +10,7 @@ #define VIDEO_H #define WINDOW_TITLE "TaiseiProject" -#define VIEWPORT_ASPECT_RATIO (4.0f/3.0f) +#define VIDEO_ASPECT_RATIO ((double)SCREEN_W/SCREEN_H) #include #include