diff --git a/src/graphics/opengl/OpenGlInterface.cpp b/src/graphics/opengl/OpenGlInterface.cpp index b015bb0..7cf5781 100644 --- a/src/graphics/opengl/OpenGlInterface.cpp +++ b/src/graphics/opengl/OpenGlInterface.cpp @@ -14,7 +14,7 @@ void OpenGlInterface::draw() glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBegin(GL_TRIANGLES); - glVertex3f(-0.7, 0.7, 0); + glVertex3f(-0.7, 0.7, 0); glVertex3f(0.7, 0.7, 0); glVertex3f(0, -1, 0); glEnd(); diff --git a/src/windows/ui_interfaces/wayland/WaylandEglInterface.cpp b/src/windows/ui_interfaces/wayland/WaylandEglInterface.cpp index e69de29..34f2695 100644 --- a/src/windows/ui_interfaces/wayland/WaylandEglInterface.cpp +++ b/src/windows/ui_interfaces/wayland/WaylandEglInterface.cpp @@ -0,0 +1,73 @@ +#include "WaylandEglInterface.h" + +#include "FileLogger.h" + +#include + +void WaylandEglInterface::initialize(wl_display* display) +{ + mEglDisplay = eglGetDisplay((EGLNativeDisplayType) display); + if (mEglDisplay == EGL_NO_DISPLAY) + { + MLOG_ERROR("Can't create egl display") + return; + } + + EGLint major{0}; + EGLint minor{0}; + if (eglInitialize(mEglDisplay, &major, &minor) != EGL_TRUE) + { + MLOG_ERROR("Can't initialise egl display") + return; + } + + EGLint count{0}; + eglGetConfigs(mEglDisplay, nullptr, 0, &count); + + EGLConfig* configs; + configs = static_cast(calloc(count, sizeof* configs)); + + EGLint n{0}; + EGLint config_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + eglChooseConfig(mEglDisplay, config_attribs, configs, count, &n); + EGLint size{0}; + for (int i = 0; i < n; i++) + { + eglGetConfigAttrib(mEglDisplay, configs[i], EGL_BUFFER_SIZE, &size); + // printf("Buffer size for config %d is %d\n", i, size); + eglGetConfigAttrib(mEglDisplay, configs[i], EGL_RED_SIZE, &size); + // printf("Red size for config %d is %d\n", i, size); + + // just choose the first one + mEglConfig = configs[i]; + break; + } + + static const EGLint context_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, context_attribs); +} + +EGLDisplay WaylandEglInterface::getDisplay() const +{ + return mEglDisplay; +} + +EGLConfig WaylandEglInterface::getConfig() const +{ + return mEglConfig; +} + +EGLContext WaylandEglInterface::getContext() const +{ + return mEglContext; +} diff --git a/src/windows/ui_interfaces/wayland/WaylandEglInterface.h b/src/windows/ui_interfaces/wayland/WaylandEglInterface.h index c0d0285..cfc1e86 100644 --- a/src/windows/ui_interfaces/wayland/WaylandEglInterface.h +++ b/src/windows/ui_interfaces/wayland/WaylandEglInterface.h @@ -1,86 +1,20 @@ #pragma once -#include #include -#include + +struct wl_display; class WaylandEglInterface { public: - void initialize(wl_display* display) - { - mEglDisplay = eglGetDisplay((EGLNativeDisplayType) display); - if (mEglDisplay == EGL_NO_DISPLAY) - { - fprintf(stderr, "Can't create egl display\n"); - return; - } - else - { - fprintf(stderr, "Created egl display\n"); - } + void initialize(wl_display* display); - EGLint major{0}; - EGLint minor{0}; - if (eglInitialize(mEglDisplay, &major, &minor) != EGL_TRUE) - { - fprintf(stderr, "Can't initialise egl display\n"); - return; - } - printf("EGL major: %d, minor %d\n", major, minor); + EGLDisplay getDisplay() const; - EGLint count{0}; - eglGetConfigs(mEglDisplay, nullptr, 0, &count); - printf("EGL has %d configs\n", count); + EGLConfig getConfig() const; - EGLConfig* configs; - configs = static_cast(calloc(count, sizeof* configs)); - - EGLint n{0}; - EGLint config_attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - eglChooseConfig(mEglDisplay, config_attribs, configs, count, &n); - EGLint size{0}; - for (int i = 0; i < n; i++) - { - eglGetConfigAttrib(mEglDisplay, configs[i], EGL_BUFFER_SIZE, &size); - printf("Buffer size for config %d is %d\n", i, size); - eglGetConfigAttrib(mEglDisplay, configs[i], EGL_RED_SIZE, &size); - printf("Red size for config %d is %d\n", i, size); - - // just choose the first one - mEglConfig = configs[i]; - break; - } - - static const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, context_attribs); - } - - EGLDisplay getDisplay() const - { - return mEglDisplay; - } - - EGLConfig getConfig() const - { - return mEglConfig; - } - - EGLContext getContext() const - { - return mEglContext; - } + EGLContext getContext() const; private: EGLDisplay mEglDisplay; diff --git a/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.cpp b/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.cpp index e69de29..74d81d0 100644 --- a/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.cpp +++ b/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.cpp @@ -0,0 +1,80 @@ +#include "WaylandEglWindowInterface.h" + +#include "FileLogger.h" +#include "OpenGlInterface.h" + +#include + +WaylandEglWindowInterface::WaylandEglWindowInterface(WaylandEglInterface* eglInterface) + : mEglInterface(eglInterface) +{ + +} + +void WaylandEglWindowInterface::initialize(wl_surface* surface, int width, int height) +{ + if (mEglSurface) + { + return; + } + + mEglWindow = wl_egl_window_create(surface, width, height); + if (mEglWindow == EGL_NO_SURFACE) + { + MLOG_ERROR("Can't create egl window"); + return; + } + + mEglSurface = eglCreateWindowSurface(mEglInterface->getDisplay(), mEglInterface->getConfig(), reinterpret_cast(mEglWindow), nullptr); + + if (!mEglSurface) + { + switch(eglGetError()) + { + case EGL_BAD_DISPLAY: + fprintf(stderr, "EGL_BAD_DISPLAY\n"); + break; + case EGL_NOT_INITIALIZED: + fprintf(stderr, "EGL_NOT_INITIALIZED\n"); + break; + case EGL_BAD_CONFIG: + fprintf(stderr, "EGL_BAD_CONFIG\n"); + break; + case EGL_BAD_NATIVE_WINDOW: + fprintf(stderr, "EGL_BAD_NATIVE_WINDOW\n"); + break; + case EGL_BAD_ATTRIBUTE: + fprintf(stderr, "EGL_BAD_ATTRIBUTE\n"); + break; + case EGL_BAD_ALLOC: + fprintf(stderr, "EGL_BAD_ALLOC\n"); + break; + case EGL_BAD_MATCH: + fprintf(stderr, "EGL_BAD_MATCH\n"); + break; + default: + fprintf(stderr, "Unknown EGL error\n"); + } + MLOG_ERROR("Created surface failed"); + } +} + +void WaylandEglWindowInterface::draw() +{ + if (!mEglSurface) + { + return; + } + + if (!eglMakeCurrent(mEglInterface->getDisplay(), mEglSurface, mEglSurface, mEglInterface->getContext())) + { + MLOG_ERROR("Made current failed"); + } + + OpenGlInterface::draw(); + + if (!eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface)) + { + MLOG_ERROR("Swapped buffers failed"); + } +} diff --git a/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h b/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h index df9c869..31c7236 100644 --- a/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h +++ b/src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h @@ -2,104 +2,20 @@ #include "WaylandEglInterface.h" -#include #include -#include + +struct wl_egl_window; +struct wl_surface; class WaylandEglWindowInterface { public: - WaylandEglWindowInterface(WaylandEglInterface* eglInterface) - : mEglInterface(eglInterface) - { + WaylandEglWindowInterface(WaylandEglInterface* eglInterface); - } + void initialize(wl_surface* surface, int width, int height); - void initialize(wl_surface* surface, int width, int height) - { - if (mEglSurface) - { - return; - } - - mEglWindow = wl_egl_window_create(surface, width, height); - if (mEglWindow == EGL_NO_SURFACE) - { - fprintf(stderr, "Can't create egl window\n"); - return; - } - else - { - fprintf(stderr, "Created egl window\n"); - } - - mEglSurface = eglCreateWindowSurface(mEglInterface->getDisplay(), mEglInterface->getConfig(), mEglWindow, nullptr); - - if (!mEglSurface) - { - switch(eglGetError()) - { - //case EGL_NO_SURFACE: - //fprintf(stderr, "EGL_NO_SURFACE\n"); - //break; - case EGL_BAD_DISPLAY: - fprintf(stderr, "EGL_BAD_DISPLAY\n"); - break; - case EGL_NOT_INITIALIZED: - fprintf(stderr, "EGL_NOT_INITIALIZED\n"); - break; - case EGL_BAD_CONFIG: - fprintf(stderr, "EGL_BAD_CONFIG\n"); - break; - case EGL_BAD_NATIVE_WINDOW: - fprintf(stderr, "EGL_BAD_NATIVE_WINDOW\n"); - break; - case EGL_BAD_ATTRIBUTE: - fprintf(stderr, "EGL_BAD_ATTRIBUTE\n"); - break; - case EGL_BAD_ALLOC: - fprintf(stderr, "EGL_BAD_ALLOC\n"); - break; - case EGL_BAD_MATCH: - fprintf(stderr, "EGL_BAD_MATCH\n"); - break; - default: - fprintf(stderr, "Unknown EGL error\n"); - } - - fprintf(stderr, "Created surface failed\n"); - } - - } - - void draw() - { - if (!mEglSurface) - { - return; - } - - if (eglMakeCurrent(mEglInterface->getDisplay(), mEglSurface, mEglSurface, mEglInterface->getContext())) - { - fprintf(stderr, "Made current\n"); - } - else { - fprintf(stderr, "Made current failed\n"); - } - - glClearColor(1.0, 1.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glFlush(); - - if (eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface)) - { - fprintf(stderr, "Swapped buffers\n"); - } - else { - fprintf(stderr, "Swapped buffers failed\n"); - } - } + void draw(); private: wl_egl_window* mEglWindow{nullptr};