diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | TODO | 1 | ||||
m--------- | depends/mgl | 0 | ||||
-rw-r--r-- | include/mglpp/graphics/Texture.hpp | 11 | ||||
-rw-r--r-- | include/mglpp/mglpp.hpp | 12 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 3 | ||||
-rw-r--r-- | meson.build | 26 | ||||
-rw-r--r-- | src/graphics/Texture.cpp | 9 | ||||
-rw-r--r-- | src/mglpp.cpp | 4 | ||||
-rw-r--r-- | src/window/Window.cpp | 24 |
10 files changed, 49 insertions, 52 deletions
@@ -2,10 +2,13 @@ C++ wrapper for [mgl](https://git.dec05eba.com/mgl/about/) # Dependencies ## Build -`x11, libxrender, libxrandr` +`libx11, libxrender, libxrandr`\ +`wayland-client, wayland-egl, wayland-scanner` ## Runtime -`libglvnd (libGL.so, libEGL.so)` +`libglvnd (libGL.so, libGLX.so, libEGL.so)` # Notes -Every window _get_ function is cached from the last event poll, no calls to x11 is made. +Every window _get_ function is cached from the last event poll, no calls to x11/wayland is made.\ Only one window can be created and used at once.\ -mglpp needs to be initialized first and then a window created, before other functions are called. +mglpp needs to be initialized first and then a window has to be created before other functions are called. +# TODO +Wayland support is not finished yet. Use MGL_WINDOW_SYSTEM_X11 for now in mgl::Init.
\ No newline at end of file @@ -0,0 +1 @@ +Change Init(window_system) default value to WindowSystem::NATIVE. diff --git a/depends/mgl b/depends/mgl -Subproject 46962ea3fc83a26fcf0851ccb748b08eecf7f8e +Subproject c990594a93e953854b0a224a22f7e0a7db8ffe1 diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp index 1ea040e..6ab1fb4 100644 --- a/include/mglpp/graphics/Texture.hpp +++ b/include/mglpp/graphics/Texture.hpp @@ -14,24 +14,25 @@ namespace mgl { struct LoadOptions { bool compressed = false; bool pixel_coordinates = false; - bool mipmap = false; /* available since opengl 3.0 */ + mgl_texture_scale_type scale_type = MGL_TEXTURE_SCALE_LINEAR; }; struct ReferenceOptions { bool pixel_coordinates = false; + mgl_texture_scale_type scale_type = MGL_TEXTURE_SCALE_LINEAR; }; Texture(); - Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options = {false}); + Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options = {false, MGL_TEXTURE_SCALE_LINEAR}); Texture(Texture &&other); Texture& operator=(Texture &&other); ~Texture(); static Texture reference(mgl_texture ref); - bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false, false}); - bool load_from_image(Image &image, const LoadOptions load_options = {false, false, false}); - bool load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options = {false, false, false}); + bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); + bool load_from_image(Image &image, const LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); + bool load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); void clear(); vec2i get_size() const; bool is_valid() const; diff --git a/include/mglpp/mglpp.hpp b/include/mglpp/mglpp.hpp index 2e49da5..730ddf5 100644 --- a/include/mglpp/mglpp.hpp +++ b/include/mglpp/mglpp.hpp @@ -1,9 +1,15 @@ #ifndef MGLPP_MGLPP_HPP #define MGLPP_MGLPP_HPP -#include <stdexcept> +#include <exception> namespace mgl { + enum class WindowSystem { + NATIVE, // Use X11 on X11 and Wayland on Wayland + X11, // Use X11 on X11 and XWayland on Wayland + WAYLAND, // Use Wayland. If user runs on X11 then it fails to connect + }; + class InitException : public std::exception { public: const char* what() const noexcept override { @@ -13,8 +19,8 @@ namespace mgl { class Init { public: - // Throws InitException on failure - Init(); + // Throws InitException on failure. + Init(WindowSystem window_system = WindowSystem::X11); ~Init(); bool is_connected_to_display_server(); diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 6bd77f8..8458d71 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -55,7 +55,7 @@ namespace mgl { const char *class_name = nullptr; mgl_window_type window_type = MGL_WINDOW_TYPE_NORMAL; WindowHandle transient_for_window = 0; /* 0 = none */ - mgl_render_api render_api = MGL_RENDER_API_GLX; + mgl_graphics_api graphics_api = MGL_GRAPHICS_API_EGL; }; Window(); @@ -123,6 +123,7 @@ namespace mgl { mgl_window* internal_window(); private: mgl_window window; + bool window_created = false; }; } diff --git a/meson.build b/meson.build index 258fae0..829957c 100644 --- a/meson.build +++ b/meson.build @@ -23,32 +23,6 @@ src = [ 'src/mglpp.cpp', ] -project_headers = [ - 'include/mglpp/graphics/Text.hpp', - 'include/mglpp/graphics/PrimitiveType.hpp', - 'include/mglpp/graphics/Vertex.hpp', - 'include/mglpp/graphics/Drawable.hpp', - 'include/mglpp/graphics/Texture.hpp', - 'include/mglpp/graphics/Shader.hpp', - 'include/mglpp/graphics/Sprite.hpp', - 'include/mglpp/graphics/Color.hpp', - 'include/mglpp/graphics/VertexBuffer.hpp', - 'include/mglpp/graphics/Image.hpp', - 'include/mglpp/graphics/Font.hpp', - 'include/mglpp/graphics/Rectangle.hpp', - 'include/mglpp/system/Utf8.hpp', - 'include/mglpp/system/vec.hpp', - 'include/mglpp/system/Clock.hpp', - 'include/mglpp/system/MemoryMappedFile.hpp', - 'include/mglpp/system/FloatRect.hpp', - 'include/mglpp/mglpp.hpp', - 'include/mglpp/window/Window.hpp', - 'include/mglpp/window/Mouse.hpp', - 'include/mglpp/window/Event.hpp', - 'include/mglpp/window/Keyboard.hpp', - 'include/mglpp/window/Clipboard.hpp', -] - mgl_proj = subproject('mgl') mgl_dep = mgl_proj.get_variable('mgl_dep') diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 3b1f410..e22bcfb 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -10,7 +10,8 @@ namespace mgl { Texture::Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options) { memset(&texture, 0, sizeof(mgl_texture)); const mgl_texture_reference_options texture_reference_options = { - reference_options.pixel_coordinates + reference_options.pixel_coordinates, + reference_options.scale_type }; mgl_texture_init_reference_existing_gl_texture(&texture, gl_texture_id, format, &texture_reference_options); } @@ -58,7 +59,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0) { @@ -79,7 +80,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0) { @@ -100,7 +101,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0) { diff --git a/src/mglpp.cpp b/src/mglpp.cpp index ca0845d..2f0670a 100644 --- a/src/mglpp.cpp +++ b/src/mglpp.cpp @@ -4,8 +4,8 @@ extern "C" { } namespace mgl { - Init::Init() { - if(mgl_init() != 0) + Init::Init(WindowSystem window_system) { + if(mgl_init((mgl_window_system)window_system) != 0) throw InitException(); } diff --git a/src/window/Window.cpp b/src/window/Window.cpp index ab42de0..fffacca 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -16,24 +16,34 @@ namespace mgl { } Window::Window() { - window.window = 0; + } Window::~Window() { - if(window.window) + if(window_created) mgl_window_deinit(&window); } bool Window::create(const char *title, CreateParams create_params) { - if(window.window) + if(window_created) return false; - return mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0; + + if(mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0) { + window_created = true; + return true; + } + return false; } bool Window::create(WindowHandle existing_window) { - if(window.window) + if(window_created) return false; - return mgl_window_init_from_existing_window(&window, existing_window) == 0; + + if(mgl_window_init_from_existing_window(&window, existing_window) == 0) { + window_created = true; + return true; + } + return false; } bool Window::poll_event(Event &event) { @@ -197,7 +207,7 @@ namespace mgl { } WindowHandle Window::get_system_handle() const { - return window.window; + return mgl_window_get_system_handle(&window); } mgl_window* Window::internal_window() { |