[vlc-commits] opengl: converter: add GL_TEXTURE_RECTANGLE
Thomas Guillem
git at videolan.org
Thu Feb 2 09:52:50 CET 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Feb 1 09:27:13 2017 +0100| [cca5562f8bbb7ab71742ac7e1e9a7ed58f08cdc0] | committer: Thomas Guillem
opengl: converter: add GL_TEXTURE_RECTANGLE
This is the default tex format for IOSurface on Macos.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cca5562f8bbb7ab71742ac7e1e9a7ed58f08cdc0
---
modules/video_output/opengl/converters.c | 42 ++++++++++++++++++++++++++++++++
modules/video_output/opengl/internal.h | 3 ++-
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/modules/video_output/opengl/converters.c b/modules/video_output/opengl/converters.c
index e2b4d3c..79a818c 100644
--- a/modules/video_output/opengl/converters.c
+++ b/modules/video_output/opengl/converters.c
@@ -267,6 +267,15 @@ tc_base_fetch_locations(opengl_tex_converter_t *tc, GLuint program)
tc->uloc.Texture[i] = tc->api->GetUniformLocation(program, name);
if (tc->uloc.Texture[i] == -1)
return VLC_EGENERIC;
+#ifdef GL_TEXTURE_RECTANGLE
+ if (tc->tex_target == GL_TEXTURE_RECTANGLE)
+ {
+ snprintf(name, sizeof(name), "TexSize%1u", i);
+ tc->uloc.TexSize[i] = tc->api->GetUniformLocation(program, name);
+ if (tc->uloc.TexSize[i] == -1)
+ return VLC_EGENERIC;
+ }
+#endif
}
tc->uloc.FillColor = tc->api->GetUniformLocation(program, "FillColor");
@@ -289,6 +298,15 @@ tc_base_prepare_shader(const opengl_tex_converter_t *tc,
tc->api->Uniform1i(tc->uloc.Texture[i], i);
tc->api->Uniform4f(tc->uloc.FillColor, 1.0f, 1.0f, 1.0f, alpha);
+
+#ifdef GL_TEXTURE_RECTANGLE
+ if (tc->tex_target == GL_TEXTURE_RECTANGLE)
+ {
+ for (unsigned i = 0; i < tc->tex_count; ++i)
+ tc->api->Uniform2f(tc->uloc.TexSize[i], tex_width[i],
+ tex_height[i]);
+ }
+#endif
}
GLuint
@@ -316,6 +334,13 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
lookup = "texture2D";
coord_name = "TexCoord";
break;
+#ifdef GL_TEXTURE_RECTANGLE
+ case GL_TEXTURE_RECTANGLE:
+ sampler = "sampler2DRect";
+ lookup = "texture2DRect";
+ coord_name = "TexCoordRect";
+ break;
+#endif
default:
vlc_assert_unreachable();
}
@@ -333,6 +358,14 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
ADDF("uniform %s Texture%u;"
"varying vec2 TexCoord%u;", sampler, i, i);
+#ifdef GL_TEXTURE_RECTANGLE
+ if (tex_target == GL_TEXTURE_RECTANGLE)
+ {
+ for (unsigned i = 0; i < tc->tex_count; ++i)
+ ADDF("uniform vec2 TexSize%u;", i);
+ }
+#endif
+
if (is_yuv)
ADD("uniform vec4 Coefficients[4];");
@@ -340,6 +373,15 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
"void main(void) {"
"float val;vec4 colors;");
+#ifdef GL_TEXTURE_RECTANGLE
+ if (tex_target == GL_TEXTURE_RECTANGLE)
+ {
+ for (unsigned i = 0; i < tc->tex_count; ++i)
+ ADDF("vec2 TexCoordRect%u = vec2(TexCoord%u.x * TexSize%u.x, "
+ "TexCoord%u.y * TexSize%u.y);", i, i, i, i, i);
+ }
+#endif
+
unsigned color_idx = 0;
for (unsigned i = 0; i < tc->tex_count; ++i)
{
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
index 142c8e8..03b4b86 100644
--- a/modules/video_output/opengl/internal.h
+++ b/modules/video_output/opengl/internal.h
@@ -196,6 +196,7 @@ struct opengl_tex_converter_t
* function. */
struct {
GLint Texture[PICTURE_PLANE_MAX];
+ GLint TexSize[PICTURE_PLANE_MAX]; /* for GL_TEXTURE_RECTANGLE */
GLint Coefficients;
GLint FillColor;
} uloc;
@@ -305,7 +306,7 @@ struct opengl_tex_converter_t
* pf_get_pool, pf_update, and pf_release.
*
* \param tc OpenGL tex converter
- * \param tex_target GL_TEXTURE_2D
+ * \param tex_target GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE
* \param chroma chroma used to generate the fragment shader
* \param if not COLOR_SPACE_UNDEF, YUV planes will be converted to RGB
* according to the color space
More information about the vlc-commits
mailing list