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 extern void
65 _mesa_init_buffer_objects(struct gl_context *ctx);
66
67 extern void
68 _mesa_free_buffer_objects(struct gl_context *ctx);
69
70 extern bool
71 _mesa_handle_bind_buffer_gen(struct gl_context *ctx,
72 GLuint buffer,
73 struct gl_buffer_object **buf_handle,
74 const char *caller);
75
76 extern void
77 _mesa_update_default_objects_buffer_objects(struct gl_context *ctx);
78
79
80 extern struct gl_buffer_object *
81 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
82
83 extern struct gl_buffer_object *
84 _mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer);
85
86 extern struct gl_buffer_object *
87 _mesa_lookup_bufferobj_err(struct gl_context *ctx, GLuint buffer,
88 const char *caller);
89
90 extern struct gl_buffer_object *
91 _mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx,
92 const GLuint *buffers,
93 GLuint index, const char *caller,
94 bool *error);
95
96 extern void
97 _mesa_initialize_buffer_object(struct gl_context *ctx,
98 struct gl_buffer_object *obj,
99 GLuint name);
100
101 extern void
102 _mesa_delete_buffer_object(struct gl_context *ctx,
103 struct gl_buffer_object *bufObj);
104
105 extern void
106 _mesa_reference_buffer_object_(struct gl_context *ctx,
107 struct gl_buffer_object **ptr,
108 struct gl_buffer_object *bufObj,
109 bool shared_binding);
110
111 /**
112 * Assign a buffer into a pointer with reference counting. The destination
113 * must be private within a context.
114 */
115 static inline void
_mesa_reference_buffer_object(struct gl_context * ctx,struct gl_buffer_object ** ptr,struct gl_buffer_object * bufObj)116 _mesa_reference_buffer_object(struct gl_context *ctx,
117 struct gl_buffer_object **ptr,
118 struct gl_buffer_object *bufObj)
119 {
120 if (*ptr != bufObj)
121 _mesa_reference_buffer_object_(ctx, ptr, bufObj, false);
122 }
123
124 /**
125 * Assign a buffer into a pointer with reference counting. The destination
126 * must be shareable among multiple contexts.
127 */
128 static inline void
_mesa_reference_buffer_object_shared(struct gl_context * ctx,struct gl_buffer_object ** ptr,struct gl_buffer_object * bufObj)129 _mesa_reference_buffer_object_shared(struct gl_context *ctx,
130 struct gl_buffer_object **ptr,
131 struct gl_buffer_object *bufObj)
132 {
133 if (*ptr != bufObj)
134 _mesa_reference_buffer_object_(ctx, ptr, bufObj, true);
135 }
136
137 extern GLuint
138 _mesa_total_buffer_object_memory(struct gl_context *ctx);
139
140 extern void
141 _mesa_init_buffer_object_functions(struct dd_function_table *driver);
142
143 extern void
144 _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
145 GLenum target, GLsizeiptr size, const GLvoid *data,
146 GLenum usage, const char *func);
147
148 extern void
149 _mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
150 GLintptr offset, GLsizeiptr size, const GLvoid *data);
151
152 extern void
153 _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
154 struct gl_buffer_object *bufObj);
155
156 extern void
157 _mesa_ClearBufferSubData_sw(struct gl_context *ctx,
158 GLintptr offset, GLsizeiptr size,
159 const GLvoid *clearValue,
160 GLsizeiptr clearValueSize,
161 struct gl_buffer_object *bufObj);
162
163 /*
164 * API functions
165 */
166 void GLAPIENTRY
167 _mesa_BindBuffer_no_error(GLenum target, GLuint buffer);
168
169 void GLAPIENTRY
170 _mesa_BindBuffer(GLenum target, GLuint buffer);
171
172 void
173 _mesa_InternalBindElementBuffer(struct gl_context *ctx,
174 struct gl_buffer_object *buf);
175
176 void GLAPIENTRY
177 _mesa_DeleteBuffers_no_error(GLsizei n, const GLuint * buffer);
178
179 void GLAPIENTRY
180 _mesa_DeleteBuffers(GLsizei n, const GLuint * buffer);
181
182 void GLAPIENTRY
183 _mesa_GenBuffers_no_error(GLsizei n, GLuint *buffers);
184
185 void GLAPIENTRY
186 _mesa_GenBuffers(GLsizei n, GLuint *buffers);
187
188 void GLAPIENTRY
189 _mesa_CreateBuffers_no_error(GLsizei n, GLuint *buffers);
190
191 void GLAPIENTRY
192 _mesa_CreateBuffers(GLsizei n, GLuint *buffers);
193
194 GLboolean GLAPIENTRY
195 _mesa_IsBuffer(GLuint buffer);
196
197 void GLAPIENTRY
198 _mesa_BufferStorage_no_error(GLenum target, GLsizeiptr size,
199 const GLvoid *data, GLbitfield flags);
200 void GLAPIENTRY
201 _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
202 GLbitfield flags);
203 void GLAPIENTRY
204 _mesa_NamedBufferStorageEXT(GLuint buffer, GLsizeiptr size,
205 const GLvoid *data, GLbitfield flags);
206 void GLAPIENTRY
207 _mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
208 GLuint memory, GLuint64 offset);
209 void GLAPIENTRY
210 _mesa_BufferStorageMemEXT_no_error(GLenum target, GLsizeiptr size,
211 GLuint memory, GLuint64 offset);
212 void GLAPIENTRY
213 _mesa_NamedBufferStorage_no_error(GLuint buffer, GLsizeiptr size,
214 const GLvoid *data, GLbitfield flags);
215 void GLAPIENTRY
216 _mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
217 GLbitfield flags);
218 void GLAPIENTRY
219 _mesa_NamedBufferStorageMemEXT(GLuint buffer, GLsizeiptr size,
220 GLuint memory, GLuint64 offset);
221 void GLAPIENTRY
222 _mesa_NamedBufferStorageMemEXT_no_error(GLuint buffer, GLsizeiptr size,
223 GLuint memory, GLuint64 offset);
224
225 void GLAPIENTRY
226 _mesa_BufferData_no_error(GLenum target, GLsizeiptr size,
227 const GLvoid *data, GLenum usage);
228
229 void GLAPIENTRY
230 _mesa_BufferData(GLenum target, GLsizeiptr size,
231 const GLvoid *data, GLenum usage);
232
233 void GLAPIENTRY
234 _mesa_NamedBufferData_no_error(GLuint buffer, GLsizeiptr size,
235 const GLvoid *data, GLenum usage);
236
237 void GLAPIENTRY
238 _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size,
239 const GLvoid *data, GLenum usage);
240 void GLAPIENTRY
241 _mesa_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size,
242 const GLvoid *data, GLenum usage);
243
244 void GLAPIENTRY
245 _mesa_BufferSubData_no_error(GLenum target, GLintptr offset,
246 GLsizeiptr size, const GLvoid *data);
247 void GLAPIENTRY
248 _mesa_BufferSubData(GLenum target, GLintptr offset,
249 GLsizeiptr size, const GLvoid *data);
250
251 void GLAPIENTRY
252 _mesa_NamedBufferSubData_no_error(GLuint buffer, GLintptr offset,
253 GLsizeiptr size, const GLvoid *data);
254 void GLAPIENTRY
255 _mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
256 GLsizeiptr size, const GLvoid *data);
257 void GLAPIENTRY
258 _mesa_NamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
259 GLsizeiptr size, const GLvoid *data);
260
261 void GLAPIENTRY
262 _mesa_GetBufferSubData(GLenum target, GLintptr offset,
263 GLsizeiptr size, GLvoid *data);
264
265 void GLAPIENTRY
266 _mesa_GetNamedBufferSubData(GLuint buffer, GLintptr offset,
267 GLsizeiptr size, GLvoid *data);
268
269 void GLAPIENTRY
270 _mesa_GetNamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
271 GLsizeiptr size, GLvoid *data);
272
273 void GLAPIENTRY
274 _mesa_ClearBufferData_no_error(GLenum target, GLenum internalformat,
275 GLenum format, GLenum type, const GLvoid *data);
276
277 void GLAPIENTRY
278 _mesa_ClearBufferData(GLenum target, GLenum internalformat,
279 GLenum format, GLenum type,
280 const GLvoid *data);
281
282 void GLAPIENTRY
283 _mesa_ClearNamedBufferData_no_error(GLuint buffer, GLenum internalformat,
284 GLenum format, GLenum type,
285 const GLvoid *data);
286
287 void GLAPIENTRY
288 _mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
289 GLenum format, GLenum type,
290 const GLvoid *data);
291
292 void GLAPIENTRY
293 _mesa_ClearNamedBufferDataEXT(GLuint buffer, GLenum internalformat,
294 GLenum format, GLenum type,
295 const GLvoid *data);
296
297 void GLAPIENTRY
298 _mesa_ClearBufferSubData_no_error(GLenum target, GLenum internalformat,
299 GLintptr offset, GLsizeiptr size,
300 GLenum format, GLenum type,
301 const GLvoid *data);
302
303 void GLAPIENTRY
304 _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
305 GLintptr offset, GLsizeiptr size,
306 GLenum format, GLenum type,
307 const GLvoid *data);
308
309 void GLAPIENTRY
310 _mesa_ClearNamedBufferSubData_no_error(GLuint buffer, GLenum internalformat,
311 GLintptr offset, GLsizeiptr size,
312 GLenum format, GLenum type,
313 const GLvoid *data);
314
315 void GLAPIENTRY
316 _mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
317 GLintptr offset, GLsizeiptr size,
318 GLenum format, GLenum type,
319 const GLvoid *data);
320
321 void GLAPIENTRY
322 _mesa_ClearNamedBufferSubDataEXT(GLuint buffer, GLenum internalformat,
323 GLintptr offset, GLsizeiptr size,
324 GLenum format, GLenum type,
325 const GLvoid *data);
326
327 GLboolean GLAPIENTRY
328 _mesa_UnmapBuffer_no_error(GLenum target);
329 GLboolean GLAPIENTRY
330 _mesa_UnmapBuffer(GLenum target);
331
332 GLboolean GLAPIENTRY
333 _mesa_UnmapNamedBufferEXT_no_error(GLuint buffer);
334 GLboolean GLAPIENTRY
335 _mesa_UnmapNamedBufferEXT(GLuint buffer);
336
337 void GLAPIENTRY
338 _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params);
339
340 void GLAPIENTRY
341 _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params);
342
343 void GLAPIENTRY
344 _mesa_GetNamedBufferParameteriv(GLuint buffer, GLenum pname, GLint *params);
345
346 void GLAPIENTRY
347 _mesa_GetNamedBufferParameterivEXT(GLuint buffer, GLenum pname, GLint *params);
348
349 void GLAPIENTRY
350 _mesa_GetNamedBufferParameteri64v(GLuint buffer, GLenum pname,
351 GLint64 *params);
352
353 void GLAPIENTRY
354 _mesa_GetBufferPointerv(GLenum target, GLenum pname, GLvoid **params);
355
356 void GLAPIENTRY
357 _mesa_GetNamedBufferPointerv(GLuint buffer, GLenum pname, GLvoid **params);
358
359 void GLAPIENTRY
360 _mesa_GetNamedBufferPointervEXT(GLuint buffer, GLenum pname, GLvoid **params);
361
362 void GLAPIENTRY
363 _mesa_CopyBufferSubData_no_error(GLenum readTarget, GLenum writeTarget,
364 GLintptr readOffset, GLintptr writeOffset,
365 GLsizeiptr size);
366 void GLAPIENTRY
367 _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
368 GLintptr readOffset, GLintptr writeOffset,
369 GLsizeiptr size);
370
371 void GLAPIENTRY
372 _mesa_NamedCopyBufferSubDataEXT(GLuint readBuffer, GLuint writeBuffer,
373 GLintptr readOffset, GLintptr writeOffset,
374 GLsizeiptr size);
375
376 void GLAPIENTRY
377 _mesa_CopyNamedBufferSubData_no_error(GLuint readBuffer, GLuint writeBuffer,
378 GLintptr readOffset,
379 GLintptr writeOffset, GLsizeiptr size);
380 void GLAPIENTRY
381 _mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
382 GLintptr readOffset, GLintptr writeOffset,
383 GLsizeiptr size);
384 void GLAPIENTRY
385 _mesa_InternalBufferSubDataCopyMESA(GLintptr srcBuffer, GLuint srcOffset,
386 GLuint dstTargetOrName, GLintptr dstOffset,
387 GLsizeiptr size, GLboolean named,
388 GLboolean ext_dsa);
389
390 void * GLAPIENTRY
391 _mesa_MapBufferRange_no_error(GLenum target, GLintptr offset,
392 GLsizeiptr length, GLbitfield access);
393 void * GLAPIENTRY
394 _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
395 GLbitfield access);
396
397 void * GLAPIENTRY
398 _mesa_MapNamedBufferRange_no_error(GLuint buffer, GLintptr offset,
399 GLsizeiptr length, GLbitfield access);
400 void * GLAPIENTRY
401 _mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
402 GLbitfield access);
403 void * GLAPIENTRY
404 _mesa_MapNamedBufferRangeEXT(GLuint buffer, GLintptr offset,
405 GLsizeiptr length, GLbitfield access);
406
407 void * GLAPIENTRY
408 _mesa_MapBuffer_no_error(GLenum target, GLenum access);
409 void * GLAPIENTRY
410 _mesa_MapBuffer(GLenum target, GLenum access);
411
412 void * GLAPIENTRY
413 _mesa_MapNamedBuffer_no_error(GLuint buffer, GLenum access);
414 void * GLAPIENTRY
415 _mesa_MapNamedBuffer(GLuint buffer, GLenum access);
416 void * GLAPIENTRY
417 _mesa_MapNamedBufferEXT(GLuint buffer, GLenum access);
418
419 void GLAPIENTRY
420 _mesa_FlushMappedBufferRange_no_error(GLenum target, GLintptr offset,
421 GLsizeiptr length);
422 void GLAPIENTRY
423 _mesa_FlushMappedBufferRange(GLenum target,
424 GLintptr offset, GLsizeiptr length);
425
426 void GLAPIENTRY
427 _mesa_FlushMappedNamedBufferRange_no_error(GLuint buffer, GLintptr offset,
428 GLsizeiptr length);
429 void GLAPIENTRY
430 _mesa_FlushMappedNamedBufferRange(GLuint buffer, GLintptr offset,
431 GLsizeiptr length);
432
433 void GLAPIENTRY
434 _mesa_FlushMappedNamedBufferRangeEXT(GLuint buffer, GLintptr offset,
435 GLsizeiptr length);
436
437 void GLAPIENTRY
438 _mesa_BindBufferRange_no_error(GLenum target, GLuint index, GLuint buffer,
439 GLintptr offset, GLsizeiptr size);
440 void GLAPIENTRY
441 _mesa_BindBufferRange(GLenum target, GLuint index,
442 GLuint buffer, GLintptr offset, GLsizeiptr size);
443
444 void GLAPIENTRY
445 _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer);
446
447 void GLAPIENTRY
448 _mesa_BindBuffersRange(GLenum target, GLuint first, GLsizei count,
449 const GLuint *buffers,
450 const GLintptr *offsets, const GLsizeiptr *sizes);
451 void GLAPIENTRY
452 _mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
453 const GLuint *buffers);
454
455 void GLAPIENTRY
456 _mesa_InvalidateBufferSubData_no_error(GLuint buffer, GLintptr offset,
457 GLsizeiptr length);
458
459 void GLAPIENTRY
460 _mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
461 GLsizeiptr length);
462
463 void GLAPIENTRY
464 _mesa_InvalidateBufferData_no_error(GLuint buffer);
465
466 void GLAPIENTRY
467 _mesa_InvalidateBufferData(GLuint buffer);
468
469 void GLAPIENTRY
470 _mesa_BufferPageCommitmentARB(GLenum target, GLintptr offset, GLsizeiptr size,
471 GLboolean commit);
472
473 void GLAPIENTRY
474 _mesa_NamedBufferPageCommitmentARB(GLuint buffer, GLintptr offset,
475 GLsizeiptr size, GLboolean commit);
476
477 void GLAPIENTRY
478 _mesa_NamedBufferPageCommitmentEXT(GLuint buffer, GLintptr offset,
479 GLsizeiptr size, GLboolean commit);
480
481 #endif
482