blob: c156fa3c7741d45ec7fc2d355be651eb750eaf6a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com27847de2011-02-22 20:59:41 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
bsalomon@google.com27847de2011-02-22 20:59:41 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com27847de2011-02-22 20:59:41 +000010#ifndef GrGeometryBuffer_DEFINED
11#define GrGeometryBuffer_DEFINED
12
bsalomon@google.com8fe72472011-03-30 21:26:44 +000013#include "GrResource.h"
14
15class GrGpu;
bsalomon@google.com27847de2011-02-22 20:59:41 +000016
17/**
18 * Parent class for vertex and index buffers
19 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +000020class GrGeometryBuffer : public GrResource {
bsalomon@google.com27847de2011-02-22 20:59:41 +000021public:
robertphillips@google.com7fa18762012-09-11 13:02:31 +000022 SK_DECLARE_INST_COUNT(GrGeometryBuffer);
bsalomon@google.com8fe72472011-03-30 21:26:44 +000023
bsalomon@google.com27847de2011-02-22 20:59:41 +000024 /**
25 *Retrieves whether the buffer was created with the dynamic flag
26 *
27 * @return true if the buffer was created with the dynamic flag
28 */
29 bool dynamic() const { return fDynamic; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000030
bsalomon@google.com27847de2011-02-22 20:59:41 +000031 /**
32 * Locks the buffer to be written by the CPU.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000033 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000034 * The previous content of the buffer is invalidated. It is an error
35 * to draw from the buffer while it is locked. It is an error to call lock
36 * on an already locked buffer.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000037 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000038 * @return a pointer to the data or NULL if the lock fails.
39 */
40 virtual void* lock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000041
bsalomon@google.com27847de2011-02-22 20:59:41 +000042 /**
43 * Returns the same ptr that lock() returned at time of lock or NULL if the
44 * is not locked.
45 *
46 * @return ptr to locked buffer data or undefined if buffer is not locked.
47 */
48 virtual void* lockPtr() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000049
50 /**
51 * Unlocks the buffer.
52 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000053 * The pointer returned by the previous lock call will no longer be valid.
54 */
55 virtual void unlock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000056
57 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +000058 Queries whether the buffer has been locked.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000059
bsalomon@google.com27847de2011-02-22 20:59:41 +000060 @return true if the buffer is locked, false otherwise.
61 */
62 virtual bool isLocked() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000063
bsalomon@google.com27847de2011-02-22 20:59:41 +000064 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000065 * Updates the buffer data.
66 *
67 * The size of the buffer will be preserved. The src data will be
bsalomon@google.com27847de2011-02-22 20:59:41 +000068 * placed at the begining of the buffer and any remaining contents will
69 * be undefined.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000070 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000071 * @return returns true if the update succeeds, false otherwise.
72 */
73 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000074
bsalomon@google.comcee661a2011-07-26 12:32:36 +000075 // GrResource overrides
76 virtual size_t sizeInBytes() const { return fSizeInBytes; }
77
bsalomon@google.com27847de2011-02-22 20:59:41 +000078protected:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000079 GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
80 : INHERITED(gpu)
81 , fSizeInBytes(sizeInBytes)
82 , fDynamic(dynamic) {}
bsalomon@google.com27847de2011-02-22 20:59:41 +000083
84private:
85 size_t fSizeInBytes;
86 bool fDynamic;
87
bsalomon@google.com8fe72472011-03-30 21:26:44 +000088 typedef GrResource INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +000089};
90
91#endif