Mercurial > mplayer.hg
annotate libvo/vo_gl.c @ 13643:666e4819ab12
Sync with 1.777
author | gpoirier |
---|---|
date | Thu, 14 Oct 2004 17:14:11 +0000 |
parents | da85ac96600e |
children | 799f81d3cb19 |
rev | line source |
---|---|
12843
52d493f0ac79
changed misleading TEXTUREFORMAT_32BPP (was 24bpp!) to vo_gl2 style TEXTUREFORMAT_ALWAYS
reimar
parents:
12749
diff
changeset
|
1 #define TEXTUREFORMAT_ALWAYS GL_RGB8 |
1 | 2 |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #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
|
7 #include <errno.h> |
1 | 8 |
11988 | 9 #include "mp_msg.h" |
1 | 10 #include "config.h" |
11 #include "video_out.h" | |
12 #include "video_out_internal.h" | |
13585 | 13 #include "font_load.h" |
14 #include "sub.h" | |
1 | 15 |
16 #include <X11/Xlib.h> | |
17 #include <X11/Xutil.h> | |
18 //#include <X11/keysym.h> | |
19 #include <GL/glx.h> | |
20 #include <errno.h> | |
21 | |
22 #include <GL/gl.h> | |
23 | |
31 | 24 #include "x11_common.h" |
2057 | 25 #include "aspect.h" |
31 | 26 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
27 static vo_info_t info = |
1 | 28 { |
29 "X11 (OpenGL)", | |
30 "gl", | |
31 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
32 "" | |
33 }; | |
34 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
35 LIBVO_EXTERN(gl) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
36 |
1 | 37 static GLXContext wsGLXContext; |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
38 static int wsGLXAttrib[] = { GLX_RGBA, |
1 | 39 GLX_RED_SIZE,1, |
40 GLX_GREEN_SIZE,1, | |
41 GLX_BLUE_SIZE,1, | |
42 GLX_DOUBLEBUFFER, | |
43 None }; | |
44 | |
13599 | 45 static int use_osd; |
13585 | 46 #define MAX_OSD_PARTS 20 |
13599 | 47 static GLuint osdtex[MAX_OSD_PARTS]; |
13585 | 48 #ifndef FAST_OSD |
13599 | 49 static GLuint osdatex[MAX_OSD_PARTS]; |
13585 | 50 #endif |
13599 | 51 static GLuint osdDispList[MAX_OSD_PARTS]; |
52 static int osdtexCnt = 0; | |
1 | 53 |
13601 | 54 static int use_aspect; |
1 | 55 static uint32_t image_width; |
56 static uint32_t image_height; | |
57 static uint32_t image_bytes; | |
12159 | 58 static int many_fmts; |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
59 static GLenum gl_texfmt; |
12159 | 60 static GLenum gl_format; |
61 static GLenum gl_type; | |
1 | 62 |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
63 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
|
64 |
1 | 65 static uint32_t texture_width; |
66 static uint32_t texture_height; | |
67 | |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
68 static unsigned int slice_height = 1; |
8654
2c4cebb8637d
- optional slice height for -vo gl (example: -vo gl:32)
arpi
parents:
8148
diff
changeset
|
69 |
612 | 70 static void resize(int x,int y){ |
11988 | 71 mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n",x,y); |
1 | 72 glViewport( 0, 0, x, y ); |
73 | |
74 glMatrixMode(GL_PROJECTION); | |
75 glLoadIdentity(); | |
13601 | 76 if (vo_fs && use_aspect) { |
77 int new_w, new_h; | |
78 GLdouble scale_x, scale_y; | |
79 aspect(&new_w, &new_h, A_ZOOM); | |
80 panscan_calc(); | |
81 new_w += vo_panscan_x; | |
82 new_h += vo_panscan_y; | |
83 scale_x = (GLdouble) new_w / (GLdouble) x; | |
84 scale_y = (GLdouble) new_h / (GLdouble) y; | |
85 glScaled(scale_x, scale_y, 1); | |
86 } | |
1 | 87 glOrtho(0, image_width, image_height, 0, -1,1); |
88 | |
89 glMatrixMode(GL_MODELVIEW); | |
90 glLoadIdentity(); | |
13585 | 91 |
92 #ifdef HAVE_FREETYPE | |
93 // adjust font size to display size | |
94 force_load_font = 1; | |
95 #endif | |
96 vo_osd_changed(1); | |
1 | 97 } |
98 | |
12159 | 99 static int find_gl_format (uint32_t format) |
100 { | |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
101 image_bytes = (IMGFMT_RGB_DEPTH(format)+7)/8; |
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
102 gl_texfmt = 3; |
12159 | 103 switch (format) { |
104 case IMGFMT_RGB24: | |
105 gl_format = GL_RGB; | |
106 gl_type = GL_UNSIGNED_BYTE; | |
107 break; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
108 case IMGFMT_RGBA: |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
109 gl_texfmt = 4; |
12159 | 110 gl_format = GL_RGBA; |
111 gl_type = GL_UNSIGNED_BYTE; | |
112 break; | |
113 case IMGFMT_Y800: | |
114 case IMGFMT_Y8: | |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
115 gl_texfmt = 1; |
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
116 image_bytes = 1; |
12159 | 117 gl_format = GL_LUMINANCE; |
118 gl_type = GL_UNSIGNED_BYTE; | |
119 break; | |
120 #ifdef GL_VERSION_1_2 | |
121 case IMGFMT_RGB8: | |
122 gl_format = GL_RGB; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
123 gl_type = GL_UNSIGNED_BYTE_2_3_3_REV; |
12159 | 124 break; |
125 case IMGFMT_RGB15: | |
126 gl_format = GL_RGBA; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
127 gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; |
12159 | 128 break; |
129 case IMGFMT_RGB16: | |
130 gl_format = GL_RGB; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
131 gl_type = GL_UNSIGNED_SHORT_5_6_5_REV; |
12159 | 132 break; |
133 case IMGFMT_BGR8: | |
134 // special case as red and blue have a differen number of bits. | |
135 // GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least | |
136 // by nVidia drivers, and in addition would give more bits to | |
137 // blue than to red, which isn't wanted | |
138 gl_format = GL_RGB; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
139 gl_type = GL_UNSIGNED_BYTE_3_3_2; |
12159 | 140 break; |
141 case IMGFMT_BGR15: | |
142 gl_format = GL_BGRA; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
143 gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV; |
12159 | 144 break; |
145 case IMGFMT_BGR16: | |
146 gl_format = GL_RGB; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
147 gl_type = GL_UNSIGNED_SHORT_5_6_5; |
12159 | 148 break; |
149 case IMGFMT_BGR24: | |
150 gl_format = GL_BGR; | |
151 gl_type = GL_UNSIGNED_BYTE; | |
152 break; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
153 case IMGFMT_BGRA: |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
154 gl_texfmt = 4; |
12159 | 155 gl_format = GL_BGRA; |
156 gl_type = GL_UNSIGNED_BYTE; | |
157 break; | |
158 #endif | |
159 default: | |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
160 gl_texfmt = 4; |
12159 | 161 gl_format = GL_RGBA; |
162 gl_type = GL_UNSIGNED_BYTE; | |
163 return 0; | |
164 } | |
12843
52d493f0ac79
changed misleading TEXTUREFORMAT_32BPP (was 24bpp!) to vo_gl2 style TEXTUREFORMAT_ALWAYS
reimar
parents:
12749
diff
changeset
|
165 #ifdef TEXTUREFORMAT_ALWAYS |
52d493f0ac79
changed misleading TEXTUREFORMAT_32BPP (was 24bpp!) to vo_gl2 style TEXTUREFORMAT_ALWAYS
reimar
parents:
12749
diff
changeset
|
166 gl_texfmt = TEXTUREFORMAT_ALWAYS; |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
167 #endif |
12159 | 168 return 1; |
169 } | |
170 | |
1 | 171 /* connect to server, create and map window, |
172 * allocate colors and (shared) memory | |
173 */ | |
174 static uint32_t | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7111
diff
changeset
|
175 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
1 | 176 { |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
177 unsigned char *ImageData=NULL; |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
178 // int screen; |
1 | 179 unsigned int fg, bg; |
180 XSizeHints hint; | |
181 XVisualInfo *vinfo; | |
182 XEvent xev; | |
13576 | 183 GLint gl_alignment; |
1 | 184 |
1109 | 185 // XGCValues xgcv; |
1 | 186 |
187 image_height = height; | |
188 image_width = width; | |
12159 | 189 find_gl_format (format); |
10919 | 190 vo_dwidth = d_width; |
191 vo_dheight = d_height; | |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
192 |
13585 | 193 sub_bg_alpha = 255; // We need alpha = 255 for invisible part of the OSD |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
194 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
|
195 |
13601 | 196 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
|
197 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
|
198 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
|
199 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
|
200 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
201 aspect(&d_width,&d_height,A_NOZOOM); |
2040 | 202 #ifdef X11_FULLSCREEN |
6095 | 203 // if( flags&0x01 ){ // (-fs) |
204 // aspect(&d_width,&d_height,A_ZOOM); | |
205 // } | |
2040 | 206 #endif |
1 | 207 hint.x = 0; |
208 hint.y = 0; | |
209 hint.width = d_width; | |
210 hint.height = d_height; | |
211 hint.flags = PPosition | PSize; | |
212 | |
213 /* Get some colors */ | |
214 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
215 bg = WhitePixel(mDisplay, mScreen); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
216 fg = BlackPixel(mDisplay, mScreen); |
1 | 217 |
218 /* Make the window */ | |
219 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
220 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
1290 | 221 if (vinfo == NULL) |
222 { | |
11988 | 223 mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n"); |
1290 | 224 return -1; |
225 } | |
1 | 226 |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
227 |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
1109
diff
changeset
|
228 |
7777 | 229 if ( vo_window == None ) |
230 { | |
10757
3aea64e0d6d9
Avoid flickering during resizes. Keep video contents even when paused. Fix by Tomas Simonaitis <haden@homelan.lt>
mosu
parents:
10138
diff
changeset
|
231 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
|
232 vinfo->depth, XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone)); |
1 | 233 |
7777 | 234 vo_x11_classhint( mDisplay,vo_window,"gl" ); |
235 vo_hidecursor(mDisplay,vo_window); | |
1 | 236 |
7777 | 237 // if ( flags&0x01 ) vo_x11_decoration( mDisplay,vo_window,0 ); |
238 XSelectInput(mDisplay, vo_window, StructureNotifyMask); | |
239 /* 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
|
240 XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint); |
7777 | 241 /* Map window. */ |
242 XMapWindow(mDisplay, vo_window); | |
243 if ( flags&1 ) vo_x11_fullscreen(); | |
4017 | 244 #ifdef HAVE_XINERAMA |
7777 | 245 vo_x11_xinerama_move(mDisplay,vo_window); |
4017 | 246 #endif |
1 | 247 |
7777 | 248 /* Wait for map. */ |
249 do | |
250 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
251 XNextEvent(mDisplay, &xev); |
7777 | 252 } |
253 while (xev.type != MapNotify || xev.xmap.event != vo_window); | |
1 | 254 |
7777 | 255 XSelectInput(mDisplay, vo_window, NoEventMask); |
256 } | |
1 | 257 |
7777 | 258 if ( vo_config_count ) glXDestroyContext( mDisplay,wsGLXContext ); |
259 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); | |
260 glXMakeCurrent( mDisplay,vo_window,wsGLXContext ); | |
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 ); |
1 | 267 |
268 texture_width=32; | |
10138
5e286cc6ad21
Removed YUV (YV12) and BGR support, leaving the native RGB support. Also cleaned some other parts.
alex
parents:
8654
diff
changeset
|
269 while(texture_width<image_width || texture_width<image_height) texture_width*=2; |
1 | 270 texture_height=texture_width; |
271 | |
272 ImageData=malloc(texture_width*texture_height*image_bytes); | |
13601 | 273 memset(ImageData,0,texture_width*texture_height*image_bytes); |
1 | 274 |
275 glDisable(GL_BLEND); | |
276 glDisable(GL_DEPTH_TEST); | |
277 glDepthMask(GL_FALSE); | |
278 glDisable(GL_CULL_FACE); | |
279 | |
280 glEnable(GL_TEXTURE_2D); | |
281 | |
13575 | 282 // set alignment as default is 4 which will break some files |
283 if ((image_width * image_bytes) % 8 == 0) | |
284 gl_alignment=8; | |
285 else if ((image_width * image_bytes) % 4 == 0) | |
286 gl_alignment=4; | |
287 else if ((image_width * image_bytes) % 2 == 0) | |
288 gl_alignment=2; | |
289 else | |
290 gl_alignment=1; | |
291 glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment); | |
292 | |
11988 | 293 mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n",texture_width,texture_height); |
1 | 294 |
295 #if 1 | |
296 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
297 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
298 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
299 glTexImage2D(GL_TEXTURE_2D, 0, gl_texfmt, texture_width, texture_height, 0, |
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
300 gl_format, gl_type, ImageData); |
1 | 301 #endif |
12445
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
302 |
d97398ed403e
changes to get manyfmts nearer to working and fixed memory leak
reimar
parents:
12212
diff
changeset
|
303 free (ImageData); |
1 | 304 |
305 resize(d_width,d_height); | |
306 | |
13601 | 307 glClearColor( 0.0f,0.0f,0.0f,0.0f ); |
1 | 308 glClear( GL_COLOR_BUFFER_BIT ); |
309 | |
310 // printf("OpenGL setup OK!\n"); | |
311 | |
11542 | 312 if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); |
313 | |
1 | 314 return 0; |
315 } | |
316 | |
31 | 317 static void check_events(void) |
1 | 318 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
319 int e=vo_x11_check_events(mDisplay); |
31 | 320 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
|
321 if(e&VO_EVENT_EXPOSE && int_pause) flip_page(); |
31 | 322 } |
1 | 323 |
13585 | 324 /** |
325 * Creates the textures and the display list needed for displaying | |
326 * an OSD part. | |
327 * Callback function for vo_draw_text(). | |
328 */ | |
329 static void create_osd_texture(int x0, int y0, int w, int h, | |
330 unsigned char *src, unsigned char *srca, | |
331 int stride) | |
332 { | |
333 int sx = 1, sy = 1; | |
334 GLfloat xcov, ycov; | |
335 char *clearTexture; | |
336 while (sx < w) sx *= 2; | |
337 while (sy < h) sy *= 2; | |
338 xcov = (GLfloat) w / (GLfloat) sx; | |
339 ycov = (GLfloat) h / (GLfloat) sy; | |
340 | |
341 if (osdtexCnt >= MAX_OSD_PARTS) { | |
342 mp_msg(MSGT_VO, MSGL_ERR, "Too many OSD parts, contact the developers!\n"); | |
343 return; | |
344 } | |
345 clearTexture = malloc(sx * sy); | |
346 memset(clearTexture, 0, sx * sy); | |
347 | |
348 // create Textures for OSD part | |
349 glGenTextures(1, &osdtex[osdtexCnt]); | |
350 glBindTexture(GL_TEXTURE_2D, osdtex[osdtexCnt]); | |
351 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, sx, sy, 0, | |
352 GL_LUMINANCE, GL_UNSIGNED_BYTE, clearTexture); | |
353 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
354 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
355 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); | |
356 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_LUMINANCE, | |
357 GL_UNSIGNED_BYTE, src); | |
358 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | |
359 | |
360 #ifndef FAST_OSD | |
361 glGenTextures(1, &osdatex[osdtexCnt]); | |
362 glBindTexture(GL_TEXTURE_2D, osdatex[osdtexCnt]); | |
363 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, sx, sy, 0, | |
364 GL_LUMINANCE, GL_UNSIGNED_BYTE, clearTexture); | |
365 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
366 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
367 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); | |
368 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_ALPHA, | |
369 GL_UNSIGNED_BYTE, srca); | |
370 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | |
371 #endif | |
372 | |
373 glBindTexture(GL_TEXTURE_2D, 0); | |
374 free(clearTexture); | |
375 | |
376 // Create a list for rendering this OSD part | |
377 osdDispList[osdtexCnt] = glGenLists(1); | |
378 glNewList(osdDispList[osdtexCnt], GL_COMPILE); | |
379 #ifndef FAST_OSD | |
380 // render alpha | |
381 glBlendFunc(GL_ZERO, GL_SRC_ALPHA); | |
382 glBindTexture(GL_TEXTURE_2D, osdatex[osdtexCnt]); | |
383 glBegin(GL_QUADS); | |
384 glTexCoord2f (0, 0); | |
385 glVertex2f (x0, y0); | |
386 glTexCoord2f (0, ycov); | |
387 glVertex2f (x0, y0 + h); | |
388 glTexCoord2f (xcov, ycov); | |
389 glVertex2f (x0 + w, y0 + h); | |
390 glTexCoord2f (xcov, 0); | |
391 glVertex2f (x0 + w, y0); | |
392 glEnd(); | |
393 #endif | |
394 // render OSD | |
395 glBlendFunc (GL_ONE, GL_ONE); | |
396 glBindTexture(GL_TEXTURE_2D, osdtex[osdtexCnt]); | |
397 glBegin(GL_QUADS); | |
398 glTexCoord2f (0, 0); | |
399 glVertex2f (x0, y0); | |
400 glTexCoord2f (0, ycov); | |
401 glVertex2f (x0, y0 + h); | |
402 glTexCoord2f (xcov, ycov); | |
403 glVertex2f (x0 + w, y0 + h); | |
404 glTexCoord2f (xcov, 0); | |
405 glVertex2f (x0 + w, y0); | |
406 glEnd(); | |
407 glEndList(); | |
408 | |
409 osdtexCnt++; | |
410 } | |
411 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
412 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
413 { |
13585 | 414 int i; |
415 if (!use_osd) return; | |
416 if (vo_osd_changed(0)) { | |
417 for (i = 0; i < osdtexCnt; i++) { | |
418 glDeleteTextures(1, &osdtex[i]); | |
419 #ifndef FAST_OSD | |
420 glDeleteTextures(1, &osdatex[i]); | |
421 #endif | |
422 glDeleteLists(osdDispList[i], 1); | |
423 } | |
424 osdtexCnt = 0; | |
425 // draw OSD with full resolution | |
426 vo_draw_text(vo_dwidth, vo_dheight, create_osd_texture); | |
427 } | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
428 } |
31 | 429 |
430 static void | |
431 flip_page(void) | |
432 { | |
433 | |
1 | 434 // glEnable(GL_TEXTURE_2D); |
435 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
436 | |
437 glColor3f(1,1,1); | |
438 glBegin(GL_QUADS); | |
439 glTexCoord2f(0,0);glVertex2i(0,0); | |
440 glTexCoord2f(0,1);glVertex2i(0,texture_height); | |
441 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); | |
442 glTexCoord2f(1,0);glVertex2i(texture_width,0); | |
443 glEnd(); | |
444 | |
13585 | 445 if (osdtexCnt > 0) { |
446 // set special rendering parameters | |
447 glMatrixMode(GL_PROJECTION); | |
448 glPushMatrix(); | |
449 glLoadIdentity(); | |
450 glOrtho(0, vo_dwidth, vo_dheight, 0, -1, 1); | |
451 glEnable(GL_BLEND); | |
452 // draw OSD | |
453 glCallLists(osdtexCnt, GL_UNSIGNED_INT, osdDispList); | |
454 // set rendering parameters back to defaults | |
455 glDisable (GL_BLEND); | |
456 glPopMatrix(); | |
457 glBindTexture(GL_TEXTURE_2D, 0); | |
458 } | |
459 | |
1 | 460 // glFlush(); |
461 glFinish(); | |
6095 | 462 glXSwapBuffers( mDisplay,vo_window ); |
463 | |
13601 | 464 if (vo_fs && use_aspect) |
465 glClear(GL_COLOR_BUFFER_BIT); | |
1 | 466 } |
467 | |
468 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | |
469 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
470 { | |
471 return 0; | |
472 } | |
473 | |
474 | |
10138
5e286cc6ad21
Removed YUV (YV12) and BGR support, leaving the native RGB support. Also cleaned some other parts.
alex
parents:
8654
diff
changeset
|
475 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
|
476 draw_frame(uint8_t *src[]) |
1 | 477 { |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
478 unsigned int i; |
1 | 479 uint8_t *ImageData=src[0]; |
480 | |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
481 if (slice_height == 0) |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
482 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_width, image_height, |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
483 gl_format, gl_type, ImageData); |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
484 else |
8654
2c4cebb8637d
- optional slice height for -vo gl (example: -vo gl:32)
arpi
parents:
8148
diff
changeset
|
485 for(i=0;i<image_height;i+=slice_height){ |
1 | 486 glTexSubImage2D( GL_TEXTURE_2D, // target |
487 0, // level | |
488 0, // x offset | |
489 // image_height-1-i, // y offset | |
490 i, // y offset | |
491 image_width, // width | |
8654
2c4cebb8637d
- optional slice height for -vo gl (example: -vo gl:32)
arpi
parents:
8148
diff
changeset
|
492 (i+slice_height<=image_height)?slice_height:image_height-i, // height |
12159 | 493 gl_format, |
494 gl_type, | |
1 | 495 ImageData+i*image_bytes*image_width ); // *pixels |
496 } | |
497 | |
498 return 0; | |
499 } | |
500 | |
501 static uint32_t | |
502 query_format(uint32_t format) | |
503 { | |
13585 | 504 int caps = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; |
505 if (use_osd) | |
506 caps |= VFCAP_OSD; | |
13206
6e8d1ac141fc
Using updated colorspace specifications from colorspaces.txt.
reimar
parents:
13188
diff
changeset
|
507 if ((format == IMGFMT_RGB24) || (format == IMGFMT_RGBA)) |
13585 | 508 return caps; |
12159 | 509 if (many_fmts && find_gl_format(format)) |
13585 | 510 return caps; |
1 | 511 return 0; |
512 } | |
513 | |
514 | |
515 static void | |
516 uninit(void) | |
517 { | |
6095 | 518 if ( !vo_config_count ) return; |
519 vo_x11_uninit(); | |
1 | 520 } |
4352 | 521 |
522 static uint32_t preinit(const char *arg) | |
523 { | |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
524 int parse_err = 0; |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
525 unsigned int parse_pos = 0; |
12159 | 526 many_fmts = 0; |
13585 | 527 use_osd = 1; |
13601 | 528 use_aspect = 1; |
12159 | 529 slice_height = 4; |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
530 if(arg) |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
531 { |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
532 while (arg[parse_pos] && !parse_err) { |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
533 if (strncmp (&arg[parse_pos], "manyfmts", 8) == 0) { |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
534 parse_pos += 8; |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
535 many_fmts = 1; |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
536 } else if (strncmp (&arg[parse_pos], "nomanyfmts", 10) == 0) { |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
537 parse_pos += 10; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
538 many_fmts = 0; |
13585 | 539 } else if (strncmp (&arg[parse_pos], "osd", 3) == 0) { |
540 parse_pos += 3; | |
541 use_osd = 1; | |
542 } else if (strncmp (&arg[parse_pos], "noosd", 5) == 0) { | |
543 parse_pos += 5; | |
544 use_osd = 0; | |
13601 | 545 } else if (strncmp (&arg[parse_pos], "aspect", 6) == 0) { |
546 parse_pos += 6; | |
547 use_aspect = 1; | |
548 } else if (strncmp (&arg[parse_pos], "noaspect", 8) == 0) { | |
549 parse_pos += 8; | |
550 use_aspect = 0; | |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
551 } else if (strncmp (&arg[parse_pos], "slice-height=", 13) == 0) { |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
552 int val; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
553 char *end; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
554 parse_pos += 13; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
555 val = strtol(&arg[parse_pos], &end, 0); |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
556 if (val < 0) parse_err = 1; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
557 else { |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
558 slice_height = val; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
559 parse_pos = end - arg; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
560 } |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
561 } |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
562 if (arg[parse_pos] == ':') parse_pos++; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
563 else if (arg[parse_pos]) parse_err = 1; |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
564 } |
8654
2c4cebb8637d
- optional slice height for -vo gl (example: -vo gl:32)
arpi
parents:
8148
diff
changeset
|
565 } |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
566 if (parse_err) { |
13237
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
567 unsigned int i; |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
568 mp_msg(MSGT_VO, MSGL_FATAL, "Could not parse arguments:\n%s\n", arg); |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
569 for (i = 0; i < parse_pos; i++) |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
570 mp_msg(MSGT_VO, MSGL_FATAL, " "); |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
571 mp_msg(MSGT_VO, MSGL_FATAL, "^\n"); |
f85c105bfeaa
improved suboption parsing, fixes also compiler warnings
reimar
parents:
13206
diff
changeset
|
572 mp_msg(MSGT_VO, MSGL_FATAL, |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
573 "\n-vo gl command line help:\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
574 "Example: mplayer -vo gl:slice-height=4\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
575 "\nOptions:\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
576 " manyfmts\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
577 " Enable extended color formats for OpenGL 1.2 and later\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
578 " slice-height=<0-...>\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
579 " Slice size for texture transfer, 0 for whole image\n" |
13585 | 580 " noosd\n" |
581 " Do not use OpenGL OSD code\n" | |
13601 | 582 " noaspect\n" |
583 " Do not do aspect scaling\n" | |
12212
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
584 "\n" ); |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
585 return -1; |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
586 } |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
587 if (many_fmts) |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
588 mp_msg (MSGT_VO, MSGL_WARN, "[gl] using extended formats.\n" |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
589 "Make sure you have OpenGL >= 1.2 and used corresponding " |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
590 "headers for compiling!\n"); |
2e8b305586a0
fixed suboption parsing, added help for suboptions
reimar
parents:
12159
diff
changeset
|
591 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
|
592 "(0 means image height).\n", slice_height); |
7931 | 593 if( !vo_init() ) return -1; // Can't open X11 |
7777 | 594 |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
595 return 0; |
4352 | 596 } |
597 | |
4596 | 598 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 599 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
600 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
|
601 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
|
602 case VOCTRL_RESUME: return (int_pause=0); |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
603 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
604 return query_format(*((uint32_t*)data)); |
11542 | 605 case VOCTRL_ONTOP: |
606 vo_x11_ontop(); | |
607 return VO_TRUE; | |
6095 | 608 case VOCTRL_FULLSCREEN: |
609 vo_x11_fullscreen(); | |
610 return VO_TRUE; | |
13601 | 611 case VOCTRL_GET_PANSCAN: |
612 if (!use_aspect) return VO_NOTIMPL; | |
613 return VO_TRUE; | |
614 case VOCTRL_SET_PANSCAN: | |
615 if (!use_aspect) return VO_NOTIMPL; | |
616 resize (vo_dwidth, vo_dheight); | |
617 return VO_TRUE; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
618 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
619 return VO_NOTIMPL; |
4352 | 620 } |