[vlc-devel] [PATCH 2/2] OpenGL: draw the subpictures in a separate function
Adrien Maglo
magsoft at videolan.org
Mon Jul 31 16:30:20 CEST 2017
Add DrawSubPicutresWithShaders to be consistent with DrawWithShaders.
---
modules/video_output/opengl/vout_helper.c | 123 ++++++++++++++++--------------
1 file changed, 67 insertions(+), 56 deletions(-)
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index a46d8dee12..a2bc60a2d7 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -1180,64 +1180,9 @@ static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
glDrawElements(GL_TRIANGLES, vgl->nb_indices, GL_UNSIGNED_SHORT, 0);
}
-int vout_display_opengl_Display(vout_display_opengl_t *vgl,
- const video_format_t *source)
+static int DrawSubPicutresWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
{
- /* Why drawing here and not in Render()? Because this way, the
- OpenGL providers can call vout_display_opengl_Display to force redraw.
- Currently, the OS X provider uses it to get a smooth window resizing */
- glClear(GL_COLOR_BUFFER_BIT);
-
- vgl->api.UseProgram(vgl->prgm->id);
-
- if (source->i_x_offset != vgl->last_source.i_x_offset
- || source->i_y_offset != vgl->last_source.i_y_offset
- || source->i_visible_width != vgl->last_source.i_visible_width
- || source->i_visible_height != vgl->last_source.i_visible_height)
- {
- float left[PICTURE_PLANE_MAX];
- float top[PICTURE_PLANE_MAX];
- float right[PICTURE_PLANE_MAX];
- float bottom[PICTURE_PLANE_MAX];
- const opengl_tex_converter_t *tc = &vgl->prgm->tc;
- for (unsigned j = 0; j < tc->tex_count; j++)
- {
- float scale_w = (float)tc->texs[j].w.num / tc->texs[j].w.den
- / vgl->tex_width[j];
- float scale_h = (float)tc->texs[j].h.num / tc->texs[j].h.den
- / vgl->tex_height[j];
-
- /* Warning: if NPOT is not supported a larger texture is
- allocated. This will cause right and bottom coordinates to
- land on the edge of two texels with the texels to the
- right/bottom uninitialized by the call to
- glTexSubImage2D. This might cause a green line to appear on
- the right/bottom of the display.
- There are two possible solutions:
- - Manually mirror the edges of the texture.
- - Add a "-1" when computing right and bottom, however the
- last row/column might not be displayed at all.
- */
- left[j] = (source->i_x_offset + 0 ) * scale_w;
- top[j] = (source->i_y_offset + 0 ) * scale_h;
- right[j] = (source->i_x_offset + source->i_visible_width ) * scale_w;
- bottom[j] = (source->i_y_offset + source->i_visible_height) * scale_h;
- }
-
- int ret = SetupCoords(vgl, left, top, right, bottom);
- if (ret != VLC_SUCCESS)
- return ret;
-
- vgl->last_source.i_x_offset = source->i_x_offset;
- vgl->last_source.i_y_offset = source->i_y_offset;
- vgl->last_source.i_visible_width = source->i_visible_width;
- vgl->last_source.i_visible_height = source->i_visible_height;
- }
- DrawWithShaders(vgl, vgl->prgm);
-
- /* Draw the subpictures */
// Change the program for overlays
- struct prgm *prgm = vgl->sub_prgm;
GLuint program = prgm->id;
opengl_tex_converter_t *tc = &prgm->tc;
vgl->api.UseProgram(program);
@@ -1311,8 +1256,74 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
+
glDisable(GL_BLEND);
+ return VLC_SUCCESS;
+}
+
+int vout_display_opengl_Display(vout_display_opengl_t *vgl,
+ const video_format_t *source)
+{
+ /* Why drawing here and not in Render()? Because this way, the
+ OpenGL providers can call vout_display_opengl_Display to force redraw.
+ Currently, the OS X provider uses it to get a smooth window resizing */
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ vgl->api.UseProgram(vgl->prgm->id);
+
+ if (source->i_x_offset != vgl->last_source.i_x_offset
+ || source->i_y_offset != vgl->last_source.i_y_offset
+ || source->i_visible_width != vgl->last_source.i_visible_width
+ || source->i_visible_height != vgl->last_source.i_visible_height)
+ {
+ float left[PICTURE_PLANE_MAX];
+ float top[PICTURE_PLANE_MAX];
+ float right[PICTURE_PLANE_MAX];
+ float bottom[PICTURE_PLANE_MAX];
+ const opengl_tex_converter_t *tc = &vgl->prgm->tc;
+ for (unsigned j = 0; j < tc->tex_count; j++)
+ {
+ float scale_w = (float)tc->texs[j].w.num / tc->texs[j].w.den
+ / vgl->tex_width[j];
+ float scale_h = (float)tc->texs[j].h.num / tc->texs[j].h.den
+ / vgl->tex_height[j];
+
+ /* Warning: if NPOT is not supported a larger texture is
+ allocated. This will cause right and bottom coordinates to
+ land on the edge of two texels with the texels to the
+ right/bottom uninitialized by the call to
+ glTexSubImage2D. This might cause a green line to appear on
+ the right/bottom of the display.
+ There are two possible solutions:
+ - Manually mirror the edges of the texture.
+ - Add a "-1" when computing right and bottom, however the
+ last row/column might not be displayed at all.
+ */
+ left[j] = (source->i_x_offset + 0 ) * scale_w;
+ top[j] = (source->i_y_offset + 0 ) * scale_h;
+ right[j] = (source->i_x_offset + source->i_visible_width ) * scale_w;
+ bottom[j] = (source->i_y_offset + source->i_visible_height) * scale_h;
+ }
+
+ int ret = SetupCoords(vgl, left, top, right, bottom);
+ if (ret != VLC_SUCCESS)
+ return ret;
+
+ vgl->last_source.i_x_offset = source->i_x_offset;
+ vgl->last_source.i_y_offset = source->i_y_offset;
+ vgl->last_source.i_visible_width = source->i_visible_width;
+ vgl->last_source.i_visible_height = source->i_visible_height;
+ }
+
+ // Draw the main frame
+ DrawWithShaders(vgl, vgl->prgm);
+
+ // Draw the subpictures
+ int ret = DrawSubPicutresWithShaders(vgl, vgl->sub_prgm);
+ if (ret != VLC_SUCCESS)
+ return ret;
+
/* Display */
vlc_gl_Swap(vgl->gl);
--
2.11.0
More information about the vlc-devel
mailing list