bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2011 Google Inc. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 3 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 7 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef GrGeometryBuffer_DEFINED |
| 18 | #define GrGeometryBuffer_DEFINED |
| 19 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 20 | #include "GrResource.h" |
| 21 | |
| 22 | class GrGpu; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Parent class for vertex and index buffers |
| 26 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 27 | class GrGeometryBuffer : public GrResource { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 28 | public: |
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 | *Retrieves whether the buffer was created with the dynamic flag |
| 32 | * |
| 33 | * @return true if the buffer was created with the dynamic flag |
| 34 | */ |
| 35 | bool dynamic() const { return fDynamic; } |
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 | /** |
| 38 | * Locks the buffer to be written by the CPU. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 39 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 40 | * The previous content of the buffer is invalidated. It is an error |
| 41 | * to draw from the buffer while it is locked. It is an error to call lock |
| 42 | * on an already locked buffer. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 43 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 44 | * @return a pointer to the data or NULL if the lock fails. |
| 45 | */ |
| 46 | virtual void* lock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 47 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 48 | /** |
| 49 | * Returns the same ptr that lock() returned at time of lock or NULL if the |
| 50 | * is not locked. |
| 51 | * |
| 52 | * @return ptr to locked buffer data or undefined if buffer is not locked. |
| 53 | */ |
| 54 | virtual void* lockPtr() const = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Unlocks the buffer. |
| 58 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 59 | * The pointer returned by the previous lock call will no longer be valid. |
| 60 | */ |
| 61 | virtual void unlock() = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 64 | Queries whether the buffer has been locked. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 65 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 66 | @return true if the buffer is locked, false otherwise. |
| 67 | */ |
| 68 | virtual bool isLocked() const = 0; |
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 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 71 | * Updates the buffer data. |
| 72 | * |
| 73 | * 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] | 74 | * placed at the begining of the buffer and any remaining contents will |
| 75 | * be undefined. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 76 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 77 | * @return returns true if the update succeeds, false otherwise. |
| 78 | */ |
| 79 | virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 81 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 82 | * Updates a portion of the buffer data. |
| 83 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 84 | * The contents of the buffer outside the update region are preserved. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 85 | * |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 86 | * @return returns true if the update succeeds, false otherwise. |
| 87 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 88 | virtual bool updateSubData(const void* src, |
| 89 | size_t srcSizeInBytes, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 90 | size_t offset) = 0; |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame^] | 91 | |
| 92 | // GrResource overrides |
| 93 | virtual size_t sizeInBytes() const { return fSizeInBytes; } |
| 94 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 95 | protected: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 96 | GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic) |
| 97 | : INHERITED(gpu) |
| 98 | , fSizeInBytes(sizeInBytes) |
| 99 | , fDynamic(dynamic) {} |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 100 | |
| 101 | private: |
| 102 | size_t fSizeInBytes; |
| 103 | bool fDynamic; |
| 104 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 105 | typedef GrResource INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | #endif |