8 #include "subopt-helper.h"
10 #include "video_out_internal.h"
11 #include "font_load.h"
14 #include "gl_common.h"
17 #include "Gui/interface.h"
20 static vo_info_t info
=
24 "Arpad Gereoffy <arpi@esp-team.scene.hu>",
31 static int gl_vinfo
= 0;
32 static HGLRC gl_context
= 0;
34 static XVisualInfo
*gl_vinfo
= NULL
;
35 static GLXContext gl_context
= 0;
36 static int wsGLXAttrib
[] = { GLX_RGBA
,
45 static int scaled_osd
;
46 //! How many parts the OSD may consist of at most
47 #define MAX_OSD_PARTS 20
49 static GLuint osdtex
[MAX_OSD_PARTS
];
51 //! Alpha textures for OSD
52 static GLuint osdatex
[MAX_OSD_PARTS
];
54 //! Display lists that draw the OSD parts
55 static GLuint osdDispList
[MAX_OSD_PARTS
];
56 //! How many parts the OSD currently consists of
60 static int use_aspect
;
62 static int use_rectangle
;
64 static uint32_t image_width
;
65 static uint32_t image_height
;
66 static uint32_t image_format
;
68 static int use_glFinish
;
69 static int swap_interval
;
70 static GLenum gl_target
;
71 static GLint gl_texfmt
;
72 static GLenum gl_format
;
73 static GLenum gl_type
;
74 static GLuint gl_buffer
;
75 static int gl_buffersize
;
76 static GLuint fragprog
;
77 static GLuint uvtexs
[2];
78 static GLuint lookupTex
;
79 static char *custom_prog
;
80 static char *custom_tex
;
81 static int custom_tlin
;
84 static int eq_bri
= 0;
85 static int eq_cont
= 0;
86 static int eq_sat
= 0;
87 static int eq_hue
= 0;
88 static int eq_rgamma
= 0;
89 static int eq_ggamma
= 0;
90 static int eq_bgamma
= 0;
92 static int texture_width
;
93 static int texture_height
;
94 static int mpi_flipped
;
96 static unsigned int slice_height
= 1;
98 static void resize(int x
,int y
){
99 mp_msg(MSGT_VO
, MSGL_V
, "[gl] Resize: %dx%d\n",x
,y
);
101 int top
= 0, left
= 0, w
= x
, h
= y
;
102 geometry(&top
, &left
, &w
, &h
, vo_screenwidth
, vo_screenheight
);
103 glViewport(top
, left
, w
, h
);
105 glViewport( 0, 0, x
, y
);
107 glMatrixMode(GL_PROJECTION
);
109 if (vo_fs
&& use_aspect
) {
111 GLdouble scale_x
, scale_y
;
112 aspect(&new_w
, &new_h
, A_ZOOM
);
114 new_w
+= vo_panscan_x
;
115 new_h
+= vo_panscan_y
;
116 scale_x
= (GLdouble
) new_w
/ (GLdouble
) x
;
117 scale_y
= (GLdouble
) new_h
/ (GLdouble
) y
;
118 glScaled(scale_x
, scale_y
, 1);
120 glOrtho(0, image_width
, image_height
, 0, -1,1);
122 glMatrixMode(GL_MODELVIEW
);
127 // adjust font size to display size
130 vo_osd_changed(OSDTYPE_OSD
);
132 if (vo_fs
&& use_aspect
&& !vo_doublebuffering
)
133 glClear(GL_COLOR_BUFFER_BIT
);
136 static void texSize(int w
, int h
, int *texw
, int *texh
) {
138 *texw
= w
; *texh
= h
;
149 //! maximum size of custom fragment program
150 #define MAX_CUSTOM_PROG_SIZE (1024 * 1024)
151 static void update_yuvconv(void) {
152 float bri
= eq_bri
/ 100.0;
153 float cont
= (eq_cont
+ 100) / 100.0;
154 float hue
= eq_hue
/ 100.0 * 3.1415927;
155 float sat
= (eq_sat
+ 100) / 100.0;
156 float rgamma
= exp(log(8.0) * eq_rgamma
/ 100.0);
157 float ggamma
= exp(log(8.0) * eq_ggamma
/ 100.0);
158 float bgamma
= exp(log(8.0) * eq_bgamma
/ 100.0);
159 glSetupYUVConversion(gl_target
, use_yuv
, bri
, cont
, hue
, sat
,
160 rgamma
, ggamma
, bgamma
);
162 FILE *f
= fopen(custom_prog
, "r");
164 mp_msg(MSGT_VO
, MSGL_WARN
,
165 "[gl] Could not read customprog %s\n", custom_prog
);
168 char *prog
= calloc(1, MAX_CUSTOM_PROG_SIZE
+ 1);
169 fread(prog
, 1, MAX_CUSTOM_PROG_SIZE
, f
);
171 ProgramString(GL_FRAGMENT_PROGRAM
, GL_PROGRAM_FORMAT_ASCII
,
173 glGetIntegerv(GL_PROGRAM_ERROR_POSITION
, &i
);
175 mp_msg(MSGT_VO
, MSGL_ERR
,
176 "[gl] Error in custom program at pos %i (%.20s)\n", i
, &prog
[i
]);
179 ProgramEnvParameter4f(GL_FRAGMENT_PROGRAM
, 0,
180 1.0 / texture_width
, 1.0 / texture_height
, 0, 0);
183 FILE *f
= fopen(custom_tex
, "r");
185 mp_msg(MSGT_VO
, MSGL_WARN
,
186 "[gl] Could not read customtex %s\n", custom_tex
);
188 int width
, height
, maxval
;
189 ActiveTexture(GL_TEXTURE3
);
190 if (glCreatePPMTex(GL_TEXTURE_2D
, 3,
191 custom_tlin
?GL_LINEAR
:GL_NEAREST
,
192 f
, &width
, &height
, &maxval
))
193 ProgramEnvParameter4f(GL_FRAGMENT_PROGRAM
, 1,
194 1.0 / width
, 1.0 / height
, 1.0 / maxval
, 0);
196 mp_msg(MSGT_VO
, MSGL_WARN
,
197 "[gl] Error parsing customtex %s\n", custom_tex
);
199 ActiveTexture(GL_TEXTURE0
);
205 * \brief remove all OSD textures and display-lists, thus clearing it.
207 static void clearOSD(void) {
211 glDeleteTextures(osdtexCnt
, osdtex
);
213 glDeleteTextures(osdtexCnt
, osdatex
);
215 for (i
= 0; i
< osdtexCnt
; i
++)
216 glDeleteLists(osdDispList
[i
], 1);
221 * \brief uninitialize OpenGL context, freeing textures, buffers etc.
223 static void uninitGl(void) {
224 if (DeletePrograms
&& fragprog
)
225 DeletePrograms(1, &fragprog
);
227 if (uvtexs
[0] || uvtexs
[1])
228 glDeleteTextures(2, uvtexs
);
229 uvtexs
[0] = uvtexs
[1] = 0;
231 glDeleteTextures(1, &lookupTex
);
234 if (DeleteBuffers
&& gl_buffer
)
235 DeleteBuffers(1, &gl_buffer
);
236 gl_buffer
= 0; gl_buffersize
= 0;
241 * \brief Initialize a (new or reused) OpenGL context.
242 * set global gl-related variables to their default values
244 static int initGl(uint32_t d_width
, uint32_t d_height
) {
245 osdtexCnt
= 0; gl_buffer
= 0; gl_buffersize
= 0; err_shown
= 0;
246 fragprog
= 0; uvtexs
[0] = 0; uvtexs
[1] = 0; lookupTex
= 0;
247 texSize(image_width
, image_height
, &texture_width
, &texture_height
);
250 glDisable(GL_DEPTH_TEST
);
251 glDepthMask(GL_FALSE
);
252 glDisable(GL_CULL_FACE
);
254 glDrawBuffer(vo_doublebuffering
?GL_BACK
:GL_FRONT
);
255 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
257 mp_msg(MSGT_VO
, MSGL_V
, "[gl] Creating %dx%d texture...\n",
258 texture_width
, texture_height
);
260 if (image_format
== IMGFMT_YV12
) {
261 glGenTextures(2, uvtexs
);
262 ActiveTexture(GL_TEXTURE1
);
263 BindTexture(gl_target
, uvtexs
[0]);
264 glCreateClearTex(gl_target
, gl_texfmt
, GL_LINEAR
,
265 texture_width
/ 2, texture_height
/ 2, 128);
266 ActiveTexture(GL_TEXTURE2
);
267 BindTexture(gl_target
, uvtexs
[1]);
268 glCreateClearTex(gl_target
, gl_texfmt
, GL_LINEAR
,
269 texture_width
/ 2, texture_height
/ 2, 128);
271 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
272 glGenTextures(1, &lookupTex
);
273 ActiveTexture(GL_TEXTURE3
);
274 glBindTexture(GL_TEXTURE_2D
, lookupTex
);
275 case YUV_CONVERSION_FRAGMENT_POW
:
276 case YUV_CONVERSION_FRAGMENT
:
277 GenPrograms(1, &fragprog
);
278 BindProgram(GL_FRAGMENT_PROGRAM
, fragprog
);
281 ActiveTexture(GL_TEXTURE0
);
282 BindTexture(gl_target
, 0);
285 glCreateClearTex(gl_target
, gl_texfmt
, GL_LINEAR
,
286 texture_width
, texture_height
, 0);
288 resize(d_width
, d_height
);
290 glClearColor( 0.0f
,0.0f
,0.0f
,0.0f
);
291 glClear( GL_COLOR_BUFFER_BIT
);
292 if (SwapInterval
&& swap_interval
>= 0)
293 SwapInterval(swap_interval
);
297 /* connect to server, create and map window,
298 * allocate colors and (shared) memory
301 config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
303 image_height
= height
;
305 image_format
= format
;
306 glFindFormat(format
, NULL
, &gl_texfmt
, &gl_format
, &gl_type
);
311 aspect_save_orig(width
,height
);
312 aspect_save_prescale(d_width
,d_height
);
313 update_xinerama_info();
315 aspect(&d_width
,&d_height
,A_NOZOOM
);
316 vo_dx
= (int)(vo_screenwidth
- d_width
) / 2;
317 vo_dy
= (int)(vo_screenheight
- d_height
) / 2;
318 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
,
319 vo_screenwidth
, vo_screenheight
);
324 // GUI creates and manages window for us
326 vo_dheight
= d_height
;
327 guiGetEvent(guiSetShVideo
, 0);
332 if (!vo_w32_config(d_width
, d_height
, flags
))
336 vo_window
= WinID
? (Window
)WinID
: mRootWin
;
337 vo_x11_selectinput_witherr(mDisplay
, vo_window
,
338 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
339 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
342 if ( vo_window
== None
) {
352 hint
.width
= d_width
;
353 hint
.height
= d_height
;
354 hint
.flags
= PPosition
| PSize
;
356 /* Get some colors */
358 bg
= WhitePixel(mDisplay
, mScreen
);
359 fg
= BlackPixel(mDisplay
, mScreen
);
361 /* Make the window */
363 vinfo
=glXChooseVisual( mDisplay
,mScreen
,wsGLXAttrib
);
366 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] no GLX support present\n");
372 vo_window
= vo_x11_create_smooth_window(mDisplay
, mRootWin
, vinfo
->visual
, hint
.x
, hint
.y
, hint
.width
, hint
.height
,
373 vinfo
->depth
, XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
, AllocNone
));
375 vo_x11_classhint( mDisplay
,vo_window
,"gl" );
376 vo_hidecursor(mDisplay
,vo_window
);
378 XSelectInput(mDisplay
, vo_window
, StructureNotifyMask
);
379 /* Tell other applications about this window */
380 XSetStandardProperties(mDisplay
, vo_window
, title
, title
, None
, NULL
, 0, &hint
);
382 XMapWindow(mDisplay
, vo_window
);
387 XNextEvent(mDisplay
, &xev
);
389 while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= vo_window
);
391 XSelectInput(mDisplay
, vo_window
, NoEventMask
);
393 XSync(mDisplay
, False
);
395 vo_x11_selectinput_witherr(mDisplay
, vo_window
, StructureNotifyMask
| KeyPressMask
| PointerMotionMask
396 | ButtonPressMask
| ButtonReleaseMask
| ExposureMask
399 if (vo_ontop
) vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
401 vo_x11_nofs_sizepos(vo_dx
, vo_dy
, d_width
, d_height
);
402 if (vo_fs
^ (flags
& VOFLAG_FULLSCREEN
))
409 setGlWindow(&gl_vinfo
, &gl_context
, vo_window
);
410 initGl(vo_dwidth
, vo_dheight
);
415 static void check_events(void)
417 int e
=vo_check_events();
418 if(e
&VO_EVENT_RESIZE
) resize(vo_dwidth
,vo_dheight
);
419 if(e
&VO_EVENT_EXPOSE
&& int_pause
) flip_page();
423 * Creates the textures and the display list needed for displaying
425 * Callback function for vo_draw_text().
427 static void create_osd_texture(int x0
, int y0
, int w
, int h
,
428 unsigned char *src
, unsigned char *srca
,
431 // initialize to 8 to avoid special-casing on alignment
433 GLint scale_type
= (scaled_osd
) ? GL_LINEAR
: GL_NEAREST
;
435 if (w
<= 0 || h
<= 0 || stride
< w
) {
436 mp_msg(MSGT_VO
, MSGL_V
, "Invalid dimensions OSD for part!\n");
439 texSize(w
, h
, &sx
, &sy
);
441 if (osdtexCnt
>= MAX_OSD_PARTS
) {
442 mp_msg(MSGT_VO
, MSGL_ERR
, "Too many OSD parts, contact the developers!\n");
446 // create Textures for OSD part
447 glGenTextures(1, &osdtex
[osdtexCnt
]);
448 BindTexture(gl_target
, osdtex
[osdtexCnt
]);
449 glCreateClearTex(gl_target
, GL_LUMINANCE
, scale_type
, sx
, sy
, 0);
450 glUploadTex(gl_target
, GL_LUMINANCE
, GL_UNSIGNED_BYTE
, src
, stride
,
454 glGenTextures(1, &osdatex
[osdtexCnt
]);
455 BindTexture(gl_target
, osdatex
[osdtexCnt
]);
456 glCreateClearTex(gl_target
, GL_ALPHA
, scale_type
, sx
, sy
, 255);
459 char *tmp
= (char *)malloc(stride
* h
);
460 // convert alpha from weird MPlayer scale.
461 // in-place is not possible since it is reused for future OSDs
462 for (i
= h
* stride
- 1; i
> 0; i
--)
463 tmp
[i
] = srca
[i
] - 1;
464 glUploadTex(gl_target
, GL_ALPHA
, GL_UNSIGNED_BYTE
, tmp
, stride
,
470 BindTexture(gl_target
, 0);
472 // Create a list for rendering this OSD part
473 osdDispList
[osdtexCnt
] = glGenLists(1);
474 glNewList(osdDispList
[osdtexCnt
], GL_COMPILE
);
477 glBlendFunc(GL_ZERO
, GL_SRC_ALPHA
);
478 BindTexture(gl_target
, osdatex
[osdtexCnt
]);
479 glDrawTex(x0
, y0
, w
, h
, 0, 0, w
, h
, sx
, sy
, use_rectangle
== 1, 0, 0);
482 glBlendFunc (GL_ONE
, GL_ONE
);
483 BindTexture(gl_target
, osdtex
[osdtexCnt
]);
484 glDrawTex(x0
, y0
, w
, h
, 0, 0, w
, h
, sx
, sy
, use_rectangle
== 1, 0, 0);
490 static void draw_osd(void)
492 if (!use_osd
) return;
493 if (vo_osd_changed(0)) {
496 osd_w
= (scaled_osd
) ? image_width
: vo_dwidth
;
497 osd_h
= (scaled_osd
) ? image_height
: vo_dheight
;
498 vo_draw_text(osd_w
, osd_h
, create_osd_texture
);
505 // glEnable(GL_TEXTURE_2D);
506 // glBindTexture(GL_TEXTURE_2D, texture_id);
509 if (image_format
== IMGFMT_YV12
)
510 glEnableYUVConversion(gl_target
, use_yuv
);
511 glDrawTex(0, 0, image_width
, image_height
,
512 0, 0, image_width
, image_height
,
513 texture_width
, texture_height
,
514 use_rectangle
== 1, image_format
== IMGFMT_YV12
, mpi_flipped
);
515 if (image_format
== IMGFMT_YV12
)
516 glDisableYUVConversion(gl_target
, use_yuv
);
519 // set special rendering parameters
521 glMatrixMode(GL_PROJECTION
);
524 glOrtho(0, vo_dwidth
, vo_dheight
, 0, -1, 1);
527 glColor4ub((osd_color
>> 16) & 0xff, (osd_color
>> 8) & 0xff, osd_color
& 0xff, 0xff);
529 glCallLists(osdtexCnt
, GL_UNSIGNED_INT
, osdDispList
);
530 // set rendering parameters back to defaults
531 glDisable (GL_BLEND
);
534 BindTexture(gl_target
, 0);
539 if (vo_doublebuffering
)
541 else if (!use_glFinish
)
544 if (vo_fs
&& use_aspect
&& vo_doublebuffering
)
545 glClear(GL_COLOR_BUFFER_BIT
);
548 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
549 static int draw_slice(uint8_t *src
[], int stride
[], int w
,int h
,int x
,int y
)
551 mpi_flipped
= (stride
[0] < 0);
552 glUploadTex(gl_target
, gl_format
, gl_type
, src
[0], stride
[0],
553 x
, y
, w
, h
, slice_height
);
554 if (image_format
== IMGFMT_YV12
) {
555 ActiveTexture(GL_TEXTURE1
);
556 glUploadTex(gl_target
, gl_format
, gl_type
, src
[1], stride
[1],
557 x
/ 2, y
/ 2, w
/ 2, h
/ 2, slice_height
);
558 ActiveTexture(GL_TEXTURE2
);
559 glUploadTex(gl_target
, gl_format
, gl_type
, src
[2], stride
[2],
560 x
/ 2, y
/ 2, w
/ 2, h
/ 2, slice_height
);
561 ActiveTexture(GL_TEXTURE0
);
566 static uint32_t get_image(mp_image_t
*mpi
) {
567 if (!GenBuffers
|| !BindBuffer
|| !BufferData
|| !MapBuffer
) {
569 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] extensions missing for dr\n"
570 "Expect a _major_ speed penalty\n");
574 if (mpi
->flags
& MP_IMGFLAG_READABLE
) return VO_FALSE
;
575 if (mpi
->type
== MP_IMGTYPE_IP
|| mpi
->type
== MP_IMGTYPE_IPB
)
576 return VO_FALSE
; // we can not provide readable buffers
578 GenBuffers(1, &gl_buffer
);
579 BindBuffer(GL_PIXEL_UNPACK_BUFFER
, gl_buffer
);
580 mpi
->stride
[0] = mpi
->width
* mpi
->bpp
/ 8;
581 if (mpi
->stride
[0] * mpi
->h
> gl_buffersize
) {
582 BufferData(GL_PIXEL_UNPACK_BUFFER
, mpi
->stride
[0] * mpi
->h
,
583 NULL
, GL_DYNAMIC_DRAW
);
584 gl_buffersize
= mpi
->stride
[0] * mpi
->h
;
586 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER
); // HACK, needed for some MPEG4 files??
587 mpi
->planes
[0] = MapBuffer(GL_PIXEL_UNPACK_BUFFER
, GL_WRITE_ONLY
);
588 BindBuffer(GL_PIXEL_UNPACK_BUFFER
, 0);
589 if (mpi
->planes
[0] == NULL
) {
591 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] could not aquire buffer for dr\n"
592 "Expect a _major_ speed penalty\n");
596 if (mpi
->imgfmt
== IMGFMT_YV12
) {
598 mpi
->flags
|= MP_IMGFLAG_COMMON_STRIDE
| MP_IMGFLAG_COMMON_PLANE
;
599 mpi
->stride
[0] = mpi
->width
;
600 mpi
->planes
[1] = mpi
->planes
[0] + mpi
->stride
[0] * mpi
->height
;
601 mpi
->stride
[1] = mpi
->width
>> 1;
602 mpi
->planes
[2] = mpi
->planes
[1] + mpi
->stride
[1] * (mpi
->height
>> 1);
603 mpi
->stride
[2] = mpi
->width
>> 1;
605 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
609 static uint32_t draw_image(mp_image_t
*mpi
) {
610 unsigned char *data
= mpi
->planes
[0];
611 int slice
= slice_height
;
612 if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
614 if (mpi
->flags
& MP_IMGFLAG_DIRECT
) {
616 BindBuffer(GL_PIXEL_UNPACK_BUFFER
, gl_buffer
);
617 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER
);
618 slice
= 0; // always "upload" full texture
620 mpi_flipped
= (mpi
->stride
[0] < 0);
621 glUploadTex(gl_target
, gl_format
, gl_type
, data
, mpi
->stride
[0],
622 mpi
->x
, mpi
->y
, mpi
->w
, mpi
->h
, slice
);
623 if (mpi
->imgfmt
== IMGFMT_YV12
) {
624 data
+= mpi
->planes
[1] - mpi
->planes
[0];
625 ActiveTexture(GL_TEXTURE1
);
626 glUploadTex(gl_target
, gl_format
, gl_type
, data
, mpi
->stride
[1],
627 mpi
->x
/ 2, mpi
->y
/ 2, mpi
->w
/ 2, mpi
->h
/ 2, slice
);
628 data
+= mpi
->planes
[2] - mpi
->planes
[1];
629 ActiveTexture(GL_TEXTURE2
);
630 glUploadTex(gl_target
, gl_format
, gl_type
, data
, mpi
->stride
[2],
631 mpi
->x
/ 2, mpi
->y
/ 2, mpi
->w
/ 2, mpi
->h
/ 2, slice
);
632 ActiveTexture(GL_TEXTURE0
);
634 if (mpi
->flags
& MP_IMGFLAG_DIRECT
)
635 BindBuffer(GL_PIXEL_UNPACK_BUFFER
, 0);
640 draw_frame(uint8_t *src
[])
646 query_format(uint32_t format
)
648 int caps
= VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
|
649 VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
| VFCAP_ACCEPT_STRIDE
;
652 if ((format
== IMGFMT_RGB24
) || (format
== IMGFMT_RGBA
))
654 if (use_yuv
&& format
== IMGFMT_YV12
)
657 glFindFormat(format
, NULL
, NULL
, NULL
, NULL
))
666 if ( !vo_config_count
) return;
668 releaseGlContext(&gl_vinfo
, &gl_context
);
669 if (custom_prog
) free(custom_prog
);
671 if (custom_tex
) free(custom_tex
);
676 static opt_t subopts
[] = {
677 {"manyfmts", OPT_ARG_BOOL
, &many_fmts
, NULL
},
678 {"osd", OPT_ARG_BOOL
, &use_osd
, NULL
},
679 {"scaled-osd", OPT_ARG_BOOL
, &scaled_osd
, NULL
},
680 {"aspect", OPT_ARG_BOOL
, &use_aspect
, NULL
},
681 {"slice-height", OPT_ARG_INT
, &slice_height
, (opt_test_f
)int_non_neg
},
682 {"rectangle", OPT_ARG_INT
, &use_rectangle
,(opt_test_f
)int_non_neg
},
683 {"yuv", OPT_ARG_INT
, &use_yuv
, (opt_test_f
)int_non_neg
},
684 {"glfinish", OPT_ARG_BOOL
, &use_glFinish
, NULL
},
685 {"swapinterval", OPT_ARG_INT
, &swap_interval
,NULL
},
686 {"customprog", OPT_ARG_MSTRZ
,&custom_prog
, NULL
},
687 {"customtex", OPT_ARG_MSTRZ
,&custom_tex
, NULL
},
688 {"customtlin", OPT_ARG_BOOL
, &custom_tlin
, NULL
},
689 {"osdcolor", OPT_ARG_INT
, &osd_color
, NULL
},
693 static int preinit(const char *arg
)
708 osd_color
= 0xffffff;
709 if (subopt_parse(arg
, subopts
) != 0) {
710 mp_msg(MSGT_VO
, MSGL_FATAL
,
711 "\n-vo gl command line help:\n"
712 "Example: mplayer -vo gl:slice-height=4\n"
715 " Enable extended color formats for OpenGL 1.2 and later\n"
716 " slice-height=<0-...>\n"
717 " Slice size for texture transfer, 0 for whole image\n"
719 " Do not use OpenGL OSD code\n"
721 " Do not do aspect scaling\n"
722 " rectangle=<0,1,2>\n"
723 " 0: use power-of-two textures\n"
724 " 1: use texture_rectangle\n"
725 " 2: use texture_non_power_of_two\n"
727 " Call glFinish() before swapping buffers\n"
728 " swapinterval=<n>\n"
729 " Interval in displayed frames between to buffer swaps.\n"
730 " 1 is equivalent to enable VSYNC, 0 to disable VSYNC.\n"
731 " Requires GLX_SGI_swap_control support to work.\n"
733 " 0: use software YUV to RGB conversion.\n"
734 " 1: use register combiners (nVidia only, for older cards).\n"
735 " 2: use fragment program.\n"
736 " 3: use fragment program with gamma correction.\n"
737 " 4: use fragment program with gamma correction via lookup.\n"
738 " 5: use ATI-specific method (for older cards).\n"
739 " customprog=<filename>\n"
740 " use a custom YUV conversion program\n"
741 " customtex=<filename>\n"
742 " use a custom YUV conversion lookup texture\n"
744 " use GL_NEAREST scaling for customtex texture\n"
745 " osdcolor=<0xRRGGBB>\n"
746 " use the given color for the OSD\n"
750 if (use_rectangle
== 1)
751 gl_target
= GL_TEXTURE_RECTANGLE
;
753 gl_target
= GL_TEXTURE_2D
;
754 if (slice_height
== -1)
755 slice_height
= use_yuv
? 16 : 4;
757 mp_msg (MSGT_VO
, MSGL_INFO
, "[gl] using extended formats. "
758 "Use -vo gl:nomanyfmts if playback fails.\n");
759 mp_msg (MSGT_VO
, MSGL_V
, "[gl] Using %d as slice height "
760 "(0 means image height).\n", slice_height
);
761 if( !vo_init() ) return -1; // Can't open X11
766 static int control(uint32_t request
, void *data
, ...)
769 case VOCTRL_PAUSE
: return (int_pause
=1);
770 case VOCTRL_RESUME
: return (int_pause
=0);
771 case VOCTRL_QUERY_FORMAT
:
772 return query_format(*((uint32_t*)data
));
773 case VOCTRL_GET_IMAGE
:
774 return get_image(data
);
775 case VOCTRL_DRAW_IMAGE
:
776 return draw_image(data
);
777 case VOCTRL_GUISUPPORT
:
782 case VOCTRL_FULLSCREEN
:
784 resize(vo_dwidth
, vo_dheight
);
791 case VOCTRL_GET_PANSCAN
:
792 if (!use_aspect
) return VO_NOTIMPL
;
794 case VOCTRL_SET_PANSCAN
:
795 if (!use_aspect
) return VO_NOTIMPL
;
796 resize (vo_dwidth
, vo_dheight
);
798 case VOCTRL_GET_EQUALIZER
:
799 if (image_format
== IMGFMT_YV12
) {
803 value
= va_arg(va
, int *);
805 if (strcasecmp(data
, "brightness") == 0) {
807 if (use_yuv
== YUV_CONVERSION_COMBINERS
) break; // not supported
808 } else if (strcasecmp(data
, "contrast") == 0) {
810 if (use_yuv
== YUV_CONVERSION_COMBINERS
) break; // not supported
811 } else if (strcasecmp(data
, "saturation") == 0) {
813 } else if (strcasecmp(data
, "hue") == 0) {
815 } else if (strcasecmp(data
, "gamma") == 0) {
817 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
818 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
819 } else if (strcasecmp(data
, "red_gamma") == 0) {
821 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
822 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
823 } else if (strcasecmp(data
, "green_gamma") == 0) {
825 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
826 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
827 } else if (strcasecmp(data
, "blue_gamma") == 0) {
829 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
830 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
835 case VOCTRL_SET_EQUALIZER
:
836 if (image_format
== IMGFMT_YV12
) {
840 value
= va_arg(va
, int);
842 if (strcasecmp(data
, "brightness") == 0) {
844 if (use_yuv
== YUV_CONVERSION_COMBINERS
) break; // not supported
845 } else if (strcasecmp(data
, "contrast") == 0) {
847 if (use_yuv
== YUV_CONVERSION_COMBINERS
) break; // not supported
848 } else if (strcasecmp(data
, "saturation") == 0) {
850 } else if (strcasecmp(data
, "hue") == 0) {
852 } else if (strcasecmp(data
, "gamma") == 0) {
853 eq_rgamma
= eq_ggamma
= eq_bgamma
= value
;
854 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
855 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
856 } else if (strcasecmp(data
, "red_gamma") == 0) {
858 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
859 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
860 } else if (strcasecmp(data
, "green_gamma") == 0) {
862 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
863 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported
864 } else if (strcasecmp(data
, "blue_gamma") == 0) {
866 if (use_yuv
== YUV_CONVERSION_COMBINERS
||
867 use_yuv
== YUV_CONVERSION_FRAGMENT
) break; // not supported