mesa: allow buffers mapped with the persistent flag to be used by the GPU
[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? */
41 static inline GLboolean
42 _mesa_bufferobj_mapped(const struct gl_buffer_object *obj)
43 {
44 return obj->Pointer != NULL;
45 }
46
47 /** Can we not use this buffer while mapped? */
48 static inline GLboolean
49 _mesa_check_disallowed_mapping(const struct gl_buffer_object *obj)
50 {
51 return _mesa_bufferobj_mapped(obj) &&
52 !(obj->AccessFlags & GL_MAP_PERSISTENT_BIT);
53 }
54
55 /**
56 * Is the given buffer object a user-created buffer object?
57 * Mesa uses default buffer objects in several places. Default buffers
58 * always have Name==0. User created buffers have Name!=0.
59 */
60 static inline GLboolean
61 _mesa_is_bufferobj(const struct gl_buffer_object *obj)
62 {
63 return obj != NULL && obj->Name != 0;
64 }
65
66
67 extern void
68 _mesa_init_buffer_objects(struct gl_context *ctx);
69
70 extern void
71 _mesa_free_buffer_objects(struct gl_context *ctx);
72
73 extern bool
74 _mesa_handle_bind_buffer_gen(struct gl_context *ctx,
75 GLenum target,
76 GLuint buffer,
77 struct gl_buffer_object **buf_handle,
78 const char *caller);
79
80 extern void
81 _mesa_update_default_objects_buffer_objects(struct gl_context *ctx);
82
83
84 extern struct gl_buffer_object *
85 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
86
87 extern void
88 _mesa_initialize_buffer_object(struct gl_context *ctx,
89 struct gl_buffer_object *obj,
90 GLuint name, GLenum target);
91
92 extern void
93 _mesa_reference_buffer_object_(struct gl_context *ctx,
94 struct gl_buffer_object **ptr,
95 struct gl_buffer_object *bufObj);
96
97 static inline void
98 _mesa_reference_buffer_object(struct gl_context *ctx,
99 struct gl_buffer_object **ptr,
100 struct gl_buffer_object *bufObj)
101 {
102 if (*ptr != bufObj)
103 _mesa_reference_buffer_object_(ctx, ptr, bufObj);
104 }
105
106 extern GLuint
107 _mesa_total_buffer_object_memory(struct gl_context *ctx);
108
109 extern void
110 _mesa_init_buffer_object_functions(struct dd_function_table *driver);
111
112
113 /*
114 * API functions
115 */
116 void GLAPIENTRY
117 _mesa_BindBuffer(GLenum target, GLuint buffer);
118
119 void GLAPIENTRY
120 _mesa_DeleteBuffers(GLsizei n, const GLuint * buffer);
121
122 void GLAPIENTRY
123 _mesa_GenBuffers(GLsizei n, GLuint * buffer);
124
125 GLboolean GLAPIENTRY
126 _mesa_IsBuffer(GLuint buffer);
127
128 void GLAPIENTRY
129 _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
130 GLbitfield flags);
131
132 void GLAPIENTRY
133 _mesa_BufferData(GLenum target, GLsizeiptrARB size,
134 const GLvoid * data, GLenum usage);
135
136 void GLAPIENTRY
137 _mesa_BufferSubData(GLenum target, GLintptrARB offset,
138 GLsizeiptrARB size, const GLvoid * data);
139
140 void GLAPIENTRY
141 _mesa_GetBufferSubData(GLenum target, GLintptrARB offset,
142 GLsizeiptrARB size, void * data);
143
144 void GLAPIENTRY
145 _mesa_ClearBufferData(GLenum target, GLenum internalformat,
146 GLenum format, GLenum type,
147 const GLvoid * data);
148
149 void GLAPIENTRY
150 _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
151 GLintptr offset, GLsizeiptr size,
152 GLenum format, GLenum type,
153 const GLvoid * data);
154
155 void * GLAPIENTRY
156 _mesa_MapBuffer(GLenum target, GLenum access);
157
158 GLboolean GLAPIENTRY
159 _mesa_UnmapBuffer(GLenum target);
160
161 void GLAPIENTRY
162 _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params);
163
164 void GLAPIENTRY
165 _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params);
166
167 void GLAPIENTRY
168 _mesa_GetBufferPointerv(GLenum target, GLenum pname, GLvoid **params);
169
170 void GLAPIENTRY
171 _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
172 GLintptr readOffset, GLintptr writeOffset,
173 GLsizeiptr size);
174
175 void * GLAPIENTRY
176 _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
177 GLbitfield access);
178
179 void GLAPIENTRY
180 _mesa_FlushMappedBufferRange(GLenum target,
181 GLintptr offset, GLsizeiptr length);
182
183 GLenum GLAPIENTRY
184 _mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
185
186 GLenum GLAPIENTRY
187 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option);
188
189 void GLAPIENTRY
190 _mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name,
191 GLenum pname, GLint* params);
192
193 void GLAPIENTRY
194 _mesa_BindBufferRange(GLenum target, GLuint index,
195 GLuint buffer, GLintptr offset, GLsizeiptr size);
196
197 void GLAPIENTRY
198 _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer);
199
200 void GLAPIENTRY
201 _mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
202 GLsizeiptr length);
203
204 void GLAPIENTRY
205 _mesa_InvalidateBufferData(GLuint buffer);
206
207
208 #endif