2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
28 * Mesa context and visual-related functions.
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.
38 * These types should be encapsulated by corresponding device driver
39 * data types. See xmesa.h and xmesaP.h for an example.
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.
44 * The following functions create and destroy these data types.
54 #include "extensions.h"
67 /** \name Visual-related functions */
70 extern struct gl_config
*
71 _mesa_create_visual( GLboolean dbFlag
,
86 _mesa_initialize_visual( struct gl_config
*v
,
102 _mesa_destroy_visual( struct gl_config
*vis
);
107 /** \name Context-related functions */
111 _mesa_initialize_context( struct gl_context
*ctx
,
113 const struct gl_config
*visual
,
114 struct gl_context
*share_list
,
115 const struct dd_function_table
*driverFunctions
);
118 _mesa_free_context_data( struct gl_context
*ctx
);
121 _mesa_destroy_context( struct gl_context
*ctx
);
125 _mesa_copy_context(const struct gl_context
*src
, struct gl_context
*dst
, GLuint mask
);
128 _mesa_make_current( struct gl_context
*ctx
, struct gl_framebuffer
*drawBuffer
,
129 struct gl_framebuffer
*readBuffer
);
132 _mesa_share_state(struct gl_context
*ctx
, struct gl_context
*ctxToShare
);
134 extern struct gl_context
*
135 _mesa_get_current_context(void);
140 _mesa_init_constants(struct gl_constants
*consts
, gl_api api
);
143 _mesa_notifySwapBuffers(struct gl_context
*gc
);
146 extern struct _glapi_table
*
147 _mesa_get_dispatch(struct gl_context
*ctx
);
150 _mesa_set_context_lost_dispatch(struct gl_context
*ctx
);
154 /** \name Miscellaneous */
158 _mesa_flush(struct gl_context
*ctx
);
160 extern void GLAPIENTRY
161 _mesa_Finish( void );
163 extern void GLAPIENTRY
170 * Are we currently between glBegin and glEnd?
171 * During execution, not display list compilation.
173 static inline GLboolean
174 _mesa_inside_begin_end(const struct gl_context
*ctx
)
176 return ctx
->Driver
.CurrentExecPrimitive
!= PRIM_OUTSIDE_BEGIN_END
;
181 * Are we currently between glBegin and glEnd in a display list?
183 static inline GLboolean
184 _mesa_inside_dlist_begin_end(const struct gl_context
*ctx
)
186 return ctx
->Driver
.CurrentSavePrimitive
<= PRIM_MAX
;
192 * \name Macros for flushing buffered rendering commands before state changes,
193 * checking if inside glBegin/glEnd, etc.
200 * \param ctx GL context.
201 * \param newstate new state.
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.
207 #define FLUSH_VERTICES(ctx, newstate) \
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; \
217 * Flush current state.
219 * \param ctx GL context.
220 * \param newstate new state.
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.
226 #define FLUSH_CURRENT(ctx, newstate) \
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; \
238 * \param ctx GL context.
240 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices
241 * or current state and calls dd_function_table::FlushVertices if so.
243 #define FLUSH_FOR_DRAW(ctx) \
245 if (MESA_VERBOSE & VERBOSE_STATE) \
246 _mesa_debug(ctx, "FLUSH_FOR_DRAW in %s\n", __func__); \
247 if (ctx->Driver.NeedFlush) \
248 vbo_exec_FlushVertices(ctx, ctx->Driver.NeedFlush); \
252 * Macro to assert that the API call was made outside the
253 * glBegin()/glEnd() pair, with return value.
255 * \param ctx GL context.
256 * \param retval value to return in case the assertion fails.
258 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
260 if (_mesa_inside_begin_end(ctx)) { \
261 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
267 * Macro to assert that the API call was made outside the
268 * glBegin()/glEnd() pair.
270 * \param ctx GL context.
272 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
274 if (_mesa_inside_begin_end(ctx)) { \
275 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
284 * Checks if the context is for Desktop GL (Compatibility or Core)
287 _mesa_is_desktop_gl(const struct gl_context
*ctx
)
289 return ctx
->API
== API_OPENGL_COMPAT
|| ctx
->API
== API_OPENGL_CORE
;
294 * Checks if the context is for any GLES version
297 _mesa_is_gles(const struct gl_context
*ctx
)
299 return ctx
->API
== API_OPENGLES
|| ctx
->API
== API_OPENGLES2
;
304 * Checks if the context is for GLES 3.0 or later
307 _mesa_is_gles3(const struct gl_context
*ctx
)
309 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30;
314 * Checks if the context is for GLES 3.1 or later
317 _mesa_is_gles31(const struct gl_context
*ctx
)
319 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 31;
324 * Checks if the context is for GLES 3.2 or later
327 _mesa_is_gles32(const struct gl_context
*ctx
)
329 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 32;
334 _mesa_is_no_error_enabled(const struct gl_context
*ctx
)
336 return ctx
->Const
.ContextFlags
& GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
341 _mesa_has_integer_textures(const struct gl_context
*ctx
)
343 return _mesa_has_EXT_texture_integer(ctx
) || _mesa_is_gles3(ctx
);
347 _mesa_has_texture_rgb10_a2ui(const struct gl_context
*ctx
)
349 return _mesa_has_ARB_texture_rgb10_a2ui(ctx
) || _mesa_is_gles3(ctx
);
353 _mesa_has_float_depth_buffer(const struct gl_context
*ctx
)
355 return _mesa_has_ARB_depth_buffer_float(ctx
) || _mesa_is_gles3(ctx
);
359 _mesa_has_packed_float(const struct gl_context
*ctx
)
361 return _mesa_has_EXT_packed_float(ctx
) || _mesa_is_gles3(ctx
);
365 * Checks if the context supports geometry shaders.
368 _mesa_has_geometry_shaders(const struct gl_context
*ctx
)
370 return _mesa_has_OES_geometry_shader(ctx
) ||
371 (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32);
376 * Checks if the context supports compute shaders.
379 _mesa_has_compute_shaders(const struct gl_context
*ctx
)
381 return _mesa_has_ARB_compute_shader(ctx
) ||
382 (ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 31);
386 * Checks if the context supports tessellation.
389 _mesa_has_tessellation(const struct gl_context
*ctx
)
391 /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES
392 * check, so don't bother calling it.
394 return _mesa_has_OES_tessellation_shader(ctx
) ||
395 _mesa_has_ARB_tessellation_shader(ctx
);
399 _mesa_has_texture_cube_map_array(const struct gl_context
*ctx
)
401 return _mesa_has_ARB_texture_cube_map_array(ctx
) ||
402 _mesa_has_OES_texture_cube_map_array(ctx
);
406 _mesa_has_texture_view(const struct gl_context
*ctx
)
408 return _mesa_has_ARB_texture_view(ctx
) ||
409 _mesa_has_OES_texture_view(ctx
);
417 #endif /* CONTEXT_H */