mesa: remove Driver.FlushVertices
[mesa.git] / src / mesa / main / context.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file context.h
28 * Mesa context and visual-related functions.
29 *
30 * There are three large Mesa data types/classes which are meant to be
31 * used by device drivers:
32 * - struct gl_context: this contains the Mesa rendering state
33 * - struct gl_config: this describes the color buffer (RGB vs. ci), whether
34 * or not there's a depth buffer, stencil buffer, etc.
35 * - struct gl_framebuffer: contains pointers to the depth buffer, stencil
36 * buffer, accum buffer and alpha buffers.
37 *
38 * These types should be encapsulated by corresponding device driver
39 * data types. See xmesa.h and xmesaP.h for an example.
40 *
41 * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer
42 * are base classes which the device driver must derive from.
43 *
44 * The following functions create and destroy these data types.
45 */
46
47
48 #ifndef CONTEXT_H
49 #define CONTEXT_H
50
51
52 #include "imports.h"
53 #include "mtypes.h"
54 #include "vbo/vbo.h"
55
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 struct _glapi_table;
63
64
65 /** \name Visual-related functions */
66 /*@{*/
67
68 extern struct gl_config *
69 _mesa_create_visual( GLboolean dbFlag,
70 GLboolean stereoFlag,
71 GLint redBits,
72 GLint greenBits,
73 GLint blueBits,
74 GLint alphaBits,
75 GLint depthBits,
76 GLint stencilBits,
77 GLint accumRedBits,
78 GLint accumGreenBits,
79 GLint accumBlueBits,
80 GLint accumAlphaBits,
81 GLint numSamples );
82
83 extern GLboolean
84 _mesa_initialize_visual( struct gl_config *v,
85 GLboolean dbFlag,
86 GLboolean stereoFlag,
87 GLint redBits,
88 GLint greenBits,
89 GLint blueBits,
90 GLint alphaBits,
91 GLint depthBits,
92 GLint stencilBits,
93 GLint accumRedBits,
94 GLint accumGreenBits,
95 GLint accumBlueBits,
96 GLint accumAlphaBits,
97 GLint numSamples );
98
99 extern void
100 _mesa_destroy_visual( struct gl_config *vis );
101
102 /*@}*/
103
104
105 /** \name Context-related functions */
106 /*@{*/
107
108 extern GLboolean
109 _mesa_initialize_context( struct gl_context *ctx,
110 gl_api api,
111 const struct gl_config *visual,
112 struct gl_context *share_list,
113 const struct dd_function_table *driverFunctions);
114
115 extern struct gl_context *
116 _mesa_create_context(gl_api api,
117 const struct gl_config *visual,
118 struct gl_context *share_list,
119 const struct dd_function_table *driverFunctions);
120
121 extern void
122 _mesa_free_context_data( struct gl_context *ctx );
123
124 extern void
125 _mesa_destroy_context( struct gl_context *ctx );
126
127
128 extern void
129 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
130
131
132 extern void
133 _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
134
135 extern GLboolean
136 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
137 struct gl_framebuffer *readBuffer );
138
139 extern GLboolean
140 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
141
142 extern struct gl_context *
143 _mesa_get_current_context(void);
144
145 /*@}*/
146
147 extern void
148 _mesa_init_constants(struct gl_constants *consts, gl_api api);
149
150 extern void
151 _mesa_init_get_hash(struct gl_context *ctx);
152
153 extern void
154 _mesa_notifySwapBuffers(struct gl_context *gc);
155
156
157 extern struct _glapi_table *
158 _mesa_get_dispatch(struct gl_context *ctx);
159
160
161 extern GLboolean
162 _mesa_valid_to_render(struct gl_context *ctx, const char *where);
163
164
165
166 /** \name Miscellaneous */
167 /*@{*/
168
169 extern void
170 _mesa_record_error( struct gl_context *ctx, GLenum error );
171
172
173 extern void
174 _mesa_finish(struct gl_context *ctx);
175
176 extern void
177 _mesa_flush(struct gl_context *ctx);
178
179 extern void GLAPIENTRY
180 _mesa_Finish( void );
181
182 extern void GLAPIENTRY
183 _mesa_Flush( void );
184
185 /*@}*/
186
187
188 /**
189 * Are we currently between glBegin and glEnd?
190 * During execution, not display list compilation.
191 */
192 static inline GLboolean
193 _mesa_inside_begin_end(const struct gl_context *ctx)
194 {
195 return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
196 }
197
198
199 /**
200 * Are we currently between glBegin and glEnd in a display list?
201 */
202 static inline GLboolean
203 _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
204 {
205 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
206 }
207
208
209
210 /**
211 * \name Macros for flushing buffered rendering commands before state changes,
212 * checking if inside glBegin/glEnd, etc.
213 */
214 /*@{*/
215
216 /**
217 * Flush vertices.
218 *
219 * \param ctx GL context.
220 * \param newstate new state.
221 *
222 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
223 * and calls dd_function_table::FlushVertices if so. Marks
224 * __struct gl_contextRec::NewState with \p newstate.
225 */
226 #define FLUSH_VERTICES(ctx, newstate) \
227 do { \
228 if (MESA_VERBOSE & VERBOSE_STATE) \
229 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
230 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
231 vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
232 ctx->NewState |= newstate; \
233 } while (0)
234
235 /**
236 * Flush current state.
237 *
238 * \param ctx GL context.
239 * \param newstate new state.
240 *
241 * Checks if dd_function_table::NeedFlush is marked to flush current state,
242 * and calls dd_function_table::FlushVertices if so. Marks
243 * __struct gl_contextRec::NewState with \p newstate.
244 */
245 #define FLUSH_CURRENT(ctx, newstate) \
246 do { \
247 if (MESA_VERBOSE & VERBOSE_STATE) \
248 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
249 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
250 vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
251 ctx->NewState |= newstate; \
252 } while (0)
253
254 /**
255 * Macro to assert that the API call was made outside the
256 * glBegin()/glEnd() pair, with return value.
257 *
258 * \param ctx GL context.
259 * \param retval value to return in case the assertion fails.
260 */
261 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
262 do { \
263 if (_mesa_inside_begin_end(ctx)) { \
264 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
265 return retval; \
266 } \
267 } while (0)
268
269 /**
270 * Macro to assert that the API call was made outside the
271 * glBegin()/glEnd() pair.
272 *
273 * \param ctx GL context.
274 */
275 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
276 do { \
277 if (_mesa_inside_begin_end(ctx)) { \
278 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
279 return; \
280 } \
281 } while (0)
282
283 /*@}*/
284
285
286 /**
287 * Checks if the context is for Desktop GL (Compatibility or Core)
288 */
289 static inline bool
290 _mesa_is_desktop_gl(const struct gl_context *ctx)
291 {
292 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
293 }
294
295
296 /**
297 * Checks if the context is for any GLES version
298 */
299 static inline bool
300 _mesa_is_gles(const struct gl_context *ctx)
301 {
302 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
303 }
304
305
306 /**
307 * Checks if the context is for GLES 3.0 or later
308 */
309 static inline bool
310 _mesa_is_gles3(const struct gl_context *ctx)
311 {
312 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
313 }
314
315
316 /**
317 * Checks if the context is for GLES 3.1 or later
318 */
319 static inline bool
320 _mesa_is_gles31(const struct gl_context *ctx)
321 {
322 return ctx->API == API_OPENGLES2 && ctx->Version >= 31;
323 }
324
325
326 /**
327 * Checks if the context supports geometry shaders.
328 */
329 static inline bool
330 _mesa_has_geometry_shaders(const struct gl_context *ctx)
331 {
332 return _mesa_is_desktop_gl(ctx) &&
333 (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4);
334 }
335
336
337 /**
338 * Checks if the context supports compute shaders.
339 */
340 static inline bool
341 _mesa_has_compute_shaders(const struct gl_context *ctx)
342 {
343 return (ctx->API == API_OPENGL_CORE && ctx->Extensions.ARB_compute_shader) ||
344 (ctx->API == API_OPENGLES2 && ctx->Version >= 31);
345 }
346
347 /**
348 * Checks if the context supports shader subroutines.
349 */
350 static inline bool
351 _mesa_has_shader_subroutine(const struct gl_context *ctx)
352 {
353 return ctx->API == API_OPENGL_CORE &&
354 (ctx->Version >= 40 || ctx->Extensions.ARB_shader_subroutine);
355 }
356
357 /**
358 * Checks if the context supports tessellation.
359 */
360 static inline GLboolean
361 _mesa_has_tessellation(const struct gl_context *ctx)
362 {
363 return ctx->API == API_OPENGL_CORE &&
364 ctx->Extensions.ARB_tessellation_shader;
365 }
366
367
368 #ifdef __cplusplus
369 }
370 #endif
371
372
373 #endif /* CONTEXT_H */