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.
53 #include "extensions.h"
66 /** \name Visual-related functions */
69 extern struct gl_config
*
70 _mesa_create_visual( GLboolean dbFlag
,
85 _mesa_initialize_visual( struct gl_config
*v
,
101 _mesa_destroy_visual( struct gl_config
*vis
);
106 /** \name Context-related functions */
110 _mesa_initialize_context( struct gl_context
*ctx
,
112 const struct gl_config
*visual
,
113 struct gl_context
*share_list
,
114 const struct dd_function_table
*driverFunctions
);
117 _mesa_free_context_data( struct gl_context
*ctx
);
120 _mesa_destroy_context( struct gl_context
*ctx
);
124 _mesa_copy_context(const struct gl_context
*src
, struct gl_context
*dst
, GLuint mask
);
128 _mesa_check_init_viewport(struct gl_context
*ctx
, GLuint width
, GLuint height
);
131 _mesa_make_current( struct gl_context
*ctx
, struct gl_framebuffer
*drawBuffer
,
132 struct gl_framebuffer
*readBuffer
);
135 _mesa_share_state(struct gl_context
*ctx
, struct gl_context
*ctxToShare
);
137 extern struct gl_context
*
138 _mesa_get_current_context(void);
143 _mesa_init_constants(struct gl_constants
*consts
, gl_api api
);
146 _mesa_notifySwapBuffers(struct gl_context
*gc
);
149 extern struct _glapi_table
*
150 _mesa_get_dispatch(struct gl_context
*ctx
);
153 _mesa_set_context_lost_dispatch(struct gl_context
*ctx
);
156 _mesa_valid_to_render(struct gl_context
*ctx
, const char *where
);
160 /** \name Miscellaneous */
164 _mesa_record_error( struct gl_context
*ctx
, GLenum error
);
168 _mesa_finish(struct gl_context
*ctx
);
171 _mesa_flush(struct gl_context
*ctx
);
173 extern void GLAPIENTRY
174 _mesa_Finish( void );
176 extern void GLAPIENTRY
183 * Are we currently between glBegin and glEnd?
184 * During execution, not display list compilation.
186 static inline GLboolean
187 _mesa_inside_begin_end(const struct gl_context
*ctx
)
189 return ctx
->Driver
.CurrentExecPrimitive
!= PRIM_OUTSIDE_BEGIN_END
;
194 * Are we currently between glBegin and glEnd in a display list?
196 static inline GLboolean
197 _mesa_inside_dlist_begin_end(const struct gl_context
*ctx
)
199 return ctx
->Driver
.CurrentSavePrimitive
<= PRIM_MAX
;
205 * \name Macros for flushing buffered rendering commands before state changes,
206 * checking if inside glBegin/glEnd, etc.
213 * \param ctx GL context.
214 * \param newstate new state.
216 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
217 * and calls dd_function_table::FlushVertices if so. Marks
218 * __struct gl_contextRec::NewState with \p newstate.
220 #define FLUSH_VERTICES(ctx, newstate) \
222 if (MESA_VERBOSE & VERBOSE_STATE) \
223 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
224 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
225 vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
226 ctx->NewState |= newstate; \
230 * Flush current state.
232 * \param ctx GL context.
233 * \param newstate new state.
235 * Checks if dd_function_table::NeedFlush is marked to flush current state,
236 * and calls dd_function_table::FlushVertices if so. Marks
237 * __struct gl_contextRec::NewState with \p newstate.
239 #define FLUSH_CURRENT(ctx, newstate) \
241 if (MESA_VERBOSE & VERBOSE_STATE) \
242 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
243 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
244 vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
245 ctx->NewState |= newstate; \
249 * Macro to assert that the API call was made outside the
250 * glBegin()/glEnd() pair, with return value.
252 * \param ctx GL context.
253 * \param retval value to return in case the assertion fails.
255 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
257 if (_mesa_inside_begin_end(ctx)) { \
258 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
264 * Macro to assert that the API call was made outside the
265 * glBegin()/glEnd() pair.
267 * \param ctx GL context.
269 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
271 if (_mesa_inside_begin_end(ctx)) { \
272 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
281 * Checks if the context is for Desktop GL (Compatibility or Core)
284 _mesa_is_desktop_gl(const struct gl_context
*ctx
)
286 return ctx
->API
== API_OPENGL_COMPAT
|| ctx
->API
== API_OPENGL_CORE
;
291 * Checks if the context is for any GLES version
294 _mesa_is_gles(const struct gl_context
*ctx
)
296 return ctx
->API
== API_OPENGLES
|| ctx
->API
== API_OPENGLES2
;
301 * Checks if the context is for GLES 3.0 or later
304 _mesa_is_gles3(const struct gl_context
*ctx
)
306 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30;
311 * Checks if the context is for GLES 3.1 or later
314 _mesa_is_gles31(const struct gl_context
*ctx
)
316 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 31;
321 * Checks if the context supports geometry shaders.
324 _mesa_has_geometry_shaders(const struct gl_context
*ctx
)
326 return _mesa_has_OES_geometry_shader(ctx
) ||
327 (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32);
332 * Checks if the context supports compute shaders.
335 _mesa_has_compute_shaders(const struct gl_context
*ctx
)
337 return _mesa_has_ARB_compute_shader(ctx
) ||
338 (ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 31);
342 * Checks if the context supports tessellation.
344 static inline GLboolean
345 _mesa_has_tessellation(const struct gl_context
*ctx
)
347 /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES
348 * check, so don't bother calling it.
350 return _mesa_has_OES_tessellation_shader(ctx
) ||
351 _mesa_has_ARB_tessellation_shader(ctx
);
355 _mesa_has_texture_cube_map_array(const struct gl_context
*ctx
)
357 return _mesa_has_ARB_texture_cube_map_array(ctx
) ||
358 _mesa_has_OES_texture_cube_map_array(ctx
);
366 #endif /* CONTEXT_H */