summaryrefslogtreecommitdiff
path: root/include/util/egl.hpp
blob: 05a137361c9f1757589f98d39cca7e13b9b093bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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