• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                      GLuint 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                          GLuint 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 void
117 _mesa_free_context_data( struct gl_context *ctx );
118 
119 extern void
120 _mesa_destroy_context( struct gl_context *ctx );
121 
122 
123 extern void
124 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
125 
126 extern GLboolean
127 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
128                     struct gl_framebuffer *readBuffer );
129 
130 extern GLboolean
131 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
132 
133 extern struct gl_context *
134 _mesa_get_current_context(void);
135 
136 /*@}*/
137 
138 extern void
139 _mesa_init_constants(struct gl_constants *consts, gl_api api);
140 
141 extern void
142 _mesa_notifySwapBuffers(struct gl_context *gc);
143 
144 
145 extern struct _glapi_table *
146 _mesa_get_dispatch(struct gl_context *ctx);
147 
148 extern void
149 _mesa_set_context_lost_dispatch(struct gl_context *ctx);
150 
151 
152 
153 /** \name Miscellaneous */
154 /*@{*/
155 
156 extern void
157 _mesa_flush(struct gl_context *ctx);
158 
159 extern void GLAPIENTRY
160 _mesa_Finish( void );
161 
162 extern void GLAPIENTRY
163 _mesa_Flush( void );
164 
165 /*@}*/
166 
167 
168 /**
169  * Are we currently between glBegin and glEnd?
170  * During execution, not display list compilation.
171  */
172 static inline GLboolean
_mesa_inside_begin_end(const struct gl_context * ctx)173 _mesa_inside_begin_end(const struct gl_context *ctx)
174 {
175    return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
176 }
177 
178 
179 /**
180  * Are we currently between glBegin and glEnd in a display list?
181  */
182 static inline GLboolean
_mesa_inside_dlist_begin_end(const struct gl_context * ctx)183 _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
184 {
185    return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
186 }
187 
188 
189 
190 /**
191  * \name Macros for flushing buffered rendering commands before state changes,
192  * checking if inside glBegin/glEnd, etc.
193  */
194 /*@{*/
195 
196 /**
197  * Flush vertices.
198  *
199  * \param ctx GL context.
200  * \param newstate new state.
201  *
202  * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
203  * and calls dd_function_table::FlushVertices if so. Marks
204  * __struct gl_contextRec::NewState with \p newstate.
205  */
206 #define FLUSH_VERTICES(ctx, newstate)				\
207 do {								\
208    if (MESA_VERBOSE & VERBOSE_STATE)				\
209       _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
210    if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)		\
211       vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES);	\
212    ctx->NewState |= newstate;					\
213 } while (0)
214 
215 /**
216  * Flush current state.
217  *
218  * \param ctx GL context.
219  * \param newstate new state.
220  *
221  * Checks if dd_function_table::NeedFlush is marked to flush current state,
222  * and calls dd_function_table::FlushVertices if so. Marks
223  * __struct gl_contextRec::NewState with \p newstate.
224  */
225 #define FLUSH_CURRENT(ctx, newstate)				\
226 do {								\
227    if (MESA_VERBOSE & VERBOSE_STATE)				\
228       _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION);	\
229    if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)		\
230       vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT);	\
231    ctx->NewState |= newstate;					\
232 } while (0)
233 
234 /**
235  * Macro to assert that the API call was made outside the
236  * glBegin()/glEnd() pair, with return value.
237  *
238  * \param ctx GL context.
239  * \param retval value to return in case the assertion fails.
240  */
241 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)		\
242 do {									\
243    if (_mesa_inside_begin_end(ctx)) {					\
244       _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
245       return retval;							\
246    }									\
247 } while (0)
248 
249 /**
250  * Macro to assert that the API call was made outside the
251  * glBegin()/glEnd() pair.
252  *
253  * \param ctx GL context.
254  */
255 #define ASSERT_OUTSIDE_BEGIN_END(ctx)					\
256 do {									\
257    if (_mesa_inside_begin_end(ctx)) {					\
258       _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
259       return;								\
260    }									\
261 } while (0)
262 
263 /*@}*/
264 
265 
266 /**
267  * Checks if the context is for Desktop GL (Compatibility or Core)
268  */
269 static inline bool
_mesa_is_desktop_gl(const struct gl_context * ctx)270 _mesa_is_desktop_gl(const struct gl_context *ctx)
271 {
272    return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
273 }
274 
275 
276 /**
277  * Checks if the context is for any GLES version
278  */
279 static inline bool
_mesa_is_gles(const struct gl_context * ctx)280 _mesa_is_gles(const struct gl_context *ctx)
281 {
282    return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
283 }
284 
285 
286 /**
287  * Checks if the context is for GLES 3.0 or later
288  */
289 static inline bool
_mesa_is_gles3(const struct gl_context * ctx)290 _mesa_is_gles3(const struct gl_context *ctx)
291 {
292    return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
293 }
294 
295 
296 /**
297  * Checks if the context is for GLES 3.1 or later
298  */
299 static inline bool
_mesa_is_gles31(const struct gl_context * ctx)300 _mesa_is_gles31(const struct gl_context *ctx)
301 {
302    return ctx->API == API_OPENGLES2 && ctx->Version >= 31;
303 }
304 
305 
306 /**
307  * Checks if the context is for GLES 3.2 or later
308  */
309 static inline bool
_mesa_is_gles32(const struct gl_context * ctx)310 _mesa_is_gles32(const struct gl_context *ctx)
311 {
312    return ctx->API == API_OPENGLES2 && ctx->Version >= 32;
313 }
314 
315 
316 static inline bool
_mesa_is_no_error_enabled(const struct gl_context * ctx)317 _mesa_is_no_error_enabled(const struct gl_context *ctx)
318 {
319    return ctx->Const.ContextFlags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
320 }
321 
322 
323 /**
324  * Checks if the context supports geometry shaders.
325  */
326 static inline bool
_mesa_has_geometry_shaders(const struct gl_context * ctx)327 _mesa_has_geometry_shaders(const struct gl_context *ctx)
328 {
329    return _mesa_has_OES_geometry_shader(ctx) ||
330           (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32);
331 }
332 
333 
334 /**
335  * Checks if the context supports compute shaders.
336  */
337 static inline bool
_mesa_has_compute_shaders(const struct gl_context * ctx)338 _mesa_has_compute_shaders(const struct gl_context *ctx)
339 {
340    return _mesa_has_ARB_compute_shader(ctx) ||
341       (ctx->API == API_OPENGLES2 && ctx->Version >= 31);
342 }
343 
344 /**
345  * Checks if the context supports tessellation.
346  */
347 static inline GLboolean
_mesa_has_tessellation(const struct gl_context * ctx)348 _mesa_has_tessellation(const struct gl_context *ctx)
349 {
350    /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES
351     * check, so don't bother calling it.
352     */
353    return _mesa_has_OES_tessellation_shader(ctx) ||
354           _mesa_has_ARB_tessellation_shader(ctx);
355 }
356 
357 static inline bool
_mesa_has_texture_cube_map_array(const struct gl_context * ctx)358 _mesa_has_texture_cube_map_array(const struct gl_context *ctx)
359 {
360    return _mesa_has_ARB_texture_cube_map_array(ctx) ||
361           _mesa_has_OES_texture_cube_map_array(ctx);
362 }
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 
369 #endif /* CONTEXT_H */
370