Clean up Wayland backend GL context and such
This commit is contained in:
parent
51f35e7af0
commit
c9d5a0b2fb
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -143,9 +144,9 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend_state* backend,
|
||||||
wlr_output->width = width;
|
wlr_output->width = width;
|
||||||
wlr_output->height = height;
|
wlr_output->height = height;
|
||||||
wlr_output->scale = 1;
|
wlr_output->scale = 1;
|
||||||
strncpy(wlr_output->make, "wayland-output", sizeof(wlr_output->make));
|
strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make));
|
||||||
strncpy(wlr_output->model, "wayland-output", sizeof(wlr_output->model));
|
strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model));
|
||||||
strncpy(wlr_output->name, "wayland-output", sizeof(wlr_output->name));
|
snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%d", 1);
|
||||||
|
|
||||||
struct wlr_output_mode mode = {
|
struct wlr_output_mode mode = {
|
||||||
.width = width,
|
.width = width,
|
||||||
|
|
|
@ -110,22 +110,22 @@ int main(int argc, char *argv[]) {
|
||||||
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
|
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
|
||||||
.clear_color = { 0.25f, 0.25f, 0.25f, 1 }
|
.clear_color = { 0.25f, 0.25f, 0.25f, 1 }
|
||||||
};
|
};
|
||||||
struct compositor_state compositor;
|
struct compositor_state compositor = { 0,
|
||||||
|
.data = &state,
|
||||||
|
.output_add_cb = handle_output_add,
|
||||||
|
.output_frame_cb = handle_output_frame,
|
||||||
|
.keyboard_key_cb = handle_keyboard_key,
|
||||||
|
.pointer_motion_cb = handle_pointer_motion,
|
||||||
|
.pointer_button_cb = handle_pointer_button,
|
||||||
|
.pointer_axis_cb = handle_pointer_axis,
|
||||||
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
compositor.output_add_cb = handle_output_add;
|
|
||||||
compositor.output_frame_cb = handle_output_frame;
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
||||||
compositor.pointer_motion_cb = handle_pointer_motion;
|
|
||||||
compositor.pointer_button_cb = handle_pointer_button;
|
|
||||||
compositor.pointer_axis_cb = handle_pointer_axis;
|
|
||||||
|
|
||||||
state.renderer = wlr_gles3_renderer_init();
|
state.renderer = wlr_gles3_renderer_init();
|
||||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||||
|
|
||||||
compositor.data = &state;
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
|
|
||||||
wlr_surface_destroy(state.cat_texture);
|
wlr_surface_destroy(state.cat_texture);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wayland-server-protocol.h>
|
#include <wayland-server-protocol.h>
|
||||||
|
@ -193,22 +194,23 @@ static void parse_args(int argc, char *argv[], struct wl_list *config) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct sample_state state = { 0 };
|
struct sample_state state = { 0 };
|
||||||
struct compositor_state compositor;
|
|
||||||
wl_list_init(&state.config);
|
wl_list_init(&state.config);
|
||||||
parse_args(argc, argv, &state.config);
|
parse_args(argc, argv, &state.config);
|
||||||
|
|
||||||
|
struct compositor_state compositor = { 0,
|
||||||
|
.data = &state,
|
||||||
|
.output_add_cb = handle_output_add,
|
||||||
|
.output_remove_cb = handle_output_remove,
|
||||||
|
.output_frame_cb = handle_output_frame,
|
||||||
|
.keyboard_key_cb = handle_keyboard_key,
|
||||||
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
compositor.output_add_cb = handle_output_add;
|
|
||||||
compositor.output_remove_cb = handle_output_remove;
|
|
||||||
compositor.output_frame_cb = handle_output_frame;
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
||||||
|
|
||||||
state.renderer = wlr_gles3_renderer_init();
|
state.renderer = wlr_gles3_renderer_init();
|
||||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||||
|
|
||||||
compositor.data = &state;
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
|
|
||||||
wlr_surface_destroy(state.cat_texture);
|
wlr_surface_destroy(state.cat_texture);
|
||||||
|
|
|
@ -418,8 +418,6 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void compositor_init(struct compositor_state *state) {
|
void compositor_init(struct compositor_state *state) {
|
||||||
memset(state, 0, sizeof(struct compositor_state));
|
|
||||||
|
|
||||||
state->display = wl_display_create();
|
state->display = wl_display_create();
|
||||||
state->event_loop = wl_display_get_event_loop(state->display);
|
state->event_loop = wl_display_get_event_loop(state->display);
|
||||||
state->session = wlr_session_start(state->display);
|
state->session = wlr_session_start(state->display);
|
||||||
|
@ -457,14 +455,14 @@ void compositor_init(struct compositor_state *state) {
|
||||||
state->backend = wlr;
|
state->backend = wlr;
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &state->last_frame);
|
clock_gettime(CLOCK_MONOTONIC, &state->last_frame);
|
||||||
}
|
|
||||||
|
|
||||||
void compositor_run(struct compositor_state *state) {
|
|
||||||
if (!wlr_backend_init(state->backend)) {
|
if (!wlr_backend_init(state->backend)) {
|
||||||
fprintf(stderr, "Failed to initialize backend\n");
|
fprintf(stderr, "Failed to initialize backend\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void compositor_run(struct compositor_state *state) {
|
||||||
while (!state->exit) {
|
while (!state->exit) {
|
||||||
wl_event_loop_dispatch(state->event_loop, 0);
|
wl_event_loop_dispatch(state->event_loop, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,11 @@ int main() {
|
||||||
.color = { 1.0, 0.0, 0.0 },
|
.color = { 1.0, 0.0, 0.0 },
|
||||||
.dec = 0,
|
.dec = 0,
|
||||||
};
|
};
|
||||||
struct compositor_state compositor;
|
struct compositor_state compositor = { 0,
|
||||||
|
.data = &state,
|
||||||
|
.output_frame_cb = handle_output_frame,
|
||||||
|
.keyboard_key_cb = handle_keyboard_key,
|
||||||
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
compositor.output_frame_cb = handle_output_frame;
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
||||||
compositor.data = &state;
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,19 +145,19 @@ int main(int argc, char *argv[]) {
|
||||||
.tool_color = { 1, 1, 1, 1 },
|
.tool_color = { 1, 1, 1, 1 },
|
||||||
.pad_color = { 0.75, 0.75, 0.75, 1.0 }
|
.pad_color = { 0.75, 0.75, 0.75, 1.0 }
|
||||||
};
|
};
|
||||||
struct compositor_state compositor;
|
struct compositor_state compositor = { 0,
|
||||||
|
.data = &state,
|
||||||
|
.output_frame_cb = handle_output_frame,
|
||||||
|
.keyboard_key_cb = handle_keyboard_key,
|
||||||
|
.tool_axis_cb = handle_tool_axis,
|
||||||
|
.tool_proximity_cb = handle_tool_proximity,
|
||||||
|
.tool_button_cb = handle_tool_button,
|
||||||
|
.pad_button_cb = handle_pad_button,
|
||||||
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
compositor.output_frame_cb = handle_output_frame;
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
||||||
compositor.tool_axis_cb = handle_tool_axis;
|
|
||||||
compositor.tool_proximity_cb = handle_tool_proximity;
|
|
||||||
compositor.tool_button_cb = handle_tool_button;
|
|
||||||
compositor.pad_button_cb = handle_pad_button;
|
|
||||||
|
|
||||||
state.renderer = wlr_gles3_renderer_init();
|
state.renderer = wlr_gles3_renderer_init();
|
||||||
|
|
||||||
compositor.data = &state;
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
|
|
||||||
wlr_renderer_destroy(state.renderer);
|
wlr_renderer_destroy(state.renderer);
|
||||||
|
|
|
@ -100,21 +100,21 @@ int main(int argc, char *argv[]) {
|
||||||
struct sample_state state = {
|
struct sample_state state = {
|
||||||
.touch_points = list_create()
|
.touch_points = list_create()
|
||||||
};
|
};
|
||||||
struct compositor_state compositor;
|
struct compositor_state compositor = { 0,
|
||||||
|
.data = &state,
|
||||||
|
.output_frame_cb = handle_output_frame,
|
||||||
|
.keyboard_key_cb = handle_keyboard_key,
|
||||||
|
.touch_down_cb = handle_touch_down,
|
||||||
|
.touch_up_cb = handle_touch_up,
|
||||||
|
.touch_motion_cb = handle_touch_motion,
|
||||||
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
compositor.output_frame_cb = handle_output_frame;
|
|
||||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
||||||
compositor.touch_down_cb = handle_touch_down;
|
|
||||||
compositor.touch_up_cb = handle_touch_up;
|
|
||||||
compositor.touch_motion_cb = handle_touch_motion;
|
|
||||||
|
|
||||||
state.renderer = wlr_gles3_renderer_init();
|
state.renderer = wlr_gles3_renderer_init();
|
||||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||||
|
|
||||||
compositor.data = &state;
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
|
|
||||||
wlr_surface_destroy(state.cat_texture);
|
wlr_surface_destroy(state.cat_texture);
|
||||||
|
|
|
@ -71,6 +71,7 @@ static void init_default_shaders() {
|
||||||
if (!compile_program(quad_vertex_src, ellipse_fragment_src, &shaders.ellipse)) {
|
if (!compile_program(quad_vertex_src, ellipse_fragment_src, &shaders.ellipse)) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
wlr_log(L_DEBUG, "Compiled default shaders");
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
wlr_log(L_ERROR, "Failed to set up default shaders!");
|
wlr_log(L_ERROR, "Failed to set up default shaders!");
|
||||||
|
@ -141,8 +142,10 @@ static bool wlr_gles3_render_surface(struct wlr_renderer_state *state,
|
||||||
GL_CALL(glUseProgram(shaders.rgba));
|
GL_CALL(glUseProgram(shaders.rgba));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
wlr_log(L_ERROR, "No shader for this surface format");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
gles3_flush_errors();
|
||||||
GL_CALL(glBindVertexArray(vao));
|
GL_CALL(glBindVertexArray(vao));
|
||||||
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, vbo));
|
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, vbo));
|
||||||
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo));
|
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo));
|
||||||
|
|
Loading…
Reference in New Issue