diff options
author | 2010-12-22 21:39:39 +0000 | |
---|---|---|
committer | 2010-12-22 21:39:39 +0000 | |
commit | ac10a2d039c5d52eed66e27cbbc503ab523c1cd5 (patch) | |
tree | c5be0c3dd15052016e7d32f376507cb1ea7101dd /gpu/src/GrGLIndexBuffer.cpp | |
parent | ea8509cd3b1771b36054313d3ccd56679df56044 (diff) |
add gpu backend (not hooked up yet)
git-svn-id: http://skia.googlecode.com/svn/trunk@649 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrGLIndexBuffer.cpp')
-rw-r--r-- | gpu/src/GrGLIndexBuffer.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/gpu/src/GrGLIndexBuffer.cpp b/gpu/src/GrGLIndexBuffer.cpp new file mode 100644 index 0000000000..82cffaaec4 --- /dev/null +++ b/gpu/src/GrGLIndexBuffer.cpp @@ -0,0 +1,106 @@ +/* + Copyright 2010 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + +#include "GrGLIndexBuffer.h" +#include "GrGpuGL.h" + +GrGLIndexBuffer::GrGLIndexBuffer(GLuint id, GrGpuGL* gl, uint32_t sizeInBytes, + bool dynamic) : + INHERITED(sizeInBytes, dynamic), + fGL(gl), + fBufferID(id), + fLockPtr(NULL) { +} + +GLuint GrGLIndexBuffer::bufferID() const { + return fBufferID; +} + +GrGLIndexBuffer::~GrGLIndexBuffer() { + // make sure we've not been abandoned + if (fBufferID) { + fGL->notifyIndexBufferDelete(this); + GR_GL(DeleteBuffers(1, &fBufferID)); + } +} + +void GrGLIndexBuffer::abandon() { + fBufferID = 0; + fGL = NULL; + fLockPtr = NULL; +} + +void* GrGLIndexBuffer::lock() { + GrAssert(fBufferID); + GrAssert(!isLocked()); + if (fGL->supportsBufferLocking()) { + GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, fBufferID)); + fGL->notifyIndexBufferBind(this); + // call bufferData with null ptr to allow driver to perform renaming + // If this call is removed revisit updateData to be sure it doesn't + // leave buffer undersized (as it currently does). + GR_GL(BufferData(GL_ELEMENT_ARRAY_BUFFER, size(), NULL, + dynamic() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW)); + fLockPtr = GR_GLEXT(fGL->extensions(), + MapBuffer(GL_ELEMENT_ARRAY_BUFFER, GR_WRITE_ONLY)); + + return fLockPtr; + } + return NULL; +} + +void GrGLIndexBuffer::unlock() { + GrAssert(fBufferID); + GrAssert(isLocked()); + + if (fGL->supportsBufferLocking()) { + GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, fBufferID)); + fGL->notifyIndexBufferBind(this); + GR_GLEXT(fGL->extensions(), + UnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)); + fLockPtr = NULL; + } +} + +bool GrGLIndexBuffer::isLocked() const { + GrAssert(fBufferID); +#if GR_DEBUG + if (fGL->supportsBufferLocking()) { + GLint mapped; + GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, fBufferID)); + fGL->notifyIndexBufferBind(this); + GR_GL(GetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, + GR_BUFFER_MAPPED, &mapped)); + GrAssert(!!mapped == !!fLockPtr); + } +#endif + return NULL != fLockPtr; +} + +bool GrGLIndexBuffer::updateData(const void* src, uint32_t srcSizeInBytes) { + GrAssert(fBufferID); + GrAssert(!isLocked()); + if (srcSizeInBytes > size()) { + return false; + } + GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, fBufferID)); + fGL->notifyIndexBufferBind(this); + GR_GL(BufferData(GL_ELEMENT_ARRAY_BUFFER, srcSizeInBytes, src, + dynamic() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW)); + return true; +} + |