Mercurial > mplayer.hg
comparison libvo/vo_gl.c @ 13843:3f28d2a56758
fullscreen fixes and GUI support for vo_gl
author | reimar |
---|---|
date | Mon, 01 Nov 2004 20:24:37 +0000 |
parents | b34c5aa5f798 |
children | 8298dc8ca78b |
comparison
equal
deleted
inserted
replaced
13842:78e5886bc211 | 13843:3f28d2a56758 |
---|---|
22 #include <GL/gl.h> | 22 #include <GL/gl.h> |
23 | 23 |
24 #include "gl_common.h" | 24 #include "gl_common.h" |
25 #include "x11_common.h" | 25 #include "x11_common.h" |
26 #include "aspect.h" | 26 #include "aspect.h" |
27 #ifdef HAVE_NEW_GUI | |
28 #include "Gui/interface.h" | |
29 #endif | |
27 | 30 |
28 static vo_info_t info = | 31 static vo_info_t info = |
29 { | 32 { |
30 "X11 (OpenGL)", | 33 "X11 (OpenGL)", |
31 "gl", | 34 "gl", |
33 "" | 36 "" |
34 }; | 37 }; |
35 | 38 |
36 LIBVO_EXTERN(gl) | 39 LIBVO_EXTERN(gl) |
37 | 40 |
38 static GLXContext wsGLXContext; | 41 static XVisualInfo *gl_vinfo = NULL; |
42 static GLXContext gl_context = 0; | |
39 static int wsGLXAttrib[] = { GLX_RGBA, | 43 static int wsGLXAttrib[] = { GLX_RGBA, |
40 GLX_RED_SIZE,1, | 44 GLX_RED_SIZE,1, |
41 GLX_GREEN_SIZE,1, | 45 GLX_GREEN_SIZE,1, |
42 GLX_BLUE_SIZE,1, | 46 GLX_BLUE_SIZE,1, |
43 GLX_DOUBLEBUFFER, | 47 GLX_DOUBLEBUFFER, |
170 gl_texfmt = TEXTUREFORMAT_ALWAYS; | 174 gl_texfmt = TEXTUREFORMAT_ALWAYS; |
171 #endif | 175 #endif |
172 return 1; | 176 return 1; |
173 } | 177 } |
174 | 178 |
179 /** | |
180 * \brief Initialize a (new or reused) OpenGL context. | |
181 */ | |
182 static int initGl(uint32_t d_width, uint32_t d_height) { | |
183 unsigned char *ImageData = NULL; | |
184 texture_width = 32; | |
185 while (texture_width < image_width || | |
186 texture_width < image_height) | |
187 texture_width *= 2; | |
188 texture_height = texture_width; | |
189 | |
190 glDisable(GL_BLEND); | |
191 glDisable(GL_DEPTH_TEST); | |
192 glDepthMask(GL_FALSE); | |
193 glDisable(GL_CULL_FACE); | |
194 glEnable(GL_TEXTURE_2D); | |
195 | |
196 mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n", | |
197 texture_width, texture_height); | |
198 | |
199 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
200 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
201 | |
202 glAdjustAlignment(texture_width * image_bytes); | |
203 ImageData = malloc(texture_width * texture_height * image_bytes); | |
204 memset(ImageData, 0, texture_width * texture_height * image_bytes); | |
205 glTexImage2D(GL_TEXTURE_2D, 0, gl_texfmt, texture_width, texture_height, 0, | |
206 gl_format, gl_type, ImageData); | |
207 free (ImageData); | |
208 | |
209 // set alignment as default is 4 which will break some files | |
210 glAdjustAlignment(image_width * image_bytes); | |
211 | |
212 resize(d_width, d_height); | |
213 | |
214 glClearColor( 0.0f,0.0f,0.0f,0.0f ); | |
215 glClear( GL_COLOR_BUFFER_BIT ); | |
216 } | |
217 | |
175 /* connect to server, create and map window, | 218 /* connect to server, create and map window, |
176 * allocate colors and (shared) memory | 219 * allocate colors and (shared) memory |
177 */ | 220 */ |
178 static uint32_t | 221 static uint32_t |
179 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) | 222 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
180 { | 223 { |
181 unsigned char *ImageData=NULL; | |
182 // int screen; | |
183 unsigned int fg, bg; | |
184 XSizeHints hint; | |
185 XVisualInfo *vinfo; | |
186 XEvent xev; | |
187 | |
188 // XGCValues xgcv; | |
189 | |
190 image_height = height; | 224 image_height = height; |
191 image_width = width; | 225 image_width = width; |
192 find_gl_format (format); | 226 find_gl_format (format); |
193 vo_dwidth = d_width; | |
194 vo_dheight = d_height; | |
195 | 227 |
196 sub_bg_alpha = 255; // We need alpha = 255 for invisible part of the OSD | 228 sub_bg_alpha = 255; // We need alpha = 255 for invisible part of the OSD |
197 int_pause = 0; | 229 int_pause = 0; |
198 | 230 |
199 panscan_init(); | 231 panscan_init(); |
205 #ifdef X11_FULLSCREEN | 237 #ifdef X11_FULLSCREEN |
206 // if( flags&0x01 ){ // (-fs) | 238 // if( flags&0x01 ){ // (-fs) |
207 // aspect(&d_width,&d_height,A_ZOOM); | 239 // aspect(&d_width,&d_height,A_ZOOM); |
208 // } | 240 // } |
209 #endif | 241 #endif |
242 #ifdef HAVE_NEW_GUI | |
243 if (use_gui) { | |
244 // GUI creates and manages window for us | |
245 vo_dwidth = d_width; | |
246 vo_dheight= d_height; | |
247 guiGetEvent(guiSetShVideo, 0); | |
248 setGlWindow(&gl_vinfo, &gl_context, vo_window); | |
249 initGl(vo_dwidth, vo_dheight); | |
250 return 0; | |
251 } | |
252 #endif | |
253 if ( vo_window == None ) { | |
254 unsigned int fg, bg; | |
255 XSizeHints hint; | |
256 XVisualInfo *vinfo; | |
257 XEvent xev; | |
258 | |
259 vo_dwidth = d_width; | |
260 vo_dheight = d_height; | |
261 | |
210 hint.x = 0; | 262 hint.x = 0; |
211 hint.y = 0; | 263 hint.y = 0; |
212 hint.width = d_width; | 264 hint.width = d_width; |
213 hint.height = d_height; | 265 hint.height = d_height; |
214 hint.flags = PPosition | PSize; | 266 hint.flags = PPosition | PSize; |
227 return -1; | 279 return -1; |
228 } | 280 } |
229 | 281 |
230 | 282 |
231 | 283 |
232 if ( vo_window == None ) | |
233 { | |
234 vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vinfo->visual, hint.x, hint.y, hint.width, hint.height, | 284 vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vinfo->visual, hint.x, hint.y, hint.width, hint.height, |
235 vinfo->depth, XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone)); | 285 vinfo->depth, XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone)); |
236 | 286 |
237 vo_x11_classhint( mDisplay,vo_window,"gl" ); | 287 vo_x11_classhint( mDisplay,vo_window,"gl" ); |
238 vo_hidecursor(mDisplay,vo_window); | 288 vo_hidecursor(mDisplay,vo_window); |
241 XSelectInput(mDisplay, vo_window, StructureNotifyMask); | 291 XSelectInput(mDisplay, vo_window, StructureNotifyMask); |
242 /* Tell other applications about this window */ | 292 /* Tell other applications about this window */ |
243 XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint); | 293 XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint); |
244 /* Map window. */ | 294 /* Map window. */ |
245 XMapWindow(mDisplay, vo_window); | 295 XMapWindow(mDisplay, vo_window); |
246 if ( flags&1 ) vo_x11_fullscreen(); | |
247 #ifdef HAVE_XINERAMA | 296 #ifdef HAVE_XINERAMA |
248 vo_x11_xinerama_move(mDisplay,vo_window); | 297 vo_x11_xinerama_move(mDisplay,vo_window); |
249 #endif | 298 #endif |
250 | 299 |
251 /* Wait for map. */ | 300 /* Wait for map. */ |
254 XNextEvent(mDisplay, &xev); | 303 XNextEvent(mDisplay, &xev); |
255 } | 304 } |
256 while (xev.type != MapNotify || xev.xmap.event != vo_window); | 305 while (xev.type != MapNotify || xev.xmap.event != vo_window); |
257 | 306 |
258 XSelectInput(mDisplay, vo_window, NoEventMask); | 307 XSelectInput(mDisplay, vo_window, NoEventMask); |
259 } | |
260 | |
261 if ( vo_config_count ) glXDestroyContext( mDisplay,wsGLXContext ); | |
262 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); | |
263 glXMakeCurrent( mDisplay,vo_window,wsGLXContext ); | |
264 | 308 |
265 XSync(mDisplay, False); | 309 XSync(mDisplay, False); |
266 | 310 |
267 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask | 311 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask |
268 | ButtonPressMask | ButtonReleaseMask | ExposureMask | 312 | ButtonPressMask | ButtonReleaseMask | ExposureMask |
269 ); | 313 ); |
270 | 314 } |
271 texture_width=32; | |
272 while(texture_width<image_width || texture_width<image_height) texture_width*=2; | |
273 texture_height=texture_width; | |
274 | |
275 ImageData=malloc(texture_width*texture_height*image_bytes); | |
276 memset(ImageData,0,texture_width*texture_height*image_bytes); | |
277 | |
278 glDisable(GL_BLEND); | |
279 glDisable(GL_DEPTH_TEST); | |
280 glDepthMask(GL_FALSE); | |
281 glDisable(GL_CULL_FACE); | |
282 | |
283 glEnable(GL_TEXTURE_2D); | |
284 | |
285 // set alignment as default is 4 which will break some files | |
286 glAdjustAlignment(image_width * image_bytes); | |
287 | |
288 mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n",texture_width,texture_height); | |
289 | |
290 #if 1 | |
291 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
292 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
293 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
294 glTexImage2D(GL_TEXTURE_2D, 0, gl_texfmt, texture_width, texture_height, 0, | |
295 gl_format, gl_type, ImageData); | |
296 #endif | |
297 | |
298 free (ImageData); | |
299 | |
300 resize(d_width,d_height); | |
301 | |
302 glClearColor( 0.0f,0.0f,0.0f,0.0f ); | |
303 glClear( GL_COLOR_BUFFER_BIT ); | |
304 | |
305 // printf("OpenGL setup OK!\n"); | |
306 | |
307 if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); | 315 if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); |
316 | |
317 vo_x11_nofs_sizepos(0, 0, d_width, d_height); | |
318 if (vo_fs ^ (flags & VOFLAG_FULLSCREEN)) | |
319 vo_x11_fullscreen(); | |
320 setGlWindow(&gl_vinfo, &gl_context, vo_window); | |
321 initGl(vo_dwidth, vo_dheight); | |
308 | 322 |
309 return 0; | 323 return 0; |
310 } | 324 } |
311 | 325 |
312 static void check_events(void) | 326 static void check_events(void) |
517 | 531 |
518 static void | 532 static void |
519 uninit(void) | 533 uninit(void) |
520 { | 534 { |
521 if ( !vo_config_count ) return; | 535 if ( !vo_config_count ) return; |
536 releaseGlContext(&gl_vinfo, &gl_context); | |
522 vo_x11_uninit(); | 537 vo_x11_uninit(); |
523 } | 538 } |
524 | 539 |
525 static uint32_t preinit(const char *arg) | 540 static uint32_t preinit(const char *arg) |
526 { | 541 { |
610 switch (request) { | 625 switch (request) { |
611 case VOCTRL_PAUSE: return (int_pause=1); | 626 case VOCTRL_PAUSE: return (int_pause=1); |
612 case VOCTRL_RESUME: return (int_pause=0); | 627 case VOCTRL_RESUME: return (int_pause=0); |
613 case VOCTRL_QUERY_FORMAT: | 628 case VOCTRL_QUERY_FORMAT: |
614 return query_format(*((uint32_t*)data)); | 629 return query_format(*((uint32_t*)data)); |
630 case VOCTRL_GUISUPPORT: | |
631 return VO_TRUE; | |
615 case VOCTRL_ONTOP: | 632 case VOCTRL_ONTOP: |
616 vo_x11_ontop(); | 633 vo_x11_ontop(); |
617 return VO_TRUE; | 634 return VO_TRUE; |
618 case VOCTRL_FULLSCREEN: | 635 case VOCTRL_FULLSCREEN: |
619 vo_x11_fullscreen(); | 636 vo_x11_fullscreen(); |