render: fix filtering; optimize VBO management
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I2f30f77e0f29437cac57a1064ca1f6796a6a6964
This commit is contained in:
parent
5bfae35738
commit
ec628eb1af
1 changed files with 35 additions and 21 deletions
18
src/render.c
18
src/render.c
|
|
@ -278,6 +278,7 @@ static int init_gl_resources(chroma_output_t *output) {
|
||||||
GL_STATIC_DRAW);
|
GL_STATIC_DRAW);
|
||||||
|
|
||||||
output->texture_id = 0; // will be created when image is assigned
|
output->texture_id = 0; // will be created when image is assigned
|
||||||
|
output->vbo_dirty = true; // VBO needs initial update
|
||||||
output->gl_resources_initialized = true;
|
output->gl_resources_initialized = true;
|
||||||
|
|
||||||
chroma_log("DEBUG", "Initialized GL resources for output %u", output->id);
|
chroma_log("DEBUG", "Initialized GL resources for output %u", output->id);
|
||||||
|
|
@ -684,11 +685,14 @@ int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output) {
|
||||||
glBindTexture(GL_TEXTURE_2D, output->texture_id);
|
glBindTexture(GL_TEXTURE_2D, output->texture_id);
|
||||||
glUniform1i(glGetUniformLocation(output->shader_program, "texture"), 0);
|
glUniform1i(glGetUniformLocation(output->shader_program, "texture"), 0);
|
||||||
|
|
||||||
|
// Update VBO only if needed. E.g, image changed, scale mode changed, or first
|
||||||
|
// render
|
||||||
|
if (output->vbo_dirty) {
|
||||||
// Calculate texture coordinates based on scaling mode
|
// Calculate texture coordinates based on scaling mode
|
||||||
float tex_coords[8];
|
float tex_coords[8];
|
||||||
calculate_texture_coords(output->scale_mode, output->image->width,
|
calculate_texture_coords(output->scale_mode, output->image->width,
|
||||||
output->image->height, output->width, output->height,
|
output->image->height, output->width,
|
||||||
tex_coords);
|
output->height, tex_coords);
|
||||||
|
|
||||||
// Create dynamic vertex data with calculated texture coordinates
|
// Create dynamic vertex data with calculated texture coordinates
|
||||||
float dynamic_vertices[] = {
|
float dynamic_vertices[] = {
|
||||||
|
|
@ -705,6 +709,13 @@ int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output) {
|
||||||
dynamic_vertices);
|
dynamic_vertices);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, output->ebo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, output->ebo);
|
||||||
|
|
||||||
|
output->vbo_dirty = false; // mark VBO as up to date
|
||||||
|
} else {
|
||||||
|
// Just bind the existing buffers
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, output->vbo);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, output->ebo);
|
||||||
|
}
|
||||||
|
|
||||||
// Set vertex attributes
|
// Set vertex attributes
|
||||||
GLint position_attr = glGetAttribLocation(output->shader_program, "position");
|
GLint position_attr = glGetAttribLocation(output->shader_program, "position");
|
||||||
GLint texcoord_attr = glGetAttribLocation(output->shader_program, "texcoord");
|
GLint texcoord_attr = glGetAttribLocation(output->shader_program, "texcoord");
|
||||||
|
|
@ -753,4 +764,7 @@ void chroma_output_invalidate_texture(chroma_output_t *output) {
|
||||||
output->texture_uploaded = false; // reset upload flag
|
output->texture_uploaded = false; // reset upload flag
|
||||||
chroma_log("DEBUG", "Invalidated texture cache for output %u", output->id);
|
chroma_log("DEBUG", "Invalidated texture cache for output %u", output->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark VBO as dirty since texture coordinates may need recalculation
|
||||||
|
output->vbo_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue