/** * \brief uninitialize OpenGL context, freeing textures, buffers etc. */ static void uninitGl(void) { int i = 0; if (mpglDeletePrograms && fragprog) mpglDeletePrograms(1, &fragprog); fragprog = 0; while (default_texs[i] != 0) i++; if (i) mpglDeleteTextures(i, default_texs); default_texs[0] = 0; clearOSD(); clearEOSD(); if (largeeosdtex[0]) mpglDeleteTextures(2, largeeosdtex); largeeosdtex[0] = 0; if (mpglDeleteBuffers && gl_buffer) mpglDeleteBuffers(1, &gl_buffer); gl_buffer = 0; gl_buffersize = 0; gl_bufferptr = NULL; if (mpglDeleteBuffers && gl_buffer_uv[0]) mpglDeleteBuffers(2, gl_buffer_uv); gl_buffer_uv[0] = gl_buffer_uv[1] = 0; gl_buffersize_uv = 0; gl_bufferptr_uv[0] = gl_bufferptr_uv[1] = 0; #ifdef CONFIG_GL_X11 if (mesa_bufferptr) mpglFreeMemoryMESA(mDisplay, mScreen, mesa_bufferptr); #endif mesa_bufferptr = NULL; err_shown = 0; }
/** * \brief uninitialize OpenGL context, freeing textures, buffers etc. */ static void uninitGl(void) { int i = 0; mp_msg(MSGT_VO, MSGL_V, "Drawn %i frames, %i using DR, DR refused %i\n", imgcnt, dr_imgcnt, dr_rejectcnt); if (mpglDeletePrograms && fragprog) mpglDeletePrograms(1, &fragprog); fragprog = 0; while (default_texs[i] != 0) i++; if (i) mpglDeleteTextures(i, default_texs); default_texs[0] = 0; clearOSD(); clearEOSD(); if (largeeosdtex[0]) mpglDeleteTextures(2, largeeosdtex); largeeosdtex[0] = 0; if (mpglDeleteBuffers && gl_buffer) mpglDeleteBuffers(1, &gl_buffer); gl_buffer = 0; gl_buffersize = 0; gl_bufferptr = NULL; if (mpglDeleteBuffers && gl_buffer_uv[0]) mpglDeleteBuffers(2, gl_buffer_uv); gl_buffer_uv[0] = gl_buffer_uv[1] = 0; gl_buffersize_uv = 0; gl_bufferptr_uv[0] = gl_bufferptr_uv[1] = 0; #ifdef CONFIG_GL_X11 if (mesa_bufferptr) mpglFreeMemoryMESA(mDisplay, mScreen, mesa_bufferptr); #endif mesa_bufferptr = NULL; err_shown = 0; }
/** * \brief construct display list from ass image list * \param img image list to create OSD from. * A value of NULL has the same effect as clearEOSD() */ static void genEOSD(struct mp_eosd_image_list *imgs) { int sx, sy; int tinytexcur = 0; int smalltexcur = 0; GLuint *curtex; GLint scale_type = scaled_osd ? GL_LINEAR : GL_NEAREST; struct mp_eosd_image *img = eosd_image_first(imgs); struct mp_eosd_image *i; if (imgs->changed == 0) // there are elements, but they are unchanged return; if (img && imgs->changed == 1) // there are elements, but they just moved goto skip_upload; clearEOSD(); if (!img) return; if (!largeeosdtex[0]) { mpglGenTextures(2, largeeosdtex); mpglBindTexture(gl_target, largeeosdtex[0]); glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, LARGE_EOSD_TEX_SIZE, LARGE_EOSD_TEX_SIZE, 0); mpglBindTexture(gl_target, largeeosdtex[1]); glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, LARGE_EOSD_TEX_SIZE, LARGE_EOSD_TEX_SIZE, 0); } for (i = img; i; i = eosd_image_next(imgs)) { if (i->w <= 0 || i->h <= 0 || i->stride < i->w) continue; if (is_tinytex(i, tinytexcur)) tinytexcur++; else if (is_smalltex(i, smalltexcur)) smalltexcur++; else eosdtexCnt++; } mp_msg(MSGT_VO, MSGL_DBG2, "EOSD counts (tiny, small, all): %i, %i, %i\n", tinytexcur, smalltexcur, eosdtexCnt); if (eosdtexCnt) { eosdtex = calloc(eosdtexCnt, sizeof(GLuint)); mpglGenTextures(eosdtexCnt, eosdtex); } tinytexcur = smalltexcur = 0; for (i = eosd_image_first(imgs), curtex = eosdtex; i; i = eosd_image_next(imgs)) { int x = 0, y = 0; if (i->w <= 0 || i->h <= 0 || i->stride < i->w) { mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n"); continue; } if (is_tinytex(i, tinytexcur)) { tinytex_pos(tinytexcur, &x, &y); mpglBindTexture(gl_target, largeeosdtex[0]); tinytexcur++; } else if (is_smalltex(i, smalltexcur)) { smalltex_pos(smalltexcur, &x, &y); mpglBindTexture(gl_target, largeeosdtex[1]); smalltexcur++; } else { texSize(i->w, i->h, &sx, &sy); mpglBindTexture(gl_target, *curtex++); glCreateClearTex(gl_target, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, scale_type, sx, sy, 0); } glUploadTex(gl_target, GL_ALPHA, GL_UNSIGNED_BYTE, i->bitmap, i->stride, x, y, i->w, i->h, 0); } eosdDispList = mpglGenLists(1); skip_upload: mpglNewList(eosdDispList, GL_COMPILE); tinytexcur = smalltexcur = 0; for (i = eosd_image_first(imgs), curtex = eosdtex; i; i = eosd_image_next(imgs)) { int x = 0, y = 0; if (i->w <= 0 || i->h <= 0 || i->stride < i->w) continue; mpglColor4ub(i->color >> 24, (i->color >> 16) & 0xff, (i->color >> 8) & 0xff, 255 - (i->color & 0xff)); if (is_tinytex(i, tinytexcur)) { tinytex_pos(tinytexcur, &x, &y); sx = sy = LARGE_EOSD_TEX_SIZE; mpglBindTexture(gl_target, largeeosdtex[0]); tinytexcur++; } else if (is_smalltex(i, smalltexcur)) { smalltex_pos(smalltexcur, &x, &y); sx = sy = LARGE_EOSD_TEX_SIZE; mpglBindTexture(gl_target, largeeosdtex[1]); smalltexcur++; } else { texSize(i->w, i->h, &sx, &sy); mpglBindTexture(gl_target, *curtex++); } glDrawTex(i->dst_x, i->dst_y, i->w, i->h, x, y, i->w, i->h, sx, sy, use_rectangle == 1, 0, 0); } mpglEndList(); mpglBindTexture(gl_target, 0); }