@@ -1700,78 +1700,82 @@ gs_platform_window_create_internal(const gs_platform_window_desc_t* desc)
1700
1700
1701
1701
// Grab window hints from application desc
1702
1702
u32 window_hints = desc -> flags ;
1703
+ bool visible = ~window_hints & GS_WINDOW_FLAGS_INVISIBLE ;
1703
1704
1704
1705
// Set whether or not the screen is resizable
1705
- glfwWindowHint (GLFW_RESIZABLE , (window_hints & GS_WINDOW_FLAGS_NO_RESIZE ) != GS_WINDOW_FLAGS_NO_RESIZE );
1706
+ glfwWindowHint (GLFW_RESIZABLE , (window_hints & GS_WINDOW_FLAGS_NO_RESIZE ) != GS_WINDOW_FLAGS_NO_RESIZE );
1707
+ glfwWindowHint (GLFW_VISIBLE , visible );
1708
+ GLFWwindow * window = NULL ;
1709
+
1710
+ #define CONSTRUCT_WINDOW (W , H , T , M , I )\
1711
+ do {\
1712
+ window = glfwCreateWindow(W, H, T, M, I);\
1713
+ win.hndl = window;\
1714
+ } while (0)
1715
+
1716
+ if (visible ) {
1717
+ // Set multi-samples
1718
+ if (desc -> num_samples ) {
1719
+ glfwWindowHint (GLFW_SAMPLES , desc -> num_samples );
1720
+ }
1721
+ else {
1722
+ glfwWindowHint (GLFW_SAMPLES , 0 );
1723
+ }
1706
1724
1707
- // Set multi-samples
1708
- if (desc -> num_samples ) {
1709
- glfwWindowHint (GLFW_SAMPLES , desc -> num_samples );
1710
- }
1711
- else {
1712
- glfwWindowHint (GLFW_SAMPLES , 0 );
1713
- }
1725
+ // Get monitor if fullscreen
1726
+ GLFWmonitor * monitor = NULL ;
1727
+ if ((window_hints & GS_WINDOW_FLAGS_FULLSCREEN ) == GS_WINDOW_FLAGS_FULLSCREEN ) {
1728
+ int monitor_count ;
1729
+ GLFWmonitor * * monitors = glfwGetMonitors (& monitor_count );
1730
+ if (desc -> monitor_index < monitor_count ) {
1731
+ monitor = monitors [desc -> monitor_index ];
1732
+ }
1733
+ }
1734
+ CONSTRUCT_WINDOW (desc -> width , desc -> height , desc -> title , monitor , NULL );
1714
1735
1715
- // Get monitor if fullscreen
1716
- GLFWmonitor * monitor = NULL ;
1717
- if ((window_hints & GS_WINDOW_FLAGS_FULLSCREEN ) == GS_WINDOW_FLAGS_FULLSCREEN )
1718
- {
1719
- int monitor_count ;
1720
- GLFWmonitor * * monitors = glfwGetMonitors (& monitor_count );
1721
- if (desc -> monitor_index < monitor_count )
1722
- {
1723
- monitor = monitors [desc -> monitor_index ];
1724
- }
1736
+ // Callbacks for window
1737
+ glfwMakeContextCurrent (window );
1738
+ glfwSetKeyCallback (window , & __glfw_key_callback );
1739
+ glfwSetCharCallback (window , & __glfw_char_callback );
1740
+ glfwSetMouseButtonCallback (window , & __glfw_mouse_button_callback );
1741
+ glfwSetCursorEnterCallback (window , & __glfw_mouse_cursor_enter_callback );
1742
+ glfwSetCursorPosCallback (window , & __glfw_mouse_cursor_position_callback );
1743
+ glfwSetScrollCallback (window , & __glfw_mouse_scroll_wheel_callback );
1744
+
1745
+ // Cache all necessary window information
1746
+ int32_t wx = 0 , wy = 0 , fx = 0 , fy = 0 , wpx = 0 , wpy = 0 ;
1747
+ glfwGetWindowSize ((GLFWwindow * )win .hndl , & wx , & wy );
1748
+ glfwGetFramebufferSize ((GLFWwindow * )win .hndl , & fx , & fy );
1749
+ glfwGetWindowPos ((GLFWwindow * )win .hndl , & wpx , & wpy );
1750
+ win .window_size = gs_v2 ((float )wx , (float )wy );
1751
+ win .window_position = gs_v2 ((float )wpx , (float )wpy );
1752
+ win .framebuffer_size = gs_v2 ((float )fx , (float )fy );
1753
+ }
1754
+ else {
1755
+ void * mwin = gs_platform_raw_window_handle (gs_platform_main_window ());
1756
+ CONSTRUCT_WINDOW (1 , 1 , desc -> title , 0 , mwin );
1725
1757
}
1726
1758
1727
- GLFWwindow * window = glfwCreateWindow (desc -> width , desc -> height , desc -> title , monitor , NULL );
1728
- if (window == NULL )
1729
- {
1759
+ if (window == NULL ) {
1730
1760
gs_log_error ("Failed to create window." );
1731
1761
glfwTerminate ();
1732
1762
return win ;
1733
- }
1734
-
1735
- win .hndl = window ;
1736
-
1737
- // Callbacks for window
1738
- glfwMakeContextCurrent (window );
1739
- glfwSetKeyCallback (window , & __glfw_key_callback );
1740
- glfwSetCharCallback (window , & __glfw_char_callback );
1741
- glfwSetMouseButtonCallback (window , & __glfw_mouse_button_callback );
1742
- glfwSetCursorEnterCallback (window , & __glfw_mouse_cursor_enter_callback );
1743
- glfwSetCursorPosCallback (window , & __glfw_mouse_cursor_position_callback );
1744
- glfwSetScrollCallback (window , & __glfw_mouse_scroll_wheel_callback );
1745
-
1746
- // Cache all necessary window information
1747
- int32_t wx = 0 , wy = 0 , fx = 0 , fy = 0 , wpx = 0 , wpy = 0 ;
1748
- glfwGetWindowSize ((GLFWwindow * )win .hndl , & wx , & wy );
1749
- glfwGetFramebufferSize ((GLFWwindow * )win .hndl , & fx , & fy );
1750
- glfwGetWindowPos ((GLFWwindow * )win .hndl , & wpx , & wpy );
1751
- win .window_size = gs_v2 ((float )wx , (float )wy );
1752
- win .window_position = gs_v2 ((float )wpx , (float )wpy );
1753
- win .framebuffer_size = gs_v2 ((float )fx , (float )fy );
1763
+ }
1754
1764
1755
1765
// Need to make sure this is ONLY done once.
1756
- if (gs_slot_array_empty (gs_subsystem (platform )-> windows ))
1757
- {
1758
- if (!gladLoadGLLoader ((GLADloadproc )glfwGetProcAddress ))
1759
- {
1766
+ if (gs_slot_array_empty (gs_subsystem (platform )-> windows )) {
1767
+ if (!gladLoadGLLoader ((GLADloadproc )glfwGetProcAddress )) {
1760
1768
gs_log_warning ("Failed to initialize GLFW." );
1761
1769
return win ;
1762
1770
}
1763
1771
1764
- switch (gs_subsystem (platform )-> settings .video .driver )
1765
- {
1766
- case GS_PLATFORM_VIDEO_DRIVER_TYPE_OPENGL :
1767
- {
1772
+ switch (gs_subsystem (platform )-> settings .video .driver ) {
1773
+ case GS_PLATFORM_VIDEO_DRIVER_TYPE_OPENGL : {
1768
1774
gs_log_info ("OpenGL Version: %s" , glGetString (GL_VERSION ));
1769
- if (gs_subsystem (platform )-> settings .video .graphics .debug )
1770
- {
1775
+ if (gs_subsystem (platform )-> settings .video .graphics .debug ) {
1771
1776
glDebugMessageCallback (__gs_platform_gl_debug , NULL );
1772
1777
}
1773
1778
} break ;
1774
-
1775
1779
default : break ;
1776
1780
}
1777
1781
}
@@ -1842,6 +1846,20 @@ gs_platform_window_swap_buffer(uint32_t handle)
1842
1846
glfwSwapBuffers ((GLFWwindow * )win -> hndl );
1843
1847
}
1844
1848
1849
+ GS_API_DECL void
1850
+ gs_platform_window_make_current (uint32_t hndl )
1851
+ {
1852
+ gs_platform_t * platform = gs_subsystem (platform );
1853
+ gs_platform_window_t * win = gs_slot_array_getp (platform -> windows , hndl );
1854
+ glfwMakeContextCurrent (win );
1855
+ }
1856
+
1857
+ GS_API_DECL void
1858
+ gs_platform_window_make_current_raw (void * win )
1859
+ {
1860
+ glfwMakeContextCurrent (win );
1861
+ }
1862
+
1845
1863
GS_API_DECL gs_vec2
1846
1864
gs_platform_window_sizev (uint32_t handle )
1847
1865
{
0 commit comments