mirror of
https://github.com/swaywm/sway.git
synced 2026-04-22 06:46:27 -04:00
small update + added test lines
This commit is contained in:
parent
ed98da84bb
commit
6ec9622ac6
4 changed files with 936 additions and 896 deletions
|
|
@ -14,7 +14,9 @@ struct gles2_tex_shader {
|
||||||
|
|
||||||
struct gles2_renderer {
|
struct gles2_renderer {
|
||||||
struct wlr_egl *egl;
|
struct wlr_egl *egl;
|
||||||
|
|
||||||
float projection[9];
|
float projection[9];
|
||||||
|
|
||||||
uint32_t viewport_width;
|
uint32_t viewport_width;
|
||||||
uint32_t viewport_height;
|
uint32_t viewport_height;
|
||||||
|
|
||||||
|
|
@ -32,4 +34,6 @@ struct gles2_renderer {
|
||||||
} shaders;
|
} shaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gles2_renderer *gles2_renderer_create(struct wlr_egl *egl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wlr/backend.h> // TODO: remove if removed from renderer_init
|
#include <wlr/render/egl.h>
|
||||||
#include <wlr/render/egl.h> // TODO: remove if removed from renderer_init
|
|
||||||
#include <wlr/types/wlr_matrix.h>
|
#include <wlr/types/wlr_matrix.h>
|
||||||
#include <wlr/util/box.h>
|
#include <wlr/util/box.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
@ -91,7 +90,7 @@ const GLchar tex_fragment_src_external[] =
|
||||||
/************************
|
/************************
|
||||||
Matrix Consts
|
Matrix Consts
|
||||||
*************************/
|
*************************/
|
||||||
|
/*
|
||||||
static const GLfloat flip_180[] = {
|
static const GLfloat flip_180[] = {
|
||||||
1.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f,
|
||||||
0.0f, -1.0f, 0.0f,
|
0.0f, -1.0f, 0.0f,
|
||||||
|
|
@ -104,7 +103,7 @@ static const GLfloat verts[] = {
|
||||||
1, 1, // bottom right
|
1, 1, // bottom right
|
||||||
0, 1, // bottom left
|
0, 1, // bottom left
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
/************************
|
/************************
|
||||||
General Functions
|
General Functions
|
||||||
*************************/
|
*************************/
|
||||||
|
|
@ -159,11 +158,12 @@ error:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gles2_renderer *gles2_renderer_create(struct wlr_backend *backend) {
|
struct gles2_renderer *gles2_renderer_create(struct wlr_egl *egl) {
|
||||||
// TODO: Hyprland way?
|
// TODO: Hyprland way?
|
||||||
// TODO: handle case of no drm_fd?
|
// TODO: handle case of no drm_fd?
|
||||||
int drm_fd = wlr_backend_get_drm_fd(backend);
|
//struct wlr_egl *egl = wlr_egl_create_with_drm_fd(drm_fd);
|
||||||
struct wlr_egl *egl = wlr_egl_create_with_drm_fd(drm_fd);
|
//struct wlr_egl *egl = wlr_egl_create_with_context(${1:EGLDisplay display}, ${2:EGLContext context});
|
||||||
|
|
||||||
if (egl == NULL) {
|
if (egl == NULL) {
|
||||||
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not initialize EGL");
|
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not initialize EGL");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -260,22 +260,41 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
// TODO: is gles2_get_renderer_in_context(wlr_renderer) implementation needed?
|
// TODO: is gles2_get_renderer_in_context(wlr_renderer) implementation needed?
|
||||||
static void gles2_begin(struct gles2_renderer *renderer, uint32_t width, uint32_t height) {
|
static void gles2_begin(struct gles2_renderer *renderer, uint32_t width,
|
||||||
glViewport(0, 0, width, height);
|
uint32_t height) { glViewport(0, 0, width, height); renderer->viewport_width =
|
||||||
renderer->viewport_width = width;
|
width; renderer->viewport_height = height;
|
||||||
renderer->viewport_height = height;
|
|
||||||
|
|
||||||
// refresh projection matrix
|
// refresh projection matrix
|
||||||
wlr_matrix_projection(renderer->projection, width, height, WL_OUTPUT_TRANSFORM_NORMAL);
|
wlr_matrix_projection(renderer->projection, width, height,
|
||||||
|
WL_OUTPUT_TRANSFORM_NORMAL);
|
||||||
|
|
||||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void gles2_clear(const float color[static 4]) {
|
||||||
|
glClearColor(color[0], color[1], color[2], color[3]);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gles2_scissor(struct wlr_box *box) {
|
||||||
|
if (box) {
|
||||||
|
glScissor(box->x, box->y, box->width, box->height);
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
} else {
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
Rendering Functions
|
Rendering Functions
|
||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
|
/*
|
||||||
static void gles2_render_rect(struct gles2_renderer *renderer, const struct wlr_box *box, const float color[static 4], const float projection[static 9]) {
|
static void gles2_render_rect(struct gles2_renderer *renderer, const struct wlr_box *box, const float color[static 4], const float projection[static 9]) {
|
||||||
if (box->width == 0 || box->height == 0) {
|
if (box->width == 0 || box->height == 0) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -310,3 +329,5 @@ static void gles2_render_rect(struct gles2_renderer *renderer, const struct wlr_
|
||||||
|
|
||||||
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/backend/drm.h>
|
#include <wlr/backend/drm.h>
|
||||||
#include <wlr/backend/headless.h>
|
#include <wlr/backend/headless.h>
|
||||||
|
#include <wlr/render/gles2.h> // TODO: remove if no egl needed to init custom renderer
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_buffer.h>
|
#include <wlr/types/wlr_buffer.h>
|
||||||
#include <wlr/types/wlr_drm_lease_v1.h>
|
#include <wlr/types/wlr_drm_lease_v1.h>
|
||||||
|
|
@ -32,6 +33,8 @@
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
|
|
||||||
|
#include "sway/desktop/opengl.h"
|
||||||
|
|
||||||
struct sway_output *output_by_name_or_id(const char *name_or_id) {
|
struct sway_output *output_by_name_or_id(const char *name_or_id) {
|
||||||
for (int i = 0; i < root->outputs->length; ++i) {
|
for (int i = 0; i < root->outputs->length; ++i) {
|
||||||
struct sway_output *output = root->outputs->items[i];
|
struct sway_output *output = root->outputs->items[i];
|
||||||
|
|
@ -841,6 +844,8 @@ static void handle_present(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
static unsigned int last_headless_num = 0;
|
static unsigned int last_headless_num = 0;
|
||||||
|
|
||||||
|
// TODO: rm comment
|
||||||
|
// hyprland Monitors.cpp: listener_newOutput
|
||||||
void handle_new_output(struct wl_listener *listener, void *data) {
|
void handle_new_output(struct wl_listener *listener, void *data) {
|
||||||
struct sway_server *server = wl_container_of(listener, server, new_output);
|
struct sway_server *server = wl_container_of(listener, server, new_output);
|
||||||
struct wlr_output *wlr_output = data;
|
struct wlr_output *wlr_output = data;
|
||||||
|
|
@ -873,6 +878,14 @@ void handle_new_output(struct wl_listener *listener, void *data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move me to proper spot
|
||||||
|
// TODO: reference wlroots render/wlr_renderer.c: wlr_renderer_autocreate
|
||||||
|
struct wlr_egl *egl = wlr_gles2_renderer_get_egl(server->renderer);
|
||||||
|
struct gles2_renderer *test = gles2_renderer_create(egl);
|
||||||
|
if (!test) {
|
||||||
|
printf("gles2_renderer is null");
|
||||||
|
}
|
||||||
|
|
||||||
struct sway_output *output = output_create(wlr_output);
|
struct sway_output *output = output_create(wlr_output);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ static int scale_length(int length, int offset, float scale) {
|
||||||
|
|
||||||
static void scissor_output(struct wlr_output *wlr_output,
|
static void scissor_output(struct wlr_output *wlr_output,
|
||||||
pixman_box32_t *rect) {
|
pixman_box32_t *rect) {
|
||||||
// TODO: Add assert for OpenGL renderer? Check main branch code + hyprland
|
struct wlr_renderer *renderer = wlr_output->renderer;
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
.x = rect->x1,
|
.x = rect->x1,
|
||||||
|
|
@ -69,8 +70,7 @@ static void scissor_output(struct wlr_output *wlr_output,
|
||||||
wlr_output_transform_invert(wlr_output->transform);
|
wlr_output_transform_invert(wlr_output->transform);
|
||||||
wlr_box_transform(&box, &box, transform, ow, oh);
|
wlr_box_transform(&box, &box, transform, ow, oh);
|
||||||
|
|
||||||
glScissor(box.x, box.y, box.width, box.height);
|
wlr_renderer_scissor(renderer, &box);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_scale_filter(struct wlr_output *wlr_output,
|
static void set_scale_filter(struct wlr_output *wlr_output,
|
||||||
|
|
@ -218,6 +218,7 @@ void render_rect(struct sway_output *output,
|
||||||
pixman_region32_t *output_damage, const struct wlr_box *_box,
|
pixman_region32_t *output_damage, const struct wlr_box *_box,
|
||||||
float color[static 4]) {
|
float color[static 4]) {
|
||||||
struct wlr_output *wlr_output = output->wlr_output;
|
struct wlr_output *wlr_output = output->wlr_output;
|
||||||
|
struct wlr_renderer *renderer = wlr_output->renderer;
|
||||||
|
|
||||||
struct wlr_box box;
|
struct wlr_box box;
|
||||||
memcpy(&box, _box, sizeof(struct wlr_box));
|
memcpy(&box, _box, sizeof(struct wlr_box));
|
||||||
|
|
@ -238,7 +239,8 @@ void render_rect(struct sway_output *output,
|
||||||
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
|
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
|
||||||
for (int i = 0; i < nrects; ++i) {
|
for (int i = 0; i < nrects; ++i) {
|
||||||
scissor_output(wlr_output, &rects[i]);
|
scissor_output(wlr_output, &rects[i]);
|
||||||
gles2_render_rect(&box, color, wlr_output->transform_matrix);
|
wlr_render_rect(renderer, &box, color,
|
||||||
|
wlr_output->transform_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
damage_finish:
|
damage_finish:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue