epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 10 | #ifndef GrGeometryBuffer_DEFINED |
| 11 | #define GrGeometryBuffer_DEFINED |
| 12 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 13 | #include "GrResource.h" |
| 14 | |
| 15 | class GrGpu; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Parent class for vertex and index buffers |
| 19 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 20 | class GrGeometryBuffer : public GrResource { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 21 | public: |
robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame^] | 22 | SK_DECLARE_INST_COUNT(GrGeometryBuffer); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 23 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 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 | */ |
| 29 | bool dynamic() const { return fDynamic; } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 30 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 31 | /** |
| 32 | * Locks the buffer to be written by the CPU. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 33 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 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. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 37 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 38 | * @return a pointer to the data or NULL if the lock fails. |
| 39 | */ |
| 40 | virtual void* lock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Unlocks the buffer. |
| 52 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 53 | * The pointer returned by the previous lock call will no longer be valid. |
| 54 | */ |
| 55 | virtual void unlock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 58 | Queries whether the buffer has been locked. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 60 | @return true if the buffer is locked, false otherwise. |
| 61 | */ |
| 62 | virtual bool isLocked() const = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 63 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 64 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 65 | * Updates the buffer data. |
| 66 | * |
| 67 | * The size of the buffer will be preserved. The src data will be |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 68 | * placed at the begining of the buffer and any remaining contents will |
| 69 | * be undefined. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 70 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 71 | * @return returns true if the update succeeds, false otherwise. |
| 72 | */ |
| 73 | virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 75 | // GrResource overrides |
| 76 | virtual size_t sizeInBytes() const { return fSizeInBytes; } |
| 77 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 78 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 79 | GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic) |
| 80 | : INHERITED(gpu) |
| 81 | , fSizeInBytes(sizeInBytes) |
| 82 | , fDynamic(dynamic) {} |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | size_t fSizeInBytes; |
| 86 | bool fDynamic; |
| 87 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 88 | typedef GrResource INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #endif |