blob: d0217b2ffa139cb79ffbeec46f14c78da95c26a9 [file] [log] [blame]
bsalomon3724e572016-03-30 18:56:19 -07001
robertphillips@google.comdd743fe2012-04-05 14:40:53 +00002/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef GrBufferObj_DEFINED
10#define GrBufferObj_DEFINED
11
12#include "GrFakeRefObj.h"
bsalomon3724e572016-03-30 18:56:19 -070013#include "gl/GrGLDefines.h"
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000014
15////////////////////////////////////////////////////////////////////////////////
16class GrBufferObj : public GrFakeRefObj {
Mike Kleinfc6c37b2016-09-27 09:34:10 -040017 GR_DEFINE_CREATOR(GrBufferObj)
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000018
19public:
rmistry@google.comfbfcd562012-08-23 18:09:54 +000020 GrBufferObj()
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000021 : GrFakeRefObj()
halcanary96fcdcc2015-08-27 07:41:13 -070022 , fDataPtr(nullptr)
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000023 , fMapped(false)
24 , fBound(false)
25 , fSize(0)
26 , fUsage(GR_GL_STATIC_DRAW) {
27 }
Brian Salomond3b65972017-03-22 12:05:03 -040028 ~GrBufferObj() override {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000029 delete[] fDataPtr;
30 }
31
32 void access() {
33 // cannot access the buffer if it is currently mapped
34 GrAlwaysAssert(!fMapped);
35 }
36
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000037 void setMapped(GrGLintptr offset, GrGLsizeiptr length) {
38 fMapped = true;
39 fMappedOffset = offset;
40 fMappedLength = length;
41 }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000042 void resetMapped() { fMapped = false; }
43 bool getMapped() const { return fMapped; }
commit-bot@chromium.org24e7b9f2014-05-07 15:46:56 +000044 GrGLintptr getMappedOffset() const { return fMappedOffset; }
45 GrGLsizeiptr getMappedLength() const { return fMappedLength; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000046
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000047 void setBound() { fBound = true; }
48 void resetBound() { fBound = false; }
49 bool getBound() const { return fBound; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000050
robertphillips@google.comae6b7772013-07-18 18:07:39 +000051 void allocate(GrGLsizeiptr size, const GrGLchar *dataPtr);
52 GrGLsizeiptr getSize() const { return fSize; }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000053 GrGLchar *getDataPtr() { return fDataPtr; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000054
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000055 void setUsage(GrGLint usage) { fUsage = usage; }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000056 GrGLint getUsage() const { return fUsage; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000057
mtklein36352bf2015-03-25 18:17:31 -070058 void deleteAction() override;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000059
60protected:
61private:
62
robertphillips@google.comae6b7772013-07-18 18:07:39 +000063 GrGLchar* fDataPtr;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000064 bool fMapped; // is the buffer object mapped via "glMapBuffer[Range]"?
65 GrGLintptr fMappedOffset; // the offset of the buffer range that is mapped
66 GrGLsizeiptr fMappedLength; // the size of the buffer range that is mapped
robertphillips@google.comae6b7772013-07-18 18:07:39 +000067 bool fBound; // is the buffer object bound via "glBindBuffer"?
68 GrGLsizeiptr fSize; // size in bytes
69 GrGLint fUsage; // one of: GL_STREAM_DRAW,
70 // GL_STATIC_DRAW,
71 // GL_DYNAMIC_DRAW
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000072
73 typedef GrFakeRefObj INHERITED;
74};
75
76#endif // GrBufferObj_DEFINED