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