project for a (works on my devices) demo
This commit is contained in:
76
SOURCES/graphics/library/application_context.c
Normal file
76
SOURCES/graphics/library/application_context.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "application_context.h"
|
||||
|
||||
#include "../os/WAYLAND/wl_context.h"
|
||||
#include "../os/EGL/egl_context.h"
|
||||
#include "../os/EGL/GLES_3_1_compatibility.h"
|
||||
#include <wayland-egl.h>
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
application_context* application_context_malloc(){
|
||||
application_context *app = malloc( sizeof( application_context));
|
||||
return app;
|
||||
}
|
||||
|
||||
application_context* application_context_new( const char *title){
|
||||
wl_context *wl;
|
||||
egl_context *egl;
|
||||
window *win;
|
||||
application_context *app;
|
||||
|
||||
app = application_context_malloc();
|
||||
/* get the builders and the display connection */
|
||||
wl = wl_context_new();
|
||||
app->w_context = wl;
|
||||
|
||||
|
||||
/* builds the minimal for a running */
|
||||
win = window_new(
|
||||
title,
|
||||
ui_dimensions_new(
|
||||
wl_context_get(GLUT_SCREEN_WIDTH),
|
||||
wl_context_get(GLUT_SCREEN_HEIGHT)
|
||||
),
|
||||
wl,
|
||||
app
|
||||
);
|
||||
|
||||
/* ??? allocates the required struct for binding a buffer to the wl_surface of the window's toplevel */
|
||||
app->win = win;
|
||||
app->running = 1;
|
||||
win->egl_window = wl_egl_window_create( win->surface, win->dimensions->w, win->dimensions->h);
|
||||
|
||||
/* EGL_NO_SURFACE */
|
||||
if (NULL == win->egl_window) {
|
||||
fprintf(stderr, "Couldn't create EGL window\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* gets the context for GLES2 graphics API */
|
||||
egl = egl_context_new( wl->display);
|
||||
app->e_context = egl;
|
||||
|
||||
win->egl_surface = eglCreateWindowSurface(
|
||||
egl->display,
|
||||
egl->config,
|
||||
(EGLNativeWindowType) win->egl_window,
|
||||
NULL
|
||||
);
|
||||
if( EGL_NO_SURFACE == win->egl_surface) {
|
||||
fprintf(stderr, "Couldn't create EGL surface\n");
|
||||
printEGLError();
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if( ! eglMakeCurrent(egl->display, win->egl_surface, win->egl_surface, egl->context)) {
|
||||
fprintf(stderr, "Couldn't make EGL context current\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
GLES_3_1_compatibility_init();
|
||||
|
||||
return app;
|
||||
}
|
||||
18
SOURCES/graphics/library/application_context.h
Normal file
18
SOURCES/graphics/library/application_context.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "../os/WAYLAND/wl_context.h"
|
||||
#include "../os/EGL/egl_context.h"
|
||||
|
||||
#include "window/window.h"
|
||||
|
||||
typedef struct {
|
||||
wl_context *w_context;
|
||||
egl_context *e_context;
|
||||
window *win;
|
||||
|
||||
uint8_t running;
|
||||
} application_context;
|
||||
|
||||
application_context *application_context_malloc();
|
||||
|
||||
application_context* application_context_new( const char *title);
|
||||
116
SOURCES/graphics/library/window/window.c
Normal file
116
SOURCES/graphics/library/window/window.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "window.h"
|
||||
#include "../application_context.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <wayland-egl.h>
|
||||
|
||||
|
||||
/******************************/
|
||||
/********XDG surface **********/
|
||||
/******************************/
|
||||
|
||||
/* listener bound to the various xdg_surfaces for listening to "configure" events
|
||||
the client should rearrange its surfaces to accomodate the new state
|
||||
the client should answer to (ACK) the event
|
||||
*/
|
||||
void surface_configure(void *data, struct xdg_surface *xdg_surface,
|
||||
uint32_t serial) {
|
||||
(void) data;
|
||||
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
}
|
||||
|
||||
/*
|
||||
listener to be bound on XDG surfaces
|
||||
|
||||
the only event declared by the xdg_surface is the "configure" one
|
||||
indicates the hint for the client to update the arrangement of surfaces ( i.e. change of resolution )
|
||||
*/
|
||||
const struct xdg_surface_listener surface_listener = {
|
||||
surface_configure
|
||||
};
|
||||
|
||||
/******************************/
|
||||
/********XDG Toplevel**********/
|
||||
/******************************/
|
||||
|
||||
/* listener bound to the toplevel surface
|
||||
the toplevel may raise a "configure" event, which hints the client about reconfiguring its state
|
||||
|
||||
here we propagate the new width and height to the EGL window ( probably for readjusting buffers )
|
||||
*/
|
||||
void toplevel_configure(
|
||||
void *data,
|
||||
struct xdg_toplevel *xdg_toplevel,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
struct wl_array *states
|
||||
) {
|
||||
(void) states;
|
||||
window *win = data;
|
||||
|
||||
if( ! win || win->xdg_toplevel != xdg_toplevel){
|
||||
fprintf(stderr, "inconsistency during toplevel configure\n");
|
||||
fprintf(stderr, "window->xdg_toplevel %p\nxdg_toplevel %p\n",
|
||||
(void*) win->xdg_toplevel,
|
||||
(void*) xdg_toplevel
|
||||
);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(!width && !height) return;
|
||||
|
||||
if( win->dimensions->w != width || win->dimensions->h != height) {
|
||||
win->dimensions->w = width;
|
||||
win->dimensions->h = height;
|
||||
|
||||
wl_egl_window_resize(win->egl_window, width, height, 0, 0);
|
||||
wl_surface_commit(win->surface);
|
||||
}
|
||||
}
|
||||
|
||||
void toplevel_close( void *data, struct xdg_toplevel *xdg_toplevel) {
|
||||
(void) xdg_toplevel;
|
||||
|
||||
application_context *app = data;
|
||||
|
||||
app->running = 0;
|
||||
}
|
||||
|
||||
const struct xdg_toplevel_listener toplevel_listener = {
|
||||
toplevel_configure,
|
||||
toplevel_close
|
||||
};
|
||||
|
||||
/******************************/
|
||||
/************APIs**************/
|
||||
/******************************/
|
||||
|
||||
window* window_malloc(){
|
||||
return malloc( sizeof( window));
|
||||
}
|
||||
|
||||
|
||||
window* window_new(
|
||||
const char *title,
|
||||
ui_dimensions *dim,
|
||||
wl_context *w,
|
||||
void *app
|
||||
){
|
||||
window *win = window_malloc();
|
||||
|
||||
win->egl_window = NULL;
|
||||
win->egl_surface = NULL;
|
||||
|
||||
win->dimensions = dim;
|
||||
|
||||
win->surface = wl_compositor_create_surface( w->builders->compositor);
|
||||
win->xdg_surface = xdg_wm_base_get_xdg_surface( w->builders->xdg_wm_base, win->surface);
|
||||
xdg_surface_add_listener( win->xdg_surface, &surface_listener, NULL);
|
||||
win->xdg_toplevel = xdg_surface_get_toplevel( win->xdg_surface);
|
||||
xdg_toplevel_set_title( win->xdg_toplevel, title);
|
||||
xdg_toplevel_add_listener( win->xdg_toplevel, &toplevel_listener, win);
|
||||
wl_surface_commit( win->surface);
|
||||
return win;
|
||||
}
|
||||
36
SOURCES/graphics/library/window/window.h
Normal file
36
SOURCES/graphics/library/window/window.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include "../../os/WAYLAND/wl_context.h"
|
||||
#include "../../2d_structs.h"
|
||||
#include "../../os/WAYLAND/xdg-shell.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
ui_dimensions *dimensions;
|
||||
|
||||
struct wl_surface *surface;
|
||||
struct xdg_surface *xdg_surface;
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
|
||||
/**/
|
||||
struct wl_egl_window *egl_window;
|
||||
EGLSurface *egl_surface;
|
||||
} window;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window *window_malloc();
|
||||
|
||||
/* the toplevel listener registration callback offers a void* arg for passing data inside the callback (our app state in this case, waiting for narrowing) */
|
||||
window *window_new(
|
||||
const char *title,
|
||||
ui_dimensions *dim,
|
||||
wl_context *w,
|
||||
void *app
|
||||
);
|
||||
Reference in New Issue
Block a user