blob: 5691176125788edcc38efad298b44bc3cba01f73 [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"
jvanverth39edf762014-12-22 11:44:19 -08009#include "GrGLGpu.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000010
bsalomon861e1032014-12-16 07:33:49 -080011GrGLVertexBuffer::GrGLVertexBuffer(GrGLGpu* 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) {
bsalomon16961262014-08-26 14:01:07 -070014 this->registerWithCache();
reed@google.comac10a2d2010-12-22 21:39:39 +000015}
16
bsalomon@google.com8fe72472011-03-30 21:26:44 +000017void GrGLVertexBuffer::onRelease() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000018 if (!this->wasDestroyed()) {
bsalomon@google.come49ad452013-02-20 19:33:20 +000019 fImpl.release(this->getGpuGL());
reed@google.comac10a2d2010-12-22 21:39:39 +000020 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000021
22 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000023}
24
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
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000030void* GrGLVertexBuffer::onMap() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000031 if (!this->wasDestroyed()) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000032 return fImpl.map(this->getGpuGL());
bsalomon@google.come49ad452013-02-20 19:33:20 +000033 } else {
34 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000035 }
reed@google.comac10a2d2010-12-22 21:39:39 +000036}
37
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000038void GrGLVertexBuffer::onUnmap() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000039 if (!this->wasDestroyed()) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000040 fImpl.unmap(this->getGpuGL());
bsalomon@google.come49ad452013-02-20 19:33:20 +000041 }
reed@google.comac10a2d2010-12-22 21:39:39 +000042}
43
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000044bool GrGLVertexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000045 if (!this->wasDestroyed()) {
bsalomon@google.come49ad452013-02-20 19:33:20 +000046 return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
47 } else {
reed@google.comac10a2d2010-12-22 21:39:39 +000048 return false;
49 }
reed@google.comac10a2d2010-12-22 21:39:39 +000050}