blob: f55f518cdb518759980c73d49ebc7d27f21721dc [file] [log] [blame]
/*
* 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,
int sampleCnt,
const Format& format)
: GrStencilBuffer(gpu, width, height, format.fStencilBits, sampleCnt)
, fFormat(format)
, fRenderbufferID(rbid) {
}
virtual ~GrGLStencilBuffer() {
this->release();
}
virtual size_t sizeInBytes() const {
return (size_t) this->width() *
this->height() *
fFormat.fTotalBits *
GrMax(1,this->numSamples());
}
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