Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/vsg/platform/android/Android_Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace vsgAndroid
Android_Window operator = (const Android_Window&) = delete;

using Result = vsg::Result<vsg::Window, VkResult, VK_SUCCESS>;
static Result create(const Window::Traits& traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr);
static Result create(vsg::ref_ptr<vsg::Window::Traits> traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr);

virtual bool valid() const { return _window; }

Expand All @@ -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<vsg::Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator);

ANativeWindow* _window;

Expand Down
4 changes: 2 additions & 2 deletions include/vsg/platform/unix/Xcb_Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<vsg::Window::Traits> traits, bool debugLayer=false, bool apiDumpLayer=false, vsg::AllocationCallbacks* allocator=nullptr);

bool valid() const override;

Expand All @@ -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<vsg::Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator);

~Xcb_Window();

Expand Down
4 changes: 2 additions & 2 deletions include/vsg/platform/win32/Win32_Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<vsg::Window::Traits> traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr);

bool valid() const override { return _window && !_shouldClose; }

Expand All @@ -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<vsg::Window::Traits> traits, bool debugLayer = false, bool apiDumpLayer = false, vsg::AllocationCallbacks* allocator = nullptr);

HWND _window;
bool _shouldClose;
Expand Down
31 changes: 16 additions & 15 deletions src/vsg/platform/android/Android_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator)
{
return vsgAndroid::Android_Window::create(traits, debugLayer, apiDumpLayer, allocator);
}
Expand Down Expand Up @@ -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<Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator)
{
try
{
Expand All @@ -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<Window::Traits> 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<ANativeWindow*>(&traits.nativeHandle);
ANativeWindow* nativeWindow = static_cast<ANativeWindow*>(traits.nativeWindow);
//ANativeWindow* nativeWindow = *std::any_cast<ANativeWindow*>(&traits->nativeHandle);
ANativeWindow* nativeWindow = static_cast<ANativeWindow*>(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<Android_Window> window;

if (traits.shareWindow)
if (traits->shareWindow)
{
// create Android surface for the ANativeWindow
vsg::ref_ptr<vsg::Surface> surface(new vsgAndroid::AndroidSurface(traits.shareWindow->instance(), nativeWindow, allocator));
vsg::ref_ptr<vsg::Surface> 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<vsg::PhysicalDevice> physicalDevice = vsg::PhysicalDevice::create(traits.shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface);
vsg::ref_ptr<vsg::PhysicalDevice> physicalDevice = vsg::PhysicalDevice::create(traits->shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface);
}
else
{
Expand Down
21 changes: 11 additions & 10 deletions src/vsg/platform/unix/Xcb_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
33 changes: 17 additions & 16 deletions src/vsg/platform/win32/Win32_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window::Traits> traits bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator)
{
return vsgWin32::Win32_Window::create(traits, debugLayer, apiDumpLayer, allocator);
}
Expand Down Expand Up @@ -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<Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator)
{
try
{
Expand All @@ -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<Window::Traits> traits, bool debugLayer, bool apiDumpLayer, vsg::AllocationCallbacks* allocator) :
Window(traits, debugLayer, apiDumpLayer, allocator),
_window(nullptr),
_shouldClose(false)
{
Expand All @@ -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)
Expand All @@ -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);

Expand All @@ -416,19 +417,19 @@ Win32_Window::Win32_Window(const Window::Traits& traits, bool debugLayer, bool a

vsg::ref_ptr<Win32_Window> 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<vsg::Surface> surface(new vsgWin32::Win32Surface(traits.shareWindow->instance(), _window, allocator));
vsg::ref_ptr<vsg::Surface> 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<vsg::PhysicalDevice> physicalDevice = vsg::PhysicalDevice::create(traits.shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface);
vsg::ref_ptr<vsg::PhysicalDevice> physicalDevice = vsg::PhysicalDevice::create(traits->shareWindow->instance(), VK_QUEUE_GRAPHICS_BIT, surface);
}
else
{
Expand Down