comparison libvo/vo_gl.c @ 19938:f862045246a9

Aggregate multiple small EOSD textures into one large since hundreds of texture creates are very slow. Might cause artefacts with scaled OSD since large textures are not cleared each time.
author reimar
date Fri, 22 Sep 2006 20:23:17 +0000
parents 34796c9b8667
children 1eb8f5470cba
comparison
equal deleted inserted replaced
19937:34796c9b8667 19938:f862045246a9
51 #ifndef FAST_OSD 51 #ifndef FAST_OSD
52 //! Alpha textures for OSD 52 //! Alpha textures for OSD
53 static GLuint osdatex[MAX_OSD_PARTS]; 53 static GLuint osdatex[MAX_OSD_PARTS];
54 #endif 54 #endif
55 static GLuint *eosdtex; 55 static GLuint *eosdtex;
56 static GLuint largeeosdtex[2];
56 //! Display lists that draw the OSD parts 57 //! Display lists that draw the OSD parts
57 static GLuint osdDispList[MAX_OSD_PARTS]; 58 static GLuint osdDispList[MAX_OSD_PARTS];
58 #ifndef FAST_OSD 59 #ifndef FAST_OSD
59 static GLuint osdaDispList[MAX_OSD_PARTS]; 60 static GLuint osdaDispList[MAX_OSD_PARTS];
60 #endif 61 #endif
245 * \param img image list to create OSD from. 246 * \param img image list to create OSD from.
246 * A value of NULL has the same effect as clearEOSD() 247 * A value of NULL has the same effect as clearEOSD()
247 */ 248 */
248 static void genEOSD(ass_image_t *img) { 249 static void genEOSD(ass_image_t *img) {
249 int sx, sy; 250 int sx, sy;
251 int tinytexcur = 0;
252 int smalltexcur = 0;
250 GLuint *curtex; 253 GLuint *curtex;
251 GLint scale_type = (scaled_osd) ? GL_LINEAR : GL_NEAREST; 254 GLint scale_type = (scaled_osd) ? GL_LINEAR : GL_NEAREST;
252 ass_image_t *i; 255 ass_image_t *i;
256 int cnt;
253 clearEOSD(); 257 clearEOSD();
254 if (!img) 258 if (!img)
255 return; 259 return;
260 if (!largeeosdtex[0]) {
261 glGenTextures(2, largeeosdtex);
262 BindTexture(gl_target, largeeosdtex[0]);
263 glCreateClearTex(gl_target, GL_ALPHA, scale_type, 512, 512, 0);
264 BindTexture(gl_target, largeeosdtex[1]);
265 glCreateClearTex(gl_target, GL_ALPHA, scale_type, 512, 512, 0);
266 }
256 for (i = img; i; i = i->next) 267 for (i = img; i; i = i->next)
268 {
269 if (i->w <= 0 || i->h <= 0 || i->stride < i->w)
270 continue;
271 if (i->w < 16 && i->h < 16 && tinytexcur < 1024)
272 tinytexcur++;
273 else if (i->w < 32 && i->h < 32 && smalltexcur < 256)
274 smalltexcur++;
275 else
257 eosdtexCnt++; 276 eosdtexCnt++;
277 }
278 if (eosdtexCnt) {
258 eosdtex = calloc(eosdtexCnt, sizeof(GLuint)); 279 eosdtex = calloc(eosdtexCnt, sizeof(GLuint));
259 glGenTextures(eosdtexCnt, eosdtex); 280 glGenTextures(eosdtexCnt, eosdtex);
281 }
282 tinytexcur = smalltexcur = 0;
260 for (i = img, curtex = eosdtex; i; i = i->next) { 283 for (i = img, curtex = eosdtex; i; i = i->next) {
284 int x = 0, y = 0;
261 if (i->w <= 0 || i->h <= 0 || i->stride < i->w) { 285 if (i->w <= 0 || i->h <= 0 || i->stride < i->w) {
262 mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n"); 286 mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n");
263 continue; 287 continue;
264 } 288 }
289 if (i->w < 16 && i->h < 16 && tinytexcur < 1024) {
290 x = (tinytexcur & 31) << 4;
291 y = (tinytexcur >> 5) << 4;
292 BindTexture(gl_target, largeeosdtex[0]);
293 tinytexcur++;
294 } else if (i->w < 32 && i->h < 32 && smalltexcur < 256) {
295 x = (smalltexcur & 15) << 5;
296 y = (smalltexcur >> 4) << 5;
297 BindTexture(gl_target, largeeosdtex[1]);
298 smalltexcur++;
299 } else {
265 texSize(i->w, i->h, &sx, &sy); 300 texSize(i->w, i->h, &sx, &sy);
266 BindTexture(gl_target, *curtex++); 301 BindTexture(gl_target, *curtex++);
267 glCreateClearTex(gl_target, GL_ALPHA, scale_type, sx, sy, 0); 302 glCreateClearTex(gl_target, GL_ALPHA, scale_type, sx, sy, 0);
303 }
268 glUploadTex(gl_target, GL_ALPHA, GL_UNSIGNED_BYTE, i->bitmap, i->stride, 304 glUploadTex(gl_target, GL_ALPHA, GL_UNSIGNED_BYTE, i->bitmap, i->stride,
269 0, 0, i->w, i->h, 0); 305 x, y, i->w, i->h, 0);
270 } 306 }
271 eosdDispList = glGenLists(1); 307 eosdDispList = glGenLists(1);
272 glNewList(eosdDispList, GL_COMPILE); 308 glNewList(eosdDispList, GL_COMPILE);
309 tinytexcur = smalltexcur = 0;
273 for (i = img, curtex = eosdtex; i; i = i->next) { 310 for (i = img, curtex = eosdtex; i; i = i->next) {
311 int x = 0, y = 0;
274 if (i->w <= 0 || i->h <= 0 || i->stride < i->w) 312 if (i->w <= 0 || i->h <= 0 || i->stride < i->w)
275 continue; 313 continue;
276 glColor4ub(i->color >> 24, (i->color >> 16) & 0xff, (i->color >> 8) & 0xff, 255 - (i->color & 0xff)); 314 glColor4ub(i->color >> 24, (i->color >> 16) & 0xff, (i->color >> 8) & 0xff, 255 - (i->color & 0xff));
315 if (i->w < 16 && i->h < 16 && tinytexcur < 1024) {
316 x = (tinytexcur & 31) << 4;
317 y = (tinytexcur >> 5) << 4;
318 sx = sy = 512;
319 BindTexture(gl_target, largeeosdtex[0]);
320 tinytexcur++;
321 } else if (i->w < 32 && i->h < 32 && smalltexcur < 256) {
322 x = (smalltexcur & 15) << 5;
323 y = (smalltexcur >> 4) << 5;
324 sx = sy = 512;
325 BindTexture(gl_target, largeeosdtex[1]);
326 smalltexcur++;
327 } else {
277 texSize(i->w, i->h, &sx, &sy); 328 texSize(i->w, i->h, &sx, &sy);
278 BindTexture(gl_target, *curtex++); 329 BindTexture(gl_target, *curtex++);
279 glDrawTex(i->dst_x, i->dst_y, i->w, i->h, 0, 0, i->w, i->h, sx, sy, use_rectangle == 1, 0, 0); 330 }
331 glDrawTex(i->dst_x, i->dst_y, i->w, i->h, x, y, i->w, i->h, sx, sy, use_rectangle == 1, 0, 0);
280 } 332 }
281 glEndList(); 333 glEndList();
282 BindTexture(gl_target, 0); 334 BindTexture(gl_target, 0);
283 } 335 }
284 336
295 if (i) 347 if (i)
296 glDeleteTextures(i, default_texs); 348 glDeleteTextures(i, default_texs);
297 default_texs[0] = 0; 349 default_texs[0] = 0;
298 clearOSD(); 350 clearOSD();
299 clearEOSD(); 351 clearEOSD();
352 if (largeeosdtex[0])
353 glDeleteTextures(2, largeeosdtex);
354 largeeosdtex[0] = 0;
300 if (DeleteBuffers && gl_buffer) 355 if (DeleteBuffers && gl_buffer)
301 DeleteBuffers(1, &gl_buffer); 356 DeleteBuffers(1, &gl_buffer);
302 gl_buffer = 0; gl_buffersize = 0; 357 gl_buffer = 0; gl_buffersize = 0;
303 err_shown = 0; 358 err_shown = 0;
304 } 359 }