blob: 46444d2c427a6c3b8a6bed62345693411ab0871d [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001/*
2 * Mesa 3-D graphics library
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00003 *
Brian Paula623e002006-07-20 04:24:42 +00004 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00005 *
jtgafb833d1999-08-19 00:55:39 +00006 * 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 Jansen5e3bc0c2000-11-22 07:32:16 +000012 *
jtgafb833d1999-08-19 00:55:39 +000013 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
jtgafb833d1999-08-19 00:55:39 +000016 * 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 Graunke3d8d5b22013-04-21 13:46:48 -070019 * 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.
jtgafb833d1999-08-19 00:55:39 +000023 */
24
25
Brian Paula623e002006-07-20 04:24:42 +000026/**
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øgsbergf9995b32010-10-12 12:26:10 -040032 * - struct gl_context: this contains the Mesa rendering state
Brian Paul032a7ef2011-04-13 07:35:25 -060033 * - 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 Paula623e002006-07-20 04:24:42 +000037 *
38 * These types should be encapsulated by corresponding device driver
39 * data types. See xmesa.h and xmesaP.h for an example.
40 *
Brian Paul032a7ef2011-04-13 07:35:25 -060041 * 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 Paula623e002006-07-20 04:24:42 +000043 *
44 * The following functions create and destroy these data types.
45 */
46
47
jtgafb833d1999-08-19 00:55:39 +000048#ifndef CONTEXT_H
49#define CONTEXT_H
50
51
Keith Whitwellae0eaf92003-11-24 15:23:18 +000052#include "imports.h"
Nanley Cheryab129a42015-09-17 15:49:40 -070053#include "extensions.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000054#include "mtypes.h"
Marek Olšák72a5dff2015-09-27 21:28:22 +020055#include "vbo/vbo.h"
jtgafb833d1999-08-19 00:55:39 +000056
57
José Fonseca63e7a4c2011-11-09 10:20:51 +000058#ifdef __cplusplus
59extern "C" {
60#endif
61
62
Brian Paul27a84322009-02-22 16:29:30 -070063struct _glapi_table;
64
65
Brian Paula623e002006-07-20 04:24:42 +000066/** \name Visual-related functions */
Keith Whitwell6dc85572003-07-17 13:43:59 +000067/*@{*/
68
Kristian Høgsbergd3491e72010-10-12 11:58:47 -040069extern struct gl_config *
Ian Romanickfcf438e2010-02-24 18:49:33 -080070_mesa_create_visual( GLboolean dbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +000071 GLboolean stereoFlag,
72 GLint redBits,
73 GLint greenBits,
74 GLint blueBits,
75 GLint alphaBits,
Brian Paulb371e0d2000-03-31 01:05:51 +000076 GLint depthBits,
77 GLint stencilBits,
78 GLint accumRedBits,
79 GLint accumGreenBits,
80 GLint accumBlueBits,
81 GLint accumAlphaBits,
82 GLint numSamples );
83
Brian Paul178a1c52000-04-22 01:05:00 +000084extern GLboolean
Kristian Høgsbergd3491e72010-10-12 11:58:47 -040085_mesa_initialize_visual( struct gl_config *v,
Brian Paul178a1c52000-04-22 01:05:00 +000086 GLboolean dbFlag,
87 GLboolean stereoFlag,
88 GLint redBits,
89 GLint greenBits,
90 GLint blueBits,
91 GLint alphaBits,
Brian Paul178a1c52000-04-22 01:05:00 +000092 GLint depthBits,
93 GLint stencilBits,
94 GLint accumRedBits,
95 GLint accumGreenBits,
96 GLint accumBlueBits,
97 GLint accumAlphaBits,
98 GLint numSamples );
99
Brian Paulb371e0d2000-03-31 01:05:51 +0000100extern void
Kristian Høgsbergd3491e72010-10-12 11:58:47 -0400101_mesa_destroy_visual( struct gl_config *vis );
Brian Paulb371e0d2000-03-31 01:05:51 +0000102
Keith Whitwell6dc85572003-07-17 13:43:59 +0000103/*@}*/
jtgafb833d1999-08-19 00:55:39 +0000104
Brian Paul178a1c52000-04-22 01:05:00 +0000105
Brian Paula623e002006-07-20 04:24:42 +0000106/** \name Context-related functions */
Keith Whitwell6dc85572003-07-17 13:43:59 +0000107/*@{*/
108
Brian Paul178a1c52000-04-22 01:05:00 +0000109extern GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400110_mesa_initialize_context( struct gl_context *ctx,
Brian Paul5e4ca1c2011-02-08 19:25:04 -0700111 gl_api api,
Kristian Høgsbergd3491e72010-10-12 11:58:47 -0400112 const struct gl_config *visual,
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400113 struct gl_context *share_list,
Brian Paul733dba22012-09-29 08:47:56 -0600114 const struct dd_function_table *driverFunctions);
Brian Paul4d053dd2000-01-14 04:45:47 +0000115
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400116extern struct gl_context *
Brian Paul6f2f4492011-02-08 19:25:04 -0700117_mesa_create_context(gl_api api,
118 const struct gl_config *visual,
119 struct gl_context *share_list,
Brian Paul733dba22012-09-29 08:47:56 -0600120 const struct dd_function_table *driverFunctions);
Kristian Høgsberg2ab18d62010-04-22 09:25:51 -0400121
Brian Paul178a1c52000-04-22 01:05:00 +0000122extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400123_mesa_free_context_data( struct gl_context *ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +0000124
Brian Paul178a1c52000-04-22 01:05:00 +0000125extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400126_mesa_destroy_context( struct gl_context *ctx );
jtgafb833d1999-08-19 00:55:39 +0000127
Brian Paul4d053dd2000-01-14 04:45:47 +0000128
Brian Paul178a1c52000-04-22 01:05:00 +0000129extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400130_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
Brian Paul04986821999-11-19 22:26:52 +0000131
132
Brian Paul3f856c62009-06-17 08:35:55 -0600133extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400134_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
Brian Paul3f856c62009-06-17 08:35:55 -0600135
José Fonseca29c6c8e2009-05-30 12:38:45 -0700136extern GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400137_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
Kristian Høgsberg31aca272010-10-12 12:02:01 -0400138 struct gl_framebuffer *readBuffer );
Brian Paul3f02f901999-11-24 18:48:30 +0000139
Brian Paul635ee2d2005-04-15 17:25:07 +0000140extern GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400141_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
Brian Paul00037781999-12-17 14:52:35 +0000142
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400143extern struct gl_context *
Brian Paulb1394fa2000-09-26 20:53:53 +0000144_mesa_get_current_context(void);
Brian Paul178a1c52000-04-22 01:05:00 +0000145
Keith Whitwell6dc85572003-07-17 13:43:59 +0000146/*@}*/
jtgafb833d1999-08-19 00:55:39 +0000147
Kristian Høgsberg199b0892010-05-11 12:07:10 -0400148extern void
Marek Olšákee9a2b12014-08-03 04:51:31 +0200149_mesa_init_constants(struct gl_constants *consts, gl_api api);
150
151extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400152_mesa_init_get_hash(struct gl_context *ctx);
Brian Paul04986821999-11-19 22:26:52 +0000153
Brian Paul9a33a112002-06-13 04:28:29 +0000154extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400155_mesa_notifySwapBuffers(struct gl_context *gc);
Brian Paul9a33a112002-06-13 04:28:29 +0000156
Brian Paul9a33a112002-06-13 04:28:29 +0000157
Brian Paulfbd8f211999-11-11 01:22:25 +0000158extern struct _glapi_table *
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400159_mesa_get_dispatch(struct gl_context *ctx);
jtgafb833d1999-08-19 00:55:39 +0000160
161
Brian Paul56c42262009-08-14 10:45:17 -0600162extern GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400163_mesa_valid_to_render(struct gl_context *ctx, const char *where);
Brian Paul56c42262009-08-14 10:45:17 -0600164
165
166
Keith Whitwell6dc85572003-07-17 13:43:59 +0000167/** \name Miscellaneous */
168/*@{*/
jtgafb833d1999-08-19 00:55:39 +0000169
Brian Paul178a1c52000-04-22 01:05:00 +0000170extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400171_mesa_record_error( struct gl_context *ctx, GLenum error );
Brian Pauld09a1d82002-06-13 04:49:17 +0000172
Brian Paul4837e012009-10-22 18:16:10 -0600173
174extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400175_mesa_finish(struct gl_context *ctx);
Brian Paul4837e012009-10-22 18:16:10 -0600176
177extern void
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400178_mesa_flush(struct gl_context *ctx);
Brian Paul4837e012009-10-22 18:16:10 -0600179
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000180extern void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +0000181_mesa_Finish( void );
jtgafb833d1999-08-19 00:55:39 +0000182
Kendall Bennettc40d1dd2003-10-21 22:22:17 +0000183extern void GLAPIENTRY
Brian Paulfa9df402000-02-02 19:16:46 +0000184_mesa_Flush( void );
185
Keith Whitwell6dc85572003-07-17 13:43:59 +0000186/*@}*/
Brian Paulfa9df402000-02-02 19:16:46 +0000187
Brian Paul06588db2003-09-18 16:45:44 +0000188
Brian Paula623e002006-07-20 04:24:42 +0000189/**
Brian Paul976b5292013-04-23 10:53:00 -0600190 * Are we currently between glBegin and glEnd?
191 * During execution, not display list compilation.
192 */
193static 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 Paulf74da3e2013-04-23 10:57:45 -0600201 * Are we currently between glBegin and glEnd in a display list?
202 */
203static inline GLboolean
204_mesa_inside_dlist_begin_end(const struct gl_context *ctx)
205{
Brian Paul84e62b72013-05-01 19:15:32 -0600206 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
Brian Paulf74da3e2013-04-23 10:57:45 -0600207}
208
209
210
211/**
Brian Paula623e002006-07-20 04:24:42 +0000212 * \name Macros for flushing buffered rendering commands before state changes,
213 * checking if inside glBegin/glEnd, etc.
214 */
Brian Paul06588db2003-09-18 16:45:44 +0000215/*@{*/
216
217/**
218 * Flush vertices.
Brian Paul12f25eb2011-02-21 17:01:00 -0700219 *
220 * \param ctx GL context.
221 * \param newstate new state.
Brian Paul06588db2003-09-18 16:45:44 +0000222 *
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øgsbergf9995b32010-10-12 12:26:10 -0400225 * __struct gl_contextRec::NewState with \p newstate.
Brian Paul06588db2003-09-18 16:45:44 +0000226 */
Brian Paul12f25eb2011-02-21 17:01:00 -0700227#define FLUSH_VERTICES(ctx, newstate) \
228do { \
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šák72a5dff2015-09-27 21:28:22 +0200232 vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
Brian Paul12f25eb2011-02-21 17:01:00 -0700233 ctx->NewState |= newstate; \
234} while (0)
Brian Paul06588db2003-09-18 16:45:44 +0000235
236/**
237 * Flush current state.
Brian Paul12f25eb2011-02-21 17:01:00 -0700238 *
239 * \param ctx GL context.
240 * \param newstate new state.
Brian Paul06588db2003-09-18 16:45:44 +0000241 *
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øgsbergf9995b32010-10-12 12:26:10 -0400244 * __struct gl_contextRec::NewState with \p newstate.
Brian Paul06588db2003-09-18 16:45:44 +0000245 */
Brian Paul12f25eb2011-02-21 17:01:00 -0700246#define FLUSH_CURRENT(ctx, newstate) \
247do { \
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šák72a5dff2015-09-27 21:28:22 +0200251 vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
Brian Paul12f25eb2011-02-21 17:01:00 -0700252 ctx->NewState |= newstate; \
253} while (0)
Brian Paul06588db2003-09-18 16:45:44 +0000254
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 Paul05720e12011-10-25 08:45:37 -0600260 * \param retval value to return in case the assertion fails.
Brian Paul06588db2003-09-18 16:45:44 +0000261 */
262#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
263do { \
Brian Paul976b5292013-04-23 10:53:00 -0600264 if (_mesa_inside_begin_end(ctx)) { \
Brian Paula623e002006-07-20 04:24:42 +0000265 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
Brian Paul06588db2003-09-18 16:45:44 +0000266 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) \
277do { \
Brian Paul976b5292013-04-23 10:53:00 -0600278 if (_mesa_inside_begin_end(ctx)) { \
Brian Paula623e002006-07-20 04:24:42 +0000279 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
Brian Paul06588db2003-09-18 16:45:44 +0000280 return; \
281 } \
282} while (0)
283
Brian Paul06588db2003-09-18 16:45:44 +0000284/*@}*/
285
286
Jordan Justen3d284dc2012-07-19 11:01:27 -0700287/**
288 * Checks if the context is for Desktop GL (Compatibility or Core)
289 */
Ian Romanickfa3475b2015-04-28 11:57:39 -0700290static inline bool
Jordan Justen3d284dc2012-07-19 11:01:27 -0700291_mesa_is_desktop_gl(const struct gl_context *ctx)
292{
Paul Berrydbd61352012-11-27 12:26:51 -0800293 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
Jordan Justen3d284dc2012-07-19 11:01:27 -0700294}
295
296
297/**
298 * Checks if the context is for any GLES version
299 */
Ian Romanickfa3475b2015-04-28 11:57:39 -0700300static inline bool
Jordan Justen3d284dc2012-07-19 11:01:27 -0700301_mesa_is_gles(const struct gl_context *ctx)
302{
303 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
304}
305
306
Ian Romanick2a1ca4f2012-08-14 13:24:00 -0700307/**
Ian Romanick7efc11e2015-04-28 11:58:56 -0700308 * Checks if the context is for GLES 3.0 or later
Ian Romanick2a1ca4f2012-08-14 13:24:00 -0700309 */
Ian Romanickfa3475b2015-04-28 11:57:39 -0700310static inline bool
Ian Romanick2a1ca4f2012-08-14 13:24:00 -0700311_mesa_is_gles3(const struct gl_context *ctx)
312{
313 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
314}
315
316
Paul Berryb272a012013-07-28 09:23:11 -0700317/**
Ian Romanick7efc11e2015-04-28 11:58:56 -0700318 * Checks if the context is for GLES 3.1 or later
319 */
320static 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 Berryb272a012013-07-28 09:23:11 -0700328 * Checks if the context supports geometry shaders.
329 */
Ian Romanickfa3475b2015-04-28 11:57:39 -0700330static inline bool
Paul Berryb272a012013-07-28 09:23:11 -0700331_mesa_has_geometry_shaders(const struct gl_context *ctx)
332{
Marta Lofstedt3e640c22016-01-21 16:17:32 +0100333 return _mesa_has_OES_geometry_shader(ctx) ||
334 (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32);
Paul Berryb272a012013-07-28 09:23:11 -0700335}
336
337
Jordan Justen2cd28312015-02-14 12:53:42 -0800338/**
339 * Checks if the context supports compute shaders.
340 */
341static 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 Airlied8a250c2015-07-23 10:23:36 +1000348/**
349 * Checks if the context supports shader subroutines.
350 */
351static 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 Justen2cd28312015-02-14 12:53:42 -0800357
Marek Olšákfa602c22015-05-28 19:11:07 +0200358/**
359 * Checks if the context supports tessellation.
360 */
361static 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é Fonseca63e7a4c2011-11-09 10:20:51 +0000369#ifdef __cplusplus
370}
371#endif
372
Brian Paul29b40762003-09-18 23:21:08 +0000373
Brian Paul4e2de952006-07-20 03:56:16 +0000374#endif /* CONTEXT_H */