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