summaryrefslogtreecommitdiff
path: root/kmscube
diff options
context:
space:
mode:
Diffstat (limited to 'kmscube')
-rw-r--r--kmscube/cube-wl.cpp64
1 files changed, 25 insertions, 39 deletions
diff --git a/kmscube/cube-wl.cpp b/kmscube/cube-wl.cpp
index c8dfa56..de75f88 100644
--- a/kmscube/cube-wl.cpp
+++ b/kmscube/cube-wl.cpp
@@ -2,22 +2,21 @@
#include <wayland-client.h>
#include <wayland-egl.h>
-#include <EGL/egl.h>
-#include <GL/gl.h>
-
#include <string.h>
+#include <stdio.h>
+
+#include "cube.h"
+#include "cube-egl.h"
+#include "cube-gles2.h"
static struct wl_compositor *s_compositor = NULL;
static struct wl_shell *s_shell = NULL;
-static EGLDisplay s_egl_display;
static char s_running = 1;
struct window {
- EGLContext egl_context;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
struct wl_egl_window *egl_window;
- EGLSurface egl_surface;
};
// listeners
@@ -53,70 +52,57 @@ static void shell_surface_popup_done(void *data, struct wl_shell_surface *shell_
}
-static struct wl_shell_surface_listener shell_surface_listener = { &shell_surface_ping, &shell_surface_configure, &shell_surface_popup_done };
+static struct wl_shell_surface_listener shell_surface_listener = {
+ &shell_surface_ping, &shell_surface_configure, &shell_surface_popup_done
+};
static void create_window(struct window *window, int32_t width, int32_t height)
{
- eglBindAPI(EGL_OPENGL_API);
- EGLint attributes[] = {
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_NONE
- };
- EGLConfig config;
- EGLint num_config;
- eglChooseConfig(s_egl_display, attributes, &config, 1, &num_config);
- window->egl_context = eglCreateContext(s_egl_display, config, EGL_NO_CONTEXT, NULL);
-
window->surface = wl_compositor_create_surface(s_compositor);
window->shell_surface = wl_shell_get_shell_surface(s_shell, window->surface);
wl_shell_surface_add_listener(window->shell_surface, &shell_surface_listener, window);
wl_shell_surface_set_toplevel(window->shell_surface);
window->egl_window = wl_egl_window_create(window->surface, width, height);
- window->egl_surface = eglCreateWindowSurface(s_egl_display, config, window->egl_window, NULL);
- eglMakeCurrent(s_egl_display, window->egl_surface, window->egl_surface, window->egl_context);
}
static void delete_window(struct window *window)
{
- eglDestroySurface(s_egl_display, window->egl_surface);
wl_egl_window_destroy(window->egl_window);
wl_shell_surface_destroy(window->shell_surface);
wl_surface_destroy(window->surface);
- eglDestroyContext(s_egl_display, window->egl_context);
-}
-
-static void draw_window(struct window *window)
-{
- glClearColor(0.0, 1.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- eglSwapBuffers(s_egl_display, window->egl_surface);
}
-int main_wl()
+void main_wl()
{
struct wl_display *display = wl_display_connect(NULL);
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(display);
- s_egl_display = eglGetDisplay(display);
- eglInitialize(s_egl_display, NULL, NULL);
-
uint32_t width = 600;
uint32_t height = 600;
struct window window;
create_window(&window, width, height);
- while (s_running) {
- wl_display_dispatch_pending(display);
- draw_window(&window);
+ {
+ EglState egl(display);
+ EglSurface surface(egl, window.egl_window);
+ GlScene scene;
+
+ scene.set_viewport(width, height);
+
+ int framenum = 0;
+
+ while (s_running) {
+ wl_display_dispatch_pending(display);
+
+ surface.make_current();
+ scene.draw(framenum++);
+ surface.swap_buffers();
+ }
}
delete_window(&window);
- eglTerminate(s_egl_display);
wl_display_disconnect(display);
- return 0;
}