reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 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 | |
| 18 | #ifndef GrIndexBuffer_DEFINED |
| 19 | #define GrIndexBuffer_DEFINED |
| 20 | |
| 21 | #include "GrRefCnt.h" |
| 22 | |
| 23 | class GrIndexBuffer : public GrRefCnt { |
| 24 | protected: |
| 25 | GrIndexBuffer(uint32_t sizeInBytes, bool dynamic) : |
| 26 | fSizeInBytes(sizeInBytes), |
| 27 | fDynamic(dynamic) {} |
| 28 | public: |
| 29 | virtual ~GrIndexBuffer() {} |
| 30 | |
| 31 | /** |
| 32 | Retrieves the size of the index buffer |
| 33 | |
| 34 | @return the size of the index buffer in bytes |
| 35 | */ |
| 36 | uint32_t size() const { return fSizeInBytes; } |
| 37 | |
| 38 | /** |
| 39 | Retrieves whether the index buffer was created with the dynamic flag |
| 40 | |
| 41 | @return true if the index buffer was created with the dynamic flag |
| 42 | */ |
| 43 | bool dynamic() const { return fDynamic; } |
| 44 | |
| 45 | /** |
| 46 | Indicates that GPU context in which this veretx buffer was created is |
| 47 | destroyed and that Ganesh should not attempt to free the texture with the |
| 48 | underlying API. |
| 49 | */ |
| 50 | virtual void abandon() = 0; |
| 51 | |
| 52 | /** |
| 53 | Locks the index buffer to be written by the CPU. |
| 54 | |
| 55 | The previous content of the index buffer is invalidated. It is an error to |
| 56 | draw whil the buffer is locked. It is an error to call lock on an already |
| 57 | locked index buffer. |
| 58 | |
| 59 | @return a pointer to the index data or NULL if the lock fails. |
| 60 | */ |
| 61 | virtual void* lock() = 0; |
| 62 | |
| 63 | /** |
| 64 | Unlocks the index buffer. |
| 65 | |
| 66 | The pointer returned by the previous lock call will no longer be valid. |
| 67 | */ |
| 68 | virtual void unlock() = 0; |
| 69 | |
| 70 | /** |
| 71 | Queries whether the index buffer has been locked. |
| 72 | |
| 73 | @return true if the index buffer is locked, false otherwise. |
| 74 | */ |
| 75 | virtual bool isLocked() const = 0; |
| 76 | |
| 77 | /** |
| 78 | Updates the index buffer data. |
| 79 | |
| 80 | The size of the index buffer will be preserved. However, only the updated |
| 81 | region will have defined contents. |
| 82 | |
| 83 | @return returns true if the update succeeds, false otherwise. |
| 84 | */ |
| 85 | virtual bool updateData(const void* src, uint32_t srcSizeInBytes) = 0; |
| 86 | |
| 87 | private: |
| 88 | uint32_t fSizeInBytes; |
| 89 | bool fDynamic; |
| 90 | }; |
| 91 | |
| 92 | #endif |