mesa: include mtypes.h less
[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 "errors.h"
53 #include "imports.h"
54 #include "extensions.h"
55 #include "mtypes.h"
56 #include "vbo/vbo.h"
57
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63
64 struct _glapi_table;
65
66
67 /** \name Visual-related functions */
68 /*@{*/
69
70 extern struct gl_config *
71 _mesa_create_visual( GLboolean dbFlag,
72 GLboolean stereoFlag,
73 GLint redBits,
74 GLint greenBits,
75 GLint blueBits,
76 GLint alphaBits,
77 GLint depthBits,
78 GLint stencilBits,
79 GLint accumRedBits,
80 GLint accumGreenBits,
81 GLint accumBlueBits,
82 GLint accumAlphaBits,
83 GLuint numSamples );
84
85 extern GLboolean
86 _mesa_initialize_visual( struct gl_config *v,
87 GLboolean dbFlag,
88 GLboolean stereoFlag,
89 GLint redBits,
90 GLint greenBits,
91 GLint blueBits,
92 GLint alphaBits,
93 GLint depthBits,
94 GLint stencilBits,
95 GLint accumRedBits,
96 GLint accumGreenBits,
97 GLint accumBlueBits,
98 GLint accumAlphaBits,
99 GLuint numSamples );
100
101 extern void
102 _mesa_destroy_visual( struct gl_config *vis );
103
104 /*@}*/
105
106
107 /** \name Context-related functions */
108 /*@{*/
109
110 extern GLboolean
111 _mesa_initialize_context( struct gl_context *ctx,
112 gl_api api,
113 const struct gl_config *visual,
114 struct gl_context *share_list,
115 const struct dd_function_table *driverFunctions);
116
117 extern void
118 _mesa_free_context_data( struct gl_context *ctx );
119
120 extern void
121 _mesa_destroy_context( struct gl_context *ctx );
122
123
124 extern void
125 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
126
127 extern GLboolean
128 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
129 struct gl_framebuffer *readBuffer );
130
131 extern GLboolean
132 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
133
134 extern struct gl_context *
135 _mesa_get_current_context(void);
136
137 /*@}*/
138
139 extern void
140 _mesa_init_constants(struct gl_constants *consts, gl_api api);
141
142 extern void
143 _mesa_notifySwapBuffers(struct gl_context *gc);
144
145
146 extern struct _glapi_table *
147 _mesa_get_dispatch(struct gl_context *ctx);
148
149 extern void
150 _mesa_set_context_lost_dispatch(struct gl_context *ctx);
151
152
153
154 /** \name Miscellaneous */
155 /*@{*/
156
157 extern void
158 _mesa_flush(struct gl_context *ctx);
159
160 extern void GLAPIENTRY
161 _mesa_Finish( void );
162
163 extern void GLAPIENTRY
164 _mesa_Flush( void );
165
166 /*@}*/
167
168
169 /**
170 * Are we currently between glBegin and glEnd?
171 * During execution, not display list compilation.
172 */
173 static inline GLboolean
174 _mesa_inside_begin_end(const struct gl_context *ctx)
175 {
176 return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
177 }
178
179
180 /**
181 * Are we currently between glBegin and glEnd in a display list?
182 */
183 static inline GLboolean
184 _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
185 {
186 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
187 }
188
189
190
191 /**
192 * \name Macros for flushing buffered rendering commands before state changes,
193 * checking if inside glBegin/glEnd, etc.
194 */
195 /*@{*/
196
197 /**
198 * Flush vertices.
199 *
200 * \param ctx GL context.
201 * \param newstate new state.
202 *
203 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
204 * and calls dd_function_table::FlushVertices if so. Marks
205 * __struct gl_contextRec::NewState with \p newstate.
206 */
207 #define FLUSH_VERTICES(ctx, newstate) \
208 do { \
209 if (MESA_VERBOSE & VERBOSE_STATE) \
210 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", __func__); \
211 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
212 vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
213 ctx->NewState |= newstate; \
214 } while (0)
215
216 /**
217 * Flush current state.
218 *
219 * \param ctx GL context.
220 * \param newstate new state.
221 *
222 * Checks if dd_function_table::NeedFlush is marked to flush current state,
223 * and calls dd_function_table::FlushVertices if so. Marks
224 * __struct gl_contextRec::NewState with \p newstate.
225 */
226 #define FLUSH_CURRENT(ctx, newstate) \
227 do { \
228 if (MESA_VERBOSE & VERBOSE_STATE) \
229 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", __func__); \
230 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
231 vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
232 ctx->NewState |= newstate; \
233 } while (0)
234
235 /**
236 * Macro to assert that the API call was made outside the
237 * glBegin()/glEnd() pair, with return value.
238 *
239 * \param ctx GL context.
240 * \param retval value to return in case the assertion fails.
241 */
242 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
243 do { \
244 if (_mesa_inside_begin_end(ctx)) { \
245 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
246 return retval; \
247 } \
248 } while (0)
249
250 /**
251 * Macro to assert that the API call was made outside the
252 * glBegin()/glEnd() pair.
253 *
254 * \param ctx GL context.
255 */
256 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
257 do { \
258 if (_mesa_inside_begin_end(ctx)) { \
259 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
260 return; \
261 } \
262 } while (0)
263
264 /*@}*/
265
266
267 /**
268 * Checks if the context is for Desktop GL (Compatibility or Core)
269 */
270 static inline bool
271 _mesa_is_desktop_gl(const struct gl_context *ctx)
272 {
273 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
274 }
275
276
277 /**
278 * Checks if the context is for any GLES version
279 */
280 static inline bool
281 _mesa_is_gles(const struct gl_context *ctx)
282 {
283 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
284 }
285
286
287 /**
288 * Checks if the context is for GLES 3.0 or later
289 */
290 static inline bool
291 _mesa_is_gles3(const struct gl_context *ctx)
292 {
293 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
294 }
295
296
297 /**
298 * Checks if the context is for GLES 3.1 or later
299 */
300 static inline bool
301 _mesa_is_gles31(const struct gl_context *ctx)
302 {
303 return ctx->API == API_OPENGLES2 && ctx->Version >= 31;
304 }
305
306
307 /**
308 * Checks if the context is for GLES 3.2 or later
309 */
310 static inline bool
311 _mesa_is_gles32(const struct gl_context *ctx)
312 {
313 return ctx->API == API_OPENGLES2 && ctx->Version >= 32;
314 }
315
316
317 static inline bool
318 _mesa_is_no_error_enabled(const struct gl_context *ctx)
319 {
320 return ctx->Const.ContextFlags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
321 }
322
323
324 /**
325 * Checks if the context supports geometry shaders.
326 */
327 static inline bool
328 _mesa_has_geometry_shaders(const struct gl_context *ctx)
329 {
330 return _mesa_has_OES_geometry_shader(ctx) ||
331 (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32);
332 }
333
334
335 /**
336 * Checks if the context supports compute shaders.
337 */
338 static inline bool
339 _mesa_has_compute_shaders(const struct gl_context *ctx)
340 {
341 return _mesa_has_ARB_compute_shader(ctx) ||
342 (ctx->API == API_OPENGLES2 && ctx->Version >= 31);
343 }
344
345 /**
346 * Checks if the context supports tessellation.
347 */
348 static inline GLboolean
349 _mesa_has_tessellation(const struct gl_context *ctx)
350 {
351 /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES
352 * check, so don't bother calling it.
353 */
354 return _mesa_has_OES_tessellation_shader(ctx) ||
355 _mesa_has_ARB_tessellation_shader(ctx);
356 }
357
358 static inline bool
359 _mesa_has_texture_cube_map_array(const struct gl_context *ctx)
360 {
361 return _mesa_has_ARB_texture_cube_map_array(ctx) ||
362 _mesa_has_OES_texture_cube_map_array(ctx);
363 }
364
365 #ifdef __cplusplus
366 }
367 #endif
368
369
370 #endif /* CONTEXT_H */