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