Skip to content

Commit

Permalink
Add wrapper areound SDL_Vulkan_GetDrawableSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Ybalrid committed Dec 30, 2019
1 parent ef927cd commit 6025301
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions sources/cpp-sdl2/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class Window
Vec2i const& size,
Uint32 flags = SDL_WINDOW_SHOWN)
: window_{SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
size.x,
size.y,
flags)}
title.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
size.x,
size.y,
flags)}
{
if (!window_) throw Exception{"SDL_CreateWindow"};
}
Expand Down Expand Up @@ -124,14 +124,14 @@ class Window
bool grabbed() const { return SDL_GetWindowGrab(window_); }

///Move window to specific location on screen
///\param v Vector pointing to the new window location
///\param size Vector pointing to the new window location
Window& move_to(Vec2i const& v)
{
SDL_SetWindowPosition(window_, v.x, v.y);
return *this;
}
///Translate window on screen
///\param v translation vector
///\param size translation vector
Window& move_by(Vec2i const& v) { return move_to(position() + v); }
///Get current window position
Vec2i position() const
Expand Down Expand Up @@ -285,6 +285,15 @@ class Window
auto nakedSurface = vk_create_surface(instance);
return vk::UniqueSurfaceKHR(nakedSurface, instance);
}

///Get the underlayoing drawable size of the window. Use this for vulkan viewport size, scissor rects and any place you need `VkExtent`s
/// \return Size in an integer 2D vector
Vec2i vk_get_drawable_size()
{
Vec2i size;
SDL_Vulkan_GetDrawableSize(window_, &size.x, &size.y);
return size;
}
#endif // vulkan methods

#ifdef CPP_SDL2_GL_WINDOW
Expand Down Expand Up @@ -401,7 +410,7 @@ class Window

private:
SDL_GLContext context_ = nullptr;
SDL_Window* owner_ = nullptr;
SDL_Window* owner_ = nullptr;
};

///Create an OpenGL context from the current window
Expand Down

0 comments on commit 6025301

Please sign in to comment.