Assorted casts to silence g++ warnings.
[mesa.git] / src / mesa / main / context.h
1 /**
2 * \file context.h
3 * Mesa context/visual/framebuffer management functions.
4 *
5 * There are three Mesa data types which are meant to be used by device
6 * drivers:
7 * - GLcontext: this contains the Mesa rendering state
8 * - GLvisual: this describes the color buffer (RGB vs. ci), whether or not
9 * there's a depth buffer, stencil buffer, etc.
10 * - GLframebuffer: contains pointers to the depth buffer, stencil buffer,
11 * accum buffer and alpha buffers.
12 *
13 * These types should be encapsulated by corresponding device driver
14 * data types. See xmesa.h and xmesaP.h for an example.
15 *
16 * In OOP terms, GLcontext, GLvisual, and GLframebuffer are base classes
17 * which the device driver must derive from.
18 *
19 * The following functions create and destroy these data types.
20 */
21
22 /*
23 * Mesa 3-D graphics library
24 * Version: 4.1
25 *
26 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a
29 * copy of this software and associated documentation files (the "Software"),
30 * to deal in the Software without restriction, including without limitation
31 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
32 * and/or sell copies of the Software, and to permit persons to whom the
33 * Software is furnished to do so, subject to the following conditions:
34 *
35 * The above copyright notice and this permission notice shall be included
36 * in all copies or substantial portions of the Software.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
41 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
42 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 */
45
46
47 #ifndef CONTEXT_H
48 #define CONTEXT_H
49
50
51 #include "glapi.h"
52 #include "mtypes.h"
53
54
55 /**********************************************************************/
56 /** \name Create/destroy a GLvisual. */
57 /*@{*/
58
59 extern GLvisual *
60 _mesa_create_visual( GLboolean rgbFlag,
61 GLboolean dbFlag,
62 GLboolean stereoFlag,
63 GLint redBits,
64 GLint greenBits,
65 GLint blueBits,
66 GLint alphaBits,
67 GLint indexBits,
68 GLint depthBits,
69 GLint stencilBits,
70 GLint accumRedBits,
71 GLint accumGreenBits,
72 GLint accumBlueBits,
73 GLint accumAlphaBits,
74 GLint numSamples );
75
76 extern GLboolean
77 _mesa_initialize_visual( GLvisual *v,
78 GLboolean rgbFlag,
79 GLboolean dbFlag,
80 GLboolean stereoFlag,
81 GLint redBits,
82 GLint greenBits,
83 GLint blueBits,
84 GLint alphaBits,
85 GLint indexBits,
86 GLint depthBits,
87 GLint stencilBits,
88 GLint accumRedBits,
89 GLint accumGreenBits,
90 GLint accumBlueBits,
91 GLint accumAlphaBits,
92 GLint numSamples );
93
94 extern void
95 _mesa_destroy_visual( GLvisual *vis );
96
97 /*@}*/
98
99
100 /**********************************************************************/
101 /** \name Create/destroy a GLframebuffer. */
102 /*@{*/
103
104 extern GLframebuffer *
105 _mesa_create_framebuffer( const GLvisual *visual,
106 GLboolean softwareDepth,
107 GLboolean softwareStencil,
108 GLboolean softwareAccum,
109 GLboolean softwareAlpha );
110
111 extern void
112 _mesa_initialize_framebuffer( GLframebuffer *fb,
113 const GLvisual *visual,
114 GLboolean softwareDepth,
115 GLboolean softwareStencil,
116 GLboolean softwareAccum,
117 GLboolean softwareAlpha );
118
119 extern void
120 _mesa_free_framebuffer_data( GLframebuffer *buffer );
121
122 extern void
123 _mesa_destroy_framebuffer( GLframebuffer *buffer );
124
125 /*@}*/
126
127
128 /**********************************************************************/
129 /** \name Create/destroy a GLcontext. */
130 /*@{*/
131
132 extern GLcontext *
133 _mesa_create_context( const GLvisual *visual,
134 GLcontext *share_list,
135 void *driver_ctx,
136 GLboolean direct );
137
138 extern GLboolean
139 _mesa_initialize_context( GLcontext *ctx,
140 const GLvisual *visual,
141 GLcontext *share_list,
142 void *driver_ctx,
143 GLboolean direct );
144
145 extern void
146 _mesa_free_context_data( GLcontext *ctx );
147
148 extern void
149 _mesa_destroy_context( GLcontext *ctx );
150
151
152 extern void
153 _mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
154
155
156 extern void
157 _mesa_make_current( GLcontext *ctx, GLframebuffer *buffer );
158
159
160 extern void
161 _mesa_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer,
162 GLframebuffer *readBuffer );
163
164
165 extern GLcontext *
166 _mesa_get_current_context(void);
167
168 /*@}*/
169
170
171 /**
172 * Macro for declaration and fetching the current context.
173 *
174 * \param C local variable which will hold the current context.
175 *
176 * It should be used in the variable declaration area of a function:
177 * \code
178 * ...
179 * {
180 * GET_CURRENT_CONTEXT(ctx);
181 * ...
182 * \endcode
183 */
184 #ifdef THREADS
185
186 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
187
188 #else
189
190 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
191
192 #endif
193
194
195
196 /**********************************************************************/
197 /** \name OpenGL SI-style export functions. */
198 /*@{*/
199
200 extern GLboolean
201 _mesa_destroyContext(__GLcontext *gc);
202
203 extern GLboolean
204 _mesa_loseCurrent(__GLcontext *gc);
205
206 extern GLboolean
207 _mesa_makeCurrent(__GLcontext *gc);
208
209 extern GLboolean
210 _mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare);
211
212 extern GLboolean
213 _mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask);
214
215 extern GLboolean
216 _mesa_forceCurrent(__GLcontext *gc);
217
218 extern GLboolean
219 _mesa_notifyResize(__GLcontext *gc);
220
221 extern void
222 _mesa_notifyDestroy(__GLcontext *gc);
223
224 extern void
225 _mesa_notifySwapBuffers(__GLcontext *gc);
226
227 extern struct __GLdispatchStateRec *
228 _mesa_dispatchExec(__GLcontext *gc);
229
230 extern void
231 _mesa_beginDispatchOverride(__GLcontext *gc);
232
233 extern void
234 _mesa_endDispatchOverride(__GLcontext *gc);
235
236 /*@}*/
237
238
239 extern struct _glapi_table *
240 _mesa_get_dispatch(GLcontext *ctx);
241
242
243
244 /**********************************************************************/
245 /** \name Miscellaneous */
246 /*@{*/
247
248 extern void
249 _mesa_record_error( GLcontext *ctx, GLenum error );
250
251
252 extern void
253 _mesa_Finish( void );
254
255 extern void
256 _mesa_Flush( void );
257
258 /*@}*/
259
260
261
262 /**********************************************************************/
263 /** \name Macros for contexts/flushing. */
264 /*@{*/
265
266 /**
267 * Flush vertices.
268 *
269 * \param ctx GL context.
270 * \param newstate new state.
271 *
272 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
273 * and calls dd_function_table::FlushVertices if so. Marks
274 * __GLcontextRec::NewState with \p newstate.
275 *
276 * \todo Eventually let the driver specify what state changes require a flush:
277 */
278 #define FLUSH_VERTICES(ctx, newstate) \
279 do { \
280 if (MESA_VERBOSE & VERBOSE_STATE) \
281 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", __FUNCTION__); \
282 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
283 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
284 ctx->NewState |= newstate; \
285 } while (0)
286
287 /**
288 * Flush current state.
289 *
290 * \param ctx GL context.
291 * \param newstate new state.
292 *
293 * Checks if dd_function_table::NeedFlush is marked to flush current state,
294 * and calls dd_function_table::FlushVertices if so. Marks
295 * __GLcontextRec::NewState with \p newstate.
296 */
297 #define FLUSH_CURRENT(ctx, newstate) \
298 do { \
299 if (MESA_VERBOSE & VERBOSE_STATE) \
300 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", __FUNCTION__); \
301 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
302 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
303 ctx->NewState |= newstate; \
304 } while (0)
305
306 /**
307 * Macro to assert that the API call was made outside the
308 * glBegin()/glEnd() pair, with return value.
309 *
310 * \param ctx GL context.
311 * \param retval value to return value in case the assertion fails.
312 */
313 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
314 do { \
315 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
316 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
317 return retval; \
318 } \
319 } while (0)
320
321 /**
322 * Macro to assert that the API call was made outside the
323 * glBegin()/glEnd() pair.
324 *
325 * \param ctx GL context.
326 */
327 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
328 do { \
329 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
330 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
331 return; \
332 } \
333 } while (0)
334
335 /**
336 * Macro to assert that the API call was made outside the
337 * glBegin()/glEnd() pair and flush the vertices.
338 *
339 * \param ctx GL context.
340 */
341 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
342 do { \
343 ASSERT_OUTSIDE_BEGIN_END(ctx); \
344 FLUSH_VERTICES(ctx, 0); \
345 } while (0)
346
347 /**
348 * Macro to assert that the API call was made outside the
349 * glBegin()/glEnd() pair and flush the vertices, with return value.
350 *
351 * \param ctx GL context.
352 * \param retval value to return value in case the assertion fails.
353 */
354 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
355 do { \
356 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
357 FLUSH_VERTICES(ctx, 0); \
358 } while (0)
359
360
361 /*@}*/
362
363
364
365 /**
366 * Macros to help evaluate current state conditions
367 */
368
369 /*@{*/
370
371 /**
372 * Is the secondary color needed?
373 */
374 #define NEED_SECONDARY_COLOR(CTX) \
375 (((CTX)->Light.Enabled && \
376 (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
377 || (CTX)->Fog.ColorSumEnabled)
378
379
380 /**
381 * Is two-sided lighting in effect?
382 */
383 #define NEED_TWO_SIDED_LIGHTING(CTX) \
384 (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
385
386
387 /*@}*/
388
389
390 #endif