robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 1 | |
| 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.com | 91bcc94 | 2012-05-07 17:28:41 +0000 | [diff] [blame] | 13 | #include "../GrGLDefines.h" |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 14 | |
| 15 | //////////////////////////////////////////////////////////////////////////////// |
| 16 | class GrBufferObj : public GrFakeRefObj { |
| 17 | GR_DEFINE_CREATOR(GrBufferObj); |
| 18 | |
| 19 | public: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 20 | GrBufferObj() |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 21 | : 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.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 37 | void setMapped(GrGLintptr offset, GrGLsizeiptr length) { |
| 38 | fMapped = true; |
| 39 | fMappedOffset = offset; |
| 40 | fMappedLength = length; |
| 41 | } |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 42 | void resetMapped() { fMapped = false; } |
| 43 | bool getMapped() const { return fMapped; } |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 44 | GrGLsizei getMappedOffset() const { return fMappedOffset; } |
| 45 | GrGLsizei getMappedLength() const { return fMappedLength; } |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 46 | |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 47 | void setBound() { fBound = true; } |
| 48 | void resetBound() { fBound = false; } |
| 49 | bool getBound() const { return fBound; } |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 50 | |
robertphillips@google.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 51 | void allocate(GrGLsizeiptr size, const GrGLchar *dataPtr); |
| 52 | GrGLsizeiptr getSize() const { return fSize; } |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 53 | GrGLchar *getDataPtr() { return fDataPtr; } |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 54 | |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 55 | void setUsage(GrGLint usage) { fUsage = usage; } |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 56 | GrGLint getUsage() const { return fUsage; } |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 57 | |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 58 | virtual void deleteAction() SK_OVERRIDE; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 59 | |
| 60 | protected: |
| 61 | private: |
| 62 | |
robertphillips@google.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 63 | GrGLchar* fDataPtr; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 64 | 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.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 67 | 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.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 72 | |
| 73 | typedef GrFakeRefObj INHERITED; |
| 74 | }; |
| 75 | |
| 76 | #endif // GrBufferObj_DEFINED |