Mercurial > mplayer.hg
comparison libvo/vo_gl.c @ 36171:94979f661d38
Add support for rotating the video via OpenGL.
author | reimar |
---|---|
date | Mon, 13 May 2013 19:34:43 +0000 |
parents | 056cd00eba14 |
children | 512629a9aa21 |
comparison
equal
deleted
inserted
replaced
36170:4fc911fa5366 | 36171:94979f661d38 |
---|---|
118 static float noise_strength; | 118 static float noise_strength; |
119 static int yuvconvtype; | 119 static int yuvconvtype; |
120 static int use_rectangle; | 120 static int use_rectangle; |
121 static int using_tex_rect; | 121 static int using_tex_rect; |
122 static int err_shown; | 122 static int err_shown; |
123 static int draw_width, draw_height; | |
123 static uint32_t image_width; | 124 static uint32_t image_width; |
124 static uint32_t image_height; | 125 static uint32_t image_height; |
125 static uint32_t image_format; | 126 static uint32_t image_format; |
126 static int many_fmts; | 127 static int many_fmts; |
127 static int ati_hack; | 128 static int ati_hack; |
174 static int did_render; | 175 static int did_render; |
175 | 176 |
176 static void redraw(void); | 177 static void redraw(void); |
177 | 178 |
178 static float video_matrix[16]; | 179 static float video_matrix[16]; |
180 static float osd_matrix[16]; | |
179 | 181 |
180 static void resize(void) { | 182 static void resize(void) { |
183 int i; | |
184 draw_width = (vo_rotate & 1) ? vo_dheight : vo_dwidth; | |
185 draw_height = (vo_rotate & 1) ? vo_dwidth : vo_dheight; | |
181 // simple orthogonal projection for 0-image_width;0-image_height | 186 // simple orthogonal projection for 0-image_width;0-image_height |
182 memset(video_matrix, 0, sizeof(video_matrix)); | 187 memset(video_matrix, 0, sizeof(video_matrix)); |
183 video_matrix[0] = 2.0/image_width; | 188 video_matrix[0] = 2.0/image_width; |
184 video_matrix[5] = -2.0/image_height; | 189 video_matrix[5] = -2.0/image_height; |
185 video_matrix[12] = -1; | 190 video_matrix[12] = -1; |
186 video_matrix[13] = 1; | 191 video_matrix[13] = 1; |
187 video_matrix[15] = 1; | 192 video_matrix[15] = 1; |
193 memcpy(osd_matrix, video_matrix, sizeof(osd_matrix)); | |
194 if (!scaled_osd) { | |
195 // simple orthogonal projection for 0-vo_dwidth;0-vo_dheight | |
196 osd_matrix[0] = 2.0/draw_width; | |
197 osd_matrix[5] = -2.0/draw_height; | |
198 } | |
188 mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n", vo_dwidth, vo_dheight); | 199 mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n", vo_dwidth, vo_dheight); |
189 if (WinID >= 0) { | 200 if (WinID >= 0) { |
190 int left = 0, top = 0, w = vo_dwidth, h = vo_dheight; | 201 int left = 0, top = 0, w = vo_dwidth, h = vo_dheight; |
191 geometry(&left, &top, &w, &h, vo_dwidth, vo_dheight); | 202 geometry(&left, &top, &w, &h, vo_dwidth, vo_dheight); |
192 top = vo_dheight - h - top; | 203 top = vo_dheight - h - top; |
193 mpglViewport(left, top, w, h); | 204 mpglViewport(left, top, w, h); |
194 } else | 205 } else |
195 mpglViewport(0, 0, vo_dwidth, vo_dheight); | 206 mpglViewport(0, 0, vo_dwidth, vo_dheight); |
207 | |
208 for (i = 0; i < (vo_rotate & 3); i++) { | |
209 int j; | |
210 for (j = 0; j < 16; j += 4) { | |
211 ROTATE(float, video_matrix[j], video_matrix[j+1]); | |
212 ROTATE(float, osd_matrix[j], osd_matrix[j+1]); | |
213 } | |
214 } | |
196 | 215 |
197 ass_border_x = ass_border_y = 0; | 216 ass_border_x = ass_border_y = 0; |
198 if (aspect_scaling() && use_aspect) { | 217 if (aspect_scaling() && use_aspect) { |
199 int new_w, new_h; | 218 int new_w, new_h; |
200 double scale_x, scale_y; | 219 double scale_x, scale_y; |
203 new_w += vo_panscan_x; | 222 new_w += vo_panscan_x; |
204 new_h += vo_panscan_y; | 223 new_h += vo_panscan_y; |
205 scale_x = (double)new_w / (double)vo_dwidth; | 224 scale_x = (double)new_w / (double)vo_dwidth; |
206 scale_y = (double)new_h / (double)vo_dheight; | 225 scale_y = (double)new_h / (double)vo_dheight; |
207 video_matrix[0] *= scale_x; | 226 video_matrix[0] *= scale_x; |
227 video_matrix[4] *= scale_x; | |
208 video_matrix[12] *= scale_x; | 228 video_matrix[12] *= scale_x; |
229 video_matrix[1] *= scale_y; | |
209 video_matrix[5] *= scale_y; | 230 video_matrix[5] *= scale_y; |
210 video_matrix[13] *= scale_y; | 231 video_matrix[13] *= scale_y; |
211 ass_border_x = (vo_dwidth - new_w) / 2; | 232 if (vo_rotate & 1) { |
212 ass_border_y = (vo_dheight - new_h) / 2; | 233 int tmp = new_w; new_w = new_h; new_h = tmp; |
234 } | |
235 ass_border_x = (draw_width - new_w) / 2; | |
236 ass_border_y = (draw_height - new_h) / 2; | |
213 } | 237 } |
214 mpglLoadMatrixf(video_matrix); | 238 mpglLoadMatrixf(video_matrix); |
215 | 239 |
216 if (!scaled_osd) { | 240 if (!scaled_osd) { |
217 #ifdef CONFIG_FREETYPE | 241 #ifdef CONFIG_FREETYPE |
829 int draw_osd = (type & RENDER_OSD) && osdtexCnt > 0; | 853 int draw_osd = (type & RENDER_OSD) && osdtexCnt > 0; |
830 int draw_eosd = (type & RENDER_EOSD) && eosdDispList; | 854 int draw_eosd = (type & RENDER_EOSD) && eosdDispList; |
831 if (!draw_osd && !draw_eosd) | 855 if (!draw_osd && !draw_eosd) |
832 return; | 856 return; |
833 // set special rendering parameters | 857 // set special rendering parameters |
834 if (!scaled_osd) { | 858 mpglLoadMatrixf(osd_matrix); |
835 // simple orthogonal projection for 0-vo_dwidth;0-vo_dheight | |
836 float matrix[16] = { | |
837 2.0/vo_dwidth, 0, 0, 0, | |
838 0, -2.0/vo_dheight, 0, 0, | |
839 0, 0, 0, 0, | |
840 -1, 1, 0, 1 | |
841 }; | |
842 mpglLoadMatrixf(matrix); | |
843 } | |
844 mpglEnable(GL_BLEND); | 859 mpglEnable(GL_BLEND); |
845 if (draw_eosd) { | 860 if (draw_eosd) { |
846 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 861 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
847 mpglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 862 mpglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
848 mpglCallList(eosdDispList); | 863 mpglCallList(eosdDispList); |
872 if (osd_color != 0xffffff) | 887 if (osd_color != 0xffffff) |
873 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 888 mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
874 } | 889 } |
875 // set rendering parameters back to defaults | 890 // set rendering parameters back to defaults |
876 mpglDisable(GL_BLEND); | 891 mpglDisable(GL_BLEND); |
877 if (!scaled_osd) | 892 mpglLoadMatrixf(video_matrix); |
878 mpglLoadMatrixf(video_matrix); | |
879 mpglBindTexture(gl_target, 0); | 893 mpglBindTexture(gl_target, 0); |
880 } | 894 } |
881 | 895 |
882 static void draw_osd(void) | 896 static void draw_osd(void) |
883 { | 897 { |
884 if (!use_osd) return; | 898 if (!use_osd) return; |
885 if (vo_osd_changed(0)) { | 899 if (vo_osd_changed(0)) { |
886 int osd_h, osd_w; | 900 int osd_h, osd_w; |
887 clearOSD(); | 901 clearOSD(); |
888 osd_w = scaled_osd ? image_width : vo_dwidth; | 902 osd_w = scaled_osd ? image_width : draw_width; |
889 osd_h = scaled_osd ? image_height : vo_dheight; | 903 osd_h = scaled_osd ? image_height : draw_height; |
890 vo_draw_text_ext(osd_w, osd_h, ass_border_x, ass_border_y, ass_border_x, ass_border_y, | 904 vo_draw_text_ext(osd_w, osd_h, ass_border_x, ass_border_y, ass_border_x, ass_border_y, |
891 image_width, image_height, create_osd_texture); | 905 image_width, image_height, create_osd_texture); |
892 } | 906 } |
893 if (vo_doublebuffering) do_render_osd(RENDER_OSD); | 907 if (vo_doublebuffering) do_render_osd(RENDER_OSD); |
894 } | 908 } |
1461 if (vo_doublebuffering) do_render_osd(RENDER_EOSD); | 1475 if (vo_doublebuffering) do_render_osd(RENDER_EOSD); |
1462 return VO_TRUE; | 1476 return VO_TRUE; |
1463 case VOCTRL_GET_EOSD_RES: | 1477 case VOCTRL_GET_EOSD_RES: |
1464 { | 1478 { |
1465 struct mp_eosd_settings *r = data; | 1479 struct mp_eosd_settings *r = data; |
1466 r->w = vo_dwidth; r->h = vo_dheight; | 1480 r->w = draw_width; r->h = draw_height; |
1467 r->srcw = image_width; r->srch = image_height; | 1481 r->srcw = image_width; r->srch = image_height; |
1468 r->mt = r->mb = r->ml = r->mr = 0; | 1482 r->mt = r->mb = r->ml = r->mr = 0; |
1469 if (scaled_osd) {r->w = image_width; r->h = image_height;} | 1483 if (scaled_osd) {r->w = image_width; r->h = image_height;} |
1470 else if (aspect_scaling()) { | 1484 else if (aspect_scaling()) { |
1471 r->ml = r->mr = ass_border_x; | 1485 r->ml = r->mr = ass_border_x; |