-- Main Loop ------------------------------------------------------------------
runMainLoopGLFW :: IORef GLFWState -> IO ()
runMainLoopGLFW ref =
  whenWindow_ ref $ \glfwWin -> do
    winShouldClose <- GLFW.windowShouldClose glfwWin
    winFocus <- GLFW.getWindowFocused glfwWin
    if winShouldClose
      then do
        GLFW.destroyWindow glfwWin
        GLFW.terminate
      else do
        case winFocus of
          GLFW.FocusState'Defocused -> GLFW.waitEvents
          GLFW.FocusState'Focused -> do
            GLFW.pollEvents

            join $ ref ^@ display

            GLFW.swapBuffers glfwWin

        runMainLoopGLFW ref


-- GLFW type Conversion -------------------------------------------------------
runMainLoopGLFW :: IORef GLFWState -> IO ()
runMainLoopGLFW ref =
  whenWindow_ ref $ \glfwWin -> do
    winShouldClose <- GLFW.windowShouldClose glfwWin
    winFocus <- GLFW.getWindowFocused glfwWin
    if winShouldClose
      then do
        GLFW.destroyWindow glfwWin
        GLFW.terminate
      else do
        case winFocus of
          GLFW.FocusState'Defocused -> GLFW.waitEvents
          GLFW.FocusState'Focused -> do
            GLFW.pollEvents

            join $ ref ^@ display

            GLFW.swapBuffers glfwWin

        runMainLoopGLFW ref


-- GLFW type Conversion -------------------------------------------------------
runMainLoopGLFW ref =
  whenWindow_ ref $ \glfwWin -> do
    winShouldClose <- GLFW.windowShouldClose glfwWin
    winFocus <- GLFW.getWindowFocused glfwWin
    if winShouldClose
      then do
        GLFW.destroyWindow glfwWin
        GLFW.terminate
      else do
        case winFocus of
          GLFW.FocusState'Defocused -> GLFW.waitEvents
          GLFW.FocusState'Focused -> do
            GLFW.pollEvents

            join $ ref ^@ display

            GLFW.swapBuffers glfwWin

        runMainLoopGLFW ref


-- GLFW type Conversion -------------------------------------------------------