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 "GrResource.h" 21 22 class GrGpu; 23 24 /** 25 * Parent class for vertex and index buffers 26 */ 27 class GrGeometryBuffer : public GrResource { 28 public: 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 * Locks the buffer to be written by the CPU. 45 * 46 * The previous content of the buffer is invalidated. It is an error 47 * to draw from the buffer while it is locked. It is an error to call lock 48 * on an already locked buffer. 49 * 50 * @return a pointer to the data or NULL if the lock fails. 51 */ 52 virtual void* lock() = 0; 53 54 /** 55 * Returns the same ptr that lock() returned at time of lock or NULL if the 56 * is not locked. 57 * 58 * @return ptr to locked buffer data or undefined if buffer is not locked. 59 */ 60 virtual void* lockPtr() const = 0; 61 62 /** 63 * Unlocks the buffer. 64 * 65 * The pointer returned by the previous lock call will no longer be valid. 66 */ 67 virtual void unlock() = 0; 68 69 /** 70 Queries whether the buffer has been locked. 71 72 @return true if the buffer is locked, false otherwise. 73 */ 74 virtual bool isLocked() const = 0; 75 76 /** 77 * Updates the buffer data. 78 * 79 * The size of the buffer will be preserved. The src data will be 80 * placed at the begining of the buffer and any remaining contents will 81 * be undefined. 82 * 83 * @return returns true if the update succeeds, false otherwise. 84 */ 85 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; 86 87 /** 88 * Updates a portion of the buffer data. 89 * 90 * The contents of the buffer outside the update region are preserved. 91 * 92 * @return returns true if the update succeeds, false otherwise. 93 */ 94 virtual bool updateSubData(const void* src, 95 size_t srcSizeInBytes, 96 size_t offset) = 0; 97 protected: 98 GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic) 99 : INHERITED(gpu) 100 , fSizeInBytes(sizeInBytes) 101 , fDynamic(dynamic) {} 102 103 private: 104 size_t fSizeInBytes; 105 bool fDynamic; 106 107 typedef GrResource INHERITED; 108 }; 109 110 #endif 111