diff --git a/include/vsg/platform/android/Android_Window.h b/include/vsg/platform/android/Android_Window.h index 67544c17cc..61fbfe16fd 100644 --- a/include/vsg/platform/android/Android_Window.h +++ b/include/vsg/platform/android/Android_Window.h @@ -68,7 +68,7 @@ namespace vsgAndroid Android_Window operator = (const Android_Window&) = delete; using Result = vsg::Result; - static Result create(const Window::Traits& traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr); + static Result create(vsg::ref_ptr traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr); virtual bool valid() const { return _window; } @@ -83,7 +83,7 @@ namespace vsgAndroid protected: virtual ~Android_Window(); - Android_Window(const vsg::Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator); + Android_Window(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator); ANativeWindow* _window; diff --git a/include/vsg/platform/unix/Xcb_Window.h b/include/vsg/platform/unix/Xcb_Window.h index f686d5fc65..7a2f568751 100644 --- a/include/vsg/platform/unix/Xcb_Window.h +++ b/include/vsg/platform/unix/Xcb_Window.h @@ -56,7 +56,7 @@ namespace vsgXcb Xcb_Window(const Xcb_Window&) = delete; Xcb_Window& operator = (const Xcb_Window&) = delete; - static Result create(const Traits& traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr); + static Result create(vsg::ref_ptr traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr); bool valid() const override; @@ -67,7 +67,7 @@ namespace vsgXcb void resize() override; protected: - Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator); + Xcb_Window(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator); ~Xcb_Window(); diff --git a/include/vsg/platform/win32/Win32_Window.h b/include/vsg/platform/win32/Win32_Window.h index f55a67da5b..b4f83b5616 100644 --- a/include/vsg/platform/win32/Win32_Window.h +++ b/include/vsg/platform/win32/Win32_Window.h @@ -113,7 +113,7 @@ namespace vsgWin32 Win32_Window(const Win32_Window&) = delete; Win32_Window operator=(const Win32_Window&) = delete; - static Result create(const Traits& traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr); + static Result create(vsg::ref_ptr traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr); bool valid() const override { return _window && !_shouldClose; } @@ -131,7 +131,7 @@ namespace vsgWin32 protected: virtual ~Win32_Window(); - Win32_Window(const Window::Traits& traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr); + Win32_Window(vsg::ref_ptr traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr); HWND _window; bool _shouldClose; diff --git a/src/vsg/platform/android/Android_Window.cpp b/src/vsg/platform/android/Android_Window.cpp index 18d4121267..0a9ae20e92 100644 --- a/src/vsg/platform/android/Android_Window.cpp +++ b/src/vsg/platform/android/Android_Window.cpp @@ -32,7 +32,7 @@ using namespace vsgAndroid; namespace vsg { // Provide the Window::create(...) implementation that automatically maps to an Android_Window - Window::Result Window::create(const Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) + Window::Result Window::create(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { return vsgAndroid::Android_Window::create(traits, debugLayer, apiDumpLayer, allocator); } @@ -327,7 +327,7 @@ KeyboardMap::KeyboardMap() }; } -vsg::Window::Result Android_Window::create(const vsg::Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) +vsg::Window::Result Android_Window::create(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { try { @@ -340,46 +340,47 @@ vsg::Window::Result Android_Window::create(const vsg::Window::Traits& traits, bo } } -Android_Window::Android_Window(const vsg::Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) +Android_Window::Android_Window(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) : + Window(traits, debugLayer, apiDumpLayer, allocator) { _keyboard = new KeyboardMap; - /*if(!traits.nativeHandle.has_value()) + /*if(!traits->nativeHandle.has_value()) { - return Result("Error: vsg::Android_Window::create(...) failed to create Window, Android requires a NativeWindow passed via traits.nativeHandle.", VK_ERROR_INVALID_EXTERNAL_HANDLE); + return Result("Error: vsg::Android_Window::create(...) failed to create Window, Android requires a NativeWindow passed via traits->nativeHandle.", VK_ERROR_INVALID_EXTERNAL_HANDLE); }*/ - //ANativeWindow* nativeWindow = *std::any_cast(&traits.nativeHandle); - ANativeWindow* nativeWindow = static_cast(traits.nativeWindow); + //ANativeWindow* nativeWindow = *std::any_cast(&traits->nativeHandle); + ANativeWindow* nativeWindow = static_cast(traits->nativeWindow); if (nativeWindow == nullptr) { - throw Result("Error: vsg::Android_Window::create(...) failed to create Window, traits.nativeHandle is not a valid ANativeWindow.", VK_ERROR_INVALID_EXTERNAL_HANDLE); + throw Result("Error: vsg::Android_Window::create(...) failed to create Window, traits->nativeHandle is not a valid ANativeWindow.", VK_ERROR_INVALID_EXTERNAL_HANDLE); } _window = nativeWindow; // we could get the width height from the window? - uint32_t finalWidth = traits.width; - uint32_t finalHeight = traits.height; + uint32_t finalWidth = traits->width; + uint32_t finalHeight = traits->height; vsg::ref_ptr window; - if (traits.shareWindow) + if (traits->shareWindow) { // create Android surface for the ANativeWindow - vsg::ref_ptr surface(new vsgAndroid::AndroidSurface(traits.shareWindow->instance(), nativeWindow, allocator)); + vsg::ref_ptr surface(new vsgAndroid::AndroidSurface(traits->shareWindow->instance(), nativeWindow, allocator)); _surface = surface; - _debugLayersEnabled = traits.shareWindow->debugLayersEnabled(); + _debugLayersEnabled = traits->shareWindow->debugLayersEnabled(); // share the _instance, _physicalDevice and _device; - window->share(*traits.shareWindow); + window->share(*traits->shareWindow); // temporary hack to force vkGetPhysicalDeviceSurfaceSupportKHR to be called as the Vulkan // debug layer is complaining about vkGetPhysicalDeviceSurfaceSupportKHR not being called // for this _surface prior to swap chain creation - vsg::ref_ptr physicalDevice = vsg::PhysicalDevice::create(traits.shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface); + vsg::ref_ptr physicalDevice = vsg::PhysicalDevice::create(traits->shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface); } else { diff --git a/src/vsg/platform/unix/Xcb_Window.cpp b/src/vsg/platform/unix/Xcb_Window.cpp index af1415583b..768e48ea1c 100644 --- a/src/vsg/platform/unix/Xcb_Window.cpp +++ b/src/vsg/platform/unix/Xcb_Window.cpp @@ -26,7 +26,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { // Provide the Window::create(...) implementation that automatically maps to a Xcb_Window - Window::Result Window::create(const Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) + Window::Result Window::create(vsg::ref_ptr<:Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { return vsgXcb::Xcb_Window::create(traits, debugLayer, apiDumpLayer, allocator); } @@ -238,7 +238,7 @@ Xcb_Surface::Xcb_Surface(vsg::Instance* instance, xcb_connection_t* connection, // // Xcb_Window // -vsg::Window::Result Xcb_Window::create(const Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) +vsg::Window::Result Xcb_Window::create(vsg::ref_ptr<:Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { try { @@ -251,12 +251,13 @@ vsg::Window::Result Xcb_Window::create(const Traits& traits, bool debugLayer, bo } } -Xcb_Window::Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) +Xcb_Window::Xcb_Window(vsg::ref_ptr<:Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) : + Window(traits, debugLayer, apiDumpLayer, allocator) { - std::cout << "Xcb_Window() " << traits.x << ", " << traits.y << ", " << traits.width << ", " << traits.height << std::endl; + std::cout << "Xcb_Window() " << traits->x << ", " << traits->y << ", " << traits->width << ", " << traits->height << std::endl; const char* displayName = 0; - int screenNum = traits.screenNum; + int screenNum = traits->screenNum; bool fullscreen = false; //true; uint32_t override_redirect = 0; // fullscreen ? 1 : 0; @@ -369,7 +370,7 @@ Xcb_Window::Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, else { xcb_create_window(_connection, depth, _window, parent, - traits.x, traits.y, traits.width, traits.height, + traits->x, traits->y, traits->width, traits->height, border_width, window_class, visual, @@ -378,10 +379,10 @@ Xcb_Window::Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, } // set class of window to enable window manager configuration with rules for positioning - xcb_change_property(_connection, XCB_PROP_MODE_REPLACE, _window, XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 8, traits.windowClass.size(), traits.windowClass.data()); + xcb_change_property(_connection, XCB_PROP_MODE_REPLACE, _window, XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 8, traits->windowClass.size(), traits->windowClass.data()); // set title of window - xcb_change_property(_connection, XCB_PROP_MODE_REPLACE, _window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, traits.windowTitle.size(), traits.windowTitle.data()); + xcb_change_property(_connection, XCB_PROP_MODE_REPLACE, _window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, traits->windowTitle.size(), traits->windowTitle.data()); // make requests for the atoms AtomRequest protocols(_connection, "WM_PROTOCOLS"); @@ -408,7 +409,7 @@ Xcb_Window::Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, MotifHints hints = fullscreen ? MotifHints::borderless() : MotifHints::window(); xcb_change_property(_connection, XCB_PROP_MODE_REPLACE, _window, motifHintAtom, motifHintAtom, 32, 5, &hints); - std::cout << "Create window : " << traits.windowTitle << std::endl; + std::cout << "Create window : " << traits->windowTitle << std::endl; // work out the X server timestamp by checking for the property notify events that result for the above xcb_change_property calls. _first_xcb_timestamp = 0; @@ -440,7 +441,7 @@ Xcb_Window::Xcb_Window(const Traits& traits, bool debugLayer, bool apiDumpLayer, #if 1 - if (traits.shareWindow) + if (traits->shareWindow) { throw Result("Error: vsg::Xcb_Window::create(...) Sharing of Windows not Not supported yet.", VK_ERROR_INVALID_EXTERNAL_HANDLE); } diff --git a/src/vsg/platform/win32/Win32_Window.cpp b/src/vsg/platform/win32/Win32_Window.cpp index 9f36884c61..0dd4cb23e1 100644 --- a/src/vsg/platform/win32/Win32_Window.cpp +++ b/src/vsg/platform/win32/Win32_Window.cpp @@ -22,7 +22,7 @@ using namespace vsgWin32; namespace vsg { // Provide the Window::create(...) implementation that automatically maps to a Win32_Window - Window::Result Window::create(const Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) + Window::Result Window::create(vsg::ref_ptr traits bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { return vsgWin32::Win32_Window::create(traits, debugLayer, apiDumpLayer, allocator); } @@ -317,7 +317,7 @@ KeyboardMap::KeyboardMap() }; } -Win32_Window::Result Win32_Window::create(const Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) +Win32_Window::Result Win32_Window::create(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) { try { @@ -330,7 +330,8 @@ Win32_Window::Result Win32_Window::create(const Traits& traits, bool debugLayer, } } -Win32_Window::Win32_Window(const Window::Traits& traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) : +Win32_Window::Win32_Window(vsg::ref_ptr traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) : + Window(traits, debugLayer, apiDumpLayer, allocator), _window(nullptr), _shouldClose(false) { @@ -348,7 +349,7 @@ Win32_Window::Win32_Window(const Window::Traits& traits, bool debugLayer, bool a wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = 0; wc.lpszMenuName = 0; - wc.lpszClassName = traits.windowClass.c_str(); + wc.lpszClassName = traits->windowClass.c_str(); wc.hIconSm = 0; if (::RegisterClassEx(&wc) == 0) @@ -371,31 +372,31 @@ Win32_Window::Win32_Window(const Window::Traits& traits, bool debugLayer, bool a displayDevices.push_back(displayDevice); } - if (traits.screenNum >= displayDevices.size()) throw Result("Error: vsg::Win32_Window::create(...) failed to create Window, screenNum is out of range.", VK_ERROR_INVALID_EXTERNAL_HANDLE); + if (traits->screenNum >= displayDevices.size()) throw Result("Error: vsg::Win32_Window::create(...) failed to create Window, screenNum is out of range.", VK_ERROR_INVALID_EXTERNAL_HANDLE); DEVMODE deviceMode; deviceMode.dmSize = sizeof(deviceMode); deviceMode.dmDriverExtra = 0; - if (!::EnumDisplaySettings(displayDevices[traits.screenNum].DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode)) throw Result("Error: vsg::Win32_Window::create(...) failed to create Window, EnumDisplaySettings failed to fetch display settings.", VK_ERROR_INVALID_EXTERNAL_HANDLE); + if (!::EnumDisplaySettings(displayDevices[traits->screenNum].DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode)) throw Result("Error: vsg::Win32_Window::create(...) failed to create Window, EnumDisplaySettings failed to fetch display settings.", VK_ERROR_INVALID_EXTERNAL_HANDLE); - int32_t screenx = deviceMode.dmPosition.x + traits.x; - int32_t screeny = deviceMode.dmPosition.y + traits.y; + int32_t screenx = deviceMode.dmPosition.x + traits->x; + int32_t screeny = deviceMode.dmPosition.y + traits->y; // setup window rect and style RECT windowRect; windowRect.left = screenx; windowRect.top = screeny; - windowRect.right = windowRect.left + traits.width; - windowRect.bottom = windowRect.top + traits.height; + windowRect.right = windowRect.left + traits->width; + windowRect.bottom = windowRect.top + traits->height; - unsigned int windowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | (traits.decoration ? WS_CAPTION : 0); + unsigned int windowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | (traits->decoration ? WS_CAPTION : 0); unsigned int extendedStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; if (!::AdjustWindowRectEx(&windowRect, windowStyle, FALSE, extendedStyle)) throw Result("Error: vsg::Win32_Window::create(...) failed to create Window, AdjustWindowRectEx failed.", VK_ERROR_INVALID_EXTERNAL_HANDLE); // create the window - _window = ::CreateWindowEx(extendedStyle, traits.windowClass.c_str(), traits.windowTitle.c_str(), windowStyle, + _window = ::CreateWindowEx(extendedStyle, traits->windowClass.c_str(), traits->windowTitle.c_str(), windowStyle, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, NULL, NULL, ::GetModuleHandle(NULL), NULL); @@ -416,19 +417,19 @@ Win32_Window::Win32_Window(const Window::Traits& traits, bool debugLayer, bool a vsg::ref_ptr window; - if (traits.shareWindow) + if (traits->shareWindow) { // share the _instance, _physicalDevice and _device; - window->share(*traits.shareWindow); + window->share(*traits->shareWindow); // create surface - vsg::ref_ptr surface(new vsgWin32::Win32Surface(traits.shareWindow->instance(), _window, allocator)); + vsg::ref_ptr surface(new vsgWin32::Win32Surface(traits->shareWindow->instance(), _window, allocator)); _surface = surface; // temporary hack to force vkGetPhysicalDeviceSurfaceSupportKHR to be called as the Vulkan // debug layer is complaining about vkGetPhysicalDeviceSurfaceSupportKHR not being called // for this _surface prior to swap chain creation - vsg::ref_ptr physicalDevice = vsg::PhysicalDevice::create(traits.shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface); + vsg::ref_ptr physicalDevice = vsg::PhysicalDevice::create(traits->shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface); } else {