blob: 685166c90b66326fa14cc7b63bff5f141e443007 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrGLVertexBuffer.h"
9#include "GrGpuGL.h"
10
bsalomon@google.come49ad452013-02-20 19:33:20 +000011GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu, const Desc& desc)
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000012 : INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID)
bsalomon@google.come49ad452013-02-20 19:33:20 +000013 , fImpl(gpu, desc, GR_GL_ARRAY_BUFFER) {
reed@google.comac10a2d2010-12-22 21:39:39 +000014}
15
bsalomon@google.com8fe72472011-03-30 21:26:44 +000016void GrGLVertexBuffer::onRelease() {
bsalomon@google.come49ad452013-02-20 19:33:20 +000017 if (this->isValid()) {
18 fImpl.release(this->getGpuGL());
reed@google.comac10a2d2010-12-22 21:39:39 +000019 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000020
21 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000022}
23
robertphillips@google.comd3645542012-09-05 18:37:39 +000024
bsalomon@google.come49ad452013-02-20 19:33:20 +000025void GrGLVertexBuffer::onAbandon() {
26 fImpl.abandon();
robertphillips@google.comd3645542012-09-05 18:37:39 +000027 INHERITED::onAbandon();
bsalomon@google.com8fe72472011-03-30 21:26:44 +000028}
29
reed@google.comac10a2d2010-12-22 21:39:39 +000030void* GrGLVertexBuffer::lock() {
bsalomon@google.come49ad452013-02-20 19:33:20 +000031 if (this->isValid()) {
32 return fImpl.lock(this->getGpuGL());
33 } else {
34 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000035 }
reed@google.comac10a2d2010-12-22 21:39:39 +000036}
37
bsalomon@google.com1c13c962011-02-14 16:51:21 +000038void* GrGLVertexBuffer::lockPtr() const {
bsalomon@google.come49ad452013-02-20 19:33:20 +000039 return fImpl.lockPtr();
bsalomon@google.com1c13c962011-02-14 16:51:21 +000040}
41
reed@google.comac10a2d2010-12-22 21:39:39 +000042void GrGLVertexBuffer::unlock() {
bsalomon@google.come49ad452013-02-20 19:33:20 +000043 if (this->isValid()) {
44 fImpl.unlock(this->getGpuGL());
45 }
reed@google.comac10a2d2010-12-22 21:39:39 +000046}
47
48bool GrGLVertexBuffer::isLocked() const {
bsalomon@google.come49ad452013-02-20 19:33:20 +000049 return fImpl.isLocked();
reed@google.comac10a2d2010-12-22 21:39:39 +000050}
51
bsalomon@google.com1c13c962011-02-14 16:51:21 +000052bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
bsalomon@google.come49ad452013-02-20 19:33:20 +000053 if (this->isValid()) {
54 return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
55 } else {
reed@google.comac10a2d2010-12-22 21:39:39 +000056 return false;
57 }
reed@google.comac10a2d2010-12-22 21:39:39 +000058}