diff options
author | 2011-03-30 21:26:44 +0000 | |
---|---|---|
committer | 2011-03-30 21:26:44 +0000 | |
commit | 8fe72477f204b1a45393e6a64caa84fd287b805b (patch) | |
tree | ee45cdc16a5e66a5a198920897d82db4284b97da /gpu/src/GrGLIndexBuffer.cpp | |
parent | a7d948523dce6044fc02db90726e5f971a93628b (diff) |
Add GrResource base class for ibs, texs, vbs, etc.
Add lostContext() to GrContext.
Review URL: http://codereview.appspot.com/4328044/
git-svn-id: http://skia.googlecode.com/svn/trunk@1026 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrGLIndexBuffer.cpp')
-rw-r--r-- | gpu/src/GrGLIndexBuffer.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/gpu/src/GrGLIndexBuffer.cpp b/gpu/src/GrGLIndexBuffer.cpp index 9d73419376..4fb1e99ce4 100644 --- a/gpu/src/GrGLIndexBuffer.cpp +++ b/gpu/src/GrGLIndexBuffer.cpp @@ -18,42 +18,46 @@ #include "GrGLIndexBuffer.h" #include "GrGpuGL.h" -GrGLIndexBuffer::GrGLIndexBuffer(GrGLuint id, GrGpuGL* gl, size_t sizeInBytes, - bool dynamic) : - INHERITED(sizeInBytes, dynamic), - fGL(gl), - fBufferID(id), - fLockPtr(NULL) { +#define GPUGL static_cast<GrGpuGL*>(getGpu()) + +GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu, + GrGLuint id, + size_t sizeInBytes, + bool dynamic) + : INHERITED(gpu, sizeInBytes, dynamic) + , fBufferID(id) + , fLockPtr(NULL) { + } -GrGLIndexBuffer::~GrGLIndexBuffer() { +void GrGLIndexBuffer::onRelease() { // make sure we've not been abandoned if (fBufferID) { - fGL->notifyIndexBufferDelete(this); + GPUGL->notifyIndexBufferDelete(this); GR_GL(DeleteBuffers(1, &fBufferID)); + fBufferID = 0; } } +void GrGLIndexBuffer::onAbandon() { + fBufferID = 0; + fLockPtr = NULL; +} + void GrGLIndexBuffer::bind() const { GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, fBufferID)); - fGL->notifyIndexBufferBind(this); + GPUGL->notifyIndexBufferBind(this); } GrGLuint GrGLIndexBuffer::bufferID() const { return fBufferID; } -void GrGLIndexBuffer::abandon() { - fBufferID = 0; - fGL = NULL; - fLockPtr = NULL; -} - void* GrGLIndexBuffer::lock() { GrAssert(fBufferID); GrAssert(!isLocked()); - if (fGL->supportsBufferLocking()) { - bind(); + if (GPUGL->supportsBufferLocking()) { + this->bind(); // Let driver know it can discard the old data GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size(), NULL, dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); @@ -71,18 +75,17 @@ void* GrGLIndexBuffer::lockPtr() const { void GrGLIndexBuffer::unlock() { GrAssert(fBufferID); GrAssert(isLocked()); - GrAssert(fGL->supportsBufferLocking()); + GrAssert(GPUGL->supportsBufferLocking()); - bind(); + this->bind(); GR_GL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER)); fLockPtr = NULL; } bool GrGLIndexBuffer::isLocked() const { - GrAssert(fBufferID); #if GR_DEBUG - if (fGL->supportsBufferLocking()) { - bind(); + if (this->isValid() && GPUGL->supportsBufferLocking()) { + this->bind(); GrGLint mapped; GR_GL(GetBufferParameteriv(GR_GL_ELEMENT_ARRAY_BUFFER, GR_GL_BUFFER_MAPPED, &mapped)); @@ -98,7 +101,7 @@ bool GrGLIndexBuffer::updateData(const void* src, size_t srcSizeInBytes) { if (srcSizeInBytes > size()) { return false; } - bind(); + this->bind(); GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW; if (size() == srcSizeInBytes) { GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, srcSizeInBytes, src, usage)); @@ -117,7 +120,7 @@ bool GrGLIndexBuffer::updateSubData(const void* src, if (srcSizeInBytes + offset > size()) { return false; } - bind(); + this->bind(); GR_GL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER, offset, srcSizeInBytes, src)); return true; } |