[virglrenderer-devel] [PATCH 4/8] vrend: Replace 1D texture by 2D one for OpenGL ES.

Jakob Bornecrantz jakob.bornecrantz at collabora.com
Tue Feb 13 14:27:26 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

Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
Signed-off-by: Jakob Bornecrantz <jakob.bornecrantz 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 abb8779..8fa225a 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4475,6 +4475,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 420bc83..b824140 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -1359,8 +1359,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 (vrend_shader_state.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);
 }
 
@@ -2439,7 +2447,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 (vrend_shader_state.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