mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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 "mtypes.h"
54
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60
61 struct _glapi_table;
62
63
64 /** \name Visual-related functions */
65 /*@{*/
66
67 extern struct gl_config *
68 _mesa_create_visual( GLboolean dbFlag,
69 GLboolean stereoFlag,
70 GLint redBits,
71 GLint greenBits,
72 GLint blueBits,
73 GLint alphaBits,
74 GLint depthBits,
75 GLint stencilBits,
76 GLint accumRedBits,
77 GLint accumGreenBits,
78 GLint accumBlueBits,
79 GLint accumAlphaBits,
80 GLint numSamples );
81
82 extern GLboolean
83 _mesa_initialize_visual( struct gl_config *v,
84 GLboolean dbFlag,
85 GLboolean stereoFlag,
86 GLint redBits,
87 GLint greenBits,
88 GLint blueBits,
89 GLint alphaBits,
90 GLint depthBits,
91 GLint stencilBits,
92 GLint accumRedBits,
93 GLint accumGreenBits,
94 GLint accumBlueBits,
95 GLint accumAlphaBits,
96 GLint numSamples );
97
98 extern void
99 _mesa_destroy_visual( struct gl_config *vis );
100
101 /*@}*/
102
103
104 /** \name Context-related functions */
105 /*@{*/
106
107 extern GLboolean
108 _mesa_initialize_context( struct gl_context *ctx,
109 gl_api api,
110 const struct gl_config *visual,
111 struct gl_context *share_list,
112 const struct dd_function_table *driverFunctions);
113
114 extern struct gl_context *
115 _mesa_create_context(gl_api api,
116 const struct gl_config *visual,
117 struct gl_context *share_list,
118 const struct dd_function_table *driverFunctions);
119
120 extern void
121 _mesa_free_context_data( struct gl_context *ctx );
122
123 extern void
124 _mesa_destroy_context( struct gl_context *ctx );
125
126
127 extern void
128 _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
129
130
131 extern void
132 _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
133
134 extern GLboolean
135 _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
136 struct gl_framebuffer *readBuffer );
137
138 extern GLboolean
139 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
140
141 extern struct gl_context *
142 _mesa_get_current_context(void);
143
144 /*@}*/
145
146 extern void
147 _mesa_init_get_hash(struct gl_context *ctx);
148
149 extern void
150 _mesa_notifySwapBuffers(struct gl_context *gc);
151
152
153 extern struct _glapi_table *
154 _mesa_get_dispatch(struct gl_context *ctx);
155
156
157 void
158 _mesa_set_mvp_with_dp4( struct gl_context *ctx,
159 GLboolean flag );
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 int
181 _mesa_generic_nop(void);
182
183 extern void GLAPIENTRY
184 _mesa_Finish( void );
185
186 extern void GLAPIENTRY
187 _mesa_Flush( void );
188
189 /*@}*/
190
191
192 /**
193 * Are we currently between glBegin and glEnd?
194 * During execution, not display list compilation.
195 */
196 static inline GLboolean
197 _mesa_inside_begin_end(const struct gl_context *ctx)
198 {
199 return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
200 }
201
202
203 /**
204 * Are we currently between glBegin and glEnd in a display list?
205 */
206 static inline GLboolean
207 _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
208 {
209 return ctx->Driver.CurrentSavePrimitive != PRIM_OUTSIDE_BEGIN_END;
210 }
211
212
213
214 /**
215 * \name Macros for flushing buffered rendering commands before state changes,
216 * checking if inside glBegin/glEnd, etc.
217 */
218 /*@{*/
219
220 /**
221 * Flush vertices.
222 *
223 * \param ctx GL context.
224 * \param newstate new state.
225 *
226 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
227 * and calls dd_function_table::FlushVertices if so. Marks
228 * __struct gl_contextRec::NewState with \p newstate.
229 */
230 #define FLUSH_VERTICES(ctx, newstate) \
231 do { \
232 if (MESA_VERBOSE & VERBOSE_STATE) \
233 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
234 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
235 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
236 ctx->NewState |= newstate; \
237 } while (0)
238
239 /**
240 * Flush current state.
241 *
242 * \param ctx GL context.
243 * \param newstate new state.
244 *
245 * Checks if dd_function_table::NeedFlush is marked to flush current state,
246 * and calls dd_function_table::FlushVertices if so. Marks
247 * __struct gl_contextRec::NewState with \p newstate.
248 */
249 #define FLUSH_CURRENT(ctx, newstate) \
250 do { \
251 if (MESA_VERBOSE & VERBOSE_STATE) \
252 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
253 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
254 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
255 ctx->NewState |= newstate; \
256 } while (0)
257
258 /**
259 * Macro to assert that the API call was made outside the
260 * glBegin()/glEnd() pair, with return value.
261 *
262 * \param ctx GL context.
263 * \param retval value to return in case the assertion fails.
264 */
265 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
266 do { \
267 if (_mesa_inside_begin_end(ctx)) { \
268 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
269 return retval; \
270 } \
271 } while (0)
272
273 /**
274 * Macro to assert that the API call was made outside the
275 * glBegin()/glEnd() pair.
276 *
277 * \param ctx GL context.
278 */
279 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
280 do { \
281 if (_mesa_inside_begin_end(ctx)) { \
282 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
283 return; \
284 } \
285 } while (0)
286
287 /*@}*/
288
289
290 /**
291 * Checks if the context is for Desktop GL (Compatibility or Core)
292 */
293 static inline GLboolean
294 _mesa_is_desktop_gl(const struct gl_context *ctx)
295 {
296 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
297 }
298
299
300 /**
301 * Checks if the context is for any GLES version
302 */
303 static inline GLboolean
304 _mesa_is_gles(const struct gl_context *ctx)
305 {
306 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
307 }
308
309
310 /**
311 * Checks if the context is for GLES 3.x
312 */
313 static inline GLboolean
314 _mesa_is_gles3(const struct gl_context *ctx)
315 {
316 return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
317 }
318
319
320 #ifdef __cplusplus
321 }
322 #endif
323
324
325 #endif /* CONTEXT_H */