1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGLBufferImpl_DEFINED 9 #define GrGLBufferImpl_DEFINED 10 11 #include "SkTypes.h" 12 #include "gl/GrGLFunctions.h" 13 14 class GrGLGpu; 15 16 /** 17 * This class serves as the implementation of GrGL*Buffer classes. It was written to avoid code 18 * duplication in those classes. 19 */ 20 class GrGLBufferImpl : SkNoncopyable { 21 public: 22 struct Desc { 23 GrGLuint fID; // set to 0 to indicate buffer is CPU-backed and not a VBO. 24 size_t fSizeInBytes; 25 bool fDynamic; 26 }; 27 28 GrGLBufferImpl(GrGLGpu*, const Desc&, GrGLenum bufferType); ~GrGLBufferImpl()29 ~GrGLBufferImpl() { 30 // either release or abandon should have been called by the owner of this object. 31 SkASSERT(0 == fDesc.fID); 32 } 33 34 void abandon(); 35 void release(GrGLGpu* gpu); 36 bufferID()37 GrGLuint bufferID() const { return fDesc.fID; } baseOffset()38 size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); } 39 40 void bind(GrGLGpu* gpu) const; 41 42 void* map(GrGLGpu* gpu); 43 void unmap(GrGLGpu* gpu); 44 bool isMapped() const; 45 bool updateData(GrGLGpu* gpu, const void* src, size_t srcSizeInBytes); 46 47 private: 48 void validate() const; 49 50 Desc fDesc; 51 GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER 52 void* fCPUData; 53 void* fMapPtr; 54 size_t fGLSizeInBytes; // In certain cases we make the size of the GL buffer object 55 // smaller or larger than the size in fDesc. 56 57 typedef SkNoncopyable INHERITED; 58 }; 59 60 #endif 61