Mercurial > mplayer.hg
annotate libvo/vo_gl.c @ 16100:32ff32c79053
-dr support for -vo gl
author | reimar |
---|---|
date | Tue, 26 Jul 2005 10:17:51 +0000 |
parents | 629c54dc7e0d |
children | 519a307e3ccf |
rev | line source |
---|---|
1 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <math.h> | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
5 #include <errno.h> |
1 | 6 |
11988 | 7 #include "mp_msg.h" |
1 | 8 #include "config.h" |
14286 | 9 #include "subopt-helper.h" |
1 | 10 #include "video_out.h" |
11 #include "video_out_internal.h" | |
13585 | 12 #include "font_load.h" |
13 #include "sub.h" | |
1 | 14 |
15 #include <errno.h> | |
16 | |
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
17 #include "gl_common.h" |
2057 | 18 #include "aspect.h" |
13843 | 19 #ifdef HAVE_NEW_GUI |
20 #include "Gui/interface.h" | |
21 #endif | |
31 | 22 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
23 static vo_info_t info = |
1 | 24 { |
25 "X11 (OpenGL)", | |
26 "gl", | |
27 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
28 "" | |
29 }; | |
30 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
31 LIBVO_EXTERN(gl) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
32 |
13843 | 33 static XVisualInfo *gl_vinfo = NULL; |
34 static GLXContext gl_context = 0; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
35 static int wsGLXAttrib[] = { GLX_RGBA, |
1 | 36 GLX_RED_SIZE,1, |
37 GLX_GREEN_SIZE,1, | |
38 GLX_BLUE_SIZE,1, | |
39 GLX_DOUBLEBUFFER, | |
40 None }; | |
41 | |
13599 | 42 static int use_osd; |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
43 static int scaled_osd; |
14269 | 44 //! How many parts the OSD may consist of at most |
13585 | 45 #define MAX_OSD_PARTS 20 |
14269 | 46 //! Textures for OSD |
13599 | 47 static GLuint osdtex[MAX_OSD_PARTS]; |
13585 | 48 #ifndef FAST_OSD |
14269 | 49 //! Alpha textures for OSD |
13599 | 50 static GLuint osdatex[MAX_OSD_PARTS]; |
13585 | 51 #endif |
14269 | 52 //! Display lists that draw the OSD parts |
13599 | 53 static GLuint osdDispList[MAX_OSD_PARTS]; |
14269 | 54 //! How many parts the OSD currently consists of |
13599 | 55 static int osdtexCnt = 0; |
1 | 56 |
13601 | 57 static int use_aspect; |
16099 | 58 static int use_rectangle; |
59 static int err_shown; | |
1 | 60 static uint32_t image_width; |
61 static uint32_t image_height; | |
62 static uint32_t image_bytes; | |
12159 | 63 static int many_fmts; |
16099 | 64 static GLenum gl_target; |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
65 static GLenum gl_texfmt; |
12159 | 66 static GLenum gl_format; |
67 static GLenum gl_type; | |
16099 | 68 static int gl_buffersize; |
1 | 69 |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
70 static int int_pause; |
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
71 |
1 | 72 static uint32_t texture_width; |
73 static uint32_t texture_height; | |
74 | |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
75 static unsigned int slice_height = 1; |
8654
2c4cebb8637d
- optional slice height for -vo gl (example: -vo gl:32)
arpi
parents:
8148
diff
changeset
|
76 |
612 | 77 static void resize(int x,int y){ |
11988 | 78 mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n",x,y); |
15748 | 79 if (WinID >= 0) { |
80 int top = 0, left = 0, w = x, h = y; | |
81 geometry(&top, &left, &w, &h, vo_screenwidth, vo_screenheight); | |
82 glViewport(top, left, w, h); | |
83 } else | |
1 | 84 glViewport( 0, 0, x, y ); |
85 | |
86 glMatrixMode(GL_PROJECTION); | |
87 glLoadIdentity(); | |
13601 | 88 if (vo_fs && use_aspect) { |
89 int new_w, new_h; | |
90 GLdouble scale_x, scale_y; | |
91 aspect(&new_w, &new_h, A_ZOOM); | |
92 panscan_calc(); | |
93 new_w += vo_panscan_x; | |
94 new_h += vo_panscan_y; | |
95 scale_x = (GLdouble) new_w / (GLdouble) x; | |
96 scale_y = (GLdouble) new_h / (GLdouble) y; | |
97 glScaled(scale_x, scale_y, 1); | |
98 } | |
1 | 99 glOrtho(0, image_width, image_height, 0, -1,1); |
100 | |
101 glMatrixMode(GL_MODELVIEW); | |
102 glLoadIdentity(); | |
13585 | 103 |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
104 if (!scaled_osd) { |
15086
c9eee448e5b2
revert the previous commit, gl needs to reload the font immediately
henry
parents:
15080
diff
changeset
|
105 #ifdef HAVE_FREETYPE |
c9eee448e5b2
revert the previous commit, gl needs to reload the font immediately
henry
parents:
15080
diff
changeset
|
106 // adjust font size to display size |
c9eee448e5b2
revert the previous commit, gl needs to reload the font immediately
henry
parents:
15080
diff
changeset
|
107 force_load_font = 1; |
c9eee448e5b2
revert the previous commit, gl needs to reload the font immediately
henry
parents:
15080
diff
changeset
|
108 #endif |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
109 vo_osd_changed(OSDTYPE_OSD); |
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
110 } |
1 | 111 } |
112 | |
16099 | 113 static void texSize(int w, int h, int *texw, int *texh) { |
114 if (use_rectangle) { | |
115 *texw = w; *texh = h; | |
116 } else { | |
117 *texw = 32; | |
118 while (*texw < w) | |
119 *texw *= 2; | |
120 *texh = 32; | |
121 while (*texh < h) | |
122 *texh *= 2; | |
123 } | |
124 } | |
125 | |
13843 | 126 /** |
127 * \brief Initialize a (new or reused) OpenGL context. | |
128 */ | |
129 static int initGl(uint32_t d_width, uint32_t d_height) { | |
130 unsigned char *ImageData = NULL; | |
16099 | 131 texSize(image_width, image_height, &texture_width, &texture_height); |
13843 | 132 |
133 glDisable(GL_BLEND); | |
134 glDisable(GL_DEPTH_TEST); | |
135 glDepthMask(GL_FALSE); | |
136 glDisable(GL_CULL_FACE); | |
16099 | 137 glEnable(gl_target); |
13843 | 138 |
139 mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n", | |
140 texture_width, texture_height); | |
141 | |
16099 | 142 glTexParameterf(gl_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
143 glTexParameterf(gl_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
13843 | 144 |
145 glAdjustAlignment(texture_width * image_bytes); | |
146 ImageData = malloc(texture_width * texture_height * image_bytes); | |
147 memset(ImageData, 0, texture_width * texture_height * image_bytes); | |
16099 | 148 glTexImage2D(gl_target, 0, gl_texfmt, texture_width, texture_height, 0, |
13843 | 149 gl_format, gl_type, ImageData); |
150 free (ImageData); | |
151 | |
152 // set alignment as default is 4 which will break some files | |
153 glAdjustAlignment(image_width * image_bytes); | |
154 | |
155 resize(d_width, d_height); | |
156 | |
157 glClearColor( 0.0f,0.0f,0.0f,0.0f ); | |
158 glClear( GL_COLOR_BUFFER_BIT ); | |
16099 | 159 gl_buffersize = 0; |
160 err_shown = 0; | |
13920 | 161 return 1; |
13843 | 162 } |
163 | |
1 | 164 /* connect to server, create and map window, |
165 * allocate colors and (shared) memory | |
166 */ | |
167 static uint32_t | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7111
diff
changeset
|
168 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
1 | 169 { |
170 image_height = height; | |
171 image_width = width; | |
14078
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13993
diff
changeset
|
172 glFindFormat(format, &image_bytes, &gl_texfmt, &gl_format, &gl_type); |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13993
diff
changeset
|
173 image_bytes = (image_bytes + 7) / 8; |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
174 |
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
175 int_pause = 0; |
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
176 |
13601 | 177 panscan_init(); |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
178 aspect_save_orig(width,height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
179 aspect_save_prescale(d_width,d_height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
180 aspect_save_screenres(vo_screenwidth,vo_screenheight); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
181 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
182 aspect(&d_width,&d_height,A_NOZOOM); |
15595
b4c3f02811dd
-geometry support for gl2 under win, default window pos centered for gl, gl2
reimar
parents:
15589
diff
changeset
|
183 vo_dx = (vo_screenwidth - d_width) / 2; |
b4c3f02811dd
-geometry support for gl2 under win, default window pos centered for gl, gl2
reimar
parents:
15589
diff
changeset
|
184 vo_dy = (vo_screenheight - d_height) / 2; |
15589 | 185 geometry(&vo_dx, &vo_dy, &d_width, &d_height, |
186 vo_screenwidth, vo_screenheight); | |
2040 | 187 #ifdef X11_FULLSCREEN |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
15086
diff
changeset
|
188 // if( flags&VOFLAG_FULLSCREEN ){ // (-fs) |
6095 | 189 // aspect(&d_width,&d_height,A_ZOOM); |
190 // } | |
2040 | 191 #endif |
13843 | 192 #ifdef HAVE_NEW_GUI |
193 if (use_gui) { | |
194 // GUI creates and manages window for us | |
195 vo_dwidth = d_width; | |
196 vo_dheight= d_height; | |
197 guiGetEvent(guiSetShVideo, 0); | |
15748 | 198 goto glconfig; |
13843 | 199 } |
200 #endif | |
15748 | 201 if (WinID >= 0) { |
202 Window win_tmp; | |
203 int int_tmp; | |
204 vo_window = WinID ? (Window)WinID : mRootWin; | |
205 goto glconfig; | |
206 } | |
13843 | 207 if ( vo_window == None ) { |
208 unsigned int fg, bg; | |
209 XSizeHints hint; | |
210 XVisualInfo *vinfo; | |
211 XEvent xev; | |
212 | |
13871 | 213 vo_fs = VO_FALSE; |
13843 | 214 |
15589 | 215 hint.x = vo_dx; |
216 hint.y = vo_dy; | |
1 | 217 hint.width = d_width; |
218 hint.height = d_height; | |
219 hint.flags = PPosition | PSize; | |
220 | |
221 /* Get some colors */ | |
222 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
223 bg = WhitePixel(mDisplay, mScreen); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
224 fg = BlackPixel(mDisplay, mScreen); |
1 | 225 |
226 /* Make the window */ | |
227 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
228 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
1290 | 229 if (vinfo == NULL) |
230 { | |
11988 | 231 mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n"); |
1290 | 232 return -1; |
233 } | |
1 | 234 |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
235 |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
1109
diff
changeset
|
236 |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
237 vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vinfo->visual, hint.x, hint.y, hint.width, hint.height, |
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
238 vinfo->depth, XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone)); |
1 | 239 |
7777 | 240 vo_x11_classhint( mDisplay,vo_window,"gl" ); |
241 vo_hidecursor(mDisplay,vo_window); | |
1 | 242 |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
15086
diff
changeset
|
243 // if ( flags&VOFLAG_FULLSCREEN ) vo_x11_decoration( mDisplay,vo_window,0 ); |
7777 | 244 XSelectInput(mDisplay, vo_window, StructureNotifyMask); |
245 /* Tell other applications about this window */ | |
10138
5e286cc6ad21
Removed YUV (YV12) and BGR support, leaving the native RGB support. Also cleaned some other parts.
alex
parents:
8654
diff
changeset
|
246 XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint); |
7777 | 247 /* Map window. */ |
248 XMapWindow(mDisplay, vo_window); | |
4017 | 249 #ifdef HAVE_XINERAMA |
7777 | 250 vo_x11_xinerama_move(mDisplay,vo_window); |
4017 | 251 #endif |
1 | 252 |
7777 | 253 /* Wait for map. */ |
254 do | |
255 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
256 XNextEvent(mDisplay, &xev); |
7777 | 257 } |
258 while (xev.type != MapNotify || xev.xmap.event != vo_window); | |
1 | 259 |
7777 | 260 XSelectInput(mDisplay, vo_window, NoEventMask); |
1 | 261 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
262 XSync(mDisplay, False); |
1 | 263 |
6953
ce67cc1f0beb
ignore BadAccess error at XSelectInput() (grabbing mouse etc) with warning
arpi
parents:
6212
diff
changeset
|
264 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
265 | ButtonPressMask | ButtonReleaseMask | ExposureMask |
4658 | 266 ); |
13843 | 267 } |
268 if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); | |
13575 | 269 |
15589 | 270 vo_x11_nofs_sizepos(vo_dx, vo_dy, d_width, d_height); |
13843 | 271 if (vo_fs ^ (flags & VOFLAG_FULLSCREEN)) |
272 vo_x11_fullscreen(); | |
15748 | 273 |
274 glconfig: | |
13843 | 275 setGlWindow(&gl_vinfo, &gl_context, vo_window); |
276 initGl(vo_dwidth, vo_dheight); | |
11542 | 277 |
1 | 278 return 0; |
279 } | |
280 | |
31 | 281 static void check_events(void) |
1 | 282 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
283 int e=vo_x11_check_events(mDisplay); |
31 | 284 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
285 if(e&VO_EVENT_EXPOSE && int_pause) flip_page(); |
31 | 286 } |
1 | 287 |
13585 | 288 /** |
289 * Creates the textures and the display list needed for displaying | |
290 * an OSD part. | |
291 * Callback function for vo_draw_text(). | |
292 */ | |
293 static void create_osd_texture(int x0, int y0, int w, int h, | |
294 unsigned char *src, unsigned char *srca, | |
295 int stride) | |
296 { | |
15719
e040252b8370
Fix OSD handling, DVD subtitles work now. Will be a bit slower though.
reimar
parents:
15595
diff
changeset
|
297 int i; |
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
298 // initialize to 8 to avoid special-casing on alignment |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
299 int sx = 8, sy = 8; |
13585 | 300 GLfloat xcov, ycov; |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
301 GLint scale_type = (scaled_osd) ? GL_LINEAR : GL_NEAREST; |
13585 | 302 char *clearTexture; |
16099 | 303 texSize(w, h, &sx, &sy); |
13585 | 304 xcov = (GLfloat) w / (GLfloat) sx; |
305 ycov = (GLfloat) h / (GLfloat) sy; | |
16099 | 306 if (use_rectangle == 1) { |
307 xcov = w; | |
308 ycov = h; | |
309 } | |
13585 | 310 |
311 if (osdtexCnt >= MAX_OSD_PARTS) { | |
312 mp_msg(MSGT_VO, MSGL_ERR, "Too many OSD parts, contact the developers!\n"); | |
313 return; | |
314 } | |
315 clearTexture = malloc(sx * sy); | |
316 memset(clearTexture, 0, sx * sy); | |
317 | |
318 // create Textures for OSD part | |
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
319 glAdjustAlignment(stride); |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
320 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); |
13585 | 321 glGenTextures(1, &osdtex[osdtexCnt]); |
16099 | 322 BindTexture(gl_target, osdtex[osdtexCnt]); |
323 glTexImage2D(gl_target, 0, GL_LUMINANCE, sx, sy, 0, | |
13585 | 324 GL_LUMINANCE, GL_UNSIGNED_BYTE, clearTexture); |
16099 | 325 glTexParameteri(gl_target, GL_TEXTURE_MIN_FILTER, scale_type); |
326 glTexParameteri(gl_target, GL_TEXTURE_MAG_FILTER, scale_type); | |
327 glTexSubImage2D(gl_target, 0, 0, 0, w, h, GL_LUMINANCE, | |
13585 | 328 GL_UNSIGNED_BYTE, src); |
329 | |
330 #ifndef FAST_OSD | |
331 glGenTextures(1, &osdatex[osdtexCnt]); | |
16099 | 332 BindTexture(gl_target, osdatex[osdtexCnt]); |
333 glTexImage2D(gl_target, 0, GL_ALPHA, sx, sy, 0, | |
13585 | 334 GL_LUMINANCE, GL_UNSIGNED_BYTE, clearTexture); |
16099 | 335 glTexParameteri(gl_target, GL_TEXTURE_MIN_FILTER, scale_type); |
336 glTexParameteri(gl_target, GL_TEXTURE_MAG_FILTER, scale_type); | |
15719
e040252b8370
Fix OSD handling, DVD subtitles work now. Will be a bit slower though.
reimar
parents:
15595
diff
changeset
|
337 for (i = 0; i < h * stride; i++) |
e040252b8370
Fix OSD handling, DVD subtitles work now. Will be a bit slower though.
reimar
parents:
15595
diff
changeset
|
338 clearTexture[i] = ~(-srca[i]); |
16099 | 339 glTexSubImage2D(gl_target, 0, 0, 0, w, h, GL_ALPHA, |
15719
e040252b8370
Fix OSD handling, DVD subtitles work now. Will be a bit slower though.
reimar
parents:
15595
diff
changeset
|
340 GL_UNSIGNED_BYTE, clearTexture); |
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
341 #endif |
13585 | 342 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
13601
diff
changeset
|
343 glAdjustAlignment(image_width * image_bytes); |
13585 | 344 |
16099 | 345 BindTexture(gl_target, 0); |
13585 | 346 free(clearTexture); |
347 | |
348 // Create a list for rendering this OSD part | |
349 osdDispList[osdtexCnt] = glGenLists(1); | |
350 glNewList(osdDispList[osdtexCnt], GL_COMPILE); | |
351 #ifndef FAST_OSD | |
352 // render alpha | |
353 glBlendFunc(GL_ZERO, GL_SRC_ALPHA); | |
16099 | 354 BindTexture(gl_target, osdatex[osdtexCnt]); |
13585 | 355 glBegin(GL_QUADS); |
356 glTexCoord2f (0, 0); | |
357 glVertex2f (x0, y0); | |
358 glTexCoord2f (0, ycov); | |
359 glVertex2f (x0, y0 + h); | |
360 glTexCoord2f (xcov, ycov); | |
361 glVertex2f (x0 + w, y0 + h); | |
362 glTexCoord2f (xcov, 0); | |
363 glVertex2f (x0 + w, y0); | |
364 glEnd(); | |
365 #endif | |
366 // render OSD | |
367 glBlendFunc (GL_ONE, GL_ONE); | |
16099 | 368 BindTexture(gl_target, osdtex[osdtexCnt]); |
13585 | 369 glBegin(GL_QUADS); |
370 glTexCoord2f (0, 0); | |
371 glVertex2f (x0, y0); | |
372 glTexCoord2f (0, ycov); | |
373 glVertex2f (x0, y0 + h); | |
374 glTexCoord2f (xcov, ycov); | |
375 glVertex2f (x0 + w, y0 + h); | |
376 glTexCoord2f (xcov, 0); | |
377 glVertex2f (x0 + w, y0); | |
378 glEnd(); | |
379 glEndList(); | |
380 | |
381 osdtexCnt++; | |
382 } | |
383 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
384 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
385 { |
13585 | 386 int i; |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
387 int osd_h, osd_w; |
13585 | 388 if (!use_osd) return; |
389 if (vo_osd_changed(0)) { | |
390 for (i = 0; i < osdtexCnt; i++) { | |
391 glDeleteTextures(1, &osdtex[i]); | |
392 #ifndef FAST_OSD | |
393 glDeleteTextures(1, &osdatex[i]); | |
394 #endif | |
395 glDeleteLists(osdDispList[i], 1); | |
396 } | |
397 osdtexCnt = 0; | |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
398 |
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
399 osd_w = (scaled_osd) ? image_width : vo_dwidth; |
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
400 osd_h = (scaled_osd) ? image_height : vo_dheight; |
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
401 vo_draw_text(osd_w, osd_h, create_osd_texture); |
13585 | 402 } |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
403 } |
31 | 404 |
405 static void | |
406 flip_page(void) | |
407 { | |
16099 | 408 int tc_x = 1, tc_y = 1; |
409 if (use_rectangle == 1) { | |
410 tc_x = texture_width; | |
411 tc_y = texture_height; | |
412 } | |
31 | 413 |
1 | 414 // glEnable(GL_TEXTURE_2D); |
415 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
416 | |
417 glColor3f(1,1,1); | |
418 glBegin(GL_QUADS); | |
419 glTexCoord2f(0,0);glVertex2i(0,0); | |
16099 | 420 glTexCoord2f(0,tc_y);glVertex2i(0,texture_height); |
421 glTexCoord2f(tc_x,tc_y);glVertex2i(texture_width,texture_height); | |
422 glTexCoord2f(tc_x,0);glVertex2i(texture_width,0); | |
1 | 423 glEnd(); |
424 | |
13585 | 425 if (osdtexCnt > 0) { |
426 // set special rendering parameters | |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
427 if (!scaled_osd) { |
13585 | 428 glMatrixMode(GL_PROJECTION); |
429 glPushMatrix(); | |
430 glLoadIdentity(); | |
431 glOrtho(0, vo_dwidth, vo_dheight, 0, -1, 1); | |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
432 } |
13585 | 433 glEnable(GL_BLEND); |
434 // draw OSD | |
435 glCallLists(osdtexCnt, GL_UNSIGNED_INT, osdDispList); | |
436 // set rendering parameters back to defaults | |
437 glDisable (GL_BLEND); | |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
438 if (!scaled_osd) |
13585 | 439 glPopMatrix(); |
16099 | 440 BindTexture(gl_target, 0); |
13585 | 441 } |
442 | |
1 | 443 // glFlush(); |
444 glFinish(); | |
6095 | 445 glXSwapBuffers( mDisplay,vo_window ); |
446 | |
13601 | 447 if (vo_fs && use_aspect) |
448 glClear(GL_COLOR_BUFFER_BIT); | |
1 | 449 } |
450 | |
451 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | |
452 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
453 { | |
454 return 0; | |
455 } | |
456 | |
16099 | 457 static uint32_t get_image(mp_image_t *mpi) { |
458 if (!BindBuffer || !BufferData || !MapBuffer) { | |
459 if (!err_shown) | |
460 mp_msg(MSGT_VO, MSGL_ERR, "[gl] extensions missing for dr\n" | |
461 "Expect a _major_ speed penalty\n"); | |
462 return VO_FALSE; | |
463 } | |
464 if (mpi->flags & MP_IMGFLAG_READABLE) return VO_FALSE; | |
465 if (mpi->type == MP_IMGTYPE_STATIC) return VO_FALSE; | |
466 BindBuffer(GL_PIXEL_UNPACK_BUFFER, 1); | |
467 mpi->stride[0] = mpi->width * mpi->bpp / 8; | |
468 if (mpi->stride[0] * mpi->h > gl_buffersize) { | |
469 BufferData(GL_PIXEL_UNPACK_BUFFER, mpi->stride[0] * mpi->h, | |
470 NULL, GL_STREAM_DRAW); | |
471 gl_buffersize = mpi->stride[0] * mpi->h; | |
472 } | |
473 mpi->planes[0] = MapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); | |
474 BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
475 mpi->flags |= MP_IMGFLAG_DIRECT; | |
476 return VO_TRUE; | |
477 } | |
478 | |
16092 | 479 static uint32_t draw_image(mp_image_t *mpi) { |
480 char *data = mpi->planes[0]; | |
481 int x = mpi->x; | |
482 int y = mpi->y; | |
483 int y_max = mpi->y + mpi->h; | |
484 int h = slice_height ? slice_height : mpi->h; | |
485 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) | |
486 return VO_TRUE; | |
16099 | 487 if (mpi->flags & MP_IMGFLAG_DIRECT) { |
488 data = NULL; | |
489 BindBuffer(GL_PIXEL_UNPACK_BUFFER, 1); | |
490 UnmapBuffer(GL_PIXEL_UNPACK_BUFFER); | |
491 h = mpi->h; // always "upload" full texture | |
492 } | |
16092 | 493 // this is not always correct, but should work for MPlayer |
494 glAdjustAlignment(mpi->stride[0]); | |
495 glPixelStorei(GL_UNPACK_ROW_LENGTH, mpi->stride[0] / (mpi->bpp / 8)); | |
496 for (y = mpi->y; y + h <= y_max; y += h) { | |
16099 | 497 glTexSubImage2D(gl_target, 0, x, y, |
16092 | 498 mpi->w, h, |
499 gl_format, gl_type, | |
500 data); | |
501 data += mpi->stride[0] * h; | |
502 } | |
503 if (y < y_max) | |
16099 | 504 glTexSubImage2D(gl_target, 0, x, y, mpi->w, y_max - y, |
16092 | 505 gl_format, gl_type, data); |
16099 | 506 if (mpi->flags & MP_IMGFLAG_DIRECT) |
507 BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
16092 | 508 return VO_TRUE; |
509 } | |
1 | 510 |
10138
5e286cc6ad21
Removed YUV (YV12) and BGR support, leaving the native RGB support. Also cleaned some other parts.
alex
parents:
8654
diff
changeset
|
511 static uint32_t |
5e286cc6ad21
Removed YUV (YV12) and BGR support, leaving the native RGB support. Also cleaned some other parts.
alex
parents:
8654
diff
changeset
|
512 draw_frame(uint8_t *src[]) |
1 | 513 { |
16092 | 514 return VO_ERROR; |
1 | 515 } |
516 | |
517 static uint32_t | |
518 query_format(uint32_t format) | |
519 { | |
16092 | 520 int caps = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | |
521 VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE; | |
13585 | 522 if (use_osd) |
523 caps |= VFCAP_OSD; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
524 if ((format == IMGFMT_RGB24) || (format == IMGFMT_RGBA)) |
13585 | 525 return caps; |
14078
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13993
diff
changeset
|
526 if (many_fmts && |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13993
diff
changeset
|
527 glFindFormat(format, NULL, NULL, NULL, NULL)) |
13585 | 528 return caps; |
1 | 529 return 0; |
530 } | |
531 | |
532 | |
533 static void | |
534 uninit(void) | |
535 { | |
6095 | 536 if ( !vo_config_count ) return; |
13843 | 537 releaseGlContext(&gl_vinfo, &gl_context); |
6095 | 538 vo_x11_uninit(); |
1 | 539 } |
4352 | 540 |
14286 | 541 static opt_t subopts[] = { |
542 {"manyfmts", OPT_ARG_BOOL, &many_fmts, NULL}, | |
543 {"osd", OPT_ARG_BOOL, &use_osd, NULL}, | |
544 {"scaled-osd", OPT_ARG_BOOL, &scaled_osd, NULL}, | |
545 {"aspect", OPT_ARG_BOOL, &use_aspect, NULL}, | |
546 {"slice-height", OPT_ARG_INT, &slice_height, (opt_test_f)int_non_neg}, | |
16099 | 547 {"rectangle", OPT_ARG_INT, &use_rectangle,(opt_test_f)int_non_neg}, |
14286 | 548 {NULL} |
549 }; | |
550 | |
4352 | 551 static uint32_t preinit(const char *arg) |
552 { | |
14286 | 553 // set defaults |
16012 | 554 many_fmts = 1; |
13585 | 555 use_osd = 1; |
13660
b34c5aa5f798
OSD variant for vo_gl.c that behaves more like the one of other vos.
reimar
parents:
13653
diff
changeset
|
556 scaled_osd = 0; |
13601 | 557 use_aspect = 1; |
16099 | 558 use_rectangle = 0; |
12159 | 559 slice_height = 4; |
14286 | 560 if (subopt_parse(arg, subopts) != 0) { |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
561 mp_msg(MSGT_VO, MSGL_FATAL, |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
562 "\n-vo gl command line help:\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
563 "Example: mplayer -vo gl:slice-height=4\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
564 "\nOptions:\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
565 " manyfmts\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
566 " Enable extended color formats for OpenGL 1.2 and later\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
567 " slice-height=<0-...>\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
568 " Slice size for texture transfer, 0 for whole image\n" |
13585 | 569 " noosd\n" |
570 " Do not use OpenGL OSD code\n" | |
13601 | 571 " noaspect\n" |
572 " Do not do aspect scaling\n" | |
16099 | 573 " rectangle=<0,1,2>\n" |
574 " 0: use power-of-two textures\n" | |
575 " 1: use texture_rectangle\n" | |
576 " 2: use texture_non_power_of_two\n" | |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
577 "\n" ); |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
578 return -1; |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
579 } |
16099 | 580 if (use_rectangle == 1) |
581 gl_target = GL_TEXTURE_RECTANGLE; | |
582 else | |
583 gl_target = GL_TEXTURE_2D; | |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
584 if (many_fmts) |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
585 mp_msg (MSGT_VO, MSGL_WARN, "[gl] using extended formats.\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
586 "Make sure you have OpenGL >= 1.2 and used corresponding " |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
587 "headers for compiling!\n"); |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
588 mp_msg (MSGT_VO, MSGL_INFO, "[gl] Using %d as slice height " |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
589 "(0 means image height).\n", slice_height); |
7931 | 590 if( !vo_init() ) return -1; // Can't open X11 |
7777 | 591 |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
592 return 0; |
4352 | 593 } |
594 | |
4596 | 595 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 596 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
597 switch (request) { |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
598 case VOCTRL_PAUSE: return (int_pause=1); |
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
599 case VOCTRL_RESUME: return (int_pause=0); |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
600 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
601 return query_format(*((uint32_t*)data)); |
16099 | 602 case VOCTRL_GET_IMAGE: |
603 return get_image(data); | |
16092 | 604 case VOCTRL_DRAW_IMAGE: |
605 return draw_image(data); | |
13843 | 606 case VOCTRL_GUISUPPORT: |
607 return VO_TRUE; | |
11542 | 608 case VOCTRL_ONTOP: |
609 vo_x11_ontop(); | |
610 return VO_TRUE; | |
6095 | 611 case VOCTRL_FULLSCREEN: |
612 vo_x11_fullscreen(); | |
613 return VO_TRUE; | |
13601 | 614 case VOCTRL_GET_PANSCAN: |
615 if (!use_aspect) return VO_NOTIMPL; | |
616 return VO_TRUE; | |
617 case VOCTRL_SET_PANSCAN: | |
618 if (!use_aspect) return VO_NOTIMPL; | |
619 resize (vo_dwidth, vo_dheight); | |
620 return VO_TRUE; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
621 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
622 return VO_NOTIMPL; |
4352 | 623 } |