render: handle mipmaps properly
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I43de088ca17559648d67e728db1179cf6a6a6964
This commit is contained in:
parent
d16a861e52
commit
c9d32e14ab
1 changed files with 17 additions and 3 deletions
20
src/render.c
20
src/render.c
|
|
@ -10,27 +10,33 @@
|
||||||
|
|
||||||
// Convert filter quality enum to OpenGL parameters
|
// Convert filter quality enum to OpenGL parameters
|
||||||
static void get_gl_filter_params(chroma_filter_quality_t quality,
|
static void get_gl_filter_params(chroma_filter_quality_t quality,
|
||||||
GLint *min_filter, GLint *mag_filter) {
|
GLint *min_filter, GLint *mag_filter,
|
||||||
|
bool *needs_mipmaps) {
|
||||||
switch (quality) {
|
switch (quality) {
|
||||||
case CHROMA_FILTER_NEAREST:
|
case CHROMA_FILTER_NEAREST:
|
||||||
*min_filter = GL_NEAREST;
|
*min_filter = GL_NEAREST;
|
||||||
*mag_filter = GL_NEAREST;
|
*mag_filter = GL_NEAREST;
|
||||||
|
*needs_mipmaps = false;
|
||||||
break;
|
break;
|
||||||
case CHROMA_FILTER_LINEAR:
|
case CHROMA_FILTER_LINEAR:
|
||||||
*min_filter = GL_LINEAR;
|
*min_filter = GL_LINEAR;
|
||||||
*mag_filter = GL_LINEAR;
|
*mag_filter = GL_LINEAR;
|
||||||
|
*needs_mipmaps = false;
|
||||||
break;
|
break;
|
||||||
case CHROMA_FILTER_BILINEAR:
|
case CHROMA_FILTER_BILINEAR:
|
||||||
*min_filter = GL_LINEAR_MIPMAP_LINEAR;
|
*min_filter = GL_LINEAR;
|
||||||
*mag_filter = GL_LINEAR;
|
*mag_filter = GL_LINEAR;
|
||||||
|
*needs_mipmaps = false;
|
||||||
break;
|
break;
|
||||||
case CHROMA_FILTER_TRILINEAR:
|
case CHROMA_FILTER_TRILINEAR:
|
||||||
*min_filter = GL_LINEAR_MIPMAP_LINEAR;
|
*min_filter = GL_LINEAR_MIPMAP_LINEAR;
|
||||||
*mag_filter = GL_LINEAR;
|
*mag_filter = GL_LINEAR;
|
||||||
|
*needs_mipmaps = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*min_filter = GL_LINEAR;
|
*min_filter = GL_LINEAR;
|
||||||
*mag_filter = GL_LINEAR;
|
*mag_filter = GL_LINEAR;
|
||||||
|
*needs_mipmaps = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -324,7 +330,9 @@ static int update_texture_from_image(chroma_output_t *output,
|
||||||
|
|
||||||
// Use configured filter quality
|
// Use configured filter quality
|
||||||
GLint min_filter, mag_filter;
|
GLint min_filter, mag_filter;
|
||||||
get_gl_filter_params(filter_quality, &min_filter, &mag_filter);
|
bool needs_mipmaps;
|
||||||
|
get_gl_filter_params(filter_quality, &min_filter, &mag_filter,
|
||||||
|
&needs_mipmaps);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
||||||
|
|
||||||
|
|
@ -332,6 +340,12 @@ static int update_texture_from_image(chroma_output_t *output,
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, image->data);
|
GL_RGBA, GL_UNSIGNED_BYTE, image->data);
|
||||||
|
|
||||||
|
// Generate mipmaps for trilinear filtering if they're needed
|
||||||
|
if (needs_mipmaps) {
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
chroma_log("DEBUG", "Generated mipmaps for trilinear filtering");
|
||||||
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
// Mark this output as having uploaded its texture
|
// Mark this output as having uploaded its texture
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue