blob: c41cb1fe14720f1fdee7c364686e702c040f1b4f [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"
13
14////////////////////////////////////////////////////////////////////////////////
15class GrBufferObj : public GrFakeRefObj {
16 GR_DEFINE_CREATOR(GrBufferObj);
17
18public:
19 GrBufferObj()
20 : GrFakeRefObj()
21 , fDataPtr(NULL)
22 , fMapped(false)
23 , fBound(false)
24 , fSize(0)
25 , fUsage(GR_GL_STATIC_DRAW) {
26 }
27 virtual ~GrBufferObj() {
28 delete[] fDataPtr;
29 }
30
31 void access() {
32 // cannot access the buffer if it is currently mapped
33 GrAlwaysAssert(!fMapped);
34 }
35
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000036 void setMapped() { fMapped = true; }
37 void resetMapped() { fMapped = false; }
38 bool getMapped() const { return fMapped; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000039
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000040 void setBound() { fBound = true; }
41 void resetBound() { fBound = false; }
42 bool getBound() const { return fBound; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000043
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000044 void allocate(GrGLint size, const GrGLchar *dataPtr);
45 GrGLint getSize() const { return fSize; }
46 GrGLchar *getDataPtr() { return fDataPtr; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000047
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000048 void setUsage(GrGLint usage) { fUsage = usage; }
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000049 GrGLint getUsage() const { return fUsage; }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000050
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000051 virtual void deleteAction() SK_OVERRIDE;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000052
53protected:
54private:
55
56 GrGLchar* fDataPtr;
57 bool fMapped; // is the buffer object mapped via "glMapBuffer"?
58 bool fBound; // is the buffer object bound via "glBindBuffer"?
59 GrGLint fSize; // size in bytes
robertphillips@google.com0dd84a32012-04-16 16:24:35 +000060 GrGLint fUsage; // one of: GL_STREAM_DRAW,
61 // GL_STATIC_DRAW,
62 // GL_DYNAMIC_DRAW
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000063
64 typedef GrFakeRefObj INHERITED;
65};
66
67#endif // GrBufferObj_DEFINED