Skip to content

Commit fde2739

Browse files
committed
allow overlays to appear behind game image; gl1, gl2, gl3
1 parent 345edcb commit fde2739

9 files changed

Lines changed: 164 additions & 24 deletions

File tree

gfx/common/gl2_common.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ enum gl2_flags
5858
GL2_FLAG_PBO_READBACK_ENABLE = (1 << 16),
5959
GL2_FLAG_OVERLAY_ENABLE = (1 << 17),
6060
GL2_FLAG_OVERLAY_FULLSCREEN = (1 << 18),
61-
GL2_FLAG_MENU_TEXTURE_ENABLE = (1 << 19),
62-
GL2_FLAG_MENU_TEXTURE_FULLSCREEN= (1 << 20),
63-
GL2_FLAG_NONE = (1 << 21),
64-
GL2_FLAG_FRAME_DUPE_LOCK = (1 << 22)
61+
GL2_FLAG_OVERLAY_BACKGROUND_FILL= (1 << 19),
62+
GL2_FLAG_MENU_TEXTURE_ENABLE = (1 << 20),
63+
GL2_FLAG_MENU_TEXTURE_FULLSCREEN= (1 << 21),
64+
GL2_FLAG_NONE = (1 << 22),
65+
GL2_FLAG_FRAME_DUPE_LOCK = (1 << 23)
6566
};
6667

6768
struct gl2

gfx/common/gl3_defines.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ enum gl3_flags
4444
GL3_FLAG_USE_SHARED_CONTEXT = (1 << 3),
4545
GL3_FLAG_OVERLAY_ENABLE = (1 << 4),
4646
GL3_FLAG_OVERLAY_FULLSCREEN = (1 << 5),
47-
GL3_FLAG_MENU_TEXTURE_ENABLE = (1 << 6),
48-
GL3_FLAG_MENU_TEXTURE_FULLSCREEN= (1 << 7),
49-
GL3_FLAG_VSYNC = (1 << 8),
50-
GL3_FLAG_FULLSCREEN = (1 << 9),
51-
GL3_FLAG_QUITTING = (1 << 10),
52-
GL3_FLAG_SHOULD_RESIZE = (1 << 11),
53-
GL3_FLAG_KEEP_ASPECT = (1 << 12),
54-
GL3_FLAG_FRAME_DUPE_LOCK = (1 << 13)
47+
GL3_FLAG_OVERLAY_BACKGROUND_FILL= (1 << 6),
48+
GL3_FLAG_MENU_TEXTURE_ENABLE = (1 << 7),
49+
GL3_FLAG_MENU_TEXTURE_FULLSCREEN= (1 << 8),
50+
GL3_FLAG_VSYNC = (1 << 9),
51+
GL3_FLAG_FULLSCREEN = (1 << 10),
52+
GL3_FLAG_QUITTING = (1 << 11),
53+
GL3_FLAG_SHOULD_RESIZE = (1 << 12),
54+
GL3_FLAG_KEEP_ASPECT = (1 << 13),
55+
GL3_FLAG_FRAME_DUPE_LOCK = (1 << 14)
5556
};
5657

5758
RETRO_END_DECLS

gfx/drivers/gl1.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ enum gl1_flags
108108
GL1_FLAG_MENU_SMOOTH = (1 << 9),
109109
GL1_FLAG_OVERLAY_ENABLE = (1 << 10),
110110
GL1_FLAG_OVERLAY_FULLSCREEN = (1 << 11),
111-
GL1_FLAG_FRAME_DUPE_LOCK = (1 << 12),
111+
GL1_FLAG_OVERLAY_BACKGROUND_FILL = (1 << 12),
112+
GL1_FLAG_FRAME_DUPE_LOCK = (1 << 13),
112113
/* GL_UNSIGNED_SHORT_4_4_4_4 is core in GL 1.2; on strict 1.1
113114
* implementations it is provided by GL_EXT_packed_pixels. When
114115
* neither is available, the menu path falls back to expanding
115116
* RGUI's RGBA4444 framebuffer to BGRA8888 on the CPU. */
116-
GL1_FLAG_SUPPORTS_PACKED_PIXELS = (1 << 13)
117+
GL1_FLAG_SUPPORTS_PACKED_PIXELS = (1 << 14)
117118
};
118119

119120
typedef struct gl1
@@ -1753,6 +1754,22 @@ static bool gl1_frame(void *data, const void *frame,
17531754
glEnable(GL_BLEND);
17541755
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
17551756

1757+
#ifdef HAVE_OVERLAY
1758+
/* Render background overlay (behind game viewport) */
1759+
if ((gl1->flags & GL1_FLAG_OVERLAY_ENABLE) && (gl1->flags & GL1_FLAG_OVERLAY_BACKGROUND_FILL))
1760+
{
1761+
/* Save current fullscreen state and force full screen for background overlay */
1762+
bool saved_fullscreen = (gl1->flags & GL1_FLAG_OVERLAY_FULLSCREEN) != 0;
1763+
gl1->flags |= GL1_FLAG_OVERLAY_FULLSCREEN;
1764+
1765+
gl1_render_overlay(gl1, video_width, video_height);
1766+
1767+
/* Restore fullscreen state */
1768+
if (!saved_fullscreen)
1769+
gl1->flags &= ~GL1_FLAG_OVERLAY_FULLSCREEN;
1770+
}
1771+
#endif
1772+
17561773
if (frame_to_copy)
17571774
gl1_draw_tex(gl1, pot_width, pot_height,
17581775
width, height, gl1->tex, frame_to_copy, false);
@@ -1846,7 +1863,8 @@ static bool gl1_frame(void *data, const void *frame,
18461863
}
18471864

18481865
#ifdef HAVE_OVERLAY
1849-
if ((gl1->flags & GL1_FLAG_OVERLAY_ENABLE) && overlay_behind_menu)
1866+
if ((gl1->flags & GL1_FLAG_OVERLAY_ENABLE) && overlay_behind_menu
1867+
&& !(gl1->flags & GL1_FLAG_OVERLAY_BACKGROUND_FILL))
18501868
gl1_render_overlay(gl1, video_width, video_height);
18511869
#endif
18521870

@@ -1880,7 +1898,8 @@ static bool gl1_frame(void *data, const void *frame,
18801898
#endif
18811899

18821900
#ifdef HAVE_OVERLAY
1883-
if ((gl1->flags & GL1_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu)
1901+
if ((gl1->flags & GL1_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu
1902+
&& !(gl1->flags & GL1_FLAG_OVERLAY_BACKGROUND_FILL))
18841903
gl1_render_overlay(gl1, video_width, video_height);
18851904
#endif
18861905

@@ -2579,6 +2598,19 @@ static void gl1_overlay_full_screen(void *data, bool enable)
25792598
}
25802599
}
25812600

2601+
static void gl1_overlay_background_fill(void *data, bool enable)
2602+
{
2603+
gl1_t *gl = (gl1_t*)data;
2604+
2605+
if (gl)
2606+
{
2607+
if (enable)
2608+
gl->flags |= GL1_FLAG_OVERLAY_BACKGROUND_FILL;
2609+
else
2610+
gl->flags &= ~GL1_FLAG_OVERLAY_BACKGROUND_FILL;
2611+
}
2612+
}
2613+
25822614
static void gl1_overlay_set_alpha(void *data, unsigned image, float mod)
25832615
{
25842616
GLfloat *color = NULL;
@@ -2601,6 +2633,7 @@ static const video_overlay_interface_t gl1_overlay_interface = {
26012633
gl1_overlay_vertex_geom,
26022634
gl1_overlay_full_screen,
26032635
gl1_overlay_set_alpha,
2636+
gl1_overlay_background_fill,
26042637
};
26052638

26062639
static void gl1_get_overlay_interface(void *data,

gfx/drivers/gl2.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,25 @@ static bool gl2_frame(void *data, const void *frame,
37523752

37533753
glClear(GL_COLOR_BUFFER_BIT);
37543754

3755+
#ifdef HAVE_OVERLAY
3756+
/* Render background overlay (behind game viewport) */
3757+
if ((gl->flags & GL2_FLAG_OVERLAY_ENABLE) && (gl->flags & GL2_FLAG_OVERLAY_BACKGROUND_FILL))
3758+
{
3759+
/* Save current fullscreen state and force full screen for background overlay */
3760+
uint64_t saved_flags = gl->flags & GL2_FLAG_OVERLAY_FULLSCREEN;
3761+
gl->flags |= GL2_FLAG_OVERLAY_FULLSCREEN;
3762+
3763+
gl2_render_overlay(gl);
3764+
3765+
/* Restore fullscreen state and viewport */
3766+
if (!saved_flags)
3767+
gl->flags &= ~GL2_FLAG_OVERLAY_FULLSCREEN;
3768+
3769+
/* Restore viewport for game rendering */
3770+
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
3771+
}
3772+
#endif
3773+
37553774
params.vp_width = gl->out_vp_width;
37563775
params.vp_height = gl->out_vp_height;
37573776
params.width = frame_width;
@@ -3795,7 +3814,8 @@ static bool gl2_frame(void *data, const void *frame,
37953814
chain, &gl->tex_info);
37963815

37973816
#ifdef HAVE_OVERLAY
3798-
if ((gl->flags & GL2_FLAG_OVERLAY_ENABLE) && overlay_behind_menu)
3817+
if ((gl->flags & GL2_FLAG_OVERLAY_ENABLE) && overlay_behind_menu
3818+
&& !(gl->flags & GL2_FLAG_OVERLAY_BACKGROUND_FILL))
37993819
gl2_render_overlay(gl);
38003820
#endif
38013821

@@ -3816,7 +3836,8 @@ static bool gl2_frame(void *data, const void *frame,
38163836
#endif
38173837

38183838
#ifdef HAVE_OVERLAY
3819-
if ((gl->flags & GL2_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu)
3839+
if ((gl->flags & GL2_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu
3840+
&& !(gl->flags & GL2_FLAG_OVERLAY_BACKGROUND_FILL))
38203841
gl2_render_overlay(gl);
38213842
#endif
38223843

@@ -5231,6 +5252,18 @@ static void gl2_overlay_full_screen(void *data, bool enable)
52315252
gl->flags &= ~GL2_FLAG_OVERLAY_FULLSCREEN;
52325253
}
52335254

5255+
static void gl2_overlay_background_fill(void *data, bool enable)
5256+
{
5257+
gl2_t *gl = (gl2_t*)data;
5258+
if (!gl)
5259+
return;
5260+
5261+
if (enable)
5262+
gl->flags |= GL2_FLAG_OVERLAY_BACKGROUND_FILL;
5263+
else
5264+
gl->flags &= ~GL2_FLAG_OVERLAY_BACKGROUND_FILL;
5265+
}
5266+
52345267
static void gl2_overlay_set_alpha(void *data, unsigned image, float mod)
52355268
{
52365269
GLfloat *color;
@@ -5253,6 +5286,7 @@ static const video_overlay_interface_t gl2_overlay_interface = {
52535286
gl2_overlay_vertex_geom,
52545287
gl2_overlay_full_screen,
52555288
gl2_overlay_set_alpha,
5289+
gl2_overlay_background_fill,
52565290
};
52575291

52585292
static void gl2_get_overlay_interface(void *data,

gfx/drivers/gl3.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,18 @@ static void gl3_overlay_full_screen(void *data, bool enable)
32453245
}
32463246
}
32473247

3248+
static void gl3_overlay_background_fill(void *data, bool enable)
3249+
{
3250+
gl3_t *gl = (gl3_t*)data;
3251+
if (gl)
3252+
{
3253+
if (enable)
3254+
gl->flags |= GL3_FLAG_OVERLAY_BACKGROUND_FILL;
3255+
else
3256+
gl->flags &= ~GL3_FLAG_OVERLAY_BACKGROUND_FILL;
3257+
}
3258+
}
3259+
32483260
static void gl3_overlay_set_alpha(void *data, unsigned image, float mod)
32493261
{
32503262
GLfloat *color = NULL;
@@ -3267,6 +3279,7 @@ static const video_overlay_interface_t gl3_overlay_interface = {
32673279
gl3_overlay_vertex_geom,
32683280
gl3_overlay_full_screen,
32693281
gl3_overlay_set_alpha,
3282+
gl3_overlay_background_fill,
32703283
};
32713284

32723285
static void gl3_get_overlay_interface(void *data,
@@ -4247,6 +4260,22 @@ static bool gl3_frame(void *data, const void *frame,
42474260
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
42484261
glClear(GL_COLOR_BUFFER_BIT);
42494262

4263+
#ifdef HAVE_OVERLAY
4264+
/* Render background overlay (behind game viewport) */
4265+
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && (gl->flags & GL3_FLAG_OVERLAY_BACKGROUND_FILL))
4266+
{
4267+
/* Save current fullscreen state and force full screen for background overlay */
4268+
uint64_t saved_flags = gl->flags & GL3_FLAG_OVERLAY_FULLSCREEN;
4269+
gl->flags |= GL3_FLAG_OVERLAY_FULLSCREEN;
4270+
4271+
gl3_render_overlay(gl, width, height);
4272+
4273+
/* Restore fullscreen state */
4274+
if (!saved_flags)
4275+
gl->flags &= ~GL3_FLAG_OVERLAY_FULLSCREEN;
4276+
}
4277+
#endif
4278+
42504279
gl->chain.shader->set_params(&params, gl->chain.shader_data);
42514280

42524281
gl->chain.coords.vertices = 4;
@@ -4358,6 +4387,23 @@ static bool gl3_frame(void *data, const void *frame,
43584387
glBindFramebuffer(GL_FRAMEBUFFER, 0);
43594388
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
43604389
glClear(GL_COLOR_BUFFER_BIT);
4390+
4391+
#ifdef HAVE_OVERLAY
4392+
/* Render background overlay (behind game viewport) */
4393+
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && (gl->flags & GL3_FLAG_OVERLAY_BACKGROUND_FILL))
4394+
{
4395+
/* Save current fullscreen state and force full screen for background overlay */
4396+
uint64_t saved_flags = gl->flags & GL3_FLAG_OVERLAY_FULLSCREEN;
4397+
gl->flags |= GL3_FLAG_OVERLAY_FULLSCREEN;
4398+
4399+
gl3_render_overlay(gl, width, height);
4400+
4401+
/* Restore fullscreen state */
4402+
if (!saved_flags)
4403+
gl->flags &= ~GL3_FLAG_OVERLAY_FULLSCREEN;
4404+
}
4405+
#endif
4406+
43614407
gl3_filter_chain_build_viewport_pass(filter_chain,
43624408
&gl->filter_chain_vp,
43634409
(gl->flags & GL3_FLAG_HW_RENDER_BOTTOM_LEFT)
@@ -4368,7 +4414,8 @@ static bool gl3_frame(void *data, const void *frame,
43684414
#endif /* HAVE_SLANG */
43694415

43704416
#ifdef HAVE_OVERLAY
4371-
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && overlay_behind_menu)
4417+
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && overlay_behind_menu
4418+
&& !(gl->flags & GL3_FLAG_OVERLAY_BACKGROUND_FILL))
43724419
gl3_render_overlay(gl, width, height);
43734420
#endif
43744421

@@ -4388,7 +4435,8 @@ static bool gl3_frame(void *data, const void *frame,
43884435
#endif
43894436

43904437
#ifdef HAVE_OVERLAY
4391-
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu)
4438+
if ((gl->flags & GL3_FLAG_OVERLAY_ENABLE) && !overlay_behind_menu
4439+
&& !(gl->flags & GL3_FLAG_OVERLAY_BACKGROUND_FILL))
43924440
gl3_render_overlay(gl, width, height);
43934441
#endif
43944442

gfx/drivers_shader/slang_cache.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@
2626
static bool spirv_cache_get_dir(char *cache_dir_out, size_t cache_dir_out_len)
2727
{
2828
settings_t *settings = config_get_ptr();
29+
int ret;
2930

3031
if (!settings || !settings->paths.directory_cache[0])
3132
return false;
3233

3334
/* Build the spirv subdirectory path */
34-
snprintf(cache_dir_out, cache_dir_out_len, "%s/%s",
35+
ret = snprintf(cache_dir_out, cache_dir_out_len, "%s/%s",
3536
settings->paths.directory_cache, SPIRV_CACHE_SUBDIR);
3637

38+
/* Check if snprintf truncated the output */
39+
if (ret < 0 || (size_t)ret >= cache_dir_out_len)
40+
return false;
41+
3742
return true;
3843
}
3944

@@ -64,13 +69,18 @@ static bool spirv_cache_get_filename(const char *hash,
6469
char *cache_file_out, size_t cache_file_out_len)
6570
{
6671
char cache_dir[PATH_MAX_LENGTH];
72+
int ret;
6773

6874
if (!spirv_cache_get_dir(cache_dir, sizeof(cache_dir)))
6975
return false;
7076

71-
snprintf(cache_file_out, cache_file_out_len, "%s/%s.spirv",
77+
ret = snprintf(cache_file_out, cache_file_out_len, "%s/%s.spirv",
7278
cache_dir, hash);
7379

80+
/* Check if snprintf truncated the output */
81+
if (ret < 0 || (size_t)ret >= cache_file_out_len)
82+
return false;
83+
7484
return true;
7585
}
7686

input/input_driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,10 @@ void input_overlay_load_active(
33963396
if (ol->iface->full_screen)
33973397
ol->iface->full_screen(ol->iface_data,
33983398
(ol->active->flags & OVERLAY_FULL_SCREEN));
3399+
3400+
if (ol->iface->background_fill)
3401+
ol->iface->background_fill(ol->iface_data,
3402+
(ol->active->flags & OVERLAY_BACKGROUND_FILL));
33993403
}
34003404

34013405
/**

input/input_overlay.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ enum OVERLAY_FLAGS
132132
OVERLAY_AUTO_X_SEPARATION = (1 << 4),
133133
OVERLAY_AUTO_Y_SEPARATION = (1 << 5),
134134
OVERLAY_HAS_VIEWPORT = (1 << 6),
135-
OVERLAY_VIEWPORT_FILL = (1 << 7)
135+
OVERLAY_VIEWPORT_FILL = (1 << 7),
136+
OVERLAY_BACKGROUND_FILL = (1 << 8)
136137
};
137138

138139
enum OVERLAY_DESC_FLAGS
@@ -193,6 +194,7 @@ typedef struct video_overlay_interface
193194
float x, float y, float w, float h);
194195
void (*full_screen)(void *data, bool enable);
195196
void (*set_alpha)(void *data, unsigned image, float mod);
197+
void (*background_fill)(void *data, bool enable);
196198
} video_overlay_interface_t;
197199

198200
typedef struct overlay_eightway_config
@@ -325,7 +327,7 @@ struct overlay
325327

326328
char name[64];
327329

328-
uint8_t flags;
330+
uint16_t flags;
329331
};
330332

331333
typedef struct input_overlay_state

tasks/task_overlay.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,13 @@ static void task_overlay_deferred_load(retro_task_t *task)
852852
else
853853
overlay->flags &= ~OVERLAY_FULL_SCREEN;
854854

855+
strlcpy(conf_key + _len, "_background_fill", sizeof(conf_key) - _len);
856+
if (config_get_bool(conf, conf_key, &tmp_bool)
857+
&& tmp_bool)
858+
overlay->flags |= OVERLAY_BACKGROUND_FILL;
859+
else
860+
overlay->flags &= ~OVERLAY_BACKGROUND_FILL;
861+
855862
/* Precache load image array for simplicity. */
856863
texture_img = (struct texture_image*)
857864
calloc(1 + overlay->size, sizeof(struct texture_image));

0 commit comments

Comments
 (0)