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: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 23 | /** |
| 24 | *Retrieves whether the buffer was created with the dynamic flag |
| 25 | * |
| 26 | * @return true if the buffer was created with the dynamic flag |
| 27 | */ |
| 28 | bool dynamic() const { return fDynamic; } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 29 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Locks the buffer to be written by the CPU. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 32 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 33 | * The previous content of the buffer is invalidated. It is an error |
| 34 | * to draw from the buffer while it is locked. It is an error to call lock |
| 35 | * on an already locked buffer. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 36 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 37 | * @return a pointer to the data or NULL if the lock fails. |
| 38 | */ |
| 39 | virtual void* lock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Returns the same ptr that lock() returned at time of lock or NULL if the |
| 43 | * is not locked. |
| 44 | * |
| 45 | * @return ptr to locked buffer data or undefined if buffer is not locked. |
| 46 | */ |
| 47 | virtual void* lockPtr() const = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Unlocks the buffer. |
| 51 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | * The pointer returned by the previous lock call will no longer be valid. |
| 53 | */ |
| 54 | virtual void unlock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 57 | Queries whether the buffer has been locked. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 59 | @return true if the buffer is locked, false otherwise. |
| 60 | */ |
| 61 | virtual bool isLocked() const = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 62 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 63 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 64 | * Updates the buffer data. |
| 65 | * |
| 66 | * 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] | 67 | * placed at the begining of the buffer and any remaining contents will |
| 68 | * be undefined. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 69 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 70 | * @return returns true if the update succeeds, false otherwise. |
| 71 | */ |
| 72 | virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 73 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 74 | // GrResource overrides |
| 75 | virtual size_t sizeInBytes() const { return fSizeInBytes; } |
| 76 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 77 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 78 | GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic) |
| 79 | : INHERITED(gpu) |
| 80 | , fSizeInBytes(sizeInBytes) |
| 81 | , fDynamic(dynamic) {} |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | size_t fSizeInBytes; |
| 85 | bool fDynamic; |
| 86 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 87 | typedef GrResource INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #endif |