|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
#include "LunarWM_wayland.h"
|
|
|
|
#include "LunarWM_wayland.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "LunarWM_render.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "vec.h"
|
|
|
|
#include "vec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <wlr/render/pass.h>
|
|
|
|
|
|
|
|
#include <wlr/render/color.h>
|
|
|
|
#include <wlr/render/color.h>
|
|
|
|
|
|
|
|
#include <wlr/render/pass.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <math.h>
|
|
|
|
@@ -18,6 +20,8 @@
|
|
|
|
#include <xkbcommon/xkbcommon-keysyms.h>
|
|
|
|
#include <xkbcommon/xkbcommon-keysyms.h>
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <rlgl.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_new_output(struct wl_listener *listener, void *data);
|
|
|
|
static void handle_new_output(struct wl_listener *listener, void *data);
|
|
|
|
static void handle_output_frame(struct wl_listener *listener, void *data);
|
|
|
|
static void handle_output_frame(struct wl_listener *listener, void *data);
|
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data);
|
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data);
|
|
|
|
@@ -1488,7 +1492,8 @@ static void setup_xwayland(LunarWM *this)
|
|
|
|
wl_signal_add(&this->wayland.xwayland->events.new_surface,
|
|
|
|
wl_signal_add(&this->wayland.xwayland->events.new_surface,
|
|
|
|
&this->wayland.xwayland_new_surface);
|
|
|
|
&this->wayland.xwayland_new_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void destroy_output(LunarWM_Output *output) {
|
|
|
|
static void destroy_output(LunarWM_Output *output)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!output) {
|
|
|
|
if (!output) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1503,7 +1508,8 @@ static void destroy_output(LunarWM_Output *output) {
|
|
|
|
free(output);
|
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)data;
|
|
|
|
LunarWM_Output *output = wl_container_of(listener, output, destroy);
|
|
|
|
LunarWM_Output *output = wl_container_of(listener, output, destroy);
|
|
|
|
LunarWM *wm = output->wm;
|
|
|
|
LunarWM *wm = output->wm;
|
|
|
|
@@ -1520,7 +1526,8 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
destroy_output(output);
|
|
|
|
destroy_output(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_output_frame(struct wl_listener *listener, void *data) {
|
|
|
|
static void handle_output_frame(struct wl_listener *listener, void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)data;
|
|
|
|
LunarWM_Output *output = wl_container_of(listener, output, frame);
|
|
|
|
LunarWM_Output *output = wl_container_of(listener, output, frame);
|
|
|
|
LunarWM *wm = output->wm;
|
|
|
|
LunarWM *wm = output->wm;
|
|
|
|
@@ -1534,6 +1541,9 @@ static void handle_output_frame(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_output_state state;
|
|
|
|
struct wlr_output_state state;
|
|
|
|
wlr_output_state_init(&state);
|
|
|
|
wlr_output_state_init(&state);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
wlr_output_effective_resolution(wlr_output, &width, &height);
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_render_pass *pass
|
|
|
|
struct wlr_render_pass *pass
|
|
|
|
= wlr_output_begin_render_pass(wlr_output, &state, NULL);
|
|
|
|
= wlr_output_begin_render_pass(wlr_output, &state, NULL);
|
|
|
|
if (pass == NULL) {
|
|
|
|
if (pass == NULL) {
|
|
|
|
@@ -1544,21 +1554,16 @@ static void handle_output_frame(struct wl_listener *listener, void *data) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_box box = {
|
|
|
|
GLint drawFboId = 0, readFboId = 0;
|
|
|
|
.x = 0,
|
|
|
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
|
|
|
|
.y = 0,
|
|
|
|
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFboId);
|
|
|
|
.width = wlr_output->width,
|
|
|
|
|
|
|
|
.height = wlr_output->height,
|
|
|
|
rlMatrixMode(RL_MODELVIEW);
|
|
|
|
};
|
|
|
|
rlLoadIdentity();
|
|
|
|
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
|
|
|
|
|
|
|
.box = box,
|
|
|
|
// if (!IsTextureValid(wm->renderer.main_rt.texture)) {
|
|
|
|
.color = {
|
|
|
|
// wm->renderer.main_rt = LoadRenderTexture(width, height);
|
|
|
|
.r = 1.0f,
|
|
|
|
// }
|
|
|
|
.g = 0.0f,
|
|
|
|
|
|
|
|
.b = 0.0f,
|
|
|
|
|
|
|
|
.a = 1.0f,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!wlr_render_pass_submit(pass)) {
|
|
|
|
if (!wlr_render_pass_submit(pass)) {
|
|
|
|
wlr_output_state_finish(&state);
|
|
|
|
wlr_output_state_finish(&state);
|
|
|
|
@@ -1576,17 +1581,82 @@ static void handle_output_frame(struct wl_listener *listener, void *data) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.id = drawFboId;
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.texture = (Texture) {
|
|
|
|
|
|
|
|
.id = drawFboId,
|
|
|
|
|
|
|
|
.width = width,
|
|
|
|
|
|
|
|
.height = height,
|
|
|
|
|
|
|
|
.mipmaps = 1,
|
|
|
|
|
|
|
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!IsRenderTextureValid(wm->renderer.tmp_rt)) {
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.depth.id = rlLoadTextureDepth(width, height, true);
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.depth.width = width;
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.depth.height = height;
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.depth.format = 19; // DEPTH_COMPONENT_24BIT?
|
|
|
|
|
|
|
|
wm->renderer.tmp_rt.depth.mipmaps = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rlFramebufferAttach(wm->renderer.tmp_rt.id, wm->renderer.tmp_rt.depth.id,
|
|
|
|
|
|
|
|
RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!IsTextureValid(wm->renderer.main_rt.texture)) {
|
|
|
|
|
|
|
|
wm->renderer.main_rt = LoadRenderTexture(width, height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int const hud_size = wm->cman->cfg.displays.hud.size;
|
|
|
|
|
|
|
|
if (!IsTextureValid(wm->renderer.hud_rt.texture)) {
|
|
|
|
|
|
|
|
wm->renderer.hud_rt = LoadRenderTexture(hud_size, hud_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BeginTextureMode(wm->renderer.hud_rt);
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LunarWM_render_hud(wm, GetFrameTime(), 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
EndTextureMode();
|
|
|
|
|
|
|
|
BeginTextureMode(wm->renderer.main_rt);
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BeginMode3D(wm->renderer.camera);
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ClearBackground(BLACK);
|
|
|
|
|
|
|
|
LunarWM_render_3d(wm, GetFrameTime());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
EndMode3D();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rlDrawRenderBatchActive();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
EndTextureMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BeginTextureMode(wm->renderer.tmp_rt);
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DrawTexturePro(wm->renderer.main_rt.texture,
|
|
|
|
|
|
|
|
(Rectangle) {
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
wm->renderer.main_rt.texture.width,
|
|
|
|
|
|
|
|
wm->renderer.main_rt.texture.height,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(Rectangle) {
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
wm->renderer.main_rt.texture.width,
|
|
|
|
|
|
|
|
-wm->renderer.main_rt.texture.height,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(Vector2) { 0, 0 }, 0, WHITE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
EndTextureMode();
|
|
|
|
|
|
|
|
|
|
|
|
wlr_output_state_finish(&state);
|
|
|
|
wlr_output_state_finish(&state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_new_output(struct wl_listener *listener, void *data) {
|
|
|
|
static void handle_new_output(struct wl_listener *listener, void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct wlr_output *wlr_output = data;
|
|
|
|
struct wlr_output *wlr_output = data;
|
|
|
|
LunarWM *wm = wl_container_of(listener, wm, wayland.new_output_listener);
|
|
|
|
LunarWM *wm = wl_container_of(listener, wm, wayland.new_output_listener);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(WLR_INFO, "Got new output.");
|
|
|
|
|
|
|
|
|
|
|
|
if (!wlr_output_init_render(
|
|
|
|
if (!wlr_output_init_render(
|
|
|
|
wlr_output, wm->wayland.allocator, wm->wayland.renderer)) {
|
|
|
|
wlr_output, wm->wayland.allocator, wm->wayland.renderer)) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to init render for output %s",
|
|
|
|
wlr_log(
|
|
|
|
wlr_output->name);
|
|
|
|
WLR_ERROR, "Failed to init render for output %s", wlr_output->name);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1626,7 +1696,6 @@ static void handle_new_output(struct wl_listener *listener, void *data) {
|
|
|
|
wlr_output_schedule_frame(wlr_output);
|
|
|
|
wlr_output_schedule_frame(wlr_output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LunarWM_wayland_init(LunarWM *this)
|
|
|
|
bool LunarWM_wayland_init(LunarWM *this)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wlr_log_init(WLR_DEBUG, nullptr);
|
|
|
|
wlr_log_init(WLR_DEBUG, nullptr);
|
|
|
|
|