Skip to content

Commit 3fed31f

Browse files
authored
added --resX --resY --pause --screenshot_and_close
1 parent ce14540 commit 3fed31f

File tree

1 file changed

+123
-32
lines changed

1 file changed

+123
-32
lines changed

launcher/main.c

Lines changed: 123 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242
#include "../vk_utils/vk_render_helper.h"
4343
#include "../os_utils/utils.h"
4444

45+
static int resX = 1280;
46+
static int resY = 720;
47+
static bool run_paused = false;
48+
static bool screenshot_and_close = false;
49+
4550
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
46-
static int resize_size[2] = {1280, 720}; // in Wayland surface should set own size
51+
static int wayland_resize_size[2] = {1280, 720}; // in Wayland surface should set own size
52+
const int wayland_fullscreen_resize_size[2] = {1920, 1080}; // used in example resize event for walynad surface
4753
#endif
4854

4955
static bool main_image_srgb = false; // srgb surface fix
@@ -290,21 +296,23 @@ static void check_hotkeys(struct app_os_window *os_window)
290296
os_window->fps_lock = !os_window->fps_lock;
291297
if (keyboard_map[Key_z][1]) {
292298
if (key_screenshot_once) { screenshot_once = true; key_screenshot_once = false; }
293-
}
294-
else key_screenshot_once = true;
299+
} else key_screenshot_once = true;
300+
301+
if(run_paused){ run_paused = false; os_window->app_data.pause = true; }
302+
295303
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
296304
//example resize event for Wayland
297305
if (keyboard_map[Key_f][1]){
298306
os_window->resize_event = true;
299307
static bool switch_res=true;
300308
if(switch_res){
301309
switch_res=false;
302-
os_window->app_data.iResolution[0]=1920;
303-
os_window->app_data.iResolution[1]=1080;
310+
os_window->app_data.iResolution[0]=wayland_fullscreen_resize_size[0];
311+
os_window->app_data.iResolution[1]=wayland_fullscreen_resize_size[1];
304312
}else{
305313
switch_res=true;
306-
os_window->app_data.iResolution[0]=1280;
307-
os_window->app_data.iResolution[1]=720;
314+
os_window->app_data.iResolution[0]=resX;
315+
os_window->app_data.iResolution[1]=resY;
308316
}
309317
}
310318
#else
@@ -474,8 +482,8 @@ static vk_error allocate_render_data(struct vk_physical_device *phy_dev, struct
474482
}
475483
struct VkExtent2D init_size;
476484
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
477-
init_size.width = resize_size[0];
478-
init_size.height = resize_size[1];
485+
init_size.width = wayland_resize_size[0];
486+
init_size.height = wayland_resize_size[1];
479487
#else
480488
init_size.width = swapchain->surface_caps.currentExtent.width;
481489
init_size.height = swapchain->surface_caps.currentExtent.height;
@@ -929,8 +937,8 @@ static bool on_window_resize(struct vk_physical_device *phy_dev, struct vk_devic
929937
os_window->prepared = false;
930938

931939
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
932-
resize_size[0] = os_window->app_data.iResolution[0];
933-
resize_size[1] = os_window->app_data.iResolution[1];
940+
wayland_resize_size[0] = os_window->app_data.iResolution[0];
941+
wayland_resize_size[1] = os_window->app_data.iResolution[1];
934942
#endif
935943

936944
vk_free_pipelines(dev, &render_data->main_pipeline, 1);
@@ -1511,11 +1519,12 @@ static bool render_loop_draw(struct vk_physical_device *phy_dev, struct vk_devic
15111519
return false;
15121520

15131521
#ifdef USE_SCREENSHOT
1514-
if(screenshot_once){
1522+
if(screenshot_once||screenshot_and_close){
15151523
screenshot_once = false;
15161524
retval = make_screenshot(phy_dev, dev, swapchain, &essentials, image_index);
15171525
if (!vk_error_is_success(&retval))
15181526
return false;
1527+
if(screenshot_and_close){ screenshot_and_close = false; return false; }
15191528
}
15201529
#endif
15211530

@@ -1524,14 +1533,35 @@ static bool render_loop_draw(struct vk_physical_device *phy_dev, struct vk_devic
15241533
os_window->pause_refresh = false;
15251534
return true;
15261535
}
1536+
void set_init_res(struct app_os_window *os_window, bool resX_set, bool resY_set)
1537+
{
1538+
if(resX_set&&(!resY_set)){
1539+
resY = (int)((resX*9)/16);
1540+
}
1541+
if(resY_set&&(!resX_set)){
1542+
resX = (int)((resY*16)/9);
1543+
}
1544+
resX = resX<2?2:resX;
1545+
resX = resX>16000?16000:resX;
1546+
resY = resY<2?2:resY;
1547+
resY = resY>16000?16000:resY;
1548+
1549+
os_window->app_data.iResolution[0] = resX;
1550+
os_window->app_data.iResolution[1] = resY;
1551+
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1552+
wayland_resize_size[0] = os_window->app_data.iResolution[0];
1553+
wayland_resize_size[1] = os_window->app_data.iResolution[1];
1554+
#endif
1555+
1556+
}
15271557

15281558
void init_win_params(struct app_os_window *os_window)
15291559
{
15301560
os_window->app_data.iResolution[0] = 1280;
15311561
os_window->app_data.iResolution[1] = 720;
15321562
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1533-
resize_size[0] = os_window->app_data.iResolution[0];
1534-
resize_size[1] = os_window->app_data.iResolution[1];
1563+
wayland_resize_size[0] = os_window->app_data.iResolution[0];
1564+
wayland_resize_size[1] = os_window->app_data.iResolution[1];
15351565
#endif
15361566
os_window->app_data.iFrame = 0;
15371567
os_window->app_data.iMouse[0] = 0;
@@ -1710,6 +1740,10 @@ void print_usage(char *name)
17101740
"\t[--debug]\n"
17111741
"\t[--reload_shaders] will reload shaders form file on resize\n"
17121742
"\t[--gpu <index(0/1/2/etc)>] use selected GPU to render\n"
1743+
"\t[--resX 1280] resolution by X - can be provided just one X/Y - will be used 16:9\n"
1744+
"\t[--resY 720] resolution by Y - for resolution min 2 max 16000\n"
1745+
"\t[--pause] pause on start after rendering one frame - iFrame will be ==0\n"
1746+
"\t[--screenshot_and_close] make screenshot BMP on iFrame ==0 and close\n"
17131747
"Control: Keyboard 1-debug, 2-vsynk 60fps, Space-pause\n",
17141748
name, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_FIFO_KHR,
17151749
VK_PRESENT_MODE_FIFO_RELAXED_KHR);
@@ -1803,15 +1837,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
18031837
{
18041838
argv = NULL;
18051839
}
1806-
1807-
vk_error res = VK_ERROR_NONE;
1808-
int retval = EXIT_FAILURE;
1809-
1810-
init_win_params(&os_window);
1811-
uint32_t dev_index = 0;
1812-
bool use_gpu_idx = false;
1813-
os_window.present_mode = VK_PRESENT_MODE_FIFO_KHR;
1814-
1840+
18151841
if (argc > 1)
18161842
{
18171843
if (strcmp(argv[1], "--help") == 0)
@@ -1823,6 +1849,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
18231849
}
18241850
}
18251851

1852+
vk_error res = VK_ERROR_NONE;
1853+
int retval = EXIT_FAILURE;
1854+
1855+
init_win_params(&os_window);
1856+
uint32_t dev_index = 0;
1857+
bool use_gpu_idx = false;
1858+
bool resX_set = false;
1859+
bool resY_set = false;
1860+
os_window.present_mode = VK_PRESENT_MODE_FIFO_KHR;
1861+
18261862
for (int i = 1; i < argc; i++)
18271863
{
18281864
if ((strcmp(argv[i], "--present_mode") == 0) && (i < argc - 1))
@@ -1848,7 +1884,33 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
18481884
os_window.reload_shaders_on_resize = true;
18491885
continue;
18501886
}
1887+
if (strcmp(argv[i], "--pause") == 0)
1888+
{
1889+
run_paused = true;
1890+
continue;
1891+
}
1892+
if (strcmp(argv[i], "--screenshot_and_close") == 0)
1893+
{
1894+
screenshot_and_close = true;
1895+
continue;
1896+
}
1897+
if ((strcmp(argv[i], "--resX") == 0) && (i < argc - 1))
1898+
{
1899+
resX = atoi(argv[i + 1]);
1900+
resX_set = true;
1901+
i++;
1902+
continue;
1903+
}
1904+
if ((strcmp(argv[i], "--resY") == 0) && (i < argc - 1))
1905+
{
1906+
resY = atoi(argv[i + 1]);
1907+
resY_set = true;
1908+
i++;
1909+
continue;
1910+
}
18511911
}
1912+
1913+
set_init_res(&os_window, resX_set, resY_set);
18521914

18531915
if (argc > 0 && argv != NULL)
18541916
{
@@ -1932,6 +1994,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
19321994

19331995
int main(int argc, char **argv)
19341996
{
1997+
1998+
if (argc > 1)
1999+
{
2000+
if (strcmp(argv[1], "--help") == 0)
2001+
{
2002+
print_usage(argv[0]);
2003+
return 0;
2004+
}
2005+
}
2006+
19352007
vk_error res;
19362008
int retval = EXIT_FAILURE;
19372009
VkInstance vk;
@@ -1942,17 +2014,10 @@ int main(int argc, char **argv)
19422014
init_win_params(&os_window);
19432015
uint32_t dev_index = 0;
19442016
bool use_gpu_idx = false;
2017+
bool resX_set = false;
2018+
bool resY_set = false;
19452019
os_window.present_mode = VK_PRESENT_MODE_FIFO_KHR;
19462020

1947-
if (argc > 1)
1948-
{
1949-
if (strcmp(argv[1], "--help") == 0)
1950-
{
1951-
print_usage(argv[0]);
1952-
return 0;
1953-
}
1954-
}
1955-
19562021
for (int i = 1; i < argc; i++)
19572022
{
19582023
if ((strcmp(argv[i], "--present_mode") == 0) && (i < argc - 1))
@@ -1978,7 +2043,33 @@ int main(int argc, char **argv)
19782043
os_window.reload_shaders_on_resize = true;
19792044
continue;
19802045
}
2046+
if (strcmp(argv[i], "--pause") == 0)
2047+
{
2048+
run_paused = true;
2049+
continue;
2050+
}
2051+
if (strcmp(argv[i], "--screenshot_and_close") == 0)
2052+
{
2053+
screenshot_and_close = true;
2054+
continue;
2055+
}
2056+
if ((strcmp(argv[i], "--resX") == 0) && (i < argc - 1))
2057+
{
2058+
resX = atoi(argv[i + 1]);
2059+
resX_set = true;
2060+
i++;
2061+
continue;
2062+
}
2063+
if ((strcmp(argv[i], "--resY") == 0) && (i < argc - 1))
2064+
{
2065+
resY = atoi(argv[i + 1]);
2066+
resY_set = true;
2067+
i++;
2068+
continue;
2069+
}
19812070
}
2071+
2072+
set_init_res(&os_window, resX_set, resY_set);
19822073

19832074
srand(time(NULL));
19842075

0 commit comments

Comments
 (0)