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