Some cleaning up.
This commit is contained in:
parent
6af296409a
commit
1180e576fa
5 changed files with 166 additions and 163 deletions
|
@ -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();
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#include "WaylandEglInterface.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
|
||||
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<EGLConfig*>(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;
|
||||
}
|
|
@ -1,86 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <wayland-egl.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
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<EGLConfig*>(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;
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
#include "WaylandEglWindowInterface.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "OpenGlInterface.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
|
||||
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<EGLNativeWindowType>(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");
|
||||
}
|
||||
}
|
|
@ -2,104 +2,20 @@
|
|||
|
||||
#include "WaylandEglInterface.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
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};
|
||||
|
|
Loading…
Reference in a new issue