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:
wm4 2017-07-30 11:38:52 +02:00
parent 5429dbf2a2
commit 53188a14bf
3 changed files with 28 additions and 51 deletions

View File

@ -294,10 +294,7 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
.w = 1, .h = 1, .d = 1,
.components = 1,
.bytes = 1,
.mpgl_type = MPGL_TYPE_UINT,
.gl_filter = GL_LINEAR,
.gl_target = GL_TEXTURE_1D,
.gl_border = GL_CLAMP_TO_EDGE,
.ctype = RA_CTYPE_UINT,
};
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");
return false;
}
static GLenum tgt[] = {GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D};
out->gl_target = tgt[num - 1];
out->dimensions = num;
continue;
}
@ -343,9 +339,7 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
out->bytes = bits / 8;
switch (fmt) {
case 'f': out->mpgl_type = MPGL_TYPE_FLOAT; break;
case 'i': out->mpgl_type = MPGL_TYPE_UINT; break;
case 'u': out->mpgl_type = MPGL_TYPE_UNORM; break;
case 'u': out->ctype = RA_CTYPE_UINT; break;
default:
mp_err(log, "Unrecognized FORMAT description: '%c'!\n", fmt);
return false;
@ -356,9 +350,9 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
if (bstr_eatstart0(&line, "FILTER")) {
line = bstr_strip(line);
if (bstr_equals0(line, "LINEAR")) {
out->gl_filter = GL_LINEAR;
out->filter = true;
} else if (bstr_equals0(line, "NEAREST")) {
out->gl_filter = GL_NEAREST;
out->filter = false;
} else {
mp_err(log, "Unrecognized FILTER: '%.*s'!\n", BSTR_P(line));
return false;
@ -369,11 +363,9 @@ static bool parse_tex(struct mp_log *log, struct bstr *body,
if (bstr_eatstart0(&line, "BORDER")) {
line = bstr_strip(line);
if (bstr_equals0(line, "CLAMP")) {
out->gl_border = GL_CLAMP_TO_EDGE;
out->border = GL_CLAMP_TO_EDGE;
} else if (bstr_equals0(line, "REPEAT")) {
out->gl_border = GL_REPEAT;
} else if (bstr_equals0(line, "MIRROR")) {
out->gl_border = GL_MIRRORED_REPEAT;
out->border = true;
} else {
mp_err(log, "Unrecognized BORDER: '%.*s'!\n", BSTR_P(line));
return false;

View File

@ -72,16 +72,16 @@ struct gl_user_shader_hook {
struct gl_user_shader_tex {
struct bstr name;
int dimensions;
int w, h, d;
int components;
int bytes;
int mpgl_type;
GLenum gl_target;
GLenum gl_filter;
GLenum gl_border;
enum ra_ctype ctype;
bool filter;
bool border;
void *texdata;
// for video.c
GLenum gl_tex;
struct ra_tex *tex;
};
// Parse the next shader block from `body`. The callbacks are invoked on every

View File

@ -506,7 +506,7 @@ static void gl_video_reset_hooks(struct gl_video *p)
talloc_free(p->tex_hooks[i].priv);
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->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++) {
struct gl_user_shader_tex *utex = &p->user_textures[u];
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;
}
}
@ -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)
{
struct gl_video *p = priv;
GL *gl = p->gl;
if (p->user_tex_num == SHADER_MAX_PASSES) {
MP_ERR(p, "Too many textures! Limit is %d.\n", SHADER_MAX_PASSES);
goto err;
}
const struct gl_format *format = gl_find_format(gl, tex.mpgl_type,
tex.gl_filter == GL_LINEAR ? F_TF : 0, tex.bytes, tex.components);
const struct ra_format *format = ra_find_unorm_format(p->ra, tex.components,
tex.bytes);
if (!format) {
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;
}
GLenum type = format->type,
ifmt = format->internal_format,
fmt = format->format;
GLenum tgt = tex.gl_target;
gl->GenTextures(1, &tex.gl_tex);
gl->BindTexture(tgt, tex.gl_tex);
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (tgt == GL_TEXTURE_3D) {
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);
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);
}
struct ra_tex_params params = {
.dimensions = tex.dimensions,
.w = tex.w,
.h = tex.h,
.d = tex.d,
.format = format,
.render_src = true,
.src_linear = tex.filter,
.src_repeat = tex.border,
.initial_data = tex.texdata,
};
tex.tex = ra_tex_create(p->ra, &params);
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;
return true;