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