]> git.sesse.net Git - vlc/blob - modules/video_output/opengl.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / video_output / opengl.c
1 /*****************************************************************************
2  * opengl.c: OpenGL video output
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet <asmax@videolan.org>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *          Eric Petit <titer@m0k.org>
10  *          Cedric Cocquebert <cedric.cocquebert@supelec.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include <errno.h>                                                 /* ENOMEM */
31
32 #include <vlc/vlc.h>
33 #include <vlc_vout.h>
34
35 #ifdef __APPLE__
36 #include <OpenGL/gl.h>
37 #include <OpenGL/glext.h>
38
39 /* On OS X, use GL_TEXTURE_RECTANGLE_EXT instead of GL_TEXTURE_2D.
40    This allows sizes which are not powers of 2 */
41 #define VLCGL_TARGET GL_TEXTURE_RECTANGLE_EXT
42
43 /* OS X OpenGL supports YUV. Hehe. */
44 #define VLCGL_FORMAT GL_YCBCR_422_APPLE
45 #define VLCGL_TYPE   GL_UNSIGNED_SHORT_8_8_APPLE
46 #else
47
48 #include <GL/gl.h>
49 #define VLCGL_TARGET GL_TEXTURE_2D
50
51 /* RV16 */
52 #ifndef GL_UNSIGNED_SHORT_5_6_5
53 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
54 #endif
55 //#define VLCGL_RGB_FORMAT GL_RGB
56 //#define VLCGL_RGB_TYPE GL_UNSIGNED_SHORT_5_6_5
57
58 /* RV24 */
59 //#define VLCGL_RGB_FORMAT GL_RGB
60 //#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
61
62 /* RV32 */
63 #define VLCGL_RGB_FORMAT GL_RGBA
64 #define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
65
66 /* YUY2 */
67 #ifndef YCBCR_MESA
68 #define YCBCR_MESA 0x8757
69 #endif
70 #ifndef UNSIGNED_SHORT_8_8_MESA
71 #define UNSIGNED_SHORT_8_8_MESA 0x85BA
72 #endif
73 #define VLCGL_YUV_FORMAT YCBCR_MESA
74 #define VLCGL_YUV_TYPE UNSIGNED_SHORT_8_8_MESA
75
76 /* Use RGB on Win32/GLX */
77 #define VLCGL_FORMAT VLCGL_RGB_FORMAT
78 #define VLCGL_TYPE   VLCGL_RGB_TYPE
79 //#define VLCGL_FORMAT VLCGL_YUV_FORMAT
80 //#define VLCGL_TYPE   VLCGL_YUV_TYPE
81 #endif
82
83 #ifndef GL_CLAMP_TO_EDGE
84 #   define GL_CLAMP_TO_EDGE 0x812F
85 #endif
86
87 /* OpenGL effects */
88 #define OPENGL_EFFECT_NONE             1
89 #define OPENGL_EFFECT_CUBE             2
90 #define OPENGL_EFFECT_TRANSPARENT_CUBE 4
91 #if defined( HAVE_GL_GLU_H ) || defined( __APPLE__ )
92     #define OPENGL_MORE_EFFECT           8
93 #endif
94
95 #ifdef OPENGL_MORE_EFFECT
96     #include <math.h>
97     #ifdef __APPLE__
98         #include <OpenGL/glu.h>
99     #else
100         #include <GL/glu.h>
101     #endif
102 /* 3D MODEL */
103     #define CYLINDER 8
104     #define TORUS     16
105     #define SPHERE   32
106 /*GRID2D TRANSFORMATION */
107     #define SQUAREXY 64
108     #define SQUARER  128
109     #define ASINXY   256
110     #define ASINR    512
111     #define SINEXY   1024
112     #define SINER    2048
113     #define INIFILE     4096                    // not used, just for mark end ...
114     #define SIGN(x)     (x < 0 ? (-1) : 1)
115     #define PID2     1.570796326794896619231322
116
117     static const char *ppsz_effects[] = {
118             "none", "cube", "transparent-cube", "cylinder", "torus", "sphere","SQUAREXY","SQUARER", "ASINXY", "ASINR", "SINEXY", "SINER" };
119     static const char *ppsz_effects_text[] = {
120             N_("None"), N_("Cube"), N_("Transparent Cube"),
121             N_("Cylinder"), N_("Torus"), N_("Sphere"), N_("SQUAREXY"),N_("SQUARER"), N_("ASINXY"), N_("ASINR"), N_("SINEXY"), N_("SINER") };
122 #endif
123
124 /*****************************************************************************
125  * Vout interface
126  *****************************************************************************/
127 static int  CreateVout   ( vlc_object_t * );
128 static void DestroyVout  ( vlc_object_t * );
129 static int  Init         ( vout_thread_t * );
130 static void End          ( vout_thread_t * );
131 static int  Manage       ( vout_thread_t * );
132 static void Render       ( vout_thread_t *, picture_t * );
133 static void DisplayVideo ( vout_thread_t *, picture_t * );
134 static int  Control      ( vout_thread_t *, int, va_list );
135
136 static inline int GetAlignedSize( int );
137
138 static int InitTextures  ( vout_thread_t * );
139 static int SendEvents    ( vlc_object_t *, char const *,
140                            vlc_value_t, vlc_value_t, void * );
141
142 #ifdef OPENGL_MORE_EFFECT
143 static float Z_Compute   ( float, int, float, float );
144 static void Transform    ( float, int, float, float, int, int, int, int, double *, double * );
145
146 /*****************************************************************************
147  * Module descriptor
148  *****************************************************************************/
149 #define ACCURACY_TEXT N_( "OpenGL sampling accuracy " )
150 #define ACCURACY_LONGTEXT N_( "Select the accuracy of 3D object sampling(1 = min and 10 = max)" )
151 #define RADIUS_TEXT N_( "OpenGL Cylinder radius" )
152 #define RADIUS_LONGTEXT N_( "Radius of the OpenGL cylinder effect, if enabled" )
153 #define POV_X_TEXT N_("Point of view x-coordinate")
154 #define POV_X_LONGTEXT N_("Point of view (X coordinate) of the cube/cylinder "\
155                            "effect, if enabled.")
156 #define POV_Y_TEXT N_("Point of view y-coordinate")
157 #define POV_Y_LONGTEXT N_("Point of view (Y coordinate) of the cube/cylinder "\
158                            "effect, if enabled.")
159 #define POV_Z_TEXT N_("Point of view z-coordinate")
160 #define POV_Z_LONGTEXT N_("Point of view (Z coordinate) of the cube/cylinder "\
161                            "effect, if enabled.")
162 #endif
163 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
164 #define SPEED_LONGTEXT N_( "Rotation speed of the OpenGL cube effect, if " \
165         "enabled." )
166 #define EFFECT_TEXT N_("Effect")
167 #define EFFECT_LONGTEXT N_( \
168     "Several visual OpenGL effects are available." )
169
170 #ifndef OPENGL_MORE_EFFECT
171 static const char *ppsz_effects[] = {
172         "none", "cube", "transparent-cube" };
173 static const char *ppsz_effects_text[] = {
174         N_("None"), N_("Cube"), N_("Transparent Cube") };
175 #endif
176
177 vlc_module_begin();
178     set_shortname( "OpenGL" );
179     set_category( CAT_VIDEO );
180     set_subcategory( SUBCAT_VIDEO_VOUT );
181     set_description( _("OpenGL video output") );
182 #ifdef __APPLE__
183     set_capability( "video output", 200 );
184 #else
185     set_capability( "video output", 20 );
186 #endif
187     add_shortcut( "opengl" );
188     add_float( "opengl-cube-speed", 2.0, NULL, SPEED_TEXT,
189                     SPEED_LONGTEXT, VLC_TRUE );
190 #ifdef OPENGL_MORE_EFFECT
191     add_integer_with_range( "opengl-accuracy", 4, 1, 10, NULL, ACCURACY_TEXT,
192                     ACCURACY_LONGTEXT, VLC_TRUE );
193     add_float_with_range( "opengl-pov-x", 0.0, -1.0, 1.0, NULL, POV_X_TEXT,
194                     POV_X_LONGTEXT, VLC_TRUE );
195     add_float_with_range( "opengl-pov-y", 0.0, -1.0, 1.0, NULL, POV_Y_TEXT,
196                     POV_Y_LONGTEXT, VLC_TRUE );
197     add_float_with_range( "opengl-pov-z", -1.0, -1.0, 1.0, NULL, POV_Z_TEXT,
198                     POV_Z_LONGTEXT, VLC_TRUE );
199     add_float( "opengl-cylinder-radius", -100.0, NULL, RADIUS_TEXT,
200                     RADIUS_LONGTEXT, VLC_TRUE );
201
202 #endif
203     set_callbacks( CreateVout, DestroyVout );
204     add_string( "opengl-effect", "none", NULL, EFFECT_TEXT,
205                  EFFECT_LONGTEXT, VLC_FALSE );
206         change_string_list( ppsz_effects, ppsz_effects_text, 0 );
207 vlc_module_end();
208
209 /*****************************************************************************
210  * vout_sys_t: video output method descriptor
211  *****************************************************************************
212  * This structure is part of the video output thread descriptor.
213  * It describes the OpenGL specific properties of the output thread.
214  *****************************************************************************/
215 struct vout_sys_t
216 {
217     vout_thread_t *p_vout;
218
219     uint8_t    *pp_buffer[2];
220     int         i_index;
221     int         i_tex_width;
222     int         i_tex_height;
223     GLuint      p_textures[2];
224
225     int         i_effect;
226
227     float       f_speed;
228     float       f_radius;
229 };
230
231 /*****************************************************************************
232  * CreateVout: This function allocates and initializes the OpenGL vout method.
233  *****************************************************************************/
234 static int CreateVout( vlc_object_t *p_this )
235 {
236     vout_thread_t *p_vout = (vout_thread_t *)p_this;
237     vout_sys_t *p_sys;
238
239     /* Allocate structure */
240     p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
241     if( p_sys == NULL )
242     {
243         msg_Err( p_vout, "out of memory" );
244         return VLC_EGENERIC;
245     }
246
247     var_Create( p_vout, "opengl-effect", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
248
249     p_sys->i_index = 0;
250 #ifdef __APPLE__
251     p_sys->i_tex_width  = p_vout->fmt_in.i_width;
252     p_sys->i_tex_height = p_vout->fmt_in.i_height;
253 #else
254     /* A texture must have a size aligned on a power of 2 */
255     p_sys->i_tex_width  = GetAlignedSize( p_vout->fmt_in.i_width );
256     p_sys->i_tex_height = GetAlignedSize( p_vout->fmt_in.i_height );
257 #endif
258
259     msg_Dbg( p_vout, "Texture size: %dx%d", p_sys->i_tex_width,
260              p_sys->i_tex_height );
261
262     /* Get window */
263     p_sys->p_vout =
264         (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
265     if( p_sys->p_vout == NULL )
266     {
267         msg_Err( p_vout, "out of memory" );
268         return VLC_ENOMEM;
269     }
270     vlc_object_attach( p_sys->p_vout, p_this );
271
272     p_sys->p_vout->i_window_width = p_vout->i_window_width;
273     p_sys->p_vout->i_window_height = p_vout->i_window_height;
274     p_sys->p_vout->b_fullscreen = p_vout->b_fullscreen;
275     p_sys->p_vout->render.i_width = p_vout->render.i_width;
276     p_sys->p_vout->render.i_height = p_vout->render.i_height;
277     p_sys->p_vout->render.i_aspect = p_vout->render.i_aspect;
278     p_sys->p_vout->fmt_render = p_vout->fmt_render;
279     p_sys->p_vout->fmt_in = p_vout->fmt_in;
280     p_sys->p_vout->b_scale = p_vout->b_scale;
281     p_sys->p_vout->i_alignment = p_vout->i_alignment;
282
283     p_sys->p_vout->p_module =
284         module_Need( p_sys->p_vout, "opengl provider", NULL, 0 );
285     if( p_sys->p_vout->p_module == NULL )
286     {
287         msg_Warn( p_vout, "No OpenGL provider found" );
288         vlc_object_detach( p_sys->p_vout );
289         vlc_object_destroy( p_sys->p_vout );
290         return VLC_ENOOBJ;
291     }
292
293     p_sys->f_speed = var_CreateGetFloat( p_vout, "opengl-cube-speed" );
294     p_sys->f_radius = var_CreateGetFloat( p_vout, "opengl-cylinder-radius" );
295
296     p_vout->pf_init = Init;
297     p_vout->pf_end = End;
298     p_vout->pf_manage = Manage;
299     p_vout->pf_render = Render;
300     p_vout->pf_display = DisplayVideo;
301     p_vout->pf_control = Control;
302
303     /* Forward events from the opengl provider */
304     var_Create( p_sys->p_vout, "mouse-x", VLC_VAR_INTEGER );
305     var_Create( p_sys->p_vout, "mouse-y", VLC_VAR_INTEGER );
306     var_Create( p_sys->p_vout, "mouse-moved", VLC_VAR_BOOL );
307     var_Create( p_sys->p_vout, "mouse-clicked", VLC_VAR_INTEGER );
308     var_Create( p_sys->p_vout, "mouse-button-down", VLC_VAR_INTEGER );
309     var_Create( p_sys->p_vout, "video-on-top",
310                 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
311
312     var_AddCallback( p_sys->p_vout, "mouse-x", SendEvents, p_vout );
313     var_AddCallback( p_sys->p_vout, "mouse-y", SendEvents, p_vout );
314     var_AddCallback( p_sys->p_vout, "mouse-moved", SendEvents, p_vout );
315     var_AddCallback( p_sys->p_vout, "mouse-clicked", SendEvents, p_vout );
316     var_AddCallback( p_sys->p_vout, "mouse-button-down", SendEvents, p_vout );
317
318     return VLC_SUCCESS;
319 }
320
321 /*****************************************************************************
322  * Init: initialize the OpenGL video thread output method
323  *****************************************************************************/
324 static int Init( vout_thread_t *p_vout )
325 {
326     vout_sys_t *p_sys = p_vout->p_sys;
327     int i_pixel_pitch;
328     vlc_value_t val;
329
330     p_sys->p_vout->pf_init( p_sys->p_vout );
331
332 /* TODO: We use YCbCr on Mac which is Y422, but on OSX it seems to == YUY2. Verify */
333 #if ( defined( WORDS_BIGENDIAN ) && VLCGL_FORMAT == GL_YCBCR_422_APPLE ) || (VLCGL_FORMAT == YCBCR_MESA)
334     p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
335     i_pixel_pitch = 2;
336
337 #elif (VLCGL_FORMAT == GL_YCBCR_422_APPLE)
338     p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
339     i_pixel_pitch = 2;
340
341 #elif VLCGL_FORMAT == GL_RGB
342 #   if VLCGL_TYPE == GL_UNSIGNED_BYTE
343     p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
344 #       if defined( WORDS_BIGENDIAN )
345     p_vout->output.i_rmask = 0x00ff0000;
346     p_vout->output.i_gmask = 0x0000ff00;
347     p_vout->output.i_bmask = 0x000000ff;
348 #       else
349     p_vout->output.i_rmask = 0x000000ff;
350     p_vout->output.i_gmask = 0x0000ff00;
351     p_vout->output.i_bmask = 0x00ff0000;
352 #       endif
353     i_pixel_pitch = 3;
354 #   else
355     p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
356 #       if defined( WORDS_BIGENDIAN )
357     p_vout->output.i_rmask = 0x001f;
358     p_vout->output.i_gmask = 0x07e0;
359     p_vout->output.i_bmask = 0xf800;
360 #       else
361     p_vout->output.i_rmask = 0xf800;
362     p_vout->output.i_gmask = 0x07e0;
363     p_vout->output.i_bmask = 0x001f;
364 #       endif
365     i_pixel_pitch = 2;
366 #   endif
367 #else
368     p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
369 #       if defined( WORDS_BIGENDIAN )
370     p_vout->output.i_rmask = 0xff000000;
371     p_vout->output.i_gmask = 0x00ff0000;
372     p_vout->output.i_bmask = 0x0000ff00;
373 #       else
374     p_vout->output.i_rmask = 0x000000ff;
375     p_vout->output.i_gmask = 0x0000ff00;
376     p_vout->output.i_bmask = 0x00ff0000;
377 #       endif
378     i_pixel_pitch = 4;
379 #endif
380
381     /* Since OpenGL can do rescaling for us, stick to the default
382      * coordinates and aspect. */
383     p_vout->output.i_width  = p_vout->render.i_width;
384     p_vout->output.i_height = p_vout->render.i_height;
385     p_vout->output.i_aspect = p_vout->render.i_aspect;
386
387     p_vout->fmt_out = p_vout->fmt_in;
388     p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
389
390     /* We know the chroma, allocate one buffer which will be used
391      * directly by the decoder */
392     p_sys->pp_buffer[0] =
393         malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
394     if( !p_sys->pp_buffer[0] )
395     {
396         msg_Err( p_vout, "out of memory" );
397         return -1;
398     }
399     p_sys->pp_buffer[1] =
400         malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
401     if( !p_sys->pp_buffer[1] )
402     {
403         msg_Err( p_vout, "out of memory" );
404         return -1;
405     }
406
407     p_vout->p_picture[0].i_planes = 1;
408     p_vout->p_picture[0].p->p_pixels = p_sys->pp_buffer[0];
409     p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;
410     p_vout->p_picture[0].p->i_visible_lines = p_vout->output.i_height;
411     p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;
412     p_vout->p_picture[0].p->i_pitch = p_vout->output.i_width *
413         p_vout->p_picture[0].p->i_pixel_pitch;
414     p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *
415         p_vout->p_picture[0].p->i_pixel_pitch;
416
417     p_vout->p_picture[0].i_status = DESTROYED_PICTURE;
418     p_vout->p_picture[0].i_type   = DIRECT_PICTURE;
419
420     PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];
421
422     I_OUTPUTPICTURES = 1;
423
424     if( p_sys->p_vout->pf_lock &&
425         p_sys->p_vout->pf_lock( p_sys->p_vout ) )
426     {
427         msg_Warn( p_vout, "could not lock OpenGL provider" );
428         return 0;
429     }
430
431     InitTextures( p_vout );
432
433     glDisable(GL_BLEND);
434     glDisable(GL_DEPTH_TEST);
435     glDepthMask(GL_FALSE);
436     glDisable(GL_CULL_FACE);
437     glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
438     glClear( GL_COLOR_BUFFER_BIT );
439
440     /* Check if the user asked for useless visual effects */
441     var_Get( p_vout, "opengl-effect", &val );
442     if( !val.psz_string || !strcmp( val.psz_string, "none" ))
443     {
444         p_sys->i_effect = OPENGL_EFFECT_NONE;
445     }
446     else if( !strcmp( val.psz_string, "cube" ) )
447     {
448         p_sys->i_effect = OPENGL_EFFECT_CUBE;
449
450         glEnable( GL_CULL_FACE);
451     }
452     else if( !strcmp( val.psz_string, "transparent-cube" ) )
453     {
454         p_sys->i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;
455
456         glDisable( GL_DEPTH_TEST );
457         glEnable( GL_BLEND );
458         glBlendFunc( GL_SRC_ALPHA, GL_ONE );
459     }
460     else
461     {
462 #ifdef OPENGL_MORE_EFFECT
463         p_sys->i_effect = 3;
464         while (( strcmp( val.psz_string, ppsz_effects[p_sys->i_effect]) ) && (pow(2,p_sys->i_effect) < INIFILE))
465         {
466             p_sys->i_effect ++;
467         }
468         if (pow(2,p_sys->i_effect) < INIFILE)
469             p_sys->i_effect = pow(2,p_sys->i_effect);
470         else if ( strcmp( val.psz_string, ppsz_effects[p_sys->i_effect]))
471         {
472             msg_Warn( p_vout, "no valid opengl effect provided, using "
473                       "\"none\"" );
474             p_sys->i_effect = OPENGL_EFFECT_NONE;
475         }
476 #else
477         msg_Warn( p_vout, "no valid opengl effect provided, using "
478                   "\"none\"" );
479         p_sys->i_effect = OPENGL_EFFECT_NONE;
480 #endif
481     }
482     if( val.psz_string ) free( val.psz_string );
483
484     if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
485                 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
486     {
487         /* Set the perpective */
488         glMatrixMode( GL_PROJECTION );
489         glLoadIdentity();
490         glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
491         glMatrixMode( GL_MODELVIEW );
492         glLoadIdentity();
493         glTranslatef( 0.0, 0.0, - 5.0 );
494     }
495 #ifdef OPENGL_MORE_EFFECT
496     else
497     {
498         /* Set the perpective */
499         glMatrixMode( GL_PROJECTION );
500         glLoadIdentity();
501         glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
502         glMatrixMode( GL_MODELVIEW );
503         glLoadIdentity();
504         glTranslatef( 0.0, 0.0, -3.0 );
505
506         float f_pov_x, f_pov_y, f_pov_z;
507         f_pov_x = var_CreateGetFloat( p_vout, "opengl-pov-x");
508         f_pov_y = var_CreateGetFloat( p_vout, "opengl-pov-y");
509         f_pov_z = var_CreateGetFloat( p_vout, "opengl-pov-z");
510         gluLookAt(0, 0, 0, f_pov_x, f_pov_y, f_pov_z, 0, 1, 0);
511     }
512 #endif
513     if( p_sys->p_vout->pf_unlock )
514     {
515         p_sys->p_vout->pf_unlock( p_sys->p_vout );
516     }
517
518     return 0;
519 }
520
521 /*****************************************************************************
522  * End: terminate GLX video thread output method
523  *****************************************************************************/
524 static void End( vout_thread_t *p_vout )
525 {
526     vout_sys_t *p_sys = p_vout->p_sys;
527
528     if( p_sys->p_vout->pf_lock &&
529         p_sys->p_vout->pf_lock( p_sys->p_vout ) )
530     {
531         msg_Warn( p_vout, "could not lock OpenGL provider" );
532         return;
533     }
534
535     glFinish();
536     glFlush();
537
538     /* Free the texture buffer*/
539     glDeleteTextures( 2, p_sys->p_textures );
540     if( p_sys->pp_buffer[0] ) free( p_sys->pp_buffer[0] );
541     if( p_sys->pp_buffer[1] ) free( p_sys->pp_buffer[1] );
542
543     if( p_sys->p_vout->pf_unlock )
544     {
545         p_sys->p_vout->pf_unlock( p_sys->p_vout );
546     }
547 }
548
549 /*****************************************************************************
550  * Destroy: destroy GLX video thread output method
551  *****************************************************************************
552  * Terminate an output method created by CreateVout
553  *****************************************************************************/
554 static void DestroyVout( vlc_object_t *p_this )
555 {
556     vout_thread_t *p_vout = (vout_thread_t *)p_this;
557     vout_sys_t *p_sys = p_vout->p_sys;
558
559     module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );
560     vlc_object_detach( p_sys->p_vout );
561     vlc_object_destroy( p_sys->p_vout );
562
563     free( p_sys );
564 }
565
566 /*****************************************************************************
567  * Manage: handle Sys events
568  *****************************************************************************
569  * This function should be called regularly by video output thread. It returns
570  * a non null value if an error occurred.
571  *****************************************************************************/
572 static int Manage( vout_thread_t *p_vout )
573 {
574     vout_sys_t *p_sys = p_vout->p_sys;
575     int i_ret, i_fullscreen_change;
576
577     i_fullscreen_change = ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE );
578
579     p_vout->fmt_out.i_x_offset = p_sys->p_vout->fmt_in.i_x_offset =
580         p_vout->fmt_in.i_x_offset;
581     p_vout->fmt_out.i_y_offset = p_sys->p_vout->fmt_in.i_y_offset =
582         p_vout->fmt_in.i_y_offset;
583     p_vout->fmt_out.i_visible_width = p_sys->p_vout->fmt_in.i_visible_width =
584         p_vout->fmt_in.i_visible_width;
585     p_vout->fmt_out.i_visible_height = p_sys->p_vout->fmt_in.i_visible_height =
586         p_vout->fmt_in.i_visible_height;
587     p_vout->fmt_out.i_aspect = p_sys->p_vout->fmt_in.i_aspect =
588         p_vout->fmt_in.i_aspect;
589     p_vout->fmt_out.i_sar_num = p_sys->p_vout->fmt_in.i_sar_num =
590         p_vout->fmt_in.i_sar_num;
591     p_vout->fmt_out.i_sar_den = p_sys->p_vout->fmt_in.i_sar_den =
592         p_vout->fmt_in.i_sar_den;
593     p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;
594
595     p_sys->p_vout->i_changes = p_vout->i_changes;
596     i_ret = p_sys->p_vout->pf_manage( p_sys->p_vout );
597     p_vout->i_changes = p_sys->p_vout->i_changes;
598
599 #ifdef __APPLE__
600     if( p_sys->p_vout->pf_lock &&
601         p_sys->p_vout->pf_lock( p_sys->p_vout ) )
602     {
603         msg_Warn( p_vout, "could not lock OpenGL provider" );
604         return i_ret;
605     }
606
607     /* On OS X, we create the window and the GL view when entering
608        fullscreen - the textures have to be inited again */
609     if( i_fullscreen_change )
610     {
611         InitTextures( p_vout );
612
613         switch( p_sys->i_effect )
614         {
615             case OPENGL_EFFECT_CUBE:
616 #ifdef OPENGL_MORE_EFFECT
617             case CYLINDER:
618             case TORUS:
619             case SPHERE:
620             case SQUAREXY:
621             case SQUARER:
622             case ASINXY:
623             case ASINR:
624             case SINEXY:
625             case SINER:
626 #endif
627                 glEnable( GL_CULL_FACE );
628                 break;
629
630             case OPENGL_EFFECT_TRANSPARENT_CUBE:
631                 glDisable( GL_DEPTH_TEST );
632                 glEnable( GL_BLEND );
633                 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
634                 break;
635         }
636
637         if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
638                     OPENGL_EFFECT_TRANSPARENT_CUBE ) )
639         {
640             /* Set the perpective */
641             glMatrixMode( GL_PROJECTION );
642             glLoadIdentity();
643             glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
644             glMatrixMode( GL_MODELVIEW );
645             glLoadIdentity();
646             glTranslatef( 0.0, 0.0, - 5.0 );
647         }
648 #ifdef OPENGL_MORE_EFFECT
649         else
650         {
651             glMatrixMode( GL_PROJECTION );
652             glLoadIdentity();
653             glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
654             glMatrixMode( GL_MODELVIEW );
655             glLoadIdentity();
656             glTranslatef( 0.0, 0.0, -3.0 );
657  
658             float f_pov_x, f_pov_y, f_pov_z;
659             f_pov_x = var_CreateGetFloat( p_vout, "opengl-pov-x");
660             f_pov_y = var_CreateGetFloat( p_vout, "opengl-pov-y");
661             f_pov_z = var_CreateGetFloat( p_vout, "opengl-pov-z");
662             gluLookAt(0, 0, 0, f_pov_x, f_pov_y, f_pov_z, 0, 1, 0);
663         }
664 #endif
665     }
666
667     if( p_sys->p_vout->pf_unlock )
668     {
669         p_sys->p_vout->pf_unlock( p_sys->p_vout );
670     }
671 #endif
672 // to align in real time in OPENGL
673     if (p_sys->p_vout->i_alignment != p_vout->i_alignment)
674     {
675         p_vout->i_changes = VOUT_CROP_CHANGE;        //to force change
676         p_sys->p_vout->i_alignment = p_vout->i_alignment;    
677     }
678     
679     return i_ret;
680 }
681
682 /*****************************************************************************
683  * Render: render previously calculated output
684  *****************************************************************************/
685 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
686 {
687     vout_sys_t *p_sys = p_vout->p_sys;
688
689     /* On Win32/GLX, we do this the usual way:
690        + Fill the buffer with new content,
691        + Reload the texture,
692        + Use the texture.
693
694        On OS X with VRAM or AGP texturing, the order has to be:
695        + Reload the texture,
696        + Fill the buffer with new content,
697        + Use the texture.
698
699        (Thanks to gcc from the Arstechnica forums for the tip)
700
701        Therefore, we have to use two buffers and textures. On Win32/GLX,
702        we reload the texture to be displayed and use it right away. On
703        OS X, we first render, then reload the texture to be used next
704        time. */
705
706     if( p_sys->p_vout->pf_lock &&
707         p_sys->p_vout->pf_lock( p_sys->p_vout ) )
708     {
709         msg_Warn( p_vout, "could not lock OpenGL provider" );
710         return;
711     }
712
713 #ifdef __APPLE__
714     int i_new_index;
715     i_new_index = ( p_sys->i_index + 1 ) & 1;
716
717
718     /* Update the texture */
719     glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_new_index] );
720     glTexSubImage2D( VLCGL_TARGET, 0, 0, 0,
721                      p_vout->fmt_out.i_width,
722                      p_vout->fmt_out.i_height,
723                      VLCGL_FORMAT, VLCGL_TYPE, p_sys->pp_buffer[i_new_index] );
724
725     /* Bind to the previous texture for drawing */
726     glBindTexture( VLCGL_TARGET, p_sys->p_textures[p_sys->i_index] );
727
728     /* Switch buffers */
729     p_sys->i_index = i_new_index;
730     p_pic->p->p_pixels = p_sys->pp_buffer[p_sys->i_index];
731
732 #else
733     /* Update the texture */
734     glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0,
735                      p_vout->fmt_out.i_width,
736                      p_vout->fmt_out.i_height,
737                      VLCGL_FORMAT, VLCGL_TYPE, p_sys->pp_buffer[0] );
738 #endif
739
740     if( p_sys->p_vout->pf_unlock )
741     {
742         p_sys->p_vout->pf_unlock( p_sys->p_vout );
743     }
744 }
745
746
747 #ifdef OPENGL_MORE_EFFECT
748 /*****************************************************************************
749  *   Transform: Calculate the distorted grid coordinates
750  *****************************************************************************/
751 static void Transform(float p, int distortion, float width, float height,int i, int j, int i_visible_width, int i_visible_height, double *ix,double *iy)
752 {
753     double x,y,xnew,ynew;
754     double r,theta,rnew,thetanew;
755
756     x = (double)i * (width / ((double)i_visible_width));
757     y = (double)j * (height / ((double)i_visible_height));
758
759     x = (2.0 * (double)x / width) - 1;
760     y = (2.0 * (double)y / height) - 1;
761     xnew = x;
762     ynew = y;
763     r = sqrt(x*x+y*y);
764     theta = atan2(y,x);
765
766     switch (distortion)
767     {
768 /* GRID2D TRANSFORMATION */
769         case SINEXY:
770             xnew = sin(PID2*x);
771             ynew = sin(PID2*y);
772             break;
773         case SINER:
774             rnew = sin(PID2*r);
775             thetanew = theta;
776             xnew = rnew * cos(thetanew);
777             ynew = rnew * sin(thetanew);
778             break;
779         case SQUAREXY:
780             xnew = x*x*SIGN(x);
781             ynew = y*y*SIGN(y);
782             break;
783         case SQUARER:
784             rnew = r*r;
785             thetanew = theta;
786             xnew = rnew * cos(thetanew);
787             ynew = rnew * sin(thetanew);
788             break;
789         case ASINXY:
790             xnew = asin(x) / PID2;
791             ynew = asin(y) / PID2;
792             break;
793         case ASINR:
794             rnew = asin(r) / PID2;
795             thetanew = theta;
796             xnew = rnew * cos(thetanew);
797             ynew = rnew * sin(thetanew);
798             break;
799 /* OTHER WAY: 3D MODEL */
800         default:
801             xnew = x;
802             ynew = y;
803     }
804
805     *ix = width * (xnew + 1) / (2.0);
806     *iy = height * (ynew + 1) / (2.0);
807 }
808
809 /*****************************************************************************
810  *   Z_Compute: Calculate the Z-coordinate
811  *****************************************************************************/
812 static float Z_Compute(float p, int distortion, float x, float y)
813 {
814     float f_z = 0.0;
815     double d_p = p / 100.0;
816
817     switch (distortion)
818     {
819 /* 3D MODEL */
820         case CYLINDER:
821             if (d_p > 0)
822                 f_z = (1 - d_p * d_p) / (2 * d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x));
823             else
824                 f_z = (1 - d_p * d_p) / (2 * d_p) + d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x));
825             break;
826         case TORUS:
827             if (d_p > 0)
828                 f_z =  (1 - d_p * d_p) / (d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x)) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - y * y));
829             else
830                 f_z =  (1 - d_p * d_p) / (d_p) + 2 * d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x)) + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - y * y));
831             break;
832         case SPHERE:
833             if (d_p > 0)
834                 f_z = (1 - d_p * d_p) / (2 * d_p) - sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x - y * y));
835             else
836                 f_z = (1 - d_p * d_p) / (2 * d_p) + d_p + sqrt(fabs((d_p * d_p + 1) / (2 * d_p) * (d_p * d_p + 1) / (2 * d_p) - x * x - y * y));
837             break;
838 /* OTHER WAY: GRID2D TRANSFORMATION */
839         case SINEXY:;
840         case SINER:
841         case SQUAREXY:
842         case SQUARER:;
843         case ASINXY:
844         case ASINR:
845             f_z = 0.0;
846             break;
847         default:
848             f_z = 0.0;
849     }
850     return f_z;
851 }
852 #endif
853
854
855 /*****************************************************************************
856  * DisplayVideo: displays previously rendered output
857  *****************************************************************************/
858 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
859 {
860     vout_sys_t *p_sys = p_vout->p_sys;
861     float f_width, f_height, f_x, f_y;
862
863     if( p_sys->p_vout->pf_lock &&
864         p_sys->p_vout->pf_lock( p_sys->p_vout ) )
865     {
866         msg_Warn( p_vout, "could not lock OpenGL provider" );
867         return;
868     }
869
870     /* glTexCoord works differently with GL_TEXTURE_2D and
871        GL_TEXTURE_RECTANGLE_EXT */
872 #ifdef __APPLE__
873     f_x = (float)p_vout->fmt_out.i_x_offset;
874     f_y = (float)p_vout->fmt_out.i_y_offset;
875     f_width = (float)p_vout->fmt_out.i_x_offset +
876               (float)p_vout->fmt_out.i_visible_width;
877     f_height = (float)p_vout->fmt_out.i_y_offset +
878                (float)p_vout->fmt_out.i_visible_height;
879 #else
880     f_x = (float)p_vout->fmt_out.i_x_offset / p_sys->i_tex_width;
881     f_y = (float)p_vout->fmt_out.i_y_offset / p_sys->i_tex_height;
882     f_width = ( (float)p_vout->fmt_out.i_x_offset +
883                 p_vout->fmt_out.i_visible_width ) / p_sys->i_tex_width;
884     f_height = ( (float)p_vout->fmt_out.i_y_offset +
885                  p_vout->fmt_out.i_visible_height ) / p_sys->i_tex_height;
886 #endif
887
888     /* Why drawing here and not in Render()? Because this way, the
889        OpenGL providers can call pf_display to force redraw. Currently,
890        the OS X provider uses it to get a smooth window resizing */
891
892     glClear( GL_COLOR_BUFFER_BIT );
893
894     if( p_sys->i_effect == OPENGL_EFFECT_NONE )
895     {
896         glEnable( VLCGL_TARGET );
897         glBegin( GL_POLYGON );
898         glTexCoord2f( f_x, f_y ); glVertex2f( -1.0, 1.0 );
899         glTexCoord2f( f_width, f_y ); glVertex2f( 1.0, 1.0 );
900         glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 );
901         glTexCoord2f( f_x, f_height ); glVertex2f( -1.0, -1.0 );
902         glEnd();
903     }
904     else
905 #ifdef OPENGL_MORE_EFFECT
906     if ((p_sys->i_effect > OPENGL_EFFECT_TRANSPARENT_CUBE) ||
907         ((p_sys->i_effect == OPENGL_EFFECT_NONE)))
908     {
909        unsigned int i_i, i_j;
910        unsigned int i_accuracy  = config_GetInt( p_vout, "opengl-accuracy");
911        unsigned int i_n = pow(2, i_accuracy);
912        unsigned int i_n_x = (p_vout->fmt_out.i_visible_width / (i_n * 2));
913        unsigned int i_n_y = (p_vout->fmt_out.i_visible_height / i_n);
914        double d_x, d_y;
915        int i_distortion = p_sys->i_effect;
916        float f_p = p_sys->f_radius;
917  
918        glEnable( VLCGL_TARGET );
919        glBegin(GL_QUADS);
920        for (i_i = 0; i_i < p_vout->fmt_out.i_visible_width; i_i += i_n_x)
921        {
922           if ( i_i == i_n_x * i_n / 2) i_n_x += p_vout->fmt_out.i_visible_width % i_n;
923           if ((i_i == (p_vout->fmt_out.i_visible_width / i_n) * i_n / 2 + i_n_x) &&
924               (p_vout->fmt_out.i_visible_width / i_n != i_n_x))
925                 i_n_x -= p_vout->fmt_out.i_visible_width % i_n;
926
927           int i_m;
928           int i_index_max = 0;
929  
930           for (i_j = 0; i_j < p_vout->fmt_out.i_visible_height; i_j += i_n_y)
931           {
932             if ( i_j == i_n_y * i_n / 2) i_n_y += p_vout->fmt_out.i_visible_height % i_n;
933             if ((i_j == (p_vout->fmt_out.i_visible_height / i_n) * i_n / 2 + i_n_y) &&
934                 (p_vout->fmt_out.i_visible_height / i_n != i_n_y))
935                     i_n_y -= p_vout->fmt_out.i_visible_height % i_n;
936
937             for (i_m = i_index_max; i_m < i_index_max + 4; i_m++)
938             {
939                 int i_k = ((i_m % 4) == 1) || ((i_m % 4) == 2);
940                 int i_l = ((i_m % 4) == 2) || ((i_m % 4) == 3);
941
942                 Transform(f_p, i_distortion, f_width, f_height, i_i + i_k * i_n_x, i_j + i_l * i_n_y, p_vout->fmt_out.i_visible_width, p_vout->fmt_out.i_visible_height, &d_x, &d_y);
943                 glTexCoord2f(f_x + d_x, f_y + d_y);
944                 d_x =  - 1.0 + 2.0 * ((double)(i_k * i_n_x + i_i) / (double)p_vout->fmt_out.i_visible_width);
945                 d_y =    1.0 - 2.0 * (((double)i_l * i_n_y + i_j) / (double)p_vout->fmt_out.i_visible_height);
946                 glVertex3f((float)d_x, (float)d_y, Z_Compute(f_p, i_distortion, (float)d_x, (float)d_y));
947             }
948           }
949        }
950        glEnd();
951     }
952     else
953 #endif
954     {
955         glRotatef( 0.5 * p_sys->f_speed , 0.3, 0.5, 0.7 );
956
957         glEnable( VLCGL_TARGET );
958         glBegin( GL_QUADS );
959
960         /* Front */
961         glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, 1.0 );
962         glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
963         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
964         glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, 1.0 );
965
966         /* Left */
967         glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
968         glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
969         glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
970         glTexCoord2f( f_width, f_y ); glVertex3f( - 1.0, 1.0, 1.0 );
971
972         /* Back */
973         glTexCoord2f( f_x, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
974         glTexCoord2f( f_x, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
975         glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
976         glTexCoord2f( f_width, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
977
978         /* Right */
979         glTexCoord2f( f_x, f_y ); glVertex3f( 1.0, 1.0, 1.0 );
980         glTexCoord2f( f_x, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
981         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
982         glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
983
984         /* Top */
985         glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
986         glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, 1.0, 1.0 );
987         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 );
988         glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
989
990         /* Bottom */
991         glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, - 1.0, 1.0 );
992         glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
993         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
994         glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, - 1.0, 1.0 );
995         glEnd();
996     }
997
998     glDisable( VLCGL_TARGET );
999
1000     p_sys->p_vout->pf_swap( p_sys->p_vout );
1001
1002     if( p_sys->p_vout->pf_unlock )
1003     {
1004         p_sys->p_vout->pf_unlock( p_sys->p_vout );
1005     }
1006 }
1007
1008 int GetAlignedSize( int i_size )
1009 {
1010     /* Return the nearest power of 2 */
1011     int i_result = 1;
1012     while( i_result < i_size )
1013     {
1014         i_result *= 2;
1015     }
1016     return i_result;
1017 }
1018
1019 /*****************************************************************************
1020  * Control: control facility for the vout
1021  *****************************************************************************/
1022 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
1023 {
1024     vout_sys_t *p_sys = p_vout->p_sys;
1025
1026     switch( i_query )
1027     {
1028     case VOUT_SNAPSHOT:
1029         return vout_vaControlDefault( p_vout, i_query, args );
1030
1031     default:
1032         if( p_sys->p_vout->pf_control )
1033             return p_sys->p_vout->pf_control( p_sys->p_vout, i_query, args );
1034         else
1035             return vout_vaControlDefault( p_vout, i_query, args );
1036     }
1037 }
1038
1039 static int InitTextures( vout_thread_t *p_vout )
1040 {
1041     vout_sys_t *p_sys = p_vout->p_sys;
1042     int i_index;
1043
1044     glDeleteTextures( 2, p_sys->p_textures );
1045     glGenTextures( 2, p_sys->p_textures );
1046
1047     for( i_index = 0; i_index < 2; i_index++ )
1048     {
1049         glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_index] );
1050
1051         /* Set the texture parameters */
1052         glTexParameterf( VLCGL_TARGET, GL_TEXTURE_PRIORITY, 1.0 );
1053
1054         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1055         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1056
1057         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1058         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1059
1060         glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1061
1062 #ifdef __APPLE__
1063         /* Tell the driver not to make a copy of the texture but to use
1064            our buffer */
1065         glEnable( GL_UNPACK_CLIENT_STORAGE_APPLE );
1066         glPixelStorei( GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE );
1067
1068 #if 0
1069         /* Use VRAM texturing */
1070         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
1071                          GL_STORAGE_CACHED_APPLE );
1072 #else
1073         /* Use AGP texturing */
1074         glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
1075                          GL_STORAGE_SHARED_APPLE );
1076 #endif
1077 #endif
1078
1079         /* Call glTexImage2D only once, and use glTexSubImage2D later */
1080         glTexImage2D( VLCGL_TARGET, 0, 3, p_sys->i_tex_width,
1081                       p_sys->i_tex_height, 0, VLCGL_FORMAT, VLCGL_TYPE,
1082                       p_sys->pp_buffer[i_index] );
1083     }
1084
1085     return 0;
1086 }
1087
1088 /*****************************************************************************
1089  * SendEvents: forward mouse and keyboard events to the parent p_vout
1090  *****************************************************************************/
1091 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
1092                        vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
1093 {
1094     return var_Set( (vlc_object_t *)_p_vout, psz_var, newval );
1095 }