blob: 5c282eef31ba931bfd9e30de16bf52a5b5a897ec [file] [log] [blame]
robertphillips@google.comdd743fe2012-04-05 14:40:53 +00001
2/*
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"
bsalomon@google.com91bcc942012-05-07 17:28:41 +000013#include "../GrGLDefines.h"
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000014
15////////////////////////////////////////////////////////////////////////////////
16class GrBufferObj : public GrFakeRefObj {
17 GR_DEFINE_CREATOR(GrBufferObj);
18
19public:
rmistry@google.comfbfcd562012-08-23 18:09:54 +000020 GrBufferObj()
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000021 : GrFakeRefObj()
22 , fDataPtr(NULL)
23 , fMapped(false)
24 , fBound(false)
25 , fSize(0)
26 , fUsage(GR_GL_STATIC_DRAW) {
27 }
28 virtual ~GrBufferObj() {
29 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
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000058 virtual void deleteAction() SK_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