summaryrefslogtreecommitdiff
path: root/include/util/egl.hpp
diff options
context:
space:
mode:
authorpants <niklasjo2004@gmail.com>2026-09-21 14:18:06 -0700
committerpants <niklasjo2004@gmail.com>2026-09-21 14:18:06 -0700
commit83d5ba42f8a98fc0df177efef4333f74a0481f61 (patch)
tree6f1fcff64ec9adb2fc51a7cfcc451eb22a103fb3 /include/util/egl.hpp
Diffstat (limited to 'include/util/egl.hpp')
-rw-r--r--include/util/egl.hpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/util/egl.hpp b/include/util/egl.hpp
new file mode 100644
index 0000000..05a1373
--- /dev/null
+++ b/include/util/egl.hpp
@@ -0,0 +1,54 @@
+// Display images inside a terminal
+// Copyright (C) 2023 JustKidding
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#ifndef UTIL_EGL_H
+#define UTIL_EGL_H
+
+#include "image.hpp"
+
+#include <functional>
+#include <memory>
+
+#include <spdlog/fwd.h>
+
+#include <EGL/egl.h>
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+
+template <class T, class V>
+class EGLUtil
+{
+ public:
+ EGLUtil(EGLenum platform, T *native_display, const EGLAttrib *attrib = nullptr);
+ ~EGLUtil();
+
+ void get_texture_from_image(const Image &image, GLuint texture) const;
+ void run_contained(EGLSurface surface, EGLContext context, const std::function<void()> &func) const;
+ void make_current(EGLSurface surface, EGLContext context) const;
+ void restore() const;
+ [[nodiscard]] auto create_surface(V *native_window) const -> EGLSurface;
+ [[nodiscard]] auto create_context(EGLSurface surface) const -> EGLContext;
+
+ EGLDisplay display;
+
+ private:
+ EGLConfig config;
+ std::shared_ptr<spdlog::logger> logger;
+
+ [[nodiscard]] auto error_to_string() const -> std::string;
+};
+
+#endif