• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 
27 
28 #ifndef BUFFEROBJ_H
29 #define BUFFEROBJ_H
30 
31 #include <stdbool.h>
32 #include "mtypes.h"
33 
34 
35 /*
36  * Internal functions
37  */
38 
39 
40 /** Is the given buffer object currently mapped by the GL user? */
41 static inline GLboolean
_mesa_bufferobj_mapped(const struct gl_buffer_object * obj,gl_map_buffer_index index)42 _mesa_bufferobj_mapped(const struct gl_buffer_object *obj,
43                        gl_map_buffer_index index)
44 {
45    return obj->Mappings[index].Pointer != NULL;
46 }
47 
48 /**
49  * Check whether the given buffer object is illegally mapped prior to
50  * drawing from (or reading back to) the buffer.
51  * Note that it's legal for a buffer to be mapped at draw/readback time
52  * if it was mapped persistently (See GL_ARB_buffer_storage spec).
53  * \return true if the buffer is illegally mapped, false otherwise
54  */
55 static inline bool
_mesa_check_disallowed_mapping(const struct gl_buffer_object * obj)56 _mesa_check_disallowed_mapping(const struct gl_buffer_object *obj)
57 {
58    return _mesa_bufferobj_mapped(obj, MAP_USER) &&
59           !(obj->Mappings[MAP_USER].AccessFlags &
60             GL_MAP_PERSISTENT_BIT);
61 }
62 
63 /**
64  * Is the given buffer object a user-created buffer object?
65  * Mesa uses default buffer objects in several places.  Default buffers
66  * always have Name==0.  User created buffers have Name!=0.
67  */
68 static inline GLboolean
_mesa_is_bufferobj(const struct gl_buffer_object * obj)69 _mesa_is_bufferobj(const struct gl_buffer_object *obj)
70 {
71    return obj != NULL && obj->Name != 0;
72 }
73 
74 
75 extern void
76 _mesa_init_buffer_objects(struct gl_context *ctx);
77 
78 extern void
79 _mesa_free_buffer_objects(struct gl_context *ctx);
80 
81 extern bool
82 _mesa_handle_bind_buffer_gen(struct gl_context *ctx,
83                              GLuint buffer,
84                              struct gl_buffer_object **buf_handle,
85                              const char *caller);
86 
87 extern void
88 _mesa_update_default_objects_buffer_objects(struct gl_context *ctx);
89 
90 
91 extern struct gl_buffer_object *
92 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
93 
94 extern struct gl_buffer_object *
95 _mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer);
96 
97 extern struct gl_buffer_object *
98 _mesa_lookup_bufferobj_err(struct gl_context *ctx, GLuint buffer,
99                            const char *caller);
100 
101 extern void
102 _mesa_begin_bufferobj_lookups(struct gl_context *ctx);
103 
104 extern void
105 _mesa_end_bufferobj_lookups(struct gl_context *ctx);
106 
107 extern struct gl_buffer_object *
108 _mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx,
109                                   const GLuint *buffers,
110                                   GLuint index, const char *caller);
111 
112 extern void
113 _mesa_initialize_buffer_object(struct gl_context *ctx,
114                                struct gl_buffer_object *obj,
115                                GLuint name);
116 
117 extern void
118 _mesa_delete_buffer_object(struct gl_context *ctx,
119                            struct gl_buffer_object *bufObj);
120 
121 extern void
122 _mesa_reference_buffer_object_(struct gl_context *ctx,
123                                struct gl_buffer_object **ptr,
124                                struct gl_buffer_object *bufObj);
125 
126 static inline void
_mesa_reference_buffer_object(struct gl_context * ctx,struct gl_buffer_object ** ptr,struct gl_buffer_object * bufObj)127 _mesa_reference_buffer_object(struct gl_context *ctx,
128                               struct gl_buffer_object **ptr,
129                               struct gl_buffer_object *bufObj)
130 {
131    if (*ptr != bufObj)
132       _mesa_reference_buffer_object_(ctx, ptr, bufObj);
133 }
134 
135 extern GLuint
136 _mesa_total_buffer_object_memory(struct gl_context *ctx);
137 
138 extern void
139 _mesa_init_buffer_object_functions(struct dd_function_table *driver);
140 
141 extern void
142 _mesa_buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
143                      GLenum target, GLsizeiptr size, const GLvoid *data,
144                      GLbitfield flags, const char *func);
145 
146 extern void
147 _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
148                   GLenum target, GLsizeiptr size, const GLvoid *data,
149                   GLenum usage, const char *func);
150 
151 extern void
152 _mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
153                       GLintptr offset, GLsizeiptr size, const GLvoid *data,
154                       const char *func);
155 
156 extern void
157 _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
158                                 struct gl_buffer_object *bufObj);
159 
160 extern void
161 _mesa_copy_buffer_sub_data(struct gl_context *ctx,
162                            struct gl_buffer_object *src,
163                            struct gl_buffer_object *dst,
164                            GLintptr readOffset, GLintptr writeOffset,
165                            GLsizeiptr size, const char *func);
166 
167 extern void *
168 _mesa_map_buffer_range(struct gl_context *ctx,
169                        struct gl_buffer_object *bufObj,
170                        GLintptr offset, GLsizeiptr length,
171                        GLbitfield access, const char *func);
172 
173 extern void
174 _mesa_flush_mapped_buffer_range(struct gl_context *ctx,
175                                 struct gl_buffer_object *bufObj,
176                                 GLintptr offset, GLsizeiptr length,
177                                 const char *func);
178 
179 extern void
180 _mesa_ClearBufferSubData_sw(struct gl_context *ctx,
181                             GLintptr offset, GLsizeiptr size,
182                             const GLvoid *clearValue,
183                             GLsizeiptr clearValueSize,
184                             struct gl_buffer_object *bufObj);
185 
186 extern void
187 _mesa_clear_buffer_sub_data(struct gl_context *ctx,
188                             struct gl_buffer_object *bufObj,
189                             GLenum internalformat,
190                             GLintptr offset, GLsizeiptr size,
191                             GLenum format, GLenum type,
192                             const GLvoid *data,
193                             const char *func, bool subdata);
194 
195 extern GLboolean
196 _mesa_unmap_buffer(struct gl_context *ctx, struct gl_buffer_object *bufObj,
197                    const char *func);
198 
199 /*
200  * API functions
201  */
202 void GLAPIENTRY
203 _mesa_BindBuffer(GLenum target, GLuint buffer);
204 
205 void GLAPIENTRY
206 _mesa_DeleteBuffers(GLsizei n, const GLuint * buffer);
207 
208 void GLAPIENTRY
209 _mesa_GenBuffers(GLsizei n, GLuint *buffers);
210 
211 void GLAPIENTRY
212 _mesa_CreateBuffers(GLsizei n, GLuint *buffers);
213 
214 GLboolean GLAPIENTRY
215 _mesa_IsBuffer(GLuint buffer);
216 
217 void GLAPIENTRY
218 _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
219                     GLbitfield flags);
220 
221 void GLAPIENTRY
222 _mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
223                          GLbitfield flags);
224 
225 void GLAPIENTRY
226 _mesa_BufferData(GLenum target, GLsizeiptr size,
227                  const GLvoid *data, GLenum usage);
228 
229 void GLAPIENTRY
230 _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size,
231                       const GLvoid *data, GLenum usage);
232 
233 void GLAPIENTRY
234 _mesa_BufferSubData(GLenum target, GLintptr offset,
235                     GLsizeiptr size, const GLvoid *data);
236 
237 void GLAPIENTRY
238 _mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
239                          GLsizeiptr size, const GLvoid *data);
240 
241 void GLAPIENTRY
242 _mesa_GetBufferSubData(GLenum target, GLintptr offset,
243                        GLsizeiptr size, GLvoid *data);
244 
245 void GLAPIENTRY
246 _mesa_GetNamedBufferSubData(GLuint buffer, GLintptr offset,
247                             GLsizeiptr size, GLvoid *data);
248 
249 void GLAPIENTRY
250 _mesa_ClearBufferData(GLenum target, GLenum internalformat,
251                       GLenum format, GLenum type,
252                       const GLvoid *data);
253 
254 void GLAPIENTRY
255 _mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
256                            GLenum format, GLenum type,
257                            const GLvoid *data);
258 
259 void GLAPIENTRY
260 _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
261                          GLintptr offset, GLsizeiptr size,
262                          GLenum format, GLenum type,
263                          const GLvoid *data);
264 
265 void GLAPIENTRY
266 _mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
267                               GLintptr offset, GLsizeiptr size,
268                               GLenum format, GLenum type,
269                               const GLvoid *data);
270 
271 GLboolean GLAPIENTRY
272 _mesa_UnmapBuffer(GLenum target);
273 
274 GLboolean GLAPIENTRY
275 _mesa_UnmapNamedBuffer(GLuint buffer);
276 
277 void GLAPIENTRY
278 _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params);
279 
280 void GLAPIENTRY
281 _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params);
282 
283 void GLAPIENTRY
284 _mesa_GetNamedBufferParameteriv(GLuint buffer, GLenum pname, GLint *params);
285 
286 void GLAPIENTRY
287 _mesa_GetNamedBufferParameteri64v(GLuint buffer, GLenum pname,
288                                   GLint64 *params);
289 
290 void GLAPIENTRY
291 _mesa_GetBufferPointerv(GLenum target, GLenum pname, GLvoid **params);
292 
293 void GLAPIENTRY
294 _mesa_GetNamedBufferPointerv(GLuint buffer, GLenum pname, GLvoid **params);
295 
296 
297 void GLAPIENTRY
298 _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
299                         GLintptr readOffset, GLintptr writeOffset,
300                         GLsizeiptr size);
301 
302 void GLAPIENTRY
303 _mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
304                              GLintptr readOffset, GLintptr writeOffset,
305                              GLsizeiptr size);
306 
307 void * GLAPIENTRY
308 _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
309                      GLbitfield access);
310 
311 void * GLAPIENTRY
312 _mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
313                           GLbitfield access);
314 
315 void * GLAPIENTRY
316 _mesa_MapBuffer(GLenum target, GLenum access);
317 
318 void * GLAPIENTRY
319 _mesa_MapNamedBuffer(GLuint buffer, GLenum access);
320 
321 
322 void GLAPIENTRY
323 _mesa_FlushMappedBufferRange(GLenum target,
324                              GLintptr offset, GLsizeiptr length);
325 
326 void GLAPIENTRY
327 _mesa_FlushMappedNamedBufferRange(GLuint buffer, GLintptr offset,
328                                   GLsizeiptr length);
329 
330 void GLAPIENTRY
331 _mesa_BindBufferRange(GLenum target, GLuint index,
332                       GLuint buffer, GLintptr offset, GLsizeiptr size);
333 
334 void GLAPIENTRY
335 _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer);
336 
337 void GLAPIENTRY
338 _mesa_BindBuffersRange(GLenum target, GLuint first, GLsizei count,
339                        const GLuint *buffers,
340                        const GLintptr *offsets, const GLsizeiptr *sizes);
341 void GLAPIENTRY
342 _mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
343                       const GLuint *buffers);
344 void GLAPIENTRY
345 _mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
346                               GLsizeiptr length);
347 
348 void GLAPIENTRY
349 _mesa_InvalidateBufferData(GLuint buffer);
350 
351 
352 #endif
353