[virglrenderer-devel] [PATCH 2/3] vrend: Replace 1D texture by 2D one for OpenGL ES v2
Jakob Bornecrantz
jakob at collabora.com
Fri Feb 23 17:32:43 UTC 2018
From: Elie Tournier <tournier.elie at gmail.com>
OpenGL ES don't support 1D texture.
So we replace these textures by some 2D texture with one of
the component set to 0.5
v2: Use new use_gles state on vrend_shader_cfg.
Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
Signed-off-by: Jakob Bornecrantz <jakob at collabora.com>
---
src/vrend_renderer.c | 10 ++++++++++
src/vrend_shader.c | 21 ++++++++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 1bf15f5..2a82025 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4499,6 +4499,16 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
gr->target = GL_TEXTURE_2D;
}
+ /* fallback for 1D textures */
+ if (vrend_state.use_gles && gr->target == GL_TEXTURE_1D) {
+ gr->target = GL_TEXTURE_2D;
+ }
+
+ /* fallback for 1D array textures */
+ if (vrend_state.use_gles && gr->target == GL_TEXTURE_1D_ARRAY) {
+ gr->target = GL_TEXTURE_2D_ARRAY;
+ }
+
glGenTextures(1, &gr->id);
glBindTexture(gr->target, gr->id);
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index f8cee35..881252a 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -1419,8 +1419,16 @@ static int translate_tex(struct dump_ctx *ctx,
const char *cname = tgsi_proc_to_prefix(ctx->prog_type);
const struct tgsi_full_src_register *src = &inst->Src[sampler_index];
snprintf(buf, 255, "%s = %s(%s(vec4(vec4(texture%s(%s, %s%s%s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], dstconv, dtypeprefix, tex_ext, srcs[sampler_index], srcs[0], twm, offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask);
- } else
- snprintf(buf, 255, "%s = %s(%s(texture%s(%s, %s%s%s%s)%s));\n", dsts[0], dstconv, dtypeprefix, tex_ext, srcs[sampler_index], srcs[0], twm, offbuf, bias, dst0_override_no_wm ? "" : writemask);
+ } else {
+ /* OpenGL ES do not support 1D texture
+ * so we use a 2D texture with a parameter set to 0.5
+ */
+ if (ctx->cfg->use_gles && inst->Texture.Texture == TGSI_TEXTURE_1D) {
+ snprintf(buf, 255, "%s = %s(%s(texture2D(%s, vec2(%s%s%s%s, 0.5))%s));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index], srcs[0], twm, offbuf, bias, dst0_override_no_wm ? "" : writemask);
+ } else {
+ snprintf(buf, 255, "%s = %s(%s(texture%s(%s, %s%s%s%s)%s));\n", dsts[0], dstconv, dtypeprefix, tex_ext, srcs[sampler_index], srcs[0], twm, offbuf, bias, dst0_override_no_wm ? "" : writemask);
+ }
+ }
return emit_buf(ctx, buf);
}
@@ -2515,7 +2523,14 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
const char *sname;
sname = tgsi_proc_to_prefix(ctx->prog_type);
- snprintf(buf, 255, "uniform %csampler%s %ssamp%d;\n", ptc, stc, sname, i);
+ /* OpenGL ES do not support 1D texture
+ * so we use a 2D texture with a parameter set to 0.5
+ */
+ if (ctx->cfg->use_gles && !memcmp(stc, "1D", sizeof(stc)))
+ snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
+ else
+ snprintf(buf, 255, "uniform %csampler%s %ssamp%d;\n", ptc, stc, sname, i);
+
STRCAT_WITH_RET(glsl_hdr, buf);
if (is_shad) {
snprintf(buf, 255, "uniform vec4 %sshadmask%d;\n", sname, i);
--
2.14.1
More information about the virglrenderer-devel
mailing list