jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 3 | * |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 5 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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: |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 12 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 15 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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 |
Kenneth Graunke | 3d8d5b2 | 2013-04-21 13:46:48 -0700 | [diff] [blame] | 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. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 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: |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 32 | * - struct gl_context: this contains the Mesa rendering state |
Brian Paul | 032a7ef | 2011-04-13 07:35:25 -0600 | [diff] [blame] | 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. |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 37 | * |
| 38 | * These types should be encapsulated by corresponding device driver |
| 39 | * data types. See xmesa.h and xmesaP.h for an example. |
| 40 | * |
Brian Paul | 032a7ef | 2011-04-13 07:35:25 -0600 | [diff] [blame] | 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. |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 43 | * |
| 44 | * The following functions create and destroy these data types. |
| 45 | */ |
| 46 | |
| 47 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 48 | #ifndef CONTEXT_H |
| 49 | #define CONTEXT_H |
| 50 | |
| 51 | |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 52 | #include "imports.h" |
Nanley Chery | ab129a4 | 2015-09-17 15:49:40 -0700 | [diff] [blame] | 53 | #include "extensions.h" |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 54 | #include "mtypes.h" |
Marek Olšák | 72a5dff | 2015-09-27 21:28:22 +0200 | [diff] [blame] | 55 | #include "vbo/vbo.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 56 | |
| 57 | |
José Fonseca | 63e7a4c | 2011-11-09 10:20:51 +0000 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
| 62 | |
Brian Paul | 27a8432 | 2009-02-22 16:29:30 -0700 | [diff] [blame] | 63 | struct _glapi_table; |
| 64 | |
| 65 | |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 66 | /** \name Visual-related functions */ |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 67 | /*@{*/ |
| 68 | |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 69 | extern struct gl_config * |
Ian Romanick | fcf438e | 2010-02-24 18:49:33 -0800 | [diff] [blame] | 70 | _mesa_create_visual( GLboolean dbFlag, |
Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 71 | GLboolean stereoFlag, |
| 72 | GLint redBits, |
| 73 | GLint greenBits, |
| 74 | GLint blueBits, |
| 75 | GLint alphaBits, |
Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 76 | GLint depthBits, |
| 77 | GLint stencilBits, |
| 78 | GLint accumRedBits, |
| 79 | GLint accumGreenBits, |
| 80 | GLint accumBlueBits, |
| 81 | GLint accumAlphaBits, |
| 82 | GLint numSamples ); |
| 83 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 84 | extern GLboolean |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 85 | _mesa_initialize_visual( struct gl_config *v, |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 86 | GLboolean dbFlag, |
| 87 | GLboolean stereoFlag, |
| 88 | GLint redBits, |
| 89 | GLint greenBits, |
| 90 | GLint blueBits, |
| 91 | GLint alphaBits, |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 92 | GLint depthBits, |
| 93 | GLint stencilBits, |
| 94 | GLint accumRedBits, |
| 95 | GLint accumGreenBits, |
| 96 | GLint accumBlueBits, |
| 97 | GLint accumAlphaBits, |
| 98 | GLint numSamples ); |
| 99 | |
Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 100 | extern void |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 101 | _mesa_destroy_visual( struct gl_config *vis ); |
Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 102 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 103 | /*@}*/ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 104 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 105 | |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 106 | /** \name Context-related functions */ |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 107 | /*@{*/ |
| 108 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 109 | extern GLboolean |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 110 | _mesa_initialize_context( struct gl_context *ctx, |
Brian Paul | 5e4ca1c | 2011-02-08 19:25:04 -0700 | [diff] [blame] | 111 | gl_api api, |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 112 | const struct gl_config *visual, |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 113 | struct gl_context *share_list, |
Brian Paul | 733dba2 | 2012-09-29 08:47:56 -0600 | [diff] [blame] | 114 | const struct dd_function_table *driverFunctions); |
Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 115 | |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 116 | extern struct gl_context * |
Brian Paul | 6f2f449 | 2011-02-08 19:25:04 -0700 | [diff] [blame] | 117 | _mesa_create_context(gl_api api, |
| 118 | const struct gl_config *visual, |
| 119 | struct gl_context *share_list, |
Brian Paul | 733dba2 | 2012-09-29 08:47:56 -0600 | [diff] [blame] | 120 | const struct dd_function_table *driverFunctions); |
Kristian Høgsberg | 2ab18d6 | 2010-04-22 09:25:51 -0400 | [diff] [blame] | 121 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 122 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 123 | _mesa_free_context_data( struct gl_context *ctx ); |
Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 124 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 125 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 126 | _mesa_destroy_context( struct gl_context *ctx ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 127 | |
Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 128 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 129 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 130 | _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask); |
Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 131 | |
| 132 | |
Brian Paul | 3f856c6 | 2009-06-17 08:35:55 -0600 | [diff] [blame] | 133 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 134 | _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height); |
Brian Paul | 3f856c6 | 2009-06-17 08:35:55 -0600 | [diff] [blame] | 135 | |
José Fonseca | 29c6c8e | 2009-05-30 12:38:45 -0700 | [diff] [blame] | 136 | extern GLboolean |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 137 | _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer, |
Kristian Høgsberg | 31aca27 | 2010-10-12 12:02:01 -0400 | [diff] [blame] | 138 | struct gl_framebuffer *readBuffer ); |
Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 139 | |
Brian Paul | 635ee2d | 2005-04-15 17:25:07 +0000 | [diff] [blame] | 140 | extern GLboolean |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 141 | _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare); |
Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 142 | |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 143 | extern struct gl_context * |
Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 144 | _mesa_get_current_context(void); |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 145 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 146 | /*@}*/ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 147 | |
Kristian Høgsberg | 199b089 | 2010-05-11 12:07:10 -0400 | [diff] [blame] | 148 | extern void |
Marek Olšák | ee9a2b1 | 2014-08-03 04:51:31 +0200 | [diff] [blame] | 149 | _mesa_init_constants(struct gl_constants *consts, gl_api api); |
| 150 | |
| 151 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 152 | _mesa_init_get_hash(struct gl_context *ctx); |
Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 153 | |
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 154 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 155 | _mesa_notifySwapBuffers(struct gl_context *gc); |
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 156 | |
Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 157 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 158 | extern struct _glapi_table * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 159 | _mesa_get_dispatch(struct gl_context *ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 160 | |
| 161 | |
Brian Paul | 56c4226 | 2009-08-14 10:45:17 -0600 | [diff] [blame] | 162 | extern GLboolean |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 163 | _mesa_valid_to_render(struct gl_context *ctx, const char *where); |
Brian Paul | 56c4226 | 2009-08-14 10:45:17 -0600 | [diff] [blame] | 164 | |
| 165 | |
| 166 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 167 | /** \name Miscellaneous */ |
| 168 | /*@{*/ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 169 | |
Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 170 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 171 | _mesa_record_error( struct gl_context *ctx, GLenum error ); |
Brian Paul | d09a1d8 | 2002-06-13 04:49:17 +0000 | [diff] [blame] | 172 | |
Brian Paul | 4837e01 | 2009-10-22 18:16:10 -0600 | [diff] [blame] | 173 | |
| 174 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 175 | _mesa_finish(struct gl_context *ctx); |
Brian Paul | 4837e01 | 2009-10-22 18:16:10 -0600 | [diff] [blame] | 176 | |
| 177 | extern void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 178 | _mesa_flush(struct gl_context *ctx); |
Brian Paul | 4837e01 | 2009-10-22 18:16:10 -0600 | [diff] [blame] | 179 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 180 | extern void GLAPIENTRY |
Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 181 | _mesa_Finish( void ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 182 | |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 183 | extern void GLAPIENTRY |
Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 184 | _mesa_Flush( void ); |
| 185 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 186 | /*@}*/ |
Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 187 | |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 188 | |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 189 | /** |
Brian Paul | 976b529 | 2013-04-23 10:53:00 -0600 | [diff] [blame] | 190 | * Are we currently between glBegin and glEnd? |
| 191 | * During execution, not display list compilation. |
| 192 | */ |
| 193 | static inline GLboolean |
| 194 | _mesa_inside_begin_end(const struct gl_context *ctx) |
| 195 | { |
| 196 | return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /** |
Brian Paul | f74da3e | 2013-04-23 10:57:45 -0600 | [diff] [blame] | 201 | * Are we currently between glBegin and glEnd in a display list? |
| 202 | */ |
| 203 | static inline GLboolean |
| 204 | _mesa_inside_dlist_begin_end(const struct gl_context *ctx) |
| 205 | { |
Brian Paul | 84e62b7 | 2013-05-01 19:15:32 -0600 | [diff] [blame] | 206 | return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX; |
Brian Paul | f74da3e | 2013-04-23 10:57:45 -0600 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
| 210 | |
| 211 | /** |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 212 | * \name Macros for flushing buffered rendering commands before state changes, |
| 213 | * checking if inside glBegin/glEnd, etc. |
| 214 | */ |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 215 | /*@{*/ |
| 216 | |
| 217 | /** |
| 218 | * Flush vertices. |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 219 | * |
| 220 | * \param ctx GL context. |
| 221 | * \param newstate new state. |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 222 | * |
| 223 | * Checks if dd_function_table::NeedFlush is marked to flush stored vertices, |
| 224 | * and calls dd_function_table::FlushVertices if so. Marks |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 225 | * __struct gl_contextRec::NewState with \p newstate. |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 226 | */ |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 227 | #define FLUSH_VERTICES(ctx, newstate) \ |
| 228 | do { \ |
| 229 | if (MESA_VERBOSE & VERBOSE_STATE) \ |
| 230 | _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\ |
| 231 | if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \ |
Marek Olšák | 72a5dff | 2015-09-27 21:28:22 +0200 | [diff] [blame] | 232 | vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \ |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 233 | ctx->NewState |= newstate; \ |
| 234 | } while (0) |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Flush current state. |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 238 | * |
| 239 | * \param ctx GL context. |
| 240 | * \param newstate new state. |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 241 | * |
| 242 | * Checks if dd_function_table::NeedFlush is marked to flush current state, |
| 243 | * and calls dd_function_table::FlushVertices if so. Marks |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 244 | * __struct gl_contextRec::NewState with \p newstate. |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 245 | */ |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 246 | #define FLUSH_CURRENT(ctx, newstate) \ |
| 247 | do { \ |
| 248 | if (MESA_VERBOSE & VERBOSE_STATE) \ |
| 249 | _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \ |
| 250 | if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \ |
Marek Olšák | 72a5dff | 2015-09-27 21:28:22 +0200 | [diff] [blame] | 251 | vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \ |
Brian Paul | 12f25eb | 2011-02-21 17:01:00 -0700 | [diff] [blame] | 252 | ctx->NewState |= newstate; \ |
| 253 | } while (0) |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * Macro to assert that the API call was made outside the |
| 257 | * glBegin()/glEnd() pair, with return value. |
| 258 | * |
| 259 | * \param ctx GL context. |
Brian Paul | 05720e1 | 2011-10-25 08:45:37 -0600 | [diff] [blame] | 260 | * \param retval value to return in case the assertion fails. |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 261 | */ |
| 262 | #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \ |
| 263 | do { \ |
Brian Paul | 976b529 | 2013-04-23 10:53:00 -0600 | [diff] [blame] | 264 | if (_mesa_inside_begin_end(ctx)) { \ |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 265 | _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 266 | return retval; \ |
| 267 | } \ |
| 268 | } while (0) |
| 269 | |
| 270 | /** |
| 271 | * Macro to assert that the API call was made outside the |
| 272 | * glBegin()/glEnd() pair. |
| 273 | * |
| 274 | * \param ctx GL context. |
| 275 | */ |
| 276 | #define ASSERT_OUTSIDE_BEGIN_END(ctx) \ |
| 277 | do { \ |
Brian Paul | 976b529 | 2013-04-23 10:53:00 -0600 | [diff] [blame] | 278 | if (_mesa_inside_begin_end(ctx)) { \ |
Brian Paul | a623e00 | 2006-07-20 04:24:42 +0000 | [diff] [blame] | 279 | _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 280 | return; \ |
| 281 | } \ |
| 282 | } while (0) |
| 283 | |
Brian Paul | 06588db | 2003-09-18 16:45:44 +0000 | [diff] [blame] | 284 | /*@}*/ |
| 285 | |
| 286 | |
Jordan Justen | 3d284dc | 2012-07-19 11:01:27 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Checks if the context is for Desktop GL (Compatibility or Core) |
| 289 | */ |
Ian Romanick | fa3475b | 2015-04-28 11:57:39 -0700 | [diff] [blame] | 290 | static inline bool |
Jordan Justen | 3d284dc | 2012-07-19 11:01:27 -0700 | [diff] [blame] | 291 | _mesa_is_desktop_gl(const struct gl_context *ctx) |
| 292 | { |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 293 | return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE; |
Jordan Justen | 3d284dc | 2012-07-19 11:01:27 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
| 297 | /** |
| 298 | * Checks if the context is for any GLES version |
| 299 | */ |
Ian Romanick | fa3475b | 2015-04-28 11:57:39 -0700 | [diff] [blame] | 300 | static inline bool |
Jordan Justen | 3d284dc | 2012-07-19 11:01:27 -0700 | [diff] [blame] | 301 | _mesa_is_gles(const struct gl_context *ctx) |
| 302 | { |
| 303 | return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2; |
| 304 | } |
| 305 | |
| 306 | |
Ian Romanick | 2a1ca4f | 2012-08-14 13:24:00 -0700 | [diff] [blame] | 307 | /** |
Ian Romanick | 7efc11e | 2015-04-28 11:58:56 -0700 | [diff] [blame] | 308 | * Checks if the context is for GLES 3.0 or later |
Ian Romanick | 2a1ca4f | 2012-08-14 13:24:00 -0700 | [diff] [blame] | 309 | */ |
Ian Romanick | fa3475b | 2015-04-28 11:57:39 -0700 | [diff] [blame] | 310 | static inline bool |
Ian Romanick | 2a1ca4f | 2012-08-14 13:24:00 -0700 | [diff] [blame] | 311 | _mesa_is_gles3(const struct gl_context *ctx) |
| 312 | { |
| 313 | return ctx->API == API_OPENGLES2 && ctx->Version >= 30; |
| 314 | } |
| 315 | |
| 316 | |
Paul Berry | b272a01 | 2013-07-28 09:23:11 -0700 | [diff] [blame] | 317 | /** |
Ian Romanick | 7efc11e | 2015-04-28 11:58:56 -0700 | [diff] [blame] | 318 | * Checks if the context is for GLES 3.1 or later |
| 319 | */ |
| 320 | static inline bool |
| 321 | _mesa_is_gles31(const struct gl_context *ctx) |
| 322 | { |
| 323 | return ctx->API == API_OPENGLES2 && ctx->Version >= 31; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /** |
Paul Berry | b272a01 | 2013-07-28 09:23:11 -0700 | [diff] [blame] | 328 | * Checks if the context supports geometry shaders. |
| 329 | */ |
Ian Romanick | fa3475b | 2015-04-28 11:57:39 -0700 | [diff] [blame] | 330 | static inline bool |
Paul Berry | b272a01 | 2013-07-28 09:23:11 -0700 | [diff] [blame] | 331 | _mesa_has_geometry_shaders(const struct gl_context *ctx) |
| 332 | { |
Marta Lofstedt | 3e640c2 | 2016-01-21 16:17:32 +0100 | [diff] [blame] | 333 | return _mesa_has_OES_geometry_shader(ctx) || |
| 334 | (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32); |
Paul Berry | b272a01 | 2013-07-28 09:23:11 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
Jordan Justen | 2cd2831 | 2015-02-14 12:53:42 -0800 | [diff] [blame] | 338 | /** |
| 339 | * Checks if the context supports compute shaders. |
| 340 | */ |
| 341 | static inline bool |
| 342 | _mesa_has_compute_shaders(const struct gl_context *ctx) |
| 343 | { |
| 344 | return (ctx->API == API_OPENGL_CORE && ctx->Extensions.ARB_compute_shader) || |
| 345 | (ctx->API == API_OPENGLES2 && ctx->Version >= 31); |
| 346 | } |
| 347 | |
Dave Airlie | d8a250c | 2015-07-23 10:23:36 +1000 | [diff] [blame] | 348 | /** |
| 349 | * Checks if the context supports shader subroutines. |
| 350 | */ |
| 351 | static inline bool |
| 352 | _mesa_has_shader_subroutine(const struct gl_context *ctx) |
| 353 | { |
| 354 | return ctx->API == API_OPENGL_CORE && |
| 355 | (ctx->Version >= 40 || ctx->Extensions.ARB_shader_subroutine); |
| 356 | } |
Jordan Justen | 2cd2831 | 2015-02-14 12:53:42 -0800 | [diff] [blame] | 357 | |
Marek Olšák | fa602c2 | 2015-05-28 19:11:07 +0200 | [diff] [blame] | 358 | /** |
| 359 | * Checks if the context supports tessellation. |
| 360 | */ |
| 361 | static inline GLboolean |
| 362 | _mesa_has_tessellation(const struct gl_context *ctx) |
| 363 | { |
| 364 | return ctx->API == API_OPENGL_CORE && |
| 365 | ctx->Extensions.ARB_tessellation_shader; |
| 366 | } |
| 367 | |
| 368 | |
José Fonseca | 63e7a4c | 2011-11-09 10:20:51 +0000 | [diff] [blame] | 369 | #ifdef __cplusplus |
| 370 | } |
| 371 | #endif |
| 372 | |
Brian Paul | 29b4076 | 2003-09-18 23:21:08 +0000 | [diff] [blame] | 373 | |
Brian Paul | 4e2de95 | 2006-07-20 03:56:16 +0000 | [diff] [blame] | 374 | #endif /* CONTEXT_H */ |