[vlc-devel] [PATCH 12/17] opengl: load uniforms from sampler
Romain Vimont
rom1v at videolabs.io
Thu Apr 2 14:24:25 CEST 2020
Load uniforms related to sampler from sampler->pf_prepare_shader.
---
.../video_output/opengl/fragment_shaders.c | 42 +++++++++++++++++++
modules/video_output/opengl/renderer.c | 20 ---------
2 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index b0b718b3c7..6efeb4b049 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -33,6 +33,8 @@
#include <vlc_common.h>
#include <vlc_memstream.h>
+
+#include "gl_util.h"
#include "interop.h"
#include "internal.h"
#include "sampler.h"
@@ -266,6 +268,17 @@ sampler_base_fetch_locations(struct vlc_gl_sampler *sampler, GLuint program)
return VLC_SUCCESS;
}
+static const GLfloat *
+GetTransformMatrix(const struct vlc_gl_interop *interop)
+{
+ const GLfloat *tm = NULL;
+ if (interop->ops && interop->ops->get_transform_matrix)
+ tm = interop->ops->get_transform_matrix(interop);
+ if (!tm)
+ tm = MATRIX4_IDENTITY;
+ return tm;
+}
+
static void
sampler_base_prepare_shader(const struct vlc_gl_sampler *sampler,
const GLsizei *tex_width,
@@ -280,10 +293,25 @@ sampler_base_prepare_shader(const struct vlc_gl_sampler *sampler,
sampler->conv_matrix);
for (unsigned i = 0; i < interop->tex_count; ++i)
+ {
vt->Uniform1i(sampler->uloc.Texture[i], i);
+ assert(sampler->textures[i] != 0);
+ vt->ActiveTexture(GL_TEXTURE0 + i);
+ vt->BindTexture(interop->tex_target, sampler->textures[i]);
+
+ vt->UniformMatrix3fv(sampler->uloc.TexCoordsMap[i], 1, GL_FALSE,
+ sampler->var.TexCoordsMap[i]);
+ }
+
vt->Uniform4f(sampler->uloc.FillColor, 1.0f, 1.0f, 1.0f, alpha);
+ const GLfloat *tm = GetTransformMatrix(interop);
+ vt->UniformMatrix4fv(sampler->uloc.TransformMatrix, 1, GL_FALSE, tm);
+
+ vt->UniformMatrix4fv(sampler->uloc.OrientationMatrix, 1, GL_FALSE,
+ sampler->var.OrientationMatrix);
+
if (interop->tex_target == GL_TEXTURE_RECTANGLE)
{
for (unsigned i = 0; i < interop->tex_count; ++i)
@@ -358,9 +386,23 @@ sampler_xyz12_prepare_shader(const struct vlc_gl_sampler *sampler,
const GLsizei *tex_height, float alpha)
{
(void) tex_width; (void) tex_height; (void) alpha;
+ const struct vlc_gl_interop *interop = sampler->interop;
const opengl_vtable_t *vt = sampler->vt;
vt->Uniform1i(sampler->uloc.Texture[0], 0);
+
+ assert(sampler->textures[0] != 0);
+ vt->ActiveTexture(GL_TEXTURE0);
+ vt->BindTexture(interop->tex_target, sampler->textures[0]);
+
+ vt->UniformMatrix3fv(sampler->uloc.TexCoordsMap[0], 1, GL_FALSE,
+ sampler->var.TexCoordsMap[0]);
+
+ const GLfloat *tm = GetTransformMatrix(interop);
+ vt->UniformMatrix4fv(sampler->uloc.TransformMatrix, 1, GL_FALSE, tm);
+
+ vt->UniformMatrix4fv(sampler->uloc.OrientationMatrix, 1, GL_FALSE,
+ sampler->var.OrientationMatrix);
}
static char *
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 5fb4f85104..ba450e063c 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -829,21 +829,11 @@ static int SetupCoords(struct vlc_gl_renderer *renderer)
static void DrawWithShaders(struct vlc_gl_renderer *renderer)
{
- const struct vlc_gl_interop *interop = renderer->interop;
struct vlc_gl_sampler *sampler = renderer->sampler;
const opengl_vtable_t *vt = renderer->vt;
sampler->pf_prepare_shader(sampler, sampler->tex_width,
sampler->tex_height, 1.0f);
- for (unsigned j = 0; j < interop->tex_count; j++) {
- assert(sampler->textures[j] != 0);
- vt->ActiveTexture(GL_TEXTURE0+j);
- vt->BindTexture(interop->tex_target, sampler->textures[j]);
-
- vt->UniformMatrix3fv(sampler->uloc.TexCoordsMap[j], 1, GL_FALSE,
- sampler->var.TexCoordsMap[j]);
- }
-
vt->BindBuffer(GL_ARRAY_BUFFER, renderer->texture_buffer_object);
assert(renderer->aloc.PicCoordsIn != -1);
vt->EnableVertexAttribArray(renderer->aloc.PicCoordsIn);
@@ -854,16 +844,6 @@ static void DrawWithShaders(struct vlc_gl_renderer *renderer)
vt->EnableVertexAttribArray(renderer->aloc.VertexPosition);
vt->VertexAttribPointer(renderer->aloc.VertexPosition, 3, GL_FLOAT, 0, 0, 0);
- const GLfloat *tm = NULL;
- if (interop->ops && interop->ops->get_transform_matrix)
- tm = interop->ops->get_transform_matrix(interop);
- if (!tm)
- tm = MATRIX4_IDENTITY;
-
- vt->UniformMatrix4fv(sampler->uloc.TransformMatrix, 1, GL_FALSE, tm);
-
- vt->UniformMatrix4fv(sampler->uloc.OrientationMatrix, 1, GL_FALSE,
- sampler->var.OrientationMatrix);
vt->UniformMatrix3fv(renderer->uloc.StereoMatrix, 1, GL_FALSE,
renderer->var.StereoMatrix);
vt->UniformMatrix4fv(renderer->uloc.ProjectionMatrix, 1, GL_FALSE,
--
2.26.0
More information about the vlc-devel
mailing list