working pixmap

This commit is contained in:
IoIxD 2025-12-05 15:18:21 -07:00
commit 495ea93c74
2 changed files with 48 additions and 4 deletions

View file

@ -104,6 +104,7 @@ struct _MwLLWaylandColor {
struct _MwLLWaylandPixmap {
struct _MwLLCommonPixmap common;
GLuint texture;
};
#endif

View file

@ -238,6 +238,8 @@ static MwBool egl_setup(MwLL self, int width, int height) {
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
self->wayland.egl_display = display;
self->wayland.egl_surface = surface;
@ -513,9 +515,12 @@ static void setup_toplevel(MwLL r, int x, int y) {
r->wayland.toplevel->xdg_top_level = xdg_surface_get_toplevel(r->wayland.toplevel->xdg_surface);
// setup mandatory listeners
r->wayland.toplevel->xdg_surface_listener.configure = xdg_surface_configure;
r->wayland.toplevel->xdg_toplevel_listener.configure = xdg_toplevel_configure;
r->wayland.toplevel->xdg_toplevel_listener.close = xdg_toplevel_close;
xdg_surface_add_listener(r->wayland.toplevel->xdg_surface, &r->wayland.toplevel->xdg_surface_listener, r);
xdg_toplevel_add_listener(r->wayland.toplevel->xdg_top_level, &r->wayland.toplevel->xdg_toplevel_listener,
r);
@ -604,7 +609,6 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y) {
}
static void framebuffer_action_begin(MwLL handle) {
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, handle->wayland.fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0);
}
@ -836,20 +840,59 @@ static void MwLLSetTitleImpl(MwLL handle, const char* title) {
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
r->common.width = width;
r->common.height = height;
r->common.raw = data;
r->common.width = width;
r->common.height = height;
r->common.raw = data;
r->wayland.texture = 0;
glGenTextures(1, &r->wayland.texture);
glBindTexture(GL_TEXTURE_2D, r->wayland.texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
MwLLPixmapUpdate(r);
return r;
}
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
glBindTexture(GL_TEXTURE_2D, r->wayland.texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, r->common.width, r->common.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, r->common.raw);
glBindTexture(GL_TEXTURE_2D, 0);
}
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
glDeleteTextures(1, &pixmap->wayland.texture);
free(pixmap);
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
int x, y;
glColor3f(1.0, 1.0, 1.0);
x = handle->wayland.x + rect->x;
y = handle->wayland.y + rect->y;
glBindTexture(GL_TEXTURE_2D, pixmap->wayland.texture);
glActiveTexture(pixmap->wayland.texture);
framebuffer_action_begin(handle);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0);
glVertex2f(x, y);
glTexCoord2f(1, 0);
glVertex2f(x + rect->width, y);
glTexCoord2f(1, 1);
glVertex2f(x + rect->width, y + rect->height);
glTexCoord2f(0.0f, 1);
glVertex2f(x, y + rect->height);
glEnd();
glFinish();
framebuffer_action_end(handle);
}
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {