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