Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef GrGeometryBuffer_DEFINED
     11 #define GrGeometryBuffer_DEFINED
     12 
     13 #include "GrResource.h"
     14 
     15 class GrGpu;
     16 
     17 /**
     18  * Parent class for vertex and index buffers
     19  */
     20 class GrGeometryBuffer : public GrResource {
     21 public:
     22 
     23     /**
     24      *Retrieves whether the buffer was created with the dynamic flag
     25      *
     26      * @return true if the buffer was created with the dynamic flag
     27      */
     28     bool dynamic() const { return fDynamic; }
     29 
     30     /**
     31      * Locks the buffer to be written by the CPU.
     32      *
     33      * The previous content of the buffer is invalidated. It is an error
     34      * to draw from the buffer while it is locked. It is an error to call lock
     35      * on an already locked buffer.
     36      *
     37      * @return a pointer to the data or NULL if the lock fails.
     38      */
     39     virtual void* lock() = 0;
     40 
     41     /**
     42      * Returns the same ptr that lock() returned at time of lock or NULL if the
     43      * is not locked.
     44      *
     45      * @return ptr to locked buffer data or undefined if buffer is not locked.
     46      */
     47     virtual void* lockPtr() const = 0;
     48 
     49     /**
     50      * Unlocks the buffer.
     51      *
     52      * The pointer returned by the previous lock call will no longer be valid.
     53      */
     54     virtual void unlock() = 0;
     55 
     56     /**
     57      Queries whether the buffer has been locked.
     58 
     59      @return true if the buffer is locked, false otherwise.
     60      */
     61     virtual bool isLocked() const = 0;
     62 
     63     /**
     64      * Updates the buffer data.
     65      *
     66      * The size of the buffer will be preserved. The src data will be
     67      * placed at the begining of the buffer and any remaining contents will
     68      * be undefined.
     69      *
     70      * @return returns true if the update succeeds, false otherwise.
     71      */
     72     virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
     73 
     74     // GrResource overrides
     75     virtual size_t sizeInBytes() const { return fSizeInBytes; }
     76 
     77 protected:
     78     GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
     79         : INHERITED(gpu)
     80         , fSizeInBytes(sizeInBytes)
     81         , fDynamic(dynamic) {}
     82 
     83 private:
     84     size_t   fSizeInBytes;
     85     bool     fDynamic;
     86 
     87     typedef GrResource INHERITED;
     88 };
     89 
     90 #endif
     91