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