Extended debug GL interface to include tracking of render buffers

http://codereview.appspot.com/5875050/



git-svn-id: http://skia.googlecode.com/svn/trunk@3469 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/SkGLContext.cpp b/src/gpu/gl/SkGLContext.cpp
index 9b197ac..2d9cd6a 100644
--- a/src/gpu/gl/SkGLContext.cpp
+++ b/src/gpu/gl/SkGLContext.cpp
@@ -9,6 +9,8 @@
 
 SkGLContext::SkGLContext()
     : fFBO(0)
+    , fColorBufferID(0)
+    , fDepthStencilBufferID(0)
     , fGL(NULL) {
 }
 
@@ -16,6 +18,8 @@
 
     if (fGL) {
         SK_GL(*this, DeleteFramebuffers(1, &fFBO));
+        SK_GL(*this, DeleteRenderbuffers(1, &fColorBufferID));
+        SK_GL(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID));
     }
 
     SkSafeUnref(fGL);
@@ -47,15 +51,12 @@
             error = SK_GL(*this, GetError());
         } while (GR_GL_NO_ERROR != error);
 
-        GrGLuint cbID;
-        GrGLuint dsID;
-
         GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
 
         SK_GL(*this, GenFramebuffers(1, &fFBO));
         SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO));
-        SK_GL(*this, GenRenderbuffers(1, &cbID));
-        SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, cbID));
+        SK_GL(*this, GenRenderbuffers(1, &fColorBufferID));
+        SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID));
         if (kES2_GrGLBinding == bindingInUse) {
             SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
                                              GR_GL_RGBA8,
@@ -68,9 +69,9 @@
         SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                              GR_GL_COLOR_ATTACHMENT0,
                                              GR_GL_RENDERBUFFER, 
-                                             cbID));
-        SK_GL(*this, GenRenderbuffers(1, &dsID));
-        SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, dsID));
+                                             fColorBufferID));
+        SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID));
+        SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID));
 
         // Some drivers that support packed depth stencil will only succeed
         // in binding a packed format an FBO. However, we can't rely on packed
@@ -97,7 +98,7 @@
             SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                                  GR_GL_DEPTH_ATTACHMENT,
                                                  GR_GL_RENDERBUFFER,
-                                                 dsID));
+                                                 fDepthStencilBufferID));
         } else {
             GrGLenum format = kES2_GrGLBinding == bindingInUse ? 
                                     GR_GL_STENCIL_INDEX8 :
@@ -109,7 +110,7 @@
         SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                              GR_GL_STENCIL_ATTACHMENT,
                                              GR_GL_RENDERBUFFER,
-                                             dsID));
+                                             fDepthStencilBufferID));
         SK_GL(*this, Viewport(0, 0, width, height));
         SK_GL(*this, ClearStencil(0));
         SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT));
@@ -121,6 +122,8 @@
         if (GR_GL_FRAMEBUFFER_COMPLETE != status ||
             GR_GL_NO_ERROR != error) {
             fFBO = 0;
+            fColorBufferID = 0;
+            fDepthStencilBufferID = 0;
             fGL->unref();
             fGL = NULL;
             this->destroyGLContext();