42
42
#include "../vk_utils/vk_render_helper.h"
43
43
#include "../os_utils/utils.h"
44
44
45
+ static int resX = 1280 ;
46
+ static int resY = 720 ;
47
+ static bool run_paused = false;
48
+ static bool screenshot_and_close = false;
49
+
45
50
#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
47
53
#endif
48
54
49
55
static bool main_image_srgb = false; // srgb surface fix
@@ -290,21 +296,23 @@ static void check_hotkeys(struct app_os_window *os_window)
290
296
os_window -> fps_lock = !os_window -> fps_lock ;
291
297
if (keyboard_map [Key_z ][1 ]) {
292
298
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
+
295
303
#if defined(VK_USE_PLATFORM_WAYLAND_KHR )
296
304
//example resize event for Wayland
297
305
if (keyboard_map [Key_f ][1 ]){
298
306
os_window -> resize_event = true;
299
307
static bool switch_res = true;
300
308
if (switch_res ){
301
309
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 ] ;
304
312
}else {
305
313
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 ;
308
316
}
309
317
}
310
318
#else
@@ -474,8 +482,8 @@ static vk_error allocate_render_data(struct vk_physical_device *phy_dev, struct
474
482
}
475
483
struct VkExtent2D init_size ;
476
484
#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 ];
479
487
#else
480
488
init_size .width = swapchain -> surface_caps .currentExtent .width ;
481
489
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
929
937
os_window -> prepared = false;
930
938
931
939
#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 ];
934
942
#endif
935
943
936
944
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
1511
1519
return false;
1512
1520
1513
1521
#ifdef USE_SCREENSHOT
1514
- if (screenshot_once ){
1522
+ if (screenshot_once || screenshot_and_close ){
1515
1523
screenshot_once = false;
1516
1524
retval = make_screenshot (phy_dev , dev , swapchain , & essentials , image_index );
1517
1525
if (!vk_error_is_success (& retval ))
1518
1526
return false;
1527
+ if (screenshot_and_close ){ screenshot_and_close = false; return false; }
1519
1528
}
1520
1529
#endif
1521
1530
@@ -1524,14 +1533,35 @@ static bool render_loop_draw(struct vk_physical_device *phy_dev, struct vk_devic
1524
1533
os_window -> pause_refresh = false;
1525
1534
return true;
1526
1535
}
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
+ }
1527
1557
1528
1558
void init_win_params (struct app_os_window * os_window )
1529
1559
{
1530
1560
os_window -> app_data .iResolution [0 ] = 1280 ;
1531
1561
os_window -> app_data .iResolution [1 ] = 720 ;
1532
1562
#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 ];
1535
1565
#endif
1536
1566
os_window -> app_data .iFrame = 0 ;
1537
1567
os_window -> app_data .iMouse [0 ] = 0 ;
@@ -1710,6 +1740,10 @@ void print_usage(char *name)
1710
1740
"\t[--debug]\n"
1711
1741
"\t[--reload_shaders] will reload shaders form file on resize\n"
1712
1742
"\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"
1713
1747
"Control: Keyboard 1-debug, 2-vsynk 60fps, Space-pause\n" ,
1714
1748
name , VK_PRESENT_MODE_IMMEDIATE_KHR , VK_PRESENT_MODE_MAILBOX_KHR , VK_PRESENT_MODE_FIFO_KHR ,
1715
1749
VK_PRESENT_MODE_FIFO_RELAXED_KHR );
@@ -1803,15 +1837,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
1803
1837
{
1804
1838
argv = NULL ;
1805
1839
}
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
+
1815
1841
if (argc > 1 )
1816
1842
{
1817
1843
if (strcmp (argv [1 ], "--help" ) == 0 )
@@ -1823,6 +1849,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
1823
1849
}
1824
1850
}
1825
1851
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
+
1826
1862
for (int i = 1 ; i < argc ; i ++ )
1827
1863
{
1828
1864
if ((strcmp (argv [i ], "--present_mode" ) == 0 ) && (i < argc - 1 ))
@@ -1848,7 +1884,33 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
1848
1884
os_window .reload_shaders_on_resize = true;
1849
1885
continue ;
1850
1886
}
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
+ }
1851
1911
}
1912
+
1913
+ set_init_res (& os_window , resX_set , resY_set );
1852
1914
1853
1915
if (argc > 0 && argv != NULL )
1854
1916
{
@@ -1932,6 +1994,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
1932
1994
1933
1995
int main (int argc , char * * argv )
1934
1996
{
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
+
1935
2007
vk_error res ;
1936
2008
int retval = EXIT_FAILURE ;
1937
2009
VkInstance vk ;
@@ -1942,17 +2014,10 @@ int main(int argc, char **argv)
1942
2014
init_win_params (& os_window );
1943
2015
uint32_t dev_index = 0 ;
1944
2016
bool use_gpu_idx = false;
2017
+ bool resX_set = false;
2018
+ bool resY_set = false;
1945
2019
os_window .present_mode = VK_PRESENT_MODE_FIFO_KHR ;
1946
2020
1947
- if (argc > 1 )
1948
- {
1949
- if (strcmp (argv [1 ], "--help" ) == 0 )
1950
- {
1951
- print_usage (argv [0 ]);
1952
- return 0 ;
1953
- }
1954
- }
1955
-
1956
2021
for (int i = 1 ; i < argc ; i ++ )
1957
2022
{
1958
2023
if ((strcmp (argv [i ], "--present_mode" ) == 0 ) && (i < argc - 1 ))
@@ -1978,7 +2043,33 @@ int main(int argc, char **argv)
1978
2043
os_window .reload_shaders_on_resize = true;
1979
2044
continue ;
1980
2045
}
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
+ }
1981
2070
}
2071
+
2072
+ set_init_res (& os_window , resX_set , resY_set );
1982
2073
1983
2074
srand (time (NULL ));
1984
2075
0 commit comments