blob: f55f518cdb518759980c73d49ebc7d27f21721dc [file] [log] [blame]
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef GrGLStencilBuffer_DEFINED
11#define GrGLStencilBuffer_DEFINED
12
13#include "GrGLInterface.h"
14#include "GrStencilBuffer.h"
15
16class GrGLStencilBuffer : public GrStencilBuffer {
17public:
18 static const GrGLenum kUnknownInternalFormat = ~0;
19 struct Format {
20 GrGLenum fInternalFormat;
21 GrGLuint fStencilBits;
22 GrGLuint fTotalBits;
23 bool fPacked;
24 };
25
26 GrGLStencilBuffer(GrGpu* gpu, GrGLint rbid,
27 int width, int height,
bsalomon@google.com558a75b2011-08-08 17:01:14 +000028 int sampleCnt,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000029 const Format& format)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000030 : GrStencilBuffer(gpu, width, height, format.fStencilBits, sampleCnt)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000031 , fFormat(format)
32 , fRenderbufferID(rbid) {
33 }
34
35 virtual ~GrGLStencilBuffer() {
36 this->release();
37 }
38
39 virtual size_t sizeInBytes() const {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000040 return (size_t) this->width() *
41 this->height() *
42 fFormat.fTotalBits *
43 GrMax(1,this->numSamples());
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000044 }
45
46 GrGLuint renderbufferID() const {
47 return fRenderbufferID;
48 }
49
50 const Format& format() const {
51 return fFormat;
52 }
53
54protected:
55 virtual void onRelease() {
56 if (0 != fRenderbufferID) {
57 GR_GL(DeleteRenderbuffers(1, &fRenderbufferID));
58 fRenderbufferID = 0;
59 }
60 }
61
62 virtual void onAbandon() {
63 fRenderbufferID = 0;
64 }
65
66private:
67 Format fFormat;
68 // may be zero for external SBs associated with external RTs
69 // (we don't require the client to give us the id, just tell
70 // us how many bits of stencil there are).
71 GrGLuint fRenderbufferID;
72
73 typedef GrStencilBuffer INHERITED;
74};
75
76#endif