blob: d7dc177c061536a71a08f9426e01719a49d0e88d [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:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000029
bsalomon@google.com27847de2011-02-22 20:59:41 +000030 /**
31 *Retrieves whether the buffer was created with the dynamic flag
32 *
33 * @return true if the buffer was created with the dynamic flag
34 */
35 bool dynamic() const { return fDynamic; }
bsalomon@google.com8fe72472011-03-30 21:26:44 +000036
bsalomon@google.com27847de2011-02-22 20:59:41 +000037 /**
38 * Locks the buffer to be written by the CPU.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000039 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000040 * The previous content of the buffer is invalidated. It is an error
41 * to draw from the buffer while it is locked. It is an error to call lock
42 * on an already locked buffer.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000043 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000044 * @return a pointer to the data or NULL if the lock fails.
45 */
46 virtual void* lock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000047
bsalomon@google.com27847de2011-02-22 20:59:41 +000048 /**
49 * Returns the same ptr that lock() returned at time of lock or NULL if the
50 * is not locked.
51 *
52 * @return ptr to locked buffer data or undefined if buffer is not locked.
53 */
54 virtual void* lockPtr() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000055
56 /**
57 * Unlocks the buffer.
58 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000059 * The pointer returned by the previous lock call will no longer be valid.
60 */
61 virtual void unlock() = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000062
63 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +000064 Queries whether the buffer has been locked.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000065
bsalomon@google.com27847de2011-02-22 20:59:41 +000066 @return true if the buffer is locked, false otherwise.
67 */
68 virtual bool isLocked() const = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000069
bsalomon@google.com27847de2011-02-22 20:59:41 +000070 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000071 * Updates the buffer data.
72 *
73 * The size of the buffer will be preserved. The src data will be
bsalomon@google.com27847de2011-02-22 20:59:41 +000074 * placed at the begining of the buffer and any remaining contents will
75 * be undefined.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000076 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000077 * @return returns true if the update succeeds, false otherwise.
78 */
79 virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000080
bsalomon@google.com27847de2011-02-22 20:59:41 +000081 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000082 * Updates a portion of the buffer data.
83 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000084 * The contents of the buffer outside the update region are preserved.
bsalomon@google.com8fe72472011-03-30 21:26:44 +000085 *
bsalomon@google.com27847de2011-02-22 20:59:41 +000086 * @return returns true if the update succeeds, false otherwise.
87 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +000088 virtual bool updateSubData(const void* src,
89 size_t srcSizeInBytes,
bsalomon@google.com27847de2011-02-22 20:59:41 +000090 size_t offset) = 0;
bsalomon@google.comcee661a2011-07-26 12:32:36 +000091
92 // GrResource overrides
93 virtual size_t sizeInBytes() const { return fSizeInBytes; }
94
bsalomon@google.com27847de2011-02-22 20:59:41 +000095protected:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000096 GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
97 : INHERITED(gpu)
98 , fSizeInBytes(sizeInBytes)
99 , fDynamic(dynamic) {}
bsalomon@google.com27847de2011-02-22 20:59:41 +0000100
101private:
102 size_t fSizeInBytes;
103 bool fDynamic;
104
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000105 typedef GrResource INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000106};
107
108#endif