changeset 16433:1deef0daf3aa

Add an uninit function.
author reimar
date Fri, 09 Sep 2005 14:47:54 +0000
parents 629dab509dcd
children db8d8039a5f4
files libvo/vo_gl.c
diffstat 1 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_gl.c	Fri Sep 09 13:29:04 2005 +0000
+++ b/libvo/vo_gl.c	Fri Sep 09 14:47:54 2005 +0000
@@ -53,7 +53,7 @@
 //! Display lists that draw the OSD parts
 static GLuint osdDispList[MAX_OSD_PARTS];
 //! How many parts the OSD currently consists of
-static int osdtexCnt = 0;
+static int osdtexCnt;
 
 static int use_aspect;
 static int use_rectangle;
@@ -126,10 +126,34 @@
   }
 }
 
+static void clearOSD() {
+  int i;
+  glDeleteTextures(osdtexCnt, osdtex);
+#ifndef FAST_OSD
+  glDeleteTextures(osdtexCnt, osdatex);
+#endif
+  for (i = 0; i < osdtexCnt; i++)
+    glDeleteLists(osdDispList[i], 1);
+  osdtexCnt = 0;
+}
+
+/**
+ * \brief uninitialize OpenGL context, freeing textures, buffers etc.
+ */
+static void uninitGl() {
+  clearOSD();
+  if (DeleteBuffers && gl_buffer)
+    DeleteBuffers(1, &gl_buffer);
+  gl_buffer = 0; gl_buffersize = 0;
+  err_shown = 0;
+}
+
 /**
  * \brief Initialize a (new or reused) OpenGL context.
+ * set global gl-related variables to their default values
  */
 static int initGl(uint32_t d_width, uint32_t d_height) {
+  osdtexCnt = 0; gl_buffer = 0; gl_buffersize = 0; err_shown = 0;
   texSize(image_width, image_height, &texture_width, &texture_height);
 
   glDisable(GL_BLEND); 
@@ -150,10 +174,6 @@
   glClear( GL_COLOR_BUFFER_BIT );
   if (SwapInterval && swap_interval >= 0)
     SwapInterval(swap_interval);
-  osdtexCnt = 0;
-  gl_buffer = 0;
-  gl_buffersize = 0;
-  err_shown = 0;
   return 1;
 }
 
@@ -280,6 +300,8 @@
 #endif
 
 glconfig:
+  if (vo_config_count)
+    uninitGl();
   setGlWindow(&gl_vinfo, &gl_context, vo_window);
   initGl(vo_dwidth, vo_dheight);
 
@@ -364,17 +386,8 @@
 {
   if (!use_osd) return;
   if (vo_osd_changed(0)) {
-    int i;
     int osd_h, osd_w;
-    glDeleteTextures(osdtexCnt, osdtex);
-#ifndef FAST_OSD
-    glDeleteTextures(osdtexCnt, osdatex);
-#endif
-    for (i = 0; i < osdtexCnt; i++) {
-      glDeleteLists(osdDispList[i], 1);
-    }
-    osdtexCnt = 0;
-
+    clearOSD();
     osd_w = (scaled_osd) ? image_width : vo_dwidth;
     osd_h = (scaled_osd) ? image_height : vo_dheight;
     vo_draw_text(osd_w, osd_h, create_osd_texture);
@@ -507,6 +520,7 @@
 uninit(void)
 {
   if ( !vo_config_count ) return;
+  uninitGl();
   releaseGlContext(&gl_vinfo, &gl_context);
 #ifdef GL_WIN32
   vo_w32_uninit();