blob: 98f58bd04f254c9b210b516e3019c199ad995815 [file] [log] [blame]
bsalomon@google.com27847de2011-02-22 20:59:41 +00001/*
2 Copyright 2011 Google Inc.
bsalomon@google.com8fe72472011-03-30 21:26:44 +00003
bsalomon@google.com27847de2011-02-22 20:59:41 +00004 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
bsalomon@google.com8fe72472011-03-30 21:26:44 +00007
bsalomon@google.com27847de2011-02-22 20:59:41 +00008 http://www.apache.org/licenses/LICENSE-2.0
bsalomon@google.com8fe72472011-03-30 21:26:44 +00009
bsalomon@google.com27847de2011-02-22 20:59:41 +000010 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17#ifndef GrGeometryBuffer_DEFINED
18#define GrGeometryBuffer_DEFINED
19
bsalomon@google.com8fe72472011-03-30 21:26:44 +000020#include "GrResource.h"
21
22class GrGpu;
bsalomon@google.com27847de2011-02-22 20:59:41 +000023
24/**
25 * Parent class for vertex and index buffers
26 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +000027class GrGeometryBuffer : public GrResource {
bsalomon@google.com27847de2011-02-22 20:59:41 +000028public:
vandebo@chromium.orgec364712011-07-26 03:44:05 +000029 /**
30 * Retrieves the size of the buffer
31 *
32 * @return the size of the buffer in bytes
33 */
34 size_t size() const { return fSizeInBytes; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000035
bsalomon@google.com27847de2011-02-22 20:59:41 +000036 /**
37 *Retrieves whether the buffer was created with the dynamic flag
38 *
39 * @return true if the buffer was created with the dynamic flag
40 */
41 bool dynamic() const { return fDynamic; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000042
bsalomon@google.com27847de2011-02-22 20:59:41 +000043 /**
44 * Locks the buffer to be written by the CPU.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000045 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000046 * The previous content of the buffer is invalidated. It is an error
47 * to draw from the buffer while it is locked. It is an error to call lock
48 * on an already locked buffer.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000049 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000050 * @return a pointer to the data or NULL if the lock fails.
51 */
52 virtual void* lock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000053
bsalomon@google.com27847de2011-02-22 20:59:41 +000054 /**
55 * Returns the same ptr that lock() returned at time of lock or NULL if the
56 * is not locked.
57 *
58 * @return ptr to locked buffer data or undefined if buffer is not locked.
59 */
60 virtual void* lockPtr() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000061
62 /**
63 * Unlocks the buffer.
64 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000065 * The pointer returned by the previous lock call will no longer be valid.
66 */
67 virtual void unlock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000068
69 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +000070 Queries whether the buffer has been locked.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000071
bsalomon@google.com27847de2011-02-22 20:59:41 +000072 @return true if the buffer is locked, false otherwise.
73 */
74 virtual bool isLocked() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000075
bsalomon@google.com27847de2011-02-22 20:59:41 +000076 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000077 * Updates the buffer data.
78 *
79 * The size of the buffer will be preserved. The src data will be
bsalomon@google.com27847de2011-02-22 20:59:41 +000080 * placed at the begining of the buffer and any remaining contents will
81 * be undefined.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000082 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000083 * @return returns true if the update succeeds, false otherwise.
84 */
85 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000086
bsalomon@google.com27847de2011-02-22 20:59:41 +000087 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000088 * Updates a portion of the buffer data.
89 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000090 * The contents of the buffer outside the update region are preserved.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000091 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000092 * @return returns true if the update succeeds, false otherwise.
93 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +000094 virtual bool updateSubData(const void* src,
95 size_t srcSizeInBytes,
bsalomon@google.com27847de2011-02-22 20:59:41 +000096 size_t offset) = 0;
97protected:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000098 GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
99 : INHERITED(gpu)
100 , fSizeInBytes(sizeInBytes)
101 , fDynamic(dynamic) {}
bsalomon@google.com27847de2011-02-22 20:59:41 +0000102
103private:
104 size_t fSizeInBytes;
105 bool fDynamic;
106
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000107 typedef GrResource INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000108};
109
110#endif