| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame^] | 1 | |
| 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 | |
| 16 | class GrGLStencilBuffer : public GrStencilBuffer { |
| 17 | public: |
| 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, |
| 28 | const Format& format) |
| 29 | : GrStencilBuffer(gpu, width, height, format.fStencilBits) |
| 30 | , fFormat(format) |
| 31 | , fRenderbufferID(rbid) { |
| 32 | } |
| 33 | |
| 34 | virtual ~GrGLStencilBuffer() { |
| 35 | this->release(); |
| 36 | } |
| 37 | |
| 38 | virtual size_t sizeInBytes() const { |
| 39 | return this->width() * this->height() * fFormat.fTotalBits; |
| 40 | } |
| 41 | |
| 42 | GrGLuint renderbufferID() const { |
| 43 | return fRenderbufferID; |
| 44 | } |
| 45 | |
| 46 | const Format& format() const { |
| 47 | return fFormat; |
| 48 | } |
| 49 | |
| 50 | protected: |
| 51 | virtual void onRelease() { |
| 52 | if (0 != fRenderbufferID) { |
| 53 | GR_GL(DeleteRenderbuffers(1, &fRenderbufferID)); |
| 54 | fRenderbufferID = 0; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | virtual void onAbandon() { |
| 59 | fRenderbufferID = 0; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | Format fFormat; |
| 64 | // may be zero for external SBs associated with external RTs |
| 65 | // (we don't require the client to give us the id, just tell |
| 66 | // us how many bits of stencil there are). |
| 67 | GrGLuint fRenderbufferID; |
| 68 | |
| 69 | typedef GrStencilBuffer INHERITED; |
| 70 | }; |
| 71 | |
| 72 | #endif |