mesa: change _mesa_inside_dlist_begin_end() to handle PRIM_UNKNOWN
[mesa.git] / src / mesa / main / context.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file context.h
29 * Mesa context and visual-related functions.
30 *
31 * There are three large Mesa data types/classes which are meant to be
32 * used by device drivers:
33 * - struct gl_context: this contains the Mesa rendering state
34 * - struct gl_config: this describes the color buffer (RGB vs. ci), whether
35 * or not there's a depth buffer, stencil buffer, etc.
36 * - struct gl_framebuffer: contains pointers to the depth buffer, stencil
37 * buffer, accum buffer and alpha buffers.
38 *
39 * These types should be encapsulated by corresponding device driver
40 * data types. See xmesa.h and xmesaP.h for an example.
41 *
42 * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer
43 * are base classes which the device driver must derive from.
44 *
45 * The following functions create and destroy these data types.
46 */
47
48
49 #ifndef CONTEXT_H
50 #define CONTEXT_H
51
52
53 #include "imports.h"
54 #include "mtypes.h"
55
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 struct _glapi_table;
63
64
65 /** \name Visual-related functions */
66 /*@{*/
67
68 extern struct gl_config *
69 _mesa_create_visual( GLboolean dbFlag,
70 GLboolean stereoFlag,
71 GLint redBits,
72 GLint greenBits,
73 GLint blueBits,
74 GLint alphaBits,
75 GLint depthBits,
76 GLint stencilBits,
77 GLint accumRedBits,
78 GLint accumGreenBits,
79 GLint accumBlueBits,
80 GLint accumAlphaBits,
81 GLint numSamples );
82
83 extern GLboolean
84 _mesa_initialize_visual( struct gl_config *v,
85 GLboolean dbFlag,
86 GLboolean stereoFlag,
87 GLint redBits,
88 GLint greenBits,
89 GLint blueBits,
90 GLint alphaBits,
91 GLint depthBits,
92 GLint stencilBits,
93 GLint accumRedBits,
94 GLint accumGreenBits,
95 GLint accumBlueBits,
96 GLint accumAlphaBits,
97 GLint numSamples );
98
99 extern void
100 _mesa_destroy_visual( struct gl_config *vis );
101
102 /*@}*/
103
104
105 /** \name Context-related functions */
106 /*@{*/
107
108 extern GLboolean
109 _mesa_initialize_context( struct gl_context *ctx,
110 gl_api api,
111 const struct gl_config *visual,
112 struct gl_context *share_list,
113 const struct dd_function_table *driverFunctions);
114
115 extern struct gl_context *
116 _mesa_create_context(gl_api api,
117 const struct gl_config *visual,
118 struct gl_context *share_list,
119 const struct dd_function_table *driverFunctions);
120
121 extern void
122 _mesa_free_context_data( struct gl_context *ctx );
123
124 extern void
125 _mesa_destroy_context( struct gl_context *ctx );
126
127
128 extern void
129 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
130
131
132 extern void
133 _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
134
135 extern GLboolean
136 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
137 struct gl_framebuffer *readBuffer );
138
139 extern GLboolean
140 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
141
142 extern struct gl_context *
143 _mesa_get_current_context(void);
144
145 /*@}*/
146
147 extern void
148 _mesa_init_get_hash(struct gl_context *ctx);
149
150 extern void
151 _mesa_notifySwapBuffers(struct gl_context *gc);
152
153
154 extern struct _glapi_table *
155 _mesa_get_dispatch(struct gl_context *ctx);
156
157
158 void
159 _mesa_set_mvp_with_dp4( struct gl_context *ctx,
160 GLboolean flag );
161
162
163 extern GLboolean
164 _mesa_valid_to_render(struct gl_context *ctx, const char *where);
165
166
167
168 /** \name Miscellaneous */
169 /*@{*/
170
171 extern void
172 _mesa_record_error( struct gl_context *ctx, GLenum error );
173
174
175 extern void
176 _mesa_finish(struct gl_context *ctx);
177
178 extern void
179 _mesa_flush(struct gl_context *ctx);
180
181 extern int
182 _mesa_generic_nop(void);
183
184 extern void GLAPIENTRY
185 _mesa_Finish( void );
186
187 extern void GLAPIENTRY
188 _mesa_Flush( void );
189
190 /*@}*/
191
192
193 /**
194 * Are we currently between glBegin and glEnd?
195 * During execution, not display list compilation.
196 */
197 static inline GLboolean
198 _mesa_inside_begin_end(const struct gl_context *ctx)
199 {
200 return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
201 }
202
203
204 /**
205 * Are we currently between glBegin and glEnd in a display list?
206 */
207 static inline GLboolean
208 _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
209 {
210 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
211 }
212
213
214
215 /**
216 * \name Macros for flushing buffered rendering commands before state changes,
217 * checking if inside glBegin/glEnd, etc.
218 */
219 /*@{*/
220
221 /**
222 * Flush vertices.
223 *
224 * \param ctx GL context.
225 * \param newstate new state.
226 *
227 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
228 * and calls dd_function_table::FlushVertices if so. Marks
229 * __struct gl_contextRec::NewState with \p newstate.
230 */
231 #define FLUSH_VERTICES(ctx, newstate) \
232 do { \
233 if (MESA_VERBOSE & VERBOSE_STATE) \
234 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
235 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
236 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
237 ctx->NewState |= newstate; \
238 } while (0)
239
240 /**
241 * Flush current state.
242 *
243 * \param ctx GL context.
244 * \param newstate new state.
245 *
246 * Checks if dd_function_table::NeedFlush is marked to flush current state,
247 * and calls dd_function_table::FlushVertices if so. Marks
248 * __struct gl_contextRec::NewState with \p newstate.
249 */
250 #define FLUSH_CURRENT(ctx, newstate) \
251 do { \
252 if (MESA_VERBOSE & VERBOSE_STATE) \
253 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
254 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
255 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
256 ctx->NewState |= newstate; \
257 } while (0)
258
259 /**
260 * Macro to assert that the API call was made outside the
261 * glBegin()/glEnd() pair, with return value.
262 *
263 * \param ctx GL context.
264 * \param retval value to return in case the assertion fails.
265 */
266 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
267 do { \
268 if (_mesa_inside_begin_end(ctx)) { \
269 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
270 return retval; \
271 } \
272 } while (0)
273
274 /**
275 * Macro to assert that the API call was made outside the
276 * glBegin()/glEnd() pair.
277 *
278 * \param ctx GL context.
279 */
280 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
281 do { \
282 if (_mesa_inside_begin_end(ctx)) { \
283 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
284 return; \
285 } \
286 } while (0)
287
288 /*@}*/
289
290
291 /**
292 * Checks if the context is for Desktop GL (Compatibility or Core)
293 */
294 static inline GLboolean
295 _mesa_is_desktop_gl(const struct gl_context *ctx)
296 {
297 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
298 }
299
300
301 /**
302 * Checks if the context is for any GLES version
303 */
304 static inline GLboolean
305 _mesa_is_gles(const struct gl_context *ctx)
306 {
307 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
308 }
309
310
311 /**
312 * Checks if the context is for GLES 3.x
313 */
314 static inline GLboolean
315 _mesa_is_gles3(const struct gl_context *ctx)
316 {
317 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
318 }
319
320
321 #ifdef __cplusplus
322 }
323 #endif
324
325
326 #endif /* CONTEXT_H */