Add GrStencilBuffer as a separate resource type from render target

This is a resubmission of the changes in r2026 with fixes for FBO completeness issues.

Review URL: http://codereview.appspot.com/4837046/


git-svn-id: http://skia.googlecode.com/svn/trunk@2035 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGLStencilBuffer.h b/gpu/src/GrGLStencilBuffer.h
new file mode 100644
index 0000000..97394e3
--- /dev/null
+++ b/gpu/src/GrGLStencilBuffer.h
@@ -0,0 +1,72 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef GrGLStencilBuffer_DEFINED
+#define GrGLStencilBuffer_DEFINED
+
+#include "GrGLInterface.h"
+#include "GrStencilBuffer.h"
+
+class GrGLStencilBuffer : public GrStencilBuffer {
+public:
+    static const GrGLenum kUnknownInternalFormat = ~0;
+    struct Format {
+        GrGLenum  fInternalFormat;
+        GrGLuint  fStencilBits;
+        GrGLuint  fTotalBits;
+        bool      fPacked;
+    };
+
+    GrGLStencilBuffer(GrGpu* gpu, GrGLint rbid, 
+                      int width, int height,
+                      const Format& format) 
+        : GrStencilBuffer(gpu, width, height, format.fStencilBits)
+        , fFormat(format)
+        , fRenderbufferID(rbid) {
+    }
+
+    virtual ~GrGLStencilBuffer() {
+        this->release();
+    }
+
+    virtual size_t sizeInBytes() const {
+        return this->width() * this->height() * fFormat.fTotalBits;
+    }
+
+    GrGLuint renderbufferID() const {
+        return fRenderbufferID;
+    }
+
+    const Format& format() const {
+        return fFormat;
+    }
+
+protected:
+    virtual void onRelease() {
+        if (0 != fRenderbufferID) {
+            GR_GL(DeleteRenderbuffers(1, &fRenderbufferID));
+            fRenderbufferID = 0;
+        }
+    }
+
+    virtual void onAbandon() {
+        fRenderbufferID = 0;
+    }
+
+private:
+    Format fFormat;
+    // may be zero for external SBs associated with external RTs
+    // (we don't require the client to give us the id, just tell
+    // us how many bits of stencil there are).
+    GrGLuint fRenderbufferID;
+
+    typedef GrStencilBuffer INHERITED;
+};
+
+#endif