1 /*****************************************************************************
2 * opengl.c: OpenGL video output
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@videolan.org>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Eric Petit <titer@m0k.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <errno.h> /* ENOMEM */
30 #include <stdlib.h> /* malloc(), free() */
37 #include <OpenGL/gl.h>
38 #include <OpenGL/glext.h>
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
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
50 #define VLCGL_TARGET GL_TEXTURE_2D
53 #ifndef GL_UNSIGNED_SHORT_5_6_5
54 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
56 //#define VLCGL_RGB_FORMAT GL_RGB
57 //#define VLCGL_RGB_TYPE GL_UNSIGNED_SHORT_5_6_5
60 //#define VLCGL_RGB_FORMAT GL_RGB
61 //#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
64 #define VLCGL_RGB_FORMAT GL_RGBA
65 #define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
67 /* Use RGB on Win32/GLX */
68 #define VLCGL_FORMAT VLCGL_RGB_FORMAT
69 #define VLCGL_TYPE VLCGL_RGB_TYPE
72 #ifndef GL_CLAMP_TO_EDGE
73 # define GL_CLAMP_TO_EDGE 0x812F
77 #define OPENGL_EFFECT_NONE 1
78 #define OPENGL_EFFECT_CUBE 2
79 #define OPENGL_EFFECT_TRANSPARENT_CUBE 4
81 /*****************************************************************************
83 *****************************************************************************/
84 static int CreateVout ( vlc_object_t * );
85 static void DestroyVout ( vlc_object_t * );
86 static int Init ( vout_thread_t * );
87 static void End ( vout_thread_t * );
88 static int Manage ( vout_thread_t * );
89 static void Render ( vout_thread_t *, picture_t * );
90 static void DisplayVideo ( vout_thread_t *, picture_t * );
91 static int Control ( vout_thread_t *, int, va_list );
93 static inline int GetAlignedSize( int );
95 static int InitTextures( vout_thread_t * );
96 static int SendEvents( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
99 /*****************************************************************************
101 *****************************************************************************/
102 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
103 /*****************************************************************************
105 *****************************************************************************/
106 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
107 #define SPEED_LONGTEXT N_( "If the OpenGL cube effect is enabled, this " \
108 "controls its rotation speed." )
110 #define EFFECT_TEXT N_("Select effect")
111 #define EFFECT_LONGTEXT N_( \
112 "Allows you to select different visual effects.")
114 static char *ppsz_effects[] = {
115 "none", "cube", "transparent-cube" };
116 static char *ppsz_effects_text[] = {
117 N_("None"), N_("Cube"), N_("Transparent Cube") };
120 set_shortname( "OpenGL" );
121 set_category( CAT_VIDEO );
122 set_subcategory( SUBCAT_VIDEO_VOUT );
123 set_description( _("OpenGL video output") );
125 set_capability( "video output", 200 );
127 set_capability( "video output", 20 );
129 add_shortcut( "opengl" );
130 add_float( "opengl-cube-speed", 2.0, NULL, SPEED_TEXT,
131 SPEED_LONGTEXT, VLC_TRUE );
132 set_callbacks( CreateVout, DestroyVout );
133 add_string( "opengl-effect", "none", NULL, EFFECT_TEXT,
134 EFFECT_LONGTEXT, VLC_FALSE );
135 change_string_list( ppsz_effects, ppsz_effects_text, 0 );
138 /*****************************************************************************
139 * vout_sys_t: video output method descriptor
140 *****************************************************************************
141 * This structure is part of the video output thread descriptor.
142 * It describes the OpenGL specific properties of the output thread.
143 *****************************************************************************/
146 vout_thread_t *p_vout;
148 uint8_t *pp_buffer[2];
152 GLuint p_textures[2];
159 /*****************************************************************************
160 * CreateVout: This function allocates and initializes the OpenGL vout method.
161 *****************************************************************************/
162 static int CreateVout( vlc_object_t *p_this )
164 vout_thread_t *p_vout = (vout_thread_t *)p_this;
167 /* Allocate structure */
168 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
171 msg_Err( p_vout, "out of memory" );
175 var_Create( p_vout, "opengl-effect", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
179 p_sys->i_tex_width = p_vout->render.i_width;
180 p_sys->i_tex_height = p_vout->render.i_height;
182 /* A texture must have a size aligned on a power of 2 */
183 p_sys->i_tex_width = GetAlignedSize( p_vout->render.i_width );
184 p_sys->i_tex_height = GetAlignedSize( p_vout->render.i_height );
187 msg_Dbg( p_vout, "Texture size: %dx%d", p_sys->i_tex_width,
188 p_sys->i_tex_height );
192 (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
193 if( p_sys->p_vout == NULL )
195 msg_Err( p_vout, "out of memory" );
198 vlc_object_attach( p_sys->p_vout, p_this );
200 p_sys->p_vout->i_window_width = p_vout->i_window_width;
201 p_sys->p_vout->i_window_height = p_vout->i_window_height;
202 p_sys->p_vout->b_fullscreen = p_vout->b_fullscreen;
203 p_sys->p_vout->render.i_width = p_vout->render.i_width;
204 p_sys->p_vout->render.i_height = p_vout->render.i_height;
205 p_sys->p_vout->render.i_aspect = p_vout->render.i_aspect;
206 p_sys->p_vout->b_scale = p_vout->b_scale;
207 p_sys->p_vout->i_alignment = p_vout->i_alignment;
209 p_sys->p_vout->p_module =
210 module_Need( p_sys->p_vout, "opengl provider", NULL, 0 );
211 if( p_sys->p_vout->p_module == NULL )
213 msg_Warn( p_vout, "No OpenGL provider found" );
214 vlc_object_detach( p_sys->p_vout );
215 vlc_object_destroy( p_sys->p_vout );
219 p_sys->f_speed = var_CreateGetFloat( p_vout, "opengl-cube-speed" );
221 p_vout->pf_init = Init;
222 p_vout->pf_end = End;
223 p_vout->pf_manage = Manage;
224 p_vout->pf_render = Render;
225 p_vout->pf_display = DisplayVideo;
226 p_vout->pf_control = Control;
228 /* Forward events from the opengl provider */
229 var_Create( p_sys->p_vout, "mouse-x", VLC_VAR_INTEGER );
230 var_Create( p_sys->p_vout, "mouse-y", VLC_VAR_INTEGER );
231 var_Create( p_sys->p_vout, "mouse-moved", VLC_VAR_BOOL );
232 var_Create( p_sys->p_vout, "mouse-clicked", VLC_VAR_INTEGER );
233 var_Create( p_sys->p_vout, "mouse-button-down", VLC_VAR_INTEGER );
234 var_Create( p_sys->p_vout, "video-on-top",
235 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
237 var_AddCallback( p_sys->p_vout, "mouse-x", SendEvents, p_vout );
238 var_AddCallback( p_sys->p_vout, "mouse-y", SendEvents, p_vout );
239 var_AddCallback( p_sys->p_vout, "mouse-moved", SendEvents, p_vout );
240 var_AddCallback( p_sys->p_vout, "mouse-clicked", SendEvents, p_vout );
241 var_AddCallback( p_sys->p_vout, "mouse-button-down", SendEvents, p_vout );
246 /*****************************************************************************
247 * Init: initialize the OpenGL video thread output method
248 *****************************************************************************/
249 static int Init( vout_thread_t *p_vout )
251 vout_sys_t *p_sys = p_vout->p_sys;
255 p_sys->p_vout->pf_init( p_sys->p_vout );
258 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
259 p_vout->output.i_rmask = 0x00ff0000;
260 p_vout->output.i_gmask = 0x0000ff00;
261 p_vout->output.i_bmask = 0x000000ff;
264 #if VLCGL_RGB_FORMAT == GL_RGB
265 # if VLCGL_RGB_TYPE == GL_UNSIGNED_BYTE
266 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
267 p_vout->output.i_rmask = 0x000000ff;
268 p_vout->output.i_gmask = 0x0000ff00;
269 p_vout->output.i_bmask = 0x00ff0000;
272 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
273 p_vout->output.i_rmask = 0xf800;
274 p_vout->output.i_gmask = 0x07e0;
275 p_vout->output.i_bmask = 0x001f;
279 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
280 p_vout->output.i_rmask = 0x000000ff;
281 p_vout->output.i_gmask = 0x0000ff00;
282 p_vout->output.i_bmask = 0x00ff0000;
287 /* Since OpenGL can do rescaling for us, stick to the default
288 * coordinates and aspect. */
289 p_vout->output.i_width = p_vout->render.i_width;
290 p_vout->output.i_height = p_vout->render.i_height;
291 p_vout->output.i_aspect = p_vout->render.i_aspect;
293 /* We know the chroma, allocate one buffer which will be used
294 * directly by the decoder */
295 p_sys->pp_buffer[0] =
296 malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
297 if( !p_sys->pp_buffer[0] )
299 msg_Err( p_vout, "Out of memory" );
302 p_sys->pp_buffer[1] =
303 malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
304 if( !p_sys->pp_buffer[1] )
306 msg_Err( p_vout, "Out of memory" );
310 p_vout->p_picture[0].i_planes = 1;
311 p_vout->p_picture[0].p->p_pixels = p_sys->pp_buffer[0];
312 p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;
313 p_vout->p_picture[0].p->i_visible_lines = p_vout->output.i_height;
314 p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;
315 p_vout->p_picture[0].p->i_pitch = p_vout->output.i_width *
316 p_vout->p_picture[0].p->i_pixel_pitch;
317 p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *
318 p_vout->p_picture[0].p->i_pixel_pitch;
320 p_vout->p_picture[0].i_status = DESTROYED_PICTURE;
321 p_vout->p_picture[0].i_type = DIRECT_PICTURE;
323 PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];
325 I_OUTPUTPICTURES = 1;
327 if( p_sys->p_vout->pf_lock &&
328 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
330 msg_Warn( p_vout, "could not lock OpenGL provider" );
334 InitTextures( p_vout );
337 glDisable(GL_DEPTH_TEST);
338 glDepthMask(GL_FALSE);
339 glDisable(GL_CULL_FACE);
340 glClear( GL_COLOR_BUFFER_BIT );
342 /* Check if the user asked for useless visual effects */
343 var_Get( p_vout, "opengl-effect", &val );
344 if( !val.psz_string || !strcmp( val.psz_string, "none" ))
346 p_sys->i_effect = OPENGL_EFFECT_NONE;
348 else if( !strcmp( val.psz_string, "cube" ) )
350 p_sys->i_effect = OPENGL_EFFECT_CUBE;
352 glEnable( GL_CULL_FACE);
353 //glEnable( GL_DEPTH_TEST );
355 else if( !strcmp( val.psz_string, "transparent-cube" ) )
357 p_sys->i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;
359 glDisable( GL_DEPTH_TEST );
360 glEnable( GL_BLEND );
361 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
365 msg_Warn( p_vout, "no valid opengl effect provided, using "
367 p_sys->i_effect = OPENGL_EFFECT_NONE;
369 if( val.psz_string ) free( val.psz_string );
371 if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
372 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
374 /* Set the perpective */
375 glMatrixMode( GL_PROJECTION );
377 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
378 glMatrixMode( GL_MODELVIEW );
380 glTranslatef( 0.0, 0.0, - 5.0 );
383 if( p_sys->p_vout->pf_unlock )
385 p_sys->p_vout->pf_unlock( p_sys->p_vout );
391 /*****************************************************************************
392 * End: terminate GLX video thread output method
393 *****************************************************************************/
394 static void End( vout_thread_t *p_vout )
396 vout_sys_t *p_sys = p_vout->p_sys;
398 if( p_sys->p_vout->pf_lock &&
399 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
401 msg_Warn( p_vout, "could not lock OpenGL provider" );
408 if( p_sys->p_vout->pf_unlock )
410 p_sys->p_vout->pf_unlock( p_sys->p_vout );
414 /*****************************************************************************
415 * Destroy: destroy GLX video thread output method
416 *****************************************************************************
417 * Terminate an output method created by CreateVout
418 *****************************************************************************/
419 static void DestroyVout( vlc_object_t *p_this )
421 vout_thread_t *p_vout = (vout_thread_t *)p_this;
422 vout_sys_t *p_sys = p_vout->p_sys;
424 module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );
425 vlc_object_detach( p_sys->p_vout );
426 vlc_object_destroy( p_sys->p_vout );
428 /* Free the texture buffer*/
429 if( p_sys->pp_buffer[0] ) free( p_sys->pp_buffer[0] );
430 if( p_sys->pp_buffer[1] ) free( p_sys->pp_buffer[1] );
435 /*****************************************************************************
436 * Manage: handle Sys events
437 *****************************************************************************
438 * This function should be called regularly by video output thread. It returns
439 * a non null value if an error occurred.
440 *****************************************************************************/
441 static int Manage( vout_thread_t *p_vout )
443 vout_sys_t *p_sys = p_vout->p_sys;
444 int i_ret, i_fullscreen_change;
446 i_fullscreen_change = ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE );
448 p_sys->p_vout->i_changes = p_vout->i_changes;
449 i_ret = p_sys->p_vout->pf_manage( p_sys->p_vout );
450 p_vout->i_changes = p_sys->p_vout->i_changes;
453 if( p_sys->p_vout->pf_lock &&
454 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
456 msg_Warn( p_vout, "could not lock OpenGL provider" );
460 /* On OS X, we create the window and the GL view when entering
461 fullscreen - the textures have to be inited again */
462 if( i_fullscreen_change )
464 InitTextures( p_vout );
466 switch( p_sys->i_effect )
468 case OPENGL_EFFECT_CUBE:
469 glEnable( GL_CULL_FACE );
472 case OPENGL_EFFECT_TRANSPARENT_CUBE:
473 glDisable( GL_DEPTH_TEST );
474 glEnable( GL_BLEND );
475 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
479 if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
480 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
482 /* Set the perpective */
483 glMatrixMode( GL_PROJECTION );
485 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
486 glMatrixMode( GL_MODELVIEW );
488 glTranslatef( 0.0, 0.0, - 5.0 );
492 if( p_sys->p_vout->pf_unlock )
494 p_sys->p_vout->pf_unlock( p_sys->p_vout );
501 /*****************************************************************************
502 * Render: render previously calculated output
503 *****************************************************************************/
504 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
506 vout_sys_t *p_sys = p_vout->p_sys;
508 /* On Win32/GLX, we do this the usual way:
509 + Fill the buffer with new content,
510 + Reload the texture,
513 On OS X with VRAM or AGP texturing, the order has to be:
514 + Reload the texture,
515 + Fill the buffer with new content,
518 (Thanks to gcc from the Arstechnica forums for the tip)
520 Therefore, we have to use two buffers and textures. On Win32/GLX,
521 we reload the texture to be displayed and use it right away. On
522 OS X, we first render, then reload the texture to be used next
525 if( p_sys->p_vout->pf_lock &&
526 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
528 msg_Warn( p_vout, "could not lock OpenGL provider" );
534 i_new_index = ( p_sys->i_index + 1 ) & 1;
537 /* Update the texture */
538 glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_new_index] );
539 glTexSubImage2D( VLCGL_TARGET, 0, 0, 0, p_sys->i_tex_width,
540 p_sys->i_tex_height, VLCGL_FORMAT, VLCGL_TYPE,
541 p_sys->pp_buffer[i_new_index] );
543 /* Bind to the previous texture for drawing */
544 glBindTexture( VLCGL_TARGET, p_sys->p_textures[p_sys->i_index] );
547 p_sys->i_index = i_new_index;
548 p_pic->p->p_pixels = p_sys->pp_buffer[p_sys->i_index];
551 /* Update the texture */
552 glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0,
553 p_vout->render.i_width, p_vout->render.i_height,
554 VLCGL_RGB_FORMAT, VLCGL_RGB_TYPE, p_sys->pp_buffer[0] );
557 if( p_sys->p_vout->pf_unlock )
559 p_sys->p_vout->pf_unlock( p_sys->p_vout );
563 /*****************************************************************************
564 * DisplayVideo: displays previously rendered output
565 *****************************************************************************/
566 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
568 vout_sys_t *p_sys = p_vout->p_sys;
569 float f_width, f_height;
571 if( p_sys->p_vout->pf_lock &&
572 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
574 msg_Warn( p_vout, "could not lock OpenGL provider" );
578 /* glTexCoord works differently with GL_TEXTURE_2D and
579 GL_TEXTURE_RECTANGLE_EXT */
581 f_width = (float)p_vout->output.i_width;
582 f_height = (float)p_vout->output.i_height;
584 f_width = (float)p_vout->output.i_width / p_sys->i_tex_width;
585 f_height = (float)p_vout->output.i_height / p_sys->i_tex_height;
588 /* Why drawing here and not in Render()? Because this way, the
589 OpenGL providers can call pf_display to force redraw. Currently,
590 the OS X provider uses it to get a smooth window resizing */
592 glClear( GL_COLOR_BUFFER_BIT );
594 if( p_sys->i_effect == OPENGL_EFFECT_NONE )
596 glEnable( VLCGL_TARGET );
597 glBegin( GL_POLYGON );
598 glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 );
599 glTexCoord2f( f_width, 0.0 ); glVertex2f( 1.0, 1.0 );
600 glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 );
601 glTexCoord2f( 0.0, f_height ); glVertex2f( -1.0, -1.0 );
606 glRotatef( 0.5 * p_sys->f_speed , 0.3, 0.5, 0.7 );
608 glEnable( VLCGL_TARGET );
612 glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
613 glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
614 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
615 glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
618 glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
619 glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
620 glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
621 glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
624 glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
625 glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
626 glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
627 glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
630 glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
631 glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
632 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
633 glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
636 glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
637 glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, 1.0, 1.0 );
638 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 );
639 glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
642 glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, - 1.0, 1.0 );
643 glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
644 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
645 glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, - 1.0, 1.0 );
649 glDisable( VLCGL_TARGET );
651 p_sys->p_vout->pf_swap( p_sys->p_vout );
653 if( p_sys->p_vout->pf_unlock )
655 p_sys->p_vout->pf_unlock( p_sys->p_vout );
659 int GetAlignedSize( int i_size )
661 /* Return the nearest power of 2 */
663 while( i_result < i_size )
670 /*****************************************************************************
671 * Control: control facility for the vout
672 *****************************************************************************/
673 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
675 vout_sys_t *p_sys = p_vout->p_sys;
680 return vout_vaControlDefault( p_vout, i_query, args );
683 if( p_sys->p_vout->pf_control )
684 return p_sys->p_vout->pf_control( p_sys->p_vout, i_query, args );
686 return vout_vaControlDefault( p_vout, i_query, args );
690 static int InitTextures( vout_thread_t *p_vout )
692 vout_sys_t *p_sys = p_vout->p_sys;
695 glDeleteTextures( 2, p_sys->p_textures );
696 glGenTextures( 2, p_sys->p_textures );
698 for( i_index = 0; i_index < 2; i_index++ )
700 glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_index] );
702 /* Set the texture parameters */
703 glTexParameterf( VLCGL_TARGET, GL_TEXTURE_PRIORITY, 1.0 );
705 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
706 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
708 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
709 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
711 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
714 /* Tell the driver not to make a copy of the texture but to use
716 glEnable( GL_UNPACK_CLIENT_STORAGE_APPLE );
717 glPixelStorei( GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE );
720 /* Use VRAM texturing */
721 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
722 GL_STORAGE_CACHED_APPLE );
724 /* Use AGP texturing */
725 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
726 GL_STORAGE_SHARED_APPLE );
730 /* Call glTexImage2D only once, and use glTexSubImage2D later */
731 glTexImage2D( VLCGL_TARGET, 0, 3, p_sys->i_tex_width,
732 p_sys->i_tex_height, 0, VLCGL_FORMAT, VLCGL_TYPE,
733 p_sys->pp_buffer[i_index] );
739 /*****************************************************************************
740 * SendEvents: forward mouse and keyboard events to the parent p_vout
741 *****************************************************************************/
742 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
743 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
745 return var_Set( (vlc_object_t *)_p_vout, psz_var, newval );