10 #ifdef CPP_SDL2_ENABLE_VULKAN 11 #include <SDL_vulkan.h> 12 #include <vulkan/vulkan.hpp> 28 title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, size.x, size.y,
flags)}
44 if (this->
window_ != other.window_)
48 other.window_ =
nullptr;
68 const auto render = SDL_CreateRenderer(
window_, -1,
flags);
69 if (!render)
throw Exception{
"SDL_CreateRenderer"};
76 const auto r = SDL_GetWindowDisplayIndex(
window_);
77 if (r == -1)
throw Exception{
"SDL_GetWindowDisplayIndex"};
85 if (SDL_SetWindowDisplayMode(
window_, &mode) != 0)
87 throw Exception{
"SDL_SetWindowDisplayMode"};
95 if (SDL_GetWindowDisplayMode(
window_, &mode) != 0)
97 throw Exception{
"SDL_GetWindowDisplayMode"};
108 SDL_SetWindowGrab(
window_, static_cast<SDL_bool>(g));
122 SDL_SetWindowPosition(
window_, v.x, v.y);
132 SDL_GetWindowPosition(
window_, &pos.x, &pos.y);
143 SDL_GetWindowSize(
window_, &s.x, &s.y);
151 SDL_SetWindowTitle(
window_, t.c_str());
155 std::string
title()
const {
return std::string{SDL_GetWindowTitle(
window_)}; }
166 SDL_SetWindowIcon(
window_, icon.ptr());
204 return flags() & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
209 if (SDL_SetWindowFullscreen(
window_, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0) != 0)
211 throw Exception{
"SDL_SetWindowFullscreen"};
223 SDL_VERSION(&info.version);
224 if (SDL_GetWindowWMInfo(
window_, &info) == SDL_FALSE)
231 #ifdef CPP_SDL2_ENABLE_VULKAN 236 std::vector<const char*> extensions;
239 if (!SDL_Vulkan_GetInstanceExtensions(
window_, &count,
nullptr))
240 throw Exception(
"SDL_Vulkan_GetInstanceExtensions");
242 extensions.resize(count);
244 if (!SDL_Vulkan_GetInstanceExtensions(
window_, &count, extensions.data()))
245 throw Exception(
"SDL_Vulkan_GetInstaceExtensions");
254 VkSurfaceKHR surface;
255 if (!SDL_Vulkan_CreateSurface(
window_, instance, &surface))
256 throw Exception(
"SDL_Vulkan_CreateSurface");
265 return vk::UniqueSurfaceKHR(nakedSurface, instance);
273 SDL_Vulkan_GetDrawableSize(
window_, &size.x, &size.y);
276 #endif // vulkan methods 278 #ifdef CPP_SDL2_ENABLE_OPENGL 286 if (SDL_GL_SetAttribute(attr, val) < 0)
throw Exception(
"SDL_GL_SetAttribute");
295 if (SDL_GL_GetAttribute(attr, &value) != 0)
throw Exception(
"SDL_GL_GetAttribute");
305 return SDL_GL_ExtensionSupported(ext_name.c_str()) == SDL_TRUE;
327 if (result != 0)
throw Exception(
"SDL_GL_SetSwapInterval");
333 const auto value = SDL_GL_GetSwapInterval();
345 GlContext(SDL_Window* w) : context_{SDL_GL_CreateContext(w)}, owner_{w}
347 if (!context_)
throw Exception(
"SDL_GL_CreateContext");
364 if (context_ != other.context_)
367 owner_ = other.owner_;
368 other.context_ =
nullptr;
375 if (SDL_GL_MakeCurrent(owner_, context_) < 0)
throw Exception(
"SDL_GL_MakeCurrent");
378 SDL_GLContext
ptr()
const {
return context_; }
381 SDL_GLContext context_ =
nullptr;
382 SDL_Window* owner_ =
nullptr;
static void gl_set_swap_interval(gl_swap_interval swap_mode)
Set the swap interval. If exception thrown while attempting to use adaptive vsync, use standard vsync.
Vec2i vk_get_drawable_size()
Get the underlayoing drawable size of the window.
GlContext & operator=(GlContext &&other) noexcept
Vec2i gl_get_drawable_size() const
Get the actual size of the OpenGL drawing area on the window. May not match window size on platform t...
Window & set_fullscreen(bool fs)
Set the window fullscreen.
Window & maximize()
Maximize the window.
static void gl_set_attribute(SDL_GLattr attr, bool val)
Generic templated 2D vector class.
void resize(Vec2i const &newsize) const
Change the size of the window the size of the window.
VkSurfaceKHR vk_create_surface(VkInstance instance)
Create a vulkan surface for the current platform.
GlContext(SDL_Window *w)
Create a GlContext for the given window.
static void gl_reset_attribute()
Reset all OpenGL attributes to their default values.
Window & move_by(Vec2i const &v)
Translate window on screen.
std::vector< const char * > vk_get_instance_extensions()
Enumerate the required extensions to create a VkSurfaceKHR on the current system. ...
void set_icon(std::string const &filename) const
Set the window icon (may require linking and activating SDL_Image)
Window & toggle_fullscreen()
Toggle the window fullscreen.
static gl_swap_interval gl_get_swap_interval()
Get the current swap interval.
virtual ~Window()
Destructor. Calls SDL_DestroyWindow() automatically for you.
Uint32 flags() const
Get the flags of this window.
Window & release(bool r=true)
Release window.
Window & move_to(Vec2i const &v)
Move window to specific location on screen.
void set_display_mode(SDL_DisplayMode const &mode) const
Set the window display mode.
Window & grab(bool g=true)
Grab window.
GlContext create_context() const
Create an OpenGL context from the current window.
SDL_Window * window_
Raw naked pointer to an SDL window.
Window()=default
Construct an invalid window object. You will need to initialize it by moving in a real sdl::Window in...
~GlContext()
Dtor will call SDL_GL_DeleteContext on the enclosed context.
Nested class that represent a managed OpenGL Context by the SDL.
Define to deactivate exception support.
static int gl_get_attribute(SDL_GLattr attr)
Get the value of the specified OpenGL attribute.
SDL_GLContext ptr() const
SDL_SysWMinfo wm_info() const
Get window manager info. Exact content of this structure is fully platform dependant.
Window & restore()
Restore the window.
static void gl_set_attribute(SDL_GLattr attr, int val)
std::string title() const
the current window title
GlContext(GlContext &&other) noexcept
int display_index() const
Get the current window display index.
Window & hide()
Hide the window.
Window & operator=(Window &&other) noexcept
Move assign operator.
static bool gl_is_extension_supported(std::string const &ext_name)
Return true if the specified extension is supported.
SDL_Surface * ptr() const
Get C SDL_Surface object.
Represent an SDL_Surface.
SDL_Window * ptr() const
Getter for the raw SDL2 window pointer.
void make_current() const
bool grabbed() const
Is window grabed.
gl_swap_interval
Define the type of window swapping strategy for opengl windows.
Vec2i size() const
Get current window size.
Vec2i position() const
Get current window position.
vk::UniqueSurfaceKHR vk_create_unique_surface(vk::Instance instance)
Create a vulkan surface using the C++ wrapper around UniqueHandle.
Renderer make_renderer(Uint32 flags=SDL_RENDERER_ACCELERATED) const
2D renderer factory.
Window & minimize()
Minimize the window.
Define to deactivate exception support.
void gl_swap() const
Swap buffers for GL when using double buffering on the current window.
SDL_DisplayMode display_mode() const
Get the current display mode.
bool fullscreen() const
Returns true if window is currently fullscreen (both real and "desktop mode")
Window(std::string const &title, Vec2i const &size, Uint32 flags=SDL_WINDOW_SHOWN)
Construct a window.
Class that represent a SDL2 2D renderer.
Window & rename(std::string const &t)
Change window name.
Window(Window &&other) noexcept
Default move ctor.
void set_icon(Surface const &icon) const
Set the window icon.