opengl: fetch locations from sampler
authorRomain Vimont <rom1v@videolabs.io>
Mon, 3 Feb 2020 15:45:08 +0000 (16:45 +0100)
committerAlexandre Janniaux <ajanni@videolabs.io>
Wed, 20 May 2020 12:51:56 +0000 (14:51 +0200)
Fetch locations related to sampler from sampler->pf_fetch_locations.

Signed-off-by: Alexandre Janniaux <ajanni@videolabs.io>
modules/video_output/opengl/fragment_shaders.c
modules/video_output/opengl/renderer.c

index 298837c..eca4e7b 100644 (file)
@@ -218,13 +218,31 @@ sampler_base_fetch_locations(struct vlc_gl_sampler *sampler, GLuint program)
             return VLC_EGENERIC;
     }
 
+    sampler->uloc.TransformMatrix =
+        vt->GetUniformLocation(program, "TransformMatrix");
+    if (sampler->uloc.TransformMatrix == -1)
+        return VLC_EGENERIC;
+
+    sampler->uloc.OrientationMatrix =
+        vt->GetUniformLocation(program, "OrientationMatrix");
+    if (sampler->uloc.OrientationMatrix == -1)
+        return VLC_EGENERIC;
+
+    assert(interop->tex_count < 10); /* to guarantee variable names length */
     for (unsigned int i = 0; i < interop->tex_count; ++i)
     {
-        char name[sizeof("TextureX")];
+        char name[sizeof("TexCoordsMapX")];
+
         snprintf(name, sizeof(name), "Texture%1u", i);
         sampler->uloc.Texture[i] = vt->GetUniformLocation(program, name);
         if (sampler->uloc.Texture[i] == -1)
             return VLC_EGENERIC;
+
+        snprintf(name, sizeof(name), "TexCoordsMap%1u", i);
+        sampler->uloc.TexCoordsMap[i] = vt->GetUniformLocation(program, name);
+        if (sampler->uloc.TexCoordsMap[i] == -1)
+            return VLC_EGENERIC;
+
         if (interop->tex_target == GL_TEXTURE_RECTANGLE)
         {
             snprintf(name, sizeof(name), "TexSize%1u", i);
@@ -314,7 +332,25 @@ sampler_xyz12_fetch_locations(struct vlc_gl_sampler *sampler, GLuint program)
     const opengl_vtable_t *vt = sampler->vt;
 
     sampler->uloc.Texture[0] = vt->GetUniformLocation(program, "Texture0");
-    return sampler->uloc.Texture[0] != -1 ? VLC_SUCCESS : VLC_EGENERIC;
+    if (sampler->uloc.Texture[0] == -1)
+        return VLC_EGENERIC;
+
+    sampler->uloc.TransformMatrix =
+        vt->GetUniformLocation(program, "TransformMatrix");
+    if (sampler->uloc.TransformMatrix == -1)
+        return VLC_EGENERIC;
+
+    sampler->uloc.OrientationMatrix =
+        vt->GetUniformLocation(program, "OrientationMatrix");
+    if (sampler->uloc.OrientationMatrix == -1)
+        return VLC_EGENERIC;
+
+    sampler->uloc.TexCoordsMap[0] =
+        vt->GetUniformLocation(program, "TexCoordsMap0");
+    if (sampler->uloc.TexCoordsMap[0] == -1)
+        return VLC_EGENERIC;
+
+    return VLC_SUCCESS;
 }
 
 static void
index 81655b9..5fb4f85 100644 (file)
@@ -357,24 +357,10 @@ opengl_link_program(struct vlc_gl_renderer *renderer)
 
     GET_ALOC(PicCoordsIn, "PicCoordsIn");
     GET_ALOC(VertexPosition, "VertexPosition");
-
-#define GET_SAMPLER_ULOC(x, str) GET_LOC(Uniform, sampler->uloc.x, str)
-    GET_SAMPLER_ULOC(TransformMatrix, "TransformMatrix");
-    GET_SAMPLER_ULOC(OrientationMatrix, "OrientationMatrix");
-    GET_SAMPLER_ULOC(TexCoordsMap[0], "TexCoordsMap0");
-    /* MultiTexCoord 1 and 2 can be optimized out if not used */
-    if (interop->tex_count > 1)
-        GET_SAMPLER_ULOC(TexCoordsMap[1], "TexCoordsMap1");
-    else
-        sampler->uloc.TexCoordsMap[1] = -1;
-    if (interop->tex_count > 2)
-        GET_SAMPLER_ULOC(TexCoordsMap[2], "TexCoordsMap2");
-    else
-        sampler->uloc.TexCoordsMap[2] = -1;
 #undef GET_LOC
 #undef GET_ULOC
 #undef GET_ALOC
-#undef GET_SAMPLER_ULOC
+
     int ret = sampler->pf_fetch_locations(sampler, program_id);
     assert(ret == VLC_SUCCESS);
     if (ret != VLC_SUCCESS)