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