diff options
author | 2012-04-05 14:40:53 +0000 | |
---|---|---|
committer | 2012-04-05 14:40:53 +0000 | |
commit | dd743fefad9764ad86d7f69deec32e9a3b5de47f (patch) | |
tree | cb07a5476a353d836510893cc146bc1ce38ae9df /src/gpu/gl/debug/GrBufferObj.h | |
parent | ded33215f6c193ba126dadcec5583f18a756e399 (diff) |
Initial split up of Debug Interface into separate files
http://codereview.appspot.com/5979048/
git-svn-id: http://skia.googlecode.com/svn/trunk@3616 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl/debug/GrBufferObj.h')
-rw-r--r-- | src/gpu/gl/debug/GrBufferObj.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/gpu/gl/debug/GrBufferObj.h b/src/gpu/gl/debug/GrBufferObj.h new file mode 100644 index 0000000000..e4cfee2a0e --- /dev/null +++ b/src/gpu/gl/debug/GrBufferObj.h @@ -0,0 +1,84 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrBufferObj_DEFINED +#define GrBufferObj_DEFINED + +#include "GrFakeRefObj.h" + +//////////////////////////////////////////////////////////////////////////////// +class GrBufferObj : public GrFakeRefObj { + GR_DEFINE_CREATOR(GrBufferObj); + +public: + GrBufferObj() + : GrFakeRefObj() + , fDataPtr(NULL) + , fMapped(false) + , fBound(false) + , fSize(0) + , fUsage(GR_GL_STATIC_DRAW) { + } + virtual ~GrBufferObj() { + delete[] fDataPtr; + } + + void access() { + // cannot access the buffer if it is currently mapped + GrAlwaysAssert(!fMapped); + } + + void setMapped() { fMapped = true; } + void resetMapped() { fMapped = false; } + bool getMapped() const { return fMapped; } + + void setBound() { fBound = true; } + void resetBound() { fBound = false; } + bool getBound() const { return fBound; } + + void allocate(GrGLint size, const GrGLchar *dataPtr) { + GrAlwaysAssert(size >= 0); + + // delete pre-existing data + delete[] fDataPtr; + + fSize = size; + fDataPtr = new GrGLchar[size]; + if (dataPtr) { + memcpy(fDataPtr, dataPtr, fSize); + } + // TODO: w/ no dataPtr the data is unitialized - this could be tracked + } + GrGLint getSize() const { return fSize; } + GrGLchar *getDataPtr() { return fDataPtr; } + + GrGLint getUsage() const { return fUsage; } + void setUsage(GrGLint usage) { fUsage = usage; } + + virtual void deleteAction() SK_OVERRIDE { + + // buffers are automatically unmapped when deleted + this->resetMapped(); + + this->INHERITED::deleteAction(); + } + + +protected: +private: + + GrGLchar* fDataPtr; + bool fMapped; // is the buffer object mapped via "glMapBuffer"? + bool fBound; // is the buffer object bound via "glBindBuffer"? + GrGLint fSize; // size in bytes + GrGLint fUsage; // one of: GL_STREAM_DRAW, GL_STATIC_DRAW, GL_DYNAMIC_DRAW + + typedef GrFakeRefObj INHERITED; +}; + +#endif // GrBufferObj_DEFINED |