bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2011 Google Inc. |
| 3 | |
| 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 |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 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 | |
| 20 | #include "GrRefCnt.h" |
| 21 | |
| 22 | /** |
| 23 | * Parent class for vertex and index buffers |
| 24 | */ |
| 25 | class GrGeometryBuffer : public GrRefCnt { |
| 26 | public: |
| 27 | virtual ~GrGeometryBuffer() {} |
| 28 | |
| 29 | /** |
| 30 | * Retrieves the size of the buffer |
| 31 | * |
| 32 | * @return the size of the buffer in bytes |
| 33 | */ |
| 34 | size_t size() const { return fSizeInBytes; } |
| 35 | |
| 36 | /** |
| 37 | *Retrieves whether the buffer was created with the dynamic flag |
| 38 | * |
| 39 | * @return true if the buffer was created with the dynamic flag |
| 40 | */ |
| 41 | bool dynamic() const { return fDynamic; } |
| 42 | |
| 43 | /** |
| 44 | * Indicates that GPU context in which this veretx buffer was created is |
| 45 | * destroyed and that Ganesh should not attempt to free the buffer in the |
| 46 | * underlying API. |
| 47 | */ |
| 48 | virtual void abandon() = 0; |
| 49 | |
| 50 | /** |
| 51 | * Locks the buffer to be written by the CPU. |
| 52 | * |
| 53 | * The previous content of the buffer is invalidated. It is an error |
| 54 | * to draw from the buffer while it is locked. It is an error to call lock |
| 55 | * on an already locked buffer. |
| 56 | * |
| 57 | * @return a pointer to the data or NULL if the lock fails. |
| 58 | */ |
| 59 | virtual void* lock() = 0; |
| 60 | |
| 61 | /** |
| 62 | * Returns the same ptr that lock() returned at time of lock or NULL if the |
| 63 | * is not locked. |
| 64 | * |
| 65 | * @return ptr to locked buffer data or undefined if buffer is not locked. |
| 66 | */ |
| 67 | virtual void* lockPtr() const = 0; |
| 68 | |
| 69 | /** |
| 70 | * Unlocks the buffer. |
| 71 | * |
| 72 | * The pointer returned by the previous lock call will no longer be valid. |
| 73 | */ |
| 74 | virtual void unlock() = 0; |
| 75 | |
| 76 | /** |
| 77 | Queries whether the buffer has been locked. |
| 78 | |
| 79 | @return true if the buffer is locked, false otherwise. |
| 80 | */ |
| 81 | virtual bool isLocked() const = 0; |
| 82 | |
| 83 | /** |
| 84 | * Updates the buffer data. |
| 85 | * |
| 86 | * The size of the buffer will be preserved. The src data will be |
| 87 | * placed at the begining of the buffer and any remaining contents will |
| 88 | * be undefined. |
| 89 | * |
| 90 | * @return returns true if the update succeeds, false otherwise. |
| 91 | */ |
| 92 | virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; |
| 93 | |
| 94 | /** |
| 95 | * Updates a portion of the buffer data. |
| 96 | * |
| 97 | * The contents of the buffer outside the update region are preserved. |
| 98 | * |
| 99 | * @return returns true if the update succeeds, false otherwise. |
| 100 | */ |
| 101 | virtual bool updateSubData(const void* src, |
| 102 | size_t srcSizeInBytes, |
| 103 | size_t offset) = 0; |
| 104 | protected: |
| 105 | GrGeometryBuffer(size_t sizeInBytes, bool dynamic) : |
| 106 | fSizeInBytes(sizeInBytes), |
| 107 | fDynamic(dynamic) {} |
| 108 | |
| 109 | private: |
| 110 | size_t fSizeInBytes; |
| 111 | bool fDynamic; |
| 112 | |
| 113 | typedef GrRefCnt INHERITED; |
| 114 | }; |
| 115 | |
| 116 | #endif |