summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/opengl/utils.c')
-rw-r--r--video/out/opengl/utils.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c
index 83bed06498..c168cc60eb 100644
--- a/video/out/opengl/utils.c
+++ b/video/out/opengl/utils.c
@@ -312,6 +312,32 @@ void gl_vao_draw_data(struct gl_vao *vao, GLenum prim, void *ptr, size_t num)
gl_vao_unbind(vao);
}
+struct gl_format {
+ GLenum format;
+ GLenum type;
+ GLint internal_format;
+};
+
+static const struct gl_format gl_formats[] = {
+ // GLES 3.0
+ {GL_RGB, GL_UNSIGNED_BYTE, GL_RGB},
+ {GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA},
+ {GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8},
+ {GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8},
+ {GL_RGB, GL_UNSIGNED_SHORT, GL_RGB16},
+ {GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2},
+ // not texture filterable in GLES 3.0
+ {GL_RGB, GL_FLOAT, GL_RGB16F},
+ {GL_RGBA, GL_FLOAT, GL_RGBA16F},
+ {GL_RGB, GL_FLOAT, GL_RGB32F},
+ {GL_RGBA, GL_FLOAT, GL_RGBA32F},
+ // Desktop GL
+ {GL_RGB, GL_UNSIGNED_SHORT, GL_RGB10},
+ {GL_RGBA, GL_UNSIGNED_SHORT, GL_RGBA12},
+ {GL_RGBA, GL_UNSIGNED_SHORT, GL_RGBA16},
+ {0}
+};
+
// Create a texture and a FBO using the texture as color attachments.
// iformat: texture internal format
// Returns success.
@@ -349,6 +375,18 @@ bool fbotex_change(struct fbotex *fbo, GL *gl, struct mp_log *log, int w, int h,
GLenum filter = fbo->tex_filter;
+ struct gl_format format = {
+ .format = GL_RGBA,
+ .type = GL_UNSIGNED_BYTE,
+ .internal_format = iformat,
+ };
+ for (int n = 0; gl_formats[n].format; n++) {
+ if (gl_formats[n].internal_format == format.internal_format) {
+ format = gl_formats[n];
+ break;
+ }
+ }
+
*fbo = (struct fbotex) {
.gl = gl,
.w = w,
@@ -364,8 +402,8 @@ bool fbotex_change(struct fbotex *fbo, GL *gl, struct mp_log *log, int w, int h,
gl->GenFramebuffers(1, &fbo->fbo);
gl->GenTextures(1, &fbo->texture);
gl->BindTexture(GL_TEXTURE_2D, fbo->texture);
- gl->TexImage2D(GL_TEXTURE_2D, 0, iformat, fbo->w, fbo->h, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ gl->TexImage2D(GL_TEXTURE_2D, 0, format.internal_format, fbo->w, fbo->h, 0,
+ format.format, format.type, NULL);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl->BindTexture(GL_TEXTURE_2D, 0);
@@ -922,6 +960,11 @@ void gl_sc_gen_shader_and_reset(struct gl_shader_cache *sc)
else
ADD(frag, "uniform %s %s;\n", u->glsl_type, u->name);
}
+
+ // Additional helpers.
+ ADD(frag, "#define LUT_POS(x, lut_size) \\\n");
+ ADD(frag, " mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))\n");
+
// custom shader header
if (sc->header_text[0]) {
ADD(frag, "// header\n");