blob: c74b25487da5e45e04411731fcf59773b6af3946 [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:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000022
bsalomon@google.com27847de2011-02-22 20:59:41 +000023 /**
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; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000029
bsalomon@google.com27847de2011-02-22 20:59:41 +000030 /**
31 * Locks the buffer to be written by the CPU.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000032 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000033 * 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.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000036 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000037 * @return a pointer to the data or NULL if the lock fails.
38 */
39 virtual void* lock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000040
bsalomon@google.com27847de2011-02-22 20:59:41 +000041 /**
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;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000048
49 /**
50 * Unlocks the buffer.
51 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000052 * The pointer returned by the previous lock call will no longer be valid.
53 */
54 virtual void unlock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000055
56 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +000057 Queries whether the buffer has been locked.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000058
bsalomon@google.com27847de2011-02-22 20:59:41 +000059 @return true if the buffer is locked, false otherwise.
60 */
61 virtual bool isLocked() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000062
bsalomon@google.com27847de2011-02-22 20:59:41 +000063 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000064 * Updates the buffer data.
65 *
66 * The size of the buffer will be preserved. The src data will be
bsalomon@google.com27847de2011-02-22 20:59:41 +000067 * placed at the begining of the buffer and any remaining contents will
68 * be undefined.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000069 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000070 * @return returns true if the update succeeds, false otherwise.
71 */
72 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000073
bsalomon@google.comcee661a2011-07-26 12:32:36 +000074 // GrResource overrides
75 virtual size_t sizeInBytes() const { return fSizeInBytes; }
76
bsalomon@google.com27847de2011-02-22 20:59:41 +000077protected:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000078 GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
79 : INHERITED(gpu)
80 , fSizeInBytes(sizeInBytes)
81 , fDynamic(dynamic) {}
bsalomon@google.com27847de2011-02-22 20:59:41 +000082
83private:
84 size_t fSizeInBytes;
85 bool fDynamic;
86
bsalomon@google.com8fe72472011-03-30 21:26:44 +000087 typedef GrResource INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +000088};
89
90#endif