blob: 8617a897d42835930a51914f847422c748769fbe [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 {
23 bool fIsWrapped;
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000024 GrGLuint fID; // set to 0 to indicate buffer is CPU-backed and not a VBO.
bsalomon@google.come49ad452013-02-20 19:33:20 +000025 size_t fSizeInBytes;
26 bool fDynamic;
27 };
28
bsalomon861e1032014-12-16 07:33:49 -080029 GrGLBufferImpl(GrGLGpu*, const Desc&, GrGLenum bufferType);
bsalomon@google.come49ad452013-02-20 19:33:20 +000030 ~GrGLBufferImpl() {
31 // either release or abandon should have been called by the owner of this object.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000032 SkASSERT(0 == fDesc.fID);
bsalomon@google.come49ad452013-02-20 19:33:20 +000033 }
34
35 void abandon();
bsalomon861e1032014-12-16 07:33:49 -080036 void release(GrGLGpu* gpu);
bsalomon@google.come49ad452013-02-20 19:33:20 +000037
38 GrGLuint bufferID() const { return fDesc.fID; }
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000039 size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); }
bsalomon@google.come49ad452013-02-20 19:33:20 +000040
bsalomon861e1032014-12-16 07:33:49 -080041 void bind(GrGLGpu* gpu) const;
bsalomon@google.come49ad452013-02-20 19:33:20 +000042
bsalomon861e1032014-12-16 07:33:49 -080043 void* map(GrGLGpu* gpu);
44 void unmap(GrGLGpu* gpu);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000045 bool isMapped() const;
bsalomon861e1032014-12-16 07:33:49 -080046 bool updateData(GrGLGpu* gpu, const void* src, size_t srcSizeInBytes);
bsalomon@google.come49ad452013-02-20 19:33:20 +000047
48private:
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000049 void validate() const;
50
bsalomon@google.come49ad452013-02-20 19:33:20 +000051 Desc fDesc;
52 GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
bsalomon@google.comee3bc3b2013-02-21 14:33:46 +000053 void* fCPUData;
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000054 void* fMapPtr;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000055 size_t fGLSizeInBytes; // In certain cases we make the size of the GL buffer object
56 // smaller or larger than the size in fDesc.
bsalomon@google.come49ad452013-02-20 19:33:20 +000057
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000058 typedef SkNoncopyable INHERITED;
bsalomon@google.come49ad452013-02-20 19:33:20 +000059};
60
61#endif