Change library to make it less buggy when destroying objects
# Conflicts: # include/window.hpp # src/window.cpp
This commit is contained in:
		
					parent
					
						
							
								32b6c523c3
							
						
					
				
			
			
				commit
				
					
						bc12874c80
					
				
			
		
					 5 changed files with 71 additions and 52 deletions
				
			
		
							
								
								
									
										22
									
								
								include/context_window.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								include/context_window.hpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
#ifndef SCRATCHBSDF_CONTEXT_WINDOW_HPP
 | 
			
		||||
#define SCRATCHBSDF_CONTEXT_WINDOW_HPP
 | 
			
		||||
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
 | 
			
		||||
namespace window {
 | 
			
		||||
    class ContextWindow final {
 | 
			
		||||
    private:
 | 
			
		||||
        bool init{ false };
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        ContextWindow() noexcept = delete;
 | 
			
		||||
 | 
			
		||||
        explicit ContextWindow(const GLFWerrorfun error_clbk) noexcept;
 | 
			
		||||
 | 
			
		||||
        ~ContextWindow() noexcept;
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] inline bool is_init() const { return init; }
 | 
			
		||||
    };
 | 
			
		||||
} // window
 | 
			
		||||
 | 
			
		||||
#endif //SCRATCHBSDF_CONTEXT_WINDOW_HPP
 | 
			
		||||
| 
						 | 
				
			
			@ -28,39 +28,33 @@ namespace gui {
 | 
			
		|||
 | 
			
		||||
        static void window_pos_callback(GLFWwindow *window, int xpos, int ypos);
 | 
			
		||||
 | 
			
		||||
        static void delete_glfw_window(GLFWwindow *glfWwindow) {
 | 
			
		||||
            glfwDestroyWindow(glfWwindow);
 | 
			
		||||
            glfwTerminate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        static std::uint_fast8_t count_instance;
 | 
			
		||||
 | 
			
		||||
        std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> wwindow{ nullptr, delete_glfw_window };
 | 
			
		||||
        std::unique_ptr<GLFWwindow, decltype(&glfwDestroyWindow)> wwindow{ nullptr, glfwDestroyWindow };
 | 
			
		||||
 | 
			
		||||
        modulesType modules;
 | 
			
		||||
 | 
			
		||||
        bool valid{ false };
 | 
			
		||||
 | 
			
		||||
        explicit Window(const bool debugOpengl,
 | 
			
		||||
                        const GLFWframebuffersizefun framebufferCallback,
 | 
			
		||||
                        GLFWwindow *shared,
 | 
			
		||||
                        std::initializer_list<modulesType::value_type> initializer);
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        [[nodiscard]] static bool init_glfw(GLFWerrorfun errorCallback) noexcept;
 | 
			
		||||
 | 
			
		||||
        Window() noexcept = delete;
 | 
			
		||||
 | 
			
		||||
        Window(Window &&window) noexcept = default;
 | 
			
		||||
        Window(const Window &) = delete;
 | 
			
		||||
 | 
			
		||||
        Window(Window &&window) noexcept;
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] static std::optional<Window> create_window(
 | 
			
		||||
            const GLFWerrorfun errorCallback,
 | 
			
		||||
            GLFWframebuffersizefun framebufferCallback,
 | 
			
		||||
            const bool debugOpengl,
 | 
			
		||||
            GLFWwindow *shared,
 | 
			
		||||
            std::initializer_list<modulesType::value_type> initializer) noexcept;
 | 
			
		||||
 | 
			
		||||
        ~Window() noexcept;
 | 
			
		||||
        ~Window() noexcept = default;
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] const std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> &get_window() const noexcept;
 | 
			
		||||
        [[nodiscard]] const std::unique_ptr<GLFWwindow, decltype(&glfwDestroyWindow)> &get_window() const noexcept;
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] bool should_close() const noexcept;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +69,9 @@ namespace gui {
 | 
			
		|||
         */
 | 
			
		||||
        void get_context() const noexcept;
 | 
			
		||||
 | 
			
		||||
        Window &operator=(Window &&other) noexcept = default;
 | 
			
		||||
        Window &operator=(const Window &) = delete;
 | 
			
		||||
 | 
			
		||||
        Window &operator=(Window &&other) noexcept;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    void color_10_bits() noexcept;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue