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