mirror of https://github.com/mpv-player/mpv
vo_opengl: manage user shader textures with ra
Drops some features I guess, no idea if those were needed. Untested due to lack of test cases.
This commit is contained in:
parent
5429dbf2a2
commit
53188a14bf
|
@ -294,10 +294,7 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
|
||||||
.w = 1, .h = 1, .d = 1,
|
.w = 1, .h = 1, .d = 1,
|
||||||
.components = 1,
|
.components = 1,
|
||||||
.bytes = 1,
|
.bytes = 1,
|
||||||
.mpgl_type = MPGL_TYPE_UINT,
|
.ctype = RA_CTYPE_UINT,
|
||||||
.gl_filter = GL_LINEAR,
|
|
||||||
.gl_target = GL_TEXTURE_1D,
|
|
||||||
.gl_border = GL_CLAMP_TO_EDGE,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -320,8 +317,7 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
|
||||||
mp_err(log, "Error while parsing SIZE!\n");
|
mp_err(log, "Error while parsing SIZE!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static GLenum tgt[] = {GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D};
|
out->dimensions = num;
|
||||||
out->gl_target = tgt[num - 1];
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,9 +339,7 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
|
||||||
|
|
||||||
out->bytes = bits / 8;
|
out->bytes = bits / 8;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case 'f': out->mpgl_type = MPGL_TYPE_FLOAT; break;
|
case 'u': out->ctype = RA_CTYPE_UINT; break;
|
||||||
case 'i': out->mpgl_type = MPGL_TYPE_UINT; break;
|
|
||||||
case 'u': out->mpgl_type = MPGL_TYPE_UNORM; break;
|
|
||||||
default:
|
default:
|
||||||
mp_err(log, "Unrecognized FORMAT description: '%c'!\n", fmt);
|
mp_err(log, "Unrecognized FORMAT description: '%c'!\n", fmt);
|
||||||
return false;
|
return false;
|
||||||
|
@ -356,9 +350,9 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
|
||||||
if (bstr_eatstart0(&line, "FILTER")) {
|
if (bstr_eatstart0(&line, "FILTER")) {
|
||||||
line = bstr_strip(line);
|
line = bstr_strip(line);
|
||||||
if (bstr_equals0(line, "LINEAR")) {
|
if (bstr_equals0(line, "LINEAR")) {
|
||||||
out->gl_filter = GL_LINEAR;
|
out->filter = true;
|
||||||
} else if (bstr_equals0(line, "NEAREST")) {
|
} else if (bstr_equals0(line, "NEAREST")) {
|
||||||
out->gl_filter = GL_NEAREST;
|
out->filter = false;
|
||||||
} else {
|
} else {
|
||||||
mp_err(log, "Unrecognized FILTER: '%.*s'!\n", BSTR_P(line));
|
mp_err(log, "Unrecognized FILTER: '%.*s'!\n", BSTR_P(line));
|
||||||
return false;
|
return false;
|
||||||
|
@ -369,11 +363,9 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
|
||||||
if (bstr_eatstart0(&line, "BORDER")) {
|
if (bstr_eatstart0(&line, "BORDER")) {
|
||||||
line = bstr_strip(line);
|
line = bstr_strip(line);
|
||||||
if (bstr_equals0(line, "CLAMP")) {
|
if (bstr_equals0(line, "CLAMP")) {
|
||||||
out->gl_border = GL_CLAMP_TO_EDGE;
|
out->border = GL_CLAMP_TO_EDGE;
|
||||||
} else if (bstr_equals0(line, "REPEAT")) {
|
} else if (bstr_equals0(line, "REPEAT")) {
|
||||||
out->gl_border = GL_REPEAT;
|
out->border = true;
|
||||||
} else if (bstr_equals0(line, "MIRROR")) {
|
|
||||||
out->gl_border = GL_MIRRORED_REPEAT;
|
|
||||||
} else {
|
} else {
|
||||||
mp_err(log, "Unrecognized BORDER: '%.*s'!\n", BSTR_P(line));
|
mp_err(log, "Unrecognized BORDER: '%.*s'!\n", BSTR_P(line));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -72,16 +72,16 @@ struct gl_user_shader_hook {
|
||||||
|
|
||||||
struct gl_user_shader_tex {
|
struct gl_user_shader_tex {
|
||||||
struct bstr name;
|
struct bstr name;
|
||||||
|
int dimensions;
|
||||||
int w, h, d;
|
int w, h, d;
|
||||||
int components;
|
int components;
|
||||||
int bytes;
|
int bytes;
|
||||||
int mpgl_type;
|
enum ra_ctype ctype;
|
||||||
GLenum gl_target;
|
bool filter;
|
||||||
GLenum gl_filter;
|
bool border;
|
||||||
GLenum gl_border;
|
|
||||||
void *texdata;
|
void *texdata;
|
||||||
// for video.c
|
// for video.c
|
||||||
GLenum gl_tex;
|
struct ra_tex *tex;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse the next shader block from `body`. The callbacks are invoked on every
|
// Parse the next shader block from `body`. The callbacks are invoked on every
|
||||||
|
|
|
@ -506,7 +506,7 @@ static void gl_video_reset_hooks(struct gl_video *p)
|
||||||
talloc_free(p->tex_hooks[i].priv);
|
talloc_free(p->tex_hooks[i].priv);
|
||||||
|
|
||||||
for (int i = 0; i < p->user_tex_num; i++)
|
for (int i = 0; i < p->user_tex_num; i++)
|
||||||
p->gl->DeleteTextures(1, &p->user_textures[i].gl_tex);
|
ra_tex_free(p->ra, &p->user_textures[i].tex);
|
||||||
|
|
||||||
p->tex_hook_num = 0;
|
p->tex_hook_num = 0;
|
||||||
p->user_tex_num = 0;
|
p->user_tex_num = 0;
|
||||||
|
@ -1408,7 +1408,7 @@ static bool pass_hook_setup_binds(struct gl_video *p, const char *name,
|
||||||
for (int u = 0; u < p->user_tex_num; u++) {
|
for (int u = 0; u < p->user_tex_num; u++) {
|
||||||
struct gl_user_shader_tex *utex = &p->user_textures[u];
|
struct gl_user_shader_tex *utex = &p->user_textures[u];
|
||||||
if (bstr_equals0(utex->name, bind_name)) {
|
if (bstr_equals0(utex->name, bind_name)) {
|
||||||
gl_sc_uniform_tex(p->sc, bind_name, utex->gl_target, utex->gl_tex);
|
gl_sc_uniform_texture(p->sc, bind_name, utex->tex);
|
||||||
goto next_bind;
|
goto next_bind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1966,15 +1966,14 @@ static bool add_user_hook(void *priv, struct gl_user_shader_hook hook)
|
||||||
static bool add_user_tex(void *priv, struct gl_user_shader_tex tex)
|
static bool add_user_tex(void *priv, struct gl_user_shader_tex tex)
|
||||||
{
|
{
|
||||||
struct gl_video *p = priv;
|
struct gl_video *p = priv;
|
||||||
GL *gl = p->gl;
|
|
||||||
|
|
||||||
if (p->user_tex_num == SHADER_MAX_PASSES) {
|
if (p->user_tex_num == SHADER_MAX_PASSES) {
|
||||||
MP_ERR(p, "Too many textures! Limit is %d.\n", SHADER_MAX_PASSES);
|
MP_ERR(p, "Too many textures! Limit is %d.\n", SHADER_MAX_PASSES);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct gl_format *format = gl_find_format(gl, tex.mpgl_type,
|
const struct ra_format *format = ra_find_unorm_format(p->ra, tex.components,
|
||||||
tex.gl_filter == GL_LINEAR ? F_TF : 0, tex.bytes, tex.components);
|
tex.bytes);
|
||||||
|
|
||||||
if (!format) {
|
if (!format) {
|
||||||
MP_ERR(p, "Could not satisfy format requirements for user "
|
MP_ERR(p, "Could not satisfy format requirements for user "
|
||||||
|
@ -1982,34 +1981,20 @@ static bool add_user_tex(void *priv, struct gl_user_shader_tex tex)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum type = format->type,
|
struct ra_tex_params params = {
|
||||||
ifmt = format->internal_format,
|
.dimensions = tex.dimensions,
|
||||||
fmt = format->format;
|
.w = tex.w,
|
||||||
|
.h = tex.h,
|
||||||
GLenum tgt = tex.gl_target;
|
.d = tex.d,
|
||||||
gl->GenTextures(1, &tex.gl_tex);
|
.format = format,
|
||||||
gl->BindTexture(tgt, tex.gl_tex);
|
.render_src = true,
|
||||||
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
.src_linear = tex.filter,
|
||||||
|
.src_repeat = tex.border,
|
||||||
if (tgt == GL_TEXTURE_3D) {
|
.initial_data = tex.texdata,
|
||||||
gl->TexImage3D(tgt, 0, ifmt, tex.w, tex.h, tex.d, 0, fmt, type, tex.texdata);
|
};
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_S, tex.gl_border);
|
tex.tex = ra_tex_create(p->ra, ¶ms);
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_T, tex.gl_border);
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_R, tex.gl_border);
|
|
||||||
} else if (tgt == GL_TEXTURE_2D) {
|
|
||||||
gl->TexImage2D(tgt, 0, ifmt, tex.w, tex.h, 0, fmt, type, tex.texdata);
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_S, tex.gl_border);
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_T, tex.gl_border);
|
|
||||||
} else {
|
|
||||||
gl->TexImage1D(tgt, 0, ifmt, tex.w, 0, fmt, type, tex.texdata);
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_WRAP_S, tex.gl_border);
|
|
||||||
}
|
|
||||||
talloc_free(tex.texdata);
|
talloc_free(tex.texdata);
|
||||||
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_MIN_FILTER, tex.gl_filter);
|
|
||||||
gl->TexParameteri(tgt, GL_TEXTURE_MAG_FILTER, tex.gl_filter);
|
|
||||||
gl->BindTexture(tgt, 0);
|
|
||||||
|
|
||||||
p->user_textures[p->user_tex_num++] = tex;
|
p->user_textures[p->user_tex_num++] = tex;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue