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
52
src/render.c
52
src/render.c
|
|
@ -277,7 +277,8 @@ static int init_gl_resources(chroma_output_t *output) {
|
|||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,
|
||||
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;
|
||||
|
||||
chroma_log("DEBUG", "Initialized GL resources for output %u", output->id);
|
||||
|
|
@ -684,26 +685,36 @@ int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output) {
|
|||
glBindTexture(GL_TEXTURE_2D, output->texture_id);
|
||||
glUniform1i(glGetUniformLocation(output->shader_program, "texture"), 0);
|
||||
|
||||
// Calculate texture coordinates based on scaling mode
|
||||
float tex_coords[8];
|
||||
calculate_texture_coords(output->scale_mode, output->image->width,
|
||||
output->image->height, output->width, output->height,
|
||||
tex_coords);
|
||||
// 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
|
||||
float tex_coords[8];
|
||||
calculate_texture_coords(output->scale_mode, output->image->width,
|
||||
output->image->height, output->width,
|
||||
output->height, tex_coords);
|
||||
|
||||
// Create dynamic vertex data with calculated texture coordinates
|
||||
float dynamic_vertices[] = {
|
||||
// Position Texcoord
|
||||
-1.0f, -1.0f, tex_coords[0], tex_coords[1], // bottom-left
|
||||
1.0f, -1.0f, tex_coords[2], tex_coords[3], // bottom-right
|
||||
1.0f, 1.0f, tex_coords[4], tex_coords[5], // top-right
|
||||
-1.0f, 1.0f, tex_coords[6], tex_coords[7] // top-left
|
||||
};
|
||||
// Create dynamic vertex data with calculated texture coordinates
|
||||
float dynamic_vertices[] = {
|
||||
// Position Texcoord
|
||||
-1.0f, -1.0f, tex_coords[0], tex_coords[1], // bottom-left
|
||||
1.0f, -1.0f, tex_coords[2], tex_coords[3], // bottom-right
|
||||
1.0f, 1.0f, tex_coords[4], tex_coords[5], // top-right
|
||||
-1.0f, 1.0f, tex_coords[6], tex_coords[7] // top-left
|
||||
};
|
||||
|
||||
// Update VBO with dynamic texture coordinates
|
||||
glBindBuffer(GL_ARRAY_BUFFER, output->vbo);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(dynamic_vertices),
|
||||
dynamic_vertices);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, output->ebo);
|
||||
// Update VBO with dynamic texture coordinates
|
||||
glBindBuffer(GL_ARRAY_BUFFER, output->vbo);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(dynamic_vertices),
|
||||
dynamic_vertices);
|
||||
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
|
||||
GLint position_attr = glGetAttribLocation(output->shader_program, "position");
|
||||
|
|
@ -753,4 +764,7 @@ void chroma_output_invalidate_texture(chroma_output_t *output) {
|
|||
output->texture_uploaded = false; // reset upload flag
|
||||
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