blob: fecfeb5e3ceb75607e3baefb5c71127176e3accb [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
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000037 void setMapped() { fMapped = true; }
38 void resetMapped() { fMapped = false; }
39 bool getMapped() const { return fMapped; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000040
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000041 void setBound() { fBound = true; }
42 void resetBound() { fBound = false; }
43 bool getBound() const { return fBound; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000044
robertphillips@google.comae6b7772013-07-18 18:07:39 +000045 void allocate(GrGLsizeiptr size, const GrGLchar *dataPtr);
46 GrGLsizeiptr getSize() const { return fSize; }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000047 GrGLchar *getDataPtr() { return fDataPtr; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000048
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000049 void setUsage(GrGLint usage) { fUsage = usage; }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000050 GrGLint getUsage() const { return fUsage; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000051
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000052 virtual void deleteAction() SK_OVERRIDE;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000053
54protected:
55private:
56
robertphillips@google.comae6b7772013-07-18 18:07:39 +000057 GrGLchar* fDataPtr;
58 bool fMapped; // is the buffer object mapped via "glMapBuffer"?
59 bool fBound; // is the buffer object bound via "glBindBuffer"?
60 GrGLsizeiptr fSize; // size in bytes
61 GrGLint fUsage; // one of: GL_STREAM_DRAW,
62 // GL_STATIC_DRAW,
63 // GL_DYNAMIC_DRAW
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000064
65 typedef GrFakeRefObj INHERITED;
66};
67
68#endif // GrBufferObj_DEFINED