• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2011 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 
10 #ifndef GrGeometryBuffer_DEFINED
11 #define GrGeometryBuffer_DEFINED
12 
13 #include "GrResource.h"
14 
15 class GrGpu;
16 
17 /**
18  * Parent class for vertex and index buffers
19  */
20 class GrGeometryBuffer : public GrResource {
21 public:
22     SK_DECLARE_INST_COUNT(GrGeometryBuffer);
23 
24     /**
25      *Retrieves whether the buffer was created with the dynamic flag
26      *
27      * @return true if the buffer was created with the dynamic flag
28      */
dynamic()29     bool dynamic() const { return fDynamic; }
30 
31     /**
32      * Locks the buffer to be written by the CPU.
33      *
34      * The previous content of the buffer is invalidated. It is an error
35      * to draw from the buffer while it is locked. It is an error to call lock
36      * on an already locked buffer.
37      *
38      * @return a pointer to the data or NULL if the lock fails.
39      */
40     virtual void* lock() = 0;
41 
42     /**
43      * Returns the same ptr that lock() returned at time of lock or NULL if the
44      * is not locked.
45      *
46      * @return ptr to locked buffer data or undefined if buffer is not locked.
47      */
48     virtual void* lockPtr() const = 0;
49 
50     /**
51      * Unlocks the buffer.
52      *
53      * The pointer returned by the previous lock call will no longer be valid.
54      */
55     virtual void unlock() = 0;
56 
57     /**
58      Queries whether the buffer has been locked.
59 
60      @return true if the buffer is locked, false otherwise.
61      */
62     virtual bool isLocked() const = 0;
63 
64     /**
65      * Updates the buffer data.
66      *
67      * The size of the buffer will be preserved. The src data will be
68      * placed at the begining of the buffer and any remaining contents will
69      * be undefined.
70      *
71      * @return returns true if the update succeeds, false otherwise.
72      */
73     virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
74 
75     // GrResource overrides
sizeInBytes()76     virtual size_t sizeInBytes() const { return fSizeInBytes; }
77 
78 protected:
GrGeometryBuffer(GrGpu * gpu,bool isWrapped,size_t sizeInBytes,bool dynamic)79     GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic)
80         : INHERITED(gpu, isWrapped)
81         , fSizeInBytes(sizeInBytes)
82         , fDynamic(dynamic) {}
83 
84 private:
85     size_t   fSizeInBytes;
86     bool     fDynamic;
87 
88     typedef GrResource INHERITED;
89 };
90 
91 #endif
92