blob: 5526ff93f18914f4cf50dc5f0ff1a8c05b670577 [file] [log] [blame]
bsalomon@google.come49ad452013-02-20 19:33:20 +00001/*
2 * Copyright 2013 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.
6 */
7
8#ifndef GrGLBufferImpl_DEFINED
9#define GrGLBufferImpl_DEFINED
10
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000011#include "SkTypes.h"
bsalomon@google.come49ad452013-02-20 19:33:20 +000012#include "gl/GrGLFunctions.h"
13
bsalomon861e1032014-12-16 07:33:49 -080014class GrGLGpu;
bsalomon@google.come49ad452013-02-20 19:33:20 +000015
16/**
17 * This class serves as the implementation of GrGL*Buffer classes. It was written to avoid code
18 * duplication in those classes.
19 */
commit-bot@chromium.orge3beb6b2014-04-07 19:34:38 +000020class GrGLBufferImpl : SkNoncopyable {
bsalomon@google.come49ad452013-02-20 19:33:20 +000021public:
22 struct Desc {
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000023 GrGLuint fID; // set to 0 to indicate buffer is CPU-backed and not a VBO.
bsalomon@google.come49ad452013-02-20 19:33:20 +000024 size_t fSizeInBytes;
25 bool fDynamic;
26 };
27
bsalomon861e1032014-12-16 07:33:49 -080028 GrGLBufferImpl(GrGLGpu*, const Desc&, GrGLenum bufferType);
bsalomon@google.come49ad452013-02-20 19:33:20 +000029 ~GrGLBufferImpl() {
30 // either release or abandon should have been called by the owner of this object.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000031 SkASSERT(0 == fDesc.fID);
bsalomon@google.come49ad452013-02-20 19:33:20 +000032 }
33
34 void abandon();
bsalomon861e1032014-12-16 07:33:49 -080035 void release(GrGLGpu* gpu);
bsalomon@google.come49ad452013-02-20 19:33:20 +000036
37 GrGLuint bufferID() const { return fDesc.fID; }
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000038 size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); }
bsalomon@google.come49ad452013-02-20 19:33:20 +000039
bsalomon861e1032014-12-16 07:33:49 -080040 void bind(GrGLGpu* gpu) const;
bsalomon@google.come49ad452013-02-20 19:33:20 +000041
bsalomon861e1032014-12-16 07:33:49 -080042 void* map(GrGLGpu* gpu);
43 void unmap(GrGLGpu* gpu);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000044 bool isMapped() const;
bsalomon861e1032014-12-16 07:33:49 -080045 bool updateData(GrGLGpu* gpu, const void* src, size_t srcSizeInBytes);
bsalomon@google.come49ad452013-02-20 19:33:20 +000046
47private:
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000048 void validate() const;
49
bsalomon@google.come49ad452013-02-20 19:33:20 +000050 Desc fDesc;
51 GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000052 void* fCPUData;
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000053 void* fMapPtr;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000054 size_t fGLSizeInBytes; // In certain cases we make the size of the GL buffer object
55 // smaller or larger than the size in fDesc.
bsalomon@google.come49ad452013-02-20 19:33:20 +000056
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000057 typedef SkNoncopyable INHERITED;
bsalomon@google.come49ad452013-02-20 19:33:20 +000058};
59
60#endif