render: add OpenGL resource caching; optimize texture handling

Mildly improves rendering performance by caching OpenGL resources.
Namely:

- Cache shader program, VBO/EBO, and textures per output
- Automatically free image data after GPU upload
- Force RGBA format for consistent texture handling
- Track texture state across output changes
- Add texture invalidation on image changes

This reduces the memory usage by a solid 30MB, but it's still not quite
enough. I expect (or rather, hope) that we can cut it by half.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a6964eebc783c5bc07b1fef7548a8d49f529c
This commit is contained in:
raf 2025-09-29 18:40:39 +03:00
commit d1116e7721
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 221 additions and 114 deletions

View file

@ -62,6 +62,14 @@ typedef struct {
// Associated wallpaper
chroma_image_t *image;
// OpenGL resource cache
GLuint texture_id;
GLuint shader_program;
GLuint vbo;
GLuint ebo;
bool gl_resources_initialized;
bool texture_uploaded;
} chroma_output_t;
// Config mapping structure
@ -150,6 +158,7 @@ void chroma_egl_cleanup(chroma_state_t *state);
int chroma_surface_create(chroma_state_t *state, chroma_output_t *output);
void chroma_surface_destroy(chroma_output_t *output);
int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output);
void chroma_output_invalidate_texture(chroma_output_t *output);
// Layer shell functions
void chroma_layer_surface_configure(void *data,
@ -219,4 +228,4 @@ extern const struct zwlr_layer_surface_v1_listener
// Global state for signal handling
extern volatile sig_atomic_t chroma_should_quit;
#endif // CHROMA_H
#endif // CHROMA_H