- vout_opengl_Unlock(vgl->gl);
- return VLC_SUCCESS;
-}
-
-#ifdef __APPLE__
-/* XXX See comment vout_display_opengl_Prepare */
-struct picture_sys_t {
- vout_display_opengl_t *vgl;
- GLuint texture;
-};
-static int PictureLock(picture_t *picture)
-{
- if (!picture->p_sys)
- return VLC_SUCCESS;
-
- vout_display_opengl_t *vgl = picture->p_sys->vgl;
- if (!vout_opengl_Lock(vgl->gl)) {
-
- glBindTexture(VLCGL_TARGET, picture->p_sys->texture);
- glTexSubImage2D(VLCGL_TARGET, 0, 0, 0,
- vgl->fmt.i_width, vgl->fmt.i_height,
- VLCGL_FORMAT, VLCGL_TYPE, picture->p[0].p_pixels);
-
- vout_opengl_Unlock(vgl->gl);
- }
- return VLC_SUCCESS;
-}
-static void PictureUnlock(picture_t *picture)
-{
- VLC_UNUSED(picture);
-}
-#endif
-
-static picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl)
-{
- picture_t *picture[VLCGL_TEXTURE_COUNT];
-
- int i;
- for (i = 0; i < VLCGL_TEXTURE_COUNT; i++) {
-
- /* TODO memalign would be way better */
- vgl->buffer[i] = malloc(vgl->tex_width * vgl->tex_height * vgl->tex_pixel_size);
- if (!vgl->buffer[i])
- break;
-
- picture_resource_t rsc;
- memset(&rsc, 0, sizeof(rsc));
-#ifdef __APPLE__
- rsc.p_sys = malloc(sizeof(*rsc.p_sys));
- if (rsc.p_sys) {
- rsc.p_sys->vgl = vgl;
- rsc.p_sys->texture = vgl->texture[i];
- }
-#endif
- rsc.p[0].p_pixels = vgl->buffer[i];
- rsc.p[0].i_pitch = vgl->fmt.i_width * vgl->tex_pixel_size;
- rsc.p[0].i_lines = vgl->fmt.i_height;
-
- picture[i] = picture_NewFromResource(&vgl->fmt, &rsc);
- if (!picture[i]) {
- free(vgl->buffer[i]);
- vgl->buffer[i] = NULL;
- break;
- }
- }
- if (i < VLCGL_TEXTURE_COUNT)
- goto error;
-
- /* */
- picture_pool_configuration_t cfg;
- memset(&cfg, 0, sizeof(cfg));
- cfg.picture_count = i;
- cfg.picture = picture;
-#ifdef __APPLE__
- cfg.lock = PictureLock;
- cfg.unlock = PictureUnlock;
-#endif
- vgl->pool = picture_pool_NewExtended(&cfg);
- if (!vgl->pool)
- goto error;
-
- vout_display_opengl_ResetTextures(vgl);
-
- return vgl->pool;
-
-error:
- for (int j = 0; j < i; j++) {
- picture_Delete(picture[j]);
- vgl->buffer[j] = NULL;
- }
- return NULL;
-}
-
-static int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
- picture_t *picture)
-{
- /* On Win32/GLX, we do this the usual way:
- + Fill the buffer with new content,
- + Reload the texture,
- + Use the texture.
-
- On OS X with VRAM or AGP texturing, the order has to be:
- + Reload the texture,
- + Fill the buffer with new content,
- + Use the texture.
-
- (Thanks to gcc from the Arstechnica forums for the tip)
-
- Therefore on OSX, we have to use two buffers and textures and use a
- lock(/unlock) managed picture pool.
- */
-
- if (vout_opengl_Lock(vgl->gl))
- return VLC_EGENERIC;
-
-#ifdef __APPLE__
- /* Bind to the texture for drawing */
- glBindTexture(VLCGL_TARGET, picture->p_sys->texture);
-#else
- /* Update the texture */
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
- vgl->fmt.i_width, vgl->fmt.i_height,
- VLCGL_FORMAT, VLCGL_TYPE, picture->p[0].p_pixels);
-#endif
-
- vout_opengl_Unlock(vgl->gl);
- return VLC_SUCCESS;
-}
-
-static int vout_display_opengl_Display(vout_display_opengl_t *vgl,
- const video_format_t *source)
-{
- if (vout_opengl_Lock(vgl->gl))
- return VLC_EGENERIC;
-
- /* glTexCoord works differently with GL_TEXTURE_2D and
- GL_TEXTURE_RECTANGLE_EXT */
-#if VLCGL_TARGET == GL_TEXTURE_2D
- const float f_normw = vgl->tex_width;
- const float f_normh = vgl->tex_height;
-#else
- assert(VLCGL_TARGET == GL_TEXTURE_RECTANGLE_EXT);
- const float f_normw = 1.0;
- const float f_normh = 1.0;
-#endif
-
- float f_x = (source->i_x_offset + 0 ) / f_normw;
- float f_y = (source->i_y_offset + 0 ) / f_normh;
- float f_width = (source->i_x_offset + source->i_visible_width ) / f_normw;
- float f_height = (source->i_y_offset + source->i_visible_height) / f_normh;
-
- /* Why drawing here and not in Render()? Because this way, the
- OpenGL providers can call vout_display_opengl_Display to force redraw.i
- Currently, the OS X provider uses it to get a smooth window resizing */
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- glEnable(VLCGL_TARGET);
-
- glBegin(GL_POLYGON);
- glTexCoord2f(f_x, f_y); glVertex2f(-1.0, 1.0);
- glTexCoord2f(f_width, f_y); glVertex2f( 1.0, 1.0);
- glTexCoord2f(f_width, f_height); glVertex2f( 1.0, -1.0);
- glTexCoord2f(f_x, f_height); glVertex2f(-1.0, -1.0);
- glEnd();
-
- glDisable(VLCGL_TARGET);
-
- vout_opengl_Swap(vgl->gl);
-
- vout_opengl_Unlock(vgl->gl);
- return VLC_SUCCESS;
-}