mesa: Update _mesa_has_geometry_shaders
[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 "extensions.h"
54 #include "mtypes.h"
55 #include "vbo/vbo.h"
56
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62
63 struct _glapi_table;
64
65
66 /** \name Visual-related functions */
67 /*@{*/
68
69 extern struct gl_config *
70 _mesa_create_visual( GLboolean dbFlag,
71 GLboolean stereoFlag,
72 GLint redBits,
73 GLint greenBits,
74 GLint blueBits,
75 GLint alphaBits,
76 GLint depthBits,
77 GLint stencilBits,
78 GLint accumRedBits,
79 GLint accumGreenBits,
80 GLint accumBlueBits,
81 GLint accumAlphaBits,
82 GLint numSamples );
83
84 extern GLboolean
85 _mesa_initialize_visual( struct gl_config *v,
86 GLboolean dbFlag,
87 GLboolean stereoFlag,
88 GLint redBits,
89 GLint greenBits,
90 GLint blueBits,
91 GLint alphaBits,
92 GLint depthBits,
93 GLint stencilBits,
94 GLint accumRedBits,
95 GLint accumGreenBits,
96 GLint accumBlueBits,
97 GLint accumAlphaBits,
98 GLint numSamples );
99
100 extern void
101 _mesa_destroy_visual( struct gl_config *vis );
102
103 /*@}*/
104
105
106 /** \name Context-related functions */
107 /*@{*/
108
109 extern GLboolean
110 _mesa_initialize_context( struct gl_context *ctx,
111 gl_api api,
112 const struct gl_config *visual,
113 struct gl_context *share_list,
114 const struct dd_function_table *driverFunctions);
115
116 extern struct gl_context *
117 _mesa_create_context(gl_api api,
118 const struct gl_config *visual,
119 struct gl_context *share_list,
120 const struct dd_function_table *driverFunctions);
121
122 extern void
123 _mesa_free_context_data( struct gl_context *ctx );
124
125 extern void
126 _mesa_destroy_context( struct gl_context *ctx );
127
128
129 extern void
130 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
131
132
133 extern void
134 _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
135
136 extern GLboolean
137 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
138 struct gl_framebuffer *readBuffer );
139
140 extern GLboolean
141 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
142
143 extern struct gl_context *
144 _mesa_get_current_context(void);
145
146 /*@}*/
147
148 extern void
149 _mesa_init_constants(struct gl_constants *consts, gl_api api);
150
151 extern void
152 _mesa_init_get_hash(struct gl_context *ctx);
153
154 extern void
155 _mesa_notifySwapBuffers(struct gl_context *gc);
156
157
158 extern struct _glapi_table *
159 _mesa_get_dispatch(struct gl_context *ctx);
160
161
162 extern GLboolean
163 _mesa_valid_to_render(struct gl_context *ctx, const char *where);
164
165
166
167 /** \name Miscellaneous */
168 /*@{*/
169
170 extern void
171 _mesa_record_error( struct gl_context *ctx, GLenum error );
172
173
174 extern void
175 _mesa_finish(struct gl_context *ctx);
176
177 extern void
178 _mesa_flush(struct gl_context *ctx);
179
180 extern void GLAPIENTRY
181 _mesa_Finish( void );
182
183 extern void GLAPIENTRY
184 _mesa_Flush( void );
185
186 /*@}*/
187
188
189 /**
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 /**
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 {
206 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
207 }
208
209
210
211 /**
212 * \name Macros for flushing buffered rendering commands before state changes,
213 * checking if inside glBegin/glEnd, etc.
214 */
215 /*@{*/
216
217 /**
218 * Flush vertices.
219 *
220 * \param ctx GL context.
221 * \param newstate new state.
222 *
223 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
224 * and calls dd_function_table::FlushVertices if so. Marks
225 * __struct gl_contextRec::NewState with \p newstate.
226 */
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) \
232 vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
233 ctx->NewState |= newstate; \
234 } while (0)
235
236 /**
237 * Flush current state.
238 *
239 * \param ctx GL context.
240 * \param newstate new state.
241 *
242 * Checks if dd_function_table::NeedFlush is marked to flush current state,
243 * and calls dd_function_table::FlushVertices if so. Marks
244 * __struct gl_contextRec::NewState with \p newstate.
245 */
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) \
251 vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
252 ctx->NewState |= newstate; \
253 } while (0)
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.
260 * \param retval value to return in case the assertion fails.
261 */
262 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
263 do { \
264 if (_mesa_inside_begin_end(ctx)) { \
265 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
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 { \
278 if (_mesa_inside_begin_end(ctx)) { \
279 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
280 return; \
281 } \
282 } while (0)
283
284 /*@}*/
285
286
287 /**
288 * Checks if the context is for Desktop GL (Compatibility or Core)
289 */
290 static inline bool
291 _mesa_is_desktop_gl(const struct gl_context *ctx)
292 {
293 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
294 }
295
296
297 /**
298 * Checks if the context is for any GLES version
299 */
300 static inline bool
301 _mesa_is_gles(const struct gl_context *ctx)
302 {
303 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
304 }
305
306
307 /**
308 * Checks if the context is for GLES 3.0 or later
309 */
310 static inline bool
311 _mesa_is_gles3(const struct gl_context *ctx)
312 {
313 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
314 }
315
316
317 /**
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 /**
328 * Checks if the context supports geometry shaders.
329 */
330 static inline bool
331 _mesa_has_geometry_shaders(const struct gl_context *ctx)
332 {
333 return _mesa_has_OES_geometry_shader(ctx) ||
334 (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32);
335 }
336
337
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
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 }
357
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
369 #ifdef __cplusplus
370 }
371 #endif
372
373
374 #endif /* CONTEXT_H */