demos: fix renderbuffer leak in progs/tests/fbotexture.c
authorBrian Paul <brianp@vmware.com>
Fri, 27 Feb 2009 22:46:40 +0000 (15:46 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 27 Feb 2009 22:57:46 +0000 (15:57 -0700)
And re-org some code for testing purposes.

progs/tests/fbotexture.c

index 1f7c45fc794d04d815f2a23cb92746a6f78e6967..ae993576b025cbc7befc1accdebff7be525ccc62 100644 (file)
 static int Win = 0;
 static int Width = 400, Height = 400;
 
-static GLenum TexTarget = GL_TEXTURE_2D; /*GL_TEXTURE_RECTANGLE_ARB;*/
+#if 1
+static GLenum TexTarget = GL_TEXTURE_2D;
 static int TexWidth = 512, TexHeight = 512;
-/*static int TexWidth = 600, TexHeight = 600;*/
+static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */
+#else
+static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB;
+static int TexWidth = 200, TexHeight = 200;
+static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */
+#endif
+static GLuint TextureLevel = 0;  /* which texture level to render to */
 
 static GLuint MyFB;
 static GLuint TexObj;
@@ -38,8 +45,6 @@ static GLfloat Rot = 0.0;
 static GLboolean UsePackedDepthStencil = GL_FALSE;
 static GLboolean UsePackedDepthStencilBoth = GL_FALSE;
 static GLboolean Use_ARB_fbo = GL_FALSE;
-static GLuint TextureLevel = 0;  /* which texture level to render to */
-static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */
 static GLboolean Cull = GL_FALSE;
 static GLboolean Wireframe = GL_FALSE;
 
@@ -404,8 +409,12 @@ AttachDepthAndStencilBuffers(GLuint fbo,
          return GL_FALSE;
 
       status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-      if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
+      if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+         glDeleteRenderbuffersEXT(1, depthRbOut);
+         *depthRbOut = 0;
+         glDeleteRenderbuffersEXT(1, &rb);
          return GL_FALSE;
+      }
 
       *stencilRbOut = rb;
    }
@@ -554,15 +563,17 @@ Init(void)
       /* make two image levels */
       glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0,
                    GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-      glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0,
-                   GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-      TexWidth = TexWidth >> TextureLevel;
-      TexHeight = TexHeight >> TextureLevel;
+      if (TexTarget == GL_TEXTURE_2D) {
+         glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0,
+                      GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+         TexWidth = TexWidth >> TextureLevel;
+         TexHeight = TexHeight >> TextureLevel;
+         glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel);
+      }
 
       glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
       glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
       glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel);
-      glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel);
       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    }