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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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
69 #define YCBCR_MESA 0x8757
71 #ifndef UNSIGNED_SHORT_8_8_MESA
72 #define UNSIGNED_SHORT_8_8_MESA 0x85BA
74 #define VLCGL_YUV_FORMAT YCBCR_MESA
75 #define VLCGL_YUV_TYPE UNSIGNED_SHORT_8_8_MESA
77 /* Use RGB on Win32/GLX */
78 #define VLCGL_FORMAT VLCGL_RGB_FORMAT
79 #define VLCGL_TYPE VLCGL_RGB_TYPE
80 //#define VLCGL_FORMAT VLCGL_YUV_FORMAT
81 //#define VLCGL_TYPE VLCGL_YUV_TYPE
84 #ifndef GL_CLAMP_TO_EDGE
85 # define GL_CLAMP_TO_EDGE 0x812F
89 #define OPENGL_EFFECT_NONE 1
90 #define OPENGL_EFFECT_CUBE 2
91 #define OPENGL_EFFECT_TRANSPARENT_CUBE 4
93 /*****************************************************************************
95 *****************************************************************************/
96 static int CreateVout ( vlc_object_t * );
97 static void DestroyVout ( vlc_object_t * );
98 static int Init ( vout_thread_t * );
99 static void End ( vout_thread_t * );
100 static int Manage ( vout_thread_t * );
101 static void Render ( vout_thread_t *, picture_t * );
102 static void DisplayVideo ( vout_thread_t *, picture_t * );
103 static int Control ( vout_thread_t *, int, va_list );
105 static inline int GetAlignedSize( int );
107 static int InitTextures( vout_thread_t * );
108 static int SendEvents( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
111 /*****************************************************************************
113 *****************************************************************************/
114 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
115 /*****************************************************************************
117 *****************************************************************************/
118 #define SPEED_TEXT N_( "OpenGL cube rotation speed" )
119 #define SPEED_LONGTEXT N_( "Rotation speed of the OpenGL cube effect, if " \
122 #define EFFECT_TEXT N_("Effect")
123 #define EFFECT_LONGTEXT N_( \
124 "Several visual OpenGL effects are available." )
126 static char *ppsz_effects[] = {
127 "none", "cube", "transparent-cube" };
128 static char *ppsz_effects_text[] = {
129 N_("None"), N_("Cube"), N_("Transparent Cube") };
132 set_shortname( "OpenGL" );
133 set_category( CAT_VIDEO );
134 set_subcategory( SUBCAT_VIDEO_VOUT );
135 set_description( _("OpenGL video output") );
137 set_capability( "video output", 200 );
139 set_capability( "video output", 20 );
141 add_shortcut( "opengl" );
142 add_float( "opengl-cube-speed", 2.0, NULL, SPEED_TEXT,
143 SPEED_LONGTEXT, VLC_TRUE );
144 set_callbacks( CreateVout, DestroyVout );
145 add_string( "opengl-effect", "none", NULL, EFFECT_TEXT,
146 EFFECT_LONGTEXT, VLC_FALSE );
147 change_string_list( ppsz_effects, ppsz_effects_text, 0 );
150 /*****************************************************************************
151 * vout_sys_t: video output method descriptor
152 *****************************************************************************
153 * This structure is part of the video output thread descriptor.
154 * It describes the OpenGL specific properties of the output thread.
155 *****************************************************************************/
158 vout_thread_t *p_vout;
160 uint8_t *pp_buffer[2];
164 GLuint p_textures[2];
171 /*****************************************************************************
172 * CreateVout: This function allocates and initializes the OpenGL vout method.
173 *****************************************************************************/
174 static int CreateVout( vlc_object_t *p_this )
176 vout_thread_t *p_vout = (vout_thread_t *)p_this;
179 /* Allocate structure */
180 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
183 msg_Err( p_vout, "out of memory" );
187 var_Create( p_vout, "opengl-effect", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
191 p_sys->i_tex_width = p_vout->fmt_in.i_width;
192 p_sys->i_tex_height = p_vout->fmt_in.i_height;
194 /* A texture must have a size aligned on a power of 2 */
195 p_sys->i_tex_width = GetAlignedSize( p_vout->fmt_in.i_width );
196 p_sys->i_tex_height = GetAlignedSize( p_vout->fmt_in.i_height );
199 msg_Dbg( p_vout, "Texture size: %dx%d", p_sys->i_tex_width,
200 p_sys->i_tex_height );
204 (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
205 if( p_sys->p_vout == NULL )
207 msg_Err( p_vout, "out of memory" );
210 vlc_object_attach( p_sys->p_vout, p_this );
212 p_sys->p_vout->i_window_width = p_vout->i_window_width;
213 p_sys->p_vout->i_window_height = p_vout->i_window_height;
214 p_sys->p_vout->b_fullscreen = p_vout->b_fullscreen;
215 p_sys->p_vout->render.i_width = p_vout->render.i_width;
216 p_sys->p_vout->render.i_height = p_vout->render.i_height;
217 p_sys->p_vout->render.i_aspect = p_vout->render.i_aspect;
218 p_sys->p_vout->fmt_render = p_vout->fmt_render;
219 p_sys->p_vout->fmt_in = p_vout->fmt_in;
220 p_sys->p_vout->b_scale = p_vout->b_scale;
221 p_sys->p_vout->i_alignment = p_vout->i_alignment;
223 p_sys->p_vout->p_module =
224 module_Need( p_sys->p_vout, "opengl provider", NULL, 0 );
225 if( p_sys->p_vout->p_module == NULL )
227 msg_Warn( p_vout, "No OpenGL provider found" );
228 vlc_object_detach( p_sys->p_vout );
229 vlc_object_destroy( p_sys->p_vout );
233 p_sys->f_speed = var_CreateGetFloat( p_vout, "opengl-cube-speed" );
235 p_vout->pf_init = Init;
236 p_vout->pf_end = End;
237 p_vout->pf_manage = Manage;
238 p_vout->pf_render = Render;
239 p_vout->pf_display = DisplayVideo;
240 p_vout->pf_control = Control;
242 /* Forward events from the opengl provider */
243 var_Create( p_sys->p_vout, "mouse-x", VLC_VAR_INTEGER );
244 var_Create( p_sys->p_vout, "mouse-y", VLC_VAR_INTEGER );
245 var_Create( p_sys->p_vout, "mouse-moved", VLC_VAR_BOOL );
246 var_Create( p_sys->p_vout, "mouse-clicked", VLC_VAR_INTEGER );
247 var_Create( p_sys->p_vout, "mouse-button-down", VLC_VAR_INTEGER );
248 var_Create( p_sys->p_vout, "video-on-top",
249 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
251 var_AddCallback( p_sys->p_vout, "mouse-x", SendEvents, p_vout );
252 var_AddCallback( p_sys->p_vout, "mouse-y", SendEvents, p_vout );
253 var_AddCallback( p_sys->p_vout, "mouse-moved", SendEvents, p_vout );
254 var_AddCallback( p_sys->p_vout, "mouse-clicked", SendEvents, p_vout );
255 var_AddCallback( p_sys->p_vout, "mouse-button-down", SendEvents, p_vout );
260 /*****************************************************************************
261 * Init: initialize the OpenGL video thread output method
262 *****************************************************************************/
263 static int Init( vout_thread_t *p_vout )
265 vout_sys_t *p_sys = p_vout->p_sys;
269 p_sys->p_vout->pf_init( p_sys->p_vout );
271 /* TODO: We use YCbCr on Mac which is Y422, but on OSX it seems to == YUY2. Verify */
272 #if ( defined( WORDS_BIGENDIAN ) && VLCGL_FORMAT == GL_YCBCR_422_APPLE ) || (VLCGL_FORMAT == YCBCR_MESA)
273 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
276 #elif (VLCGL_FORMAT == GL_YCBCR_422_APPLE)
277 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
280 #elif VLCGL_FORMAT == GL_RGB
281 # if VLCGL_TYPE == GL_UNSIGNED_BYTE
282 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
283 # if defined( WORDS_BIGENDIAN )
284 p_vout->output.i_rmask = 0x00ff0000;
285 p_vout->output.i_gmask = 0x0000ff00;
286 p_vout->output.i_bmask = 0x000000ff;
288 p_vout->output.i_rmask = 0x000000ff;
289 p_vout->output.i_gmask = 0x0000ff00;
290 p_vout->output.i_bmask = 0x00ff0000;
294 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
295 # if defined( WORDS_BIGENDIAN )
296 p_vout->output.i_rmask = 0x001f;
297 p_vout->output.i_gmask = 0x07e0;
298 p_vout->output.i_bmask = 0xf800;
300 p_vout->output.i_rmask = 0xf800;
301 p_vout->output.i_gmask = 0x07e0;
302 p_vout->output.i_bmask = 0x001f;
307 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
308 # if defined( WORDS_BIGENDIAN )
309 p_vout->output.i_rmask = 0xff000000;
310 p_vout->output.i_gmask = 0x00ff0000;
311 p_vout->output.i_bmask = 0x0000ff00;
313 p_vout->output.i_rmask = 0x000000ff;
314 p_vout->output.i_gmask = 0x0000ff00;
315 p_vout->output.i_bmask = 0x00ff0000;
320 /* Since OpenGL can do rescaling for us, stick to the default
321 * coordinates and aspect. */
322 p_vout->output.i_width = p_vout->render.i_width;
323 p_vout->output.i_height = p_vout->render.i_height;
324 p_vout->output.i_aspect = p_vout->render.i_aspect;
326 p_vout->fmt_out = p_vout->fmt_in;
327 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
329 /* We know the chroma, allocate one buffer which will be used
330 * directly by the decoder */
331 p_sys->pp_buffer[0] =
332 malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
333 if( !p_sys->pp_buffer[0] )
335 msg_Err( p_vout, "out of memory" );
338 p_sys->pp_buffer[1] =
339 malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
340 if( !p_sys->pp_buffer[1] )
342 msg_Err( p_vout, "out of memory" );
346 p_vout->p_picture[0].i_planes = 1;
347 p_vout->p_picture[0].p->p_pixels = p_sys->pp_buffer[0];
348 p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;
349 p_vout->p_picture[0].p->i_visible_lines = p_vout->output.i_height;
350 p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;
351 p_vout->p_picture[0].p->i_pitch = p_vout->output.i_width *
352 p_vout->p_picture[0].p->i_pixel_pitch;
353 p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *
354 p_vout->p_picture[0].p->i_pixel_pitch;
356 p_vout->p_picture[0].i_status = DESTROYED_PICTURE;
357 p_vout->p_picture[0].i_type = DIRECT_PICTURE;
359 PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];
361 I_OUTPUTPICTURES = 1;
363 if( p_sys->p_vout->pf_lock &&
364 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
366 msg_Warn( p_vout, "could not lock OpenGL provider" );
370 InitTextures( p_vout );
373 glDisable(GL_DEPTH_TEST);
374 glDepthMask(GL_FALSE);
375 glDisable(GL_CULL_FACE);
376 glClear( GL_COLOR_BUFFER_BIT );
378 /* Check if the user asked for useless visual effects */
379 var_Get( p_vout, "opengl-effect", &val );
380 if( !val.psz_string || !strcmp( val.psz_string, "none" ))
382 p_sys->i_effect = OPENGL_EFFECT_NONE;
384 else if( !strcmp( val.psz_string, "cube" ) )
386 p_sys->i_effect = OPENGL_EFFECT_CUBE;
388 glEnable( GL_CULL_FACE);
389 //glEnable( GL_DEPTH_TEST );
391 else if( !strcmp( val.psz_string, "transparent-cube" ) )
393 p_sys->i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;
395 glDisable( GL_DEPTH_TEST );
396 glEnable( GL_BLEND );
397 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
401 msg_Warn( p_vout, "no valid opengl effect provided, using "
403 p_sys->i_effect = OPENGL_EFFECT_NONE;
405 if( val.psz_string ) free( val.psz_string );
407 if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
408 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
410 /* Set the perpective */
411 glMatrixMode( GL_PROJECTION );
413 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
414 glMatrixMode( GL_MODELVIEW );
416 glTranslatef( 0.0, 0.0, - 5.0 );
419 if( p_sys->p_vout->pf_unlock )
421 p_sys->p_vout->pf_unlock( p_sys->p_vout );
427 /*****************************************************************************
428 * End: terminate GLX video thread output method
429 *****************************************************************************/
430 static void End( vout_thread_t *p_vout )
432 vout_sys_t *p_sys = p_vout->p_sys;
434 if( p_sys->p_vout->pf_lock &&
435 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
437 msg_Warn( p_vout, "could not lock OpenGL provider" );
444 if( p_sys->p_vout->pf_unlock )
446 p_sys->p_vout->pf_unlock( p_sys->p_vout );
450 /*****************************************************************************
451 * Destroy: destroy GLX video thread output method
452 *****************************************************************************
453 * Terminate an output method created by CreateVout
454 *****************************************************************************/
455 static void DestroyVout( vlc_object_t *p_this )
457 vout_thread_t *p_vout = (vout_thread_t *)p_this;
458 vout_sys_t *p_sys = p_vout->p_sys;
460 module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );
461 vlc_object_detach( p_sys->p_vout );
462 vlc_object_destroy( p_sys->p_vout );
464 /* Free the texture buffer*/
465 if( p_sys->pp_buffer[0] ) free( p_sys->pp_buffer[0] );
466 if( p_sys->pp_buffer[1] ) free( p_sys->pp_buffer[1] );
471 /*****************************************************************************
472 * Manage: handle Sys events
473 *****************************************************************************
474 * This function should be called regularly by video output thread. It returns
475 * a non null value if an error occurred.
476 *****************************************************************************/
477 static int Manage( vout_thread_t *p_vout )
479 vout_sys_t *p_sys = p_vout->p_sys;
480 int i_ret, i_fullscreen_change;
482 i_fullscreen_change = ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE );
484 p_vout->fmt_out.i_x_offset = p_sys->p_vout->fmt_in.i_x_offset =
485 p_vout->fmt_in.i_x_offset;
486 p_vout->fmt_out.i_y_offset = p_sys->p_vout->fmt_in.i_y_offset =
487 p_vout->fmt_in.i_y_offset;
488 p_vout->fmt_out.i_visible_width = p_sys->p_vout->fmt_in.i_visible_width =
489 p_vout->fmt_in.i_visible_width;
490 p_vout->fmt_out.i_visible_height = p_sys->p_vout->fmt_in.i_visible_height =
491 p_vout->fmt_in.i_visible_height;
492 p_vout->fmt_out.i_aspect = p_sys->p_vout->fmt_in.i_aspect =
493 p_vout->fmt_in.i_aspect;
494 p_vout->fmt_out.i_sar_num = p_sys->p_vout->fmt_in.i_sar_num =
495 p_vout->fmt_in.i_sar_num;
496 p_vout->fmt_out.i_sar_den = p_sys->p_vout->fmt_in.i_sar_den =
497 p_vout->fmt_in.i_sar_den;
498 p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;
500 p_sys->p_vout->i_changes = p_vout->i_changes;
501 i_ret = p_sys->p_vout->pf_manage( p_sys->p_vout );
502 p_vout->i_changes = p_sys->p_vout->i_changes;
505 if( p_sys->p_vout->pf_lock &&
506 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
508 msg_Warn( p_vout, "could not lock OpenGL provider" );
512 /* On OS X, we create the window and the GL view when entering
513 fullscreen - the textures have to be inited again */
514 if( i_fullscreen_change )
516 InitTextures( p_vout );
518 switch( p_sys->i_effect )
520 case OPENGL_EFFECT_CUBE:
521 glEnable( GL_CULL_FACE );
524 case OPENGL_EFFECT_TRANSPARENT_CUBE:
525 glDisable( GL_DEPTH_TEST );
526 glEnable( GL_BLEND );
527 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
531 if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |
532 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
534 /* Set the perpective */
535 glMatrixMode( GL_PROJECTION );
537 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
538 glMatrixMode( GL_MODELVIEW );
540 glTranslatef( 0.0, 0.0, - 5.0 );
544 if( p_sys->p_vout->pf_unlock )
546 p_sys->p_vout->pf_unlock( p_sys->p_vout );
553 /*****************************************************************************
554 * Render: render previously calculated output
555 *****************************************************************************/
556 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
558 vout_sys_t *p_sys = p_vout->p_sys;
560 /* On Win32/GLX, we do this the usual way:
561 + Fill the buffer with new content,
562 + Reload the texture,
565 On OS X with VRAM or AGP texturing, the order has to be:
566 + Reload the texture,
567 + Fill the buffer with new content,
570 (Thanks to gcc from the Arstechnica forums for the tip)
572 Therefore, we have to use two buffers and textures. On Win32/GLX,
573 we reload the texture to be displayed and use it right away. On
574 OS X, we first render, then reload the texture to be used next
577 if( p_sys->p_vout->pf_lock &&
578 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
580 msg_Warn( p_vout, "could not lock OpenGL provider" );
586 i_new_index = ( p_sys->i_index + 1 ) & 1;
589 /* Update the texture */
590 glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_new_index] );
591 glTexSubImage2D( VLCGL_TARGET, 0, 0, 0,
592 p_vout->fmt_out.i_width,
593 p_vout->fmt_out.i_height,
594 VLCGL_FORMAT, VLCGL_TYPE, p_sys->pp_buffer[i_new_index] );
596 /* Bind to the previous texture for drawing */
597 glBindTexture( VLCGL_TARGET, p_sys->p_textures[p_sys->i_index] );
600 p_sys->i_index = i_new_index;
601 p_pic->p->p_pixels = p_sys->pp_buffer[p_sys->i_index];
604 /* Update the texture */
605 glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0,
606 p_vout->fmt_out.i_width,
607 p_vout->fmt_out.i_height,
608 VLCGL_FORMAT, VLCGL_TYPE, p_sys->pp_buffer[0] );
611 if( p_sys->p_vout->pf_unlock )
613 p_sys->p_vout->pf_unlock( p_sys->p_vout );
617 /*****************************************************************************
618 * DisplayVideo: displays previously rendered output
619 *****************************************************************************/
620 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
622 vout_sys_t *p_sys = p_vout->p_sys;
623 float f_width, f_height, f_x, f_y;
625 if( p_sys->p_vout->pf_lock &&
626 p_sys->p_vout->pf_lock( p_sys->p_vout ) )
628 msg_Warn( p_vout, "could not lock OpenGL provider" );
632 /* glTexCoord works differently with GL_TEXTURE_2D and
633 GL_TEXTURE_RECTANGLE_EXT */
635 f_x = (float)p_vout->fmt_out.i_x_offset;
636 f_y = (float)p_vout->fmt_out.i_y_offset;
637 f_width = (float)p_vout->fmt_out.i_x_offset +
638 (float)p_vout->fmt_out.i_visible_width;
639 f_height = (float)p_vout->fmt_out.i_y_offset +
640 (float)p_vout->fmt_out.i_visible_height;
642 f_x = (float)p_vout->fmt_out.i_x_offset / p_sys->i_tex_width;
643 f_y = (float)p_vout->fmt_out.i_y_offset / p_sys->i_tex_height;
644 f_width = ( (float)p_vout->fmt_out.i_x_offset +
645 p_vout->fmt_out.i_visible_width ) / p_sys->i_tex_width;
646 f_height = ( (float)p_vout->fmt_out.i_y_offset +
647 p_vout->fmt_out.i_visible_height ) / p_sys->i_tex_height;
650 /* Why drawing here and not in Render()? Because this way, the
651 OpenGL providers can call pf_display to force redraw. Currently,
652 the OS X provider uses it to get a smooth window resizing */
654 glClear( GL_COLOR_BUFFER_BIT );
656 if( p_sys->i_effect == OPENGL_EFFECT_NONE )
658 glEnable( VLCGL_TARGET );
659 glBegin( GL_POLYGON );
660 glTexCoord2f( f_x, f_y ); glVertex2f( -1.0, 1.0 );
661 glTexCoord2f( f_width, f_y ); glVertex2f( 1.0, 1.0 );
662 glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 );
663 glTexCoord2f( f_x, f_height ); glVertex2f( -1.0, -1.0 );
668 glRotatef( 0.5 * p_sys->f_speed , 0.3, 0.5, 0.7 );
670 glEnable( VLCGL_TARGET );
674 glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, 1.0 );
675 glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
676 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
677 glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, 1.0 );
680 glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
681 glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
682 glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
683 glTexCoord2f( f_width, f_y ); glVertex3f( - 1.0, 1.0, 1.0 );
686 glTexCoord2f( f_x, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
687 glTexCoord2f( f_x, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
688 glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
689 glTexCoord2f( f_width, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
692 glTexCoord2f( f_x, f_y ); glVertex3f( 1.0, 1.0, 1.0 );
693 glTexCoord2f( f_x, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
694 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
695 glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
698 glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, 1.0, - 1.0 );
699 glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, 1.0, 1.0 );
700 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 );
701 glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, 1.0, - 1.0 );
704 glTexCoord2f( f_x, f_y ); glVertex3f( - 1.0, - 1.0, 1.0 );
705 glTexCoord2f( f_x, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
706 glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
707 glTexCoord2f( f_width, f_y ); glVertex3f( 1.0, - 1.0, 1.0 );
711 glDisable( VLCGL_TARGET );
713 p_sys->p_vout->pf_swap( p_sys->p_vout );
715 if( p_sys->p_vout->pf_unlock )
717 p_sys->p_vout->pf_unlock( p_sys->p_vout );
721 int GetAlignedSize( int i_size )
723 /* Return the nearest power of 2 */
725 while( i_result < i_size )
732 /*****************************************************************************
733 * Control: control facility for the vout
734 *****************************************************************************/
735 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
737 vout_sys_t *p_sys = p_vout->p_sys;
742 return vout_vaControlDefault( p_vout, i_query, args );
745 if( p_sys->p_vout->pf_control )
746 return p_sys->p_vout->pf_control( p_sys->p_vout, i_query, args );
748 return vout_vaControlDefault( p_vout, i_query, args );
752 static int InitTextures( vout_thread_t *p_vout )
754 vout_sys_t *p_sys = p_vout->p_sys;
757 glDeleteTextures( 2, p_sys->p_textures );
758 glGenTextures( 2, p_sys->p_textures );
760 for( i_index = 0; i_index < 2; i_index++ )
762 glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_index] );
764 /* Set the texture parameters */
765 glTexParameterf( VLCGL_TARGET, GL_TEXTURE_PRIORITY, 1.0 );
767 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
768 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
770 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
771 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
773 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
776 /* Tell the driver not to make a copy of the texture but to use
778 glEnable( GL_UNPACK_CLIENT_STORAGE_APPLE );
779 glPixelStorei( GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE );
782 /* Use VRAM texturing */
783 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
784 GL_STORAGE_CACHED_APPLE );
786 /* Use AGP texturing */
787 glTexParameteri( VLCGL_TARGET, GL_TEXTURE_STORAGE_HINT_APPLE,
788 GL_STORAGE_SHARED_APPLE );
792 /* Call glTexImage2D only once, and use glTexSubImage2D later */
793 glTexImage2D( VLCGL_TARGET, 0, 3, p_sys->i_tex_width,
794 p_sys->i_tex_height, 0, VLCGL_FORMAT, VLCGL_TYPE,
795 p_sys->pp_buffer[i_index] );
801 /*****************************************************************************
802 * SendEvents: forward mouse and keyboard events to the parent p_vout
803 *****************************************************************************/
804 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
805 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
807 return var_Set( (vlc_object_t *)_p_vout, psz_var, newval );