michael@0: michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrBufferObj_DEFINED michael@0: #define GrBufferObj_DEFINED michael@0: michael@0: #include "GrFakeRefObj.h" michael@0: #include "../GrGLDefines.h" michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: class GrBufferObj : public GrFakeRefObj { michael@0: GR_DEFINE_CREATOR(GrBufferObj); michael@0: michael@0: public: michael@0: GrBufferObj() michael@0: : GrFakeRefObj() michael@0: , fDataPtr(NULL) michael@0: , fMapped(false) michael@0: , fBound(false) michael@0: , fSize(0) michael@0: , fUsage(GR_GL_STATIC_DRAW) { michael@0: } michael@0: virtual ~GrBufferObj() { michael@0: delete[] fDataPtr; michael@0: } michael@0: michael@0: void access() { michael@0: // cannot access the buffer if it is currently mapped michael@0: GrAlwaysAssert(!fMapped); michael@0: } michael@0: michael@0: void setMapped() { fMapped = true; } michael@0: void resetMapped() { fMapped = false; } michael@0: bool getMapped() const { return fMapped; } michael@0: michael@0: void setBound() { fBound = true; } michael@0: void resetBound() { fBound = false; } michael@0: bool getBound() const { return fBound; } michael@0: michael@0: void allocate(GrGLsizeiptr size, const GrGLchar *dataPtr); michael@0: GrGLsizeiptr getSize() const { return fSize; } michael@0: GrGLchar *getDataPtr() { return fDataPtr; } michael@0: michael@0: void setUsage(GrGLint usage) { fUsage = usage; } michael@0: GrGLint getUsage() const { return fUsage; } michael@0: michael@0: virtual void deleteAction() SK_OVERRIDE; michael@0: michael@0: protected: michael@0: private: michael@0: michael@0: GrGLchar* fDataPtr; michael@0: bool fMapped; // is the buffer object mapped via "glMapBuffer"? michael@0: bool fBound; // is the buffer object bound via "glBindBuffer"? michael@0: GrGLsizeiptr fSize; // size in bytes michael@0: GrGLint fUsage; // one of: GL_STREAM_DRAW, michael@0: // GL_STATIC_DRAW, michael@0: // GL_DYNAMIC_DRAW michael@0: michael@0: typedef GrFakeRefObj INHERITED; michael@0: }; michael@0: michael@0: #endif // GrBufferObj_DEFINED