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