@@ -107,6 +107,9 @@ The RenderViewImpl for win32,linux,macos,wasm
107107
108108namespace ax
109109{
110+
111+ using namespace rhi ;
112+
110113#if defined(__EMSCRIPTEN__)
111114struct IVec2
112115{
@@ -457,15 +460,15 @@ void* RenderViewImpl::getNativeWindow() const
457460
458461SurfaceHandle RenderViewImpl::getNativeDisplay () const
459462{
460- auto driverType = rhi:: DriverRuntime::currentDriverType ();
461- if (driverType == rhi:: DriverType::Vulkan)
463+ auto driverType = DriverRuntime::currentDriverType ();
464+ if (driverType == DriverType::Vulkan)
462465 return _vkSurface;
463466
464467#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
465468 return glfwGetWin32Window (_mainWindow);
466469#elif AX_TARGET_PLATFORM == AX_PLATFORM_MAC
467- return driverType == rhi:: DriverType::Metal ? (void *)glfwGetCocoaView (_mainWindow)
468- : (void *)glfwGetNSGLContext (_mainWindow);
470+ return driverType == DriverType::Metal ? (void *)glfwGetCocoaView (_mainWindow)
471+ : (void *)glfwGetNSGLContext (_mainWindow);
469472 return (void *)glfwGetNSGLContext (_mainWindow);
470473#elif AX_TARGET_PLATFORM == AX_PLATFORM_LINUX
471474 int platform = glfwGetPlatform ();
@@ -559,20 +562,14 @@ bool RenderViewImpl::initWithRect(std::string_view viewName,
559562
560563 Vec2 requestWinSize = rect.size * windowZoomFactor;
561564
562- #if AX_ENABLE_D3D11 || AX_ENABLE_D3D12 || AX_ENABLE_VK || AX_ENABLE_MTL
563565 // Try to initialize a high-performance graphics driver first.
564566 // If any of the high-performance APIs (D3D11/D3D12/Vulkan/Metal) are enabled,
565567 // the runtime will attempt initialization in the default priority order.
566568 // If all attempts fail, OpenGL will then be explicitly selected as the fallback.
567- ax::rhi::DriverRuntime::init ();
568- #endif
569-
570- const auto driverType = rhi::DriverRuntime::currentDriverType ();
571- const auto requiresGL = driverType == rhi::DriverType::OpenGL || driverType == rhi::DriverType::Unknown;
572- if (requiresGL)
569+ DriverRuntime::makeCurrentDriver ();
570+ const auto fallbackGL = DriverRuntime::isOpenGL ();
571+ if (fallbackGL)
573572 {
574- if constexpr (!AX_ENABLE_GL)
575- throw std::runtime_error (" OpenGL driver requires AX_ENABLE_GL to be enabled" );
576573#if AX_GLES_PROFILE
577574 glfwWindowHint (GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
578575 glfwWindowHint (GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
@@ -637,13 +634,11 @@ bool RenderViewImpl::initWithRect(std::string_view viewName,
637634 glfwSetWindowSizeLimits (_mainWindow, 1 , 1 , GLFW_DONT_CARE, GLFW_DONT_CARE);
638635
639636#if AX_ENABLE_GL
640- if (requiresGL )
637+ if (fallbackGL )
641638 {
642639 glfwMakeContextCurrent (_mainWindow);
643- glfwSetWindowUserPointer (_mainWindow, rhi::gl::__state);
644-
645- if (driverType == rhi::DriverType::Unknown)
646- ax::rhi::DriverRuntime::init (rhi::DriverType::OpenGL);
640+ glfwSetWindowUserPointer (_mainWindow, gl::__state);
641+ DriverRuntime::activateCurrentDriver ();
647642 }
648643#endif
649644
@@ -666,13 +661,13 @@ bool RenderViewImpl::initWithRect(std::string_view viewName,
666661 updateRenderSurface (fbWidth, fbHeight, SurfaceUpdateFlag::RenderSizeChanged | SurfaceUpdateFlag::SilentUpdate);
667662
668663#if AX_ENABLE_VK
669- if (driverType == rhi::DriverType::Vulkan )
664+ if (DriverRuntime::isVulkan () )
670665 {
671666 auto _createSurface = [](VkInstance inst, void * window, VkSurfaceKHR* surface) {
672667 return glfwCreateWindowSurface (inst, static_cast <GLFWwindow*>(window), nullptr , surface);
673668 };
674- auto driver = static_cast <ax::rhi:: vk::DriverImpl*>(axdrv);
675- const rhi:: vk::SurfaceCreateInfo createInfo{
669+ auto driver = static_cast <vk::DriverImpl*>(axdrv);
670+ const vk::SurfaceCreateInfo createInfo{
676671 .window = _mainWindow, .width = fbWidth, .height = fbHeight, .createFunc = _createSurface};
677672 bool ok = driver->recreateSurface (createInfo);
678673 if (!ok)
@@ -729,7 +724,7 @@ bool RenderViewImpl::initWithRect(std::string_view viewName,
729724 glfwSetWindowCloseCallback (_mainWindow, GLFWEventHandler::onGLFWWindowCloseCallback);
730725
731726#if AX_ENABLE_GL
732- if (driverType == rhi::DriverType::OpenGL )
727+ if (fallbackGL )
733728 {
734729# if !defined(__EMSCRIPTEN__)
735730 glfwSwapInterval (contextAttrs.vsync ? 1 : 0 );
@@ -817,7 +812,7 @@ void RenderViewImpl::end()
817812void RenderViewImpl::swapBuffers ()
818813{
819814#if AX_ENABLE_GL
820- if (_mainWindow && rhi:: DriverRuntime::isOpenGL ())
815+ if (_mainWindow && DriverRuntime::isOpenGL ())
821816 glfwSwapBuffers (_mainWindow);
822817#endif
823818}
0 commit comments