d6d7920bb4f9cba2de1fe41c51d8128e111b7b84
[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 "imports.h"
53 #include "mtypes.h"
54
55
56 /**********************************************************************/
57 /** \name Create/destroy a GLvisual. */
58 /*@{*/
59
60 extern GLvisual *
61 _mesa_create_visual( GLboolean rgbFlag,
62 GLboolean dbFlag,
63 GLboolean stereoFlag,
64 GLint redBits,
65 GLint greenBits,
66 GLint blueBits,
67 GLint alphaBits,
68 GLint indexBits,
69 GLint depthBits,
70 GLint stencilBits,
71 GLint accumRedBits,
72 GLint accumGreenBits,
73 GLint accumBlueBits,
74 GLint accumAlphaBits,
75 GLint numSamples );
76
77 extern GLboolean
78 _mesa_initialize_visual( GLvisual *v,
79 GLboolean rgbFlag,
80 GLboolean dbFlag,
81 GLboolean stereoFlag,
82 GLint redBits,
83 GLint greenBits,
84 GLint blueBits,
85 GLint alphaBits,
86 GLint indexBits,
87 GLint depthBits,
88 GLint stencilBits,
89 GLint accumRedBits,
90 GLint accumGreenBits,
91 GLint accumBlueBits,
92 GLint accumAlphaBits,
93 GLint numSamples );
94
95 extern void
96 _mesa_destroy_visual( GLvisual *vis );
97
98 /*@}*/
99
100
101 /**********************************************************************/
102 /** \name Create/destroy a GLframebuffer. */
103 /*@{*/
104
105 extern GLframebuffer *
106 _mesa_create_framebuffer( const GLvisual *visual,
107 GLboolean softwareDepth,
108 GLboolean softwareStencil,
109 GLboolean softwareAccum,
110 GLboolean softwareAlpha );
111
112 extern void
113 _mesa_initialize_framebuffer( GLframebuffer *fb,
114 const GLvisual *visual,
115 GLboolean softwareDepth,
116 GLboolean softwareStencil,
117 GLboolean softwareAccum,
118 GLboolean softwareAlpha );
119
120 extern void
121 _mesa_free_framebuffer_data( GLframebuffer *buffer );
122
123 extern void
124 _mesa_destroy_framebuffer( GLframebuffer *buffer );
125
126 /*@}*/
127
128
129 /**********************************************************************/
130 /** \name Create/destroy a GLcontext. */
131 /*@{*/
132
133 extern GLcontext *
134 _mesa_create_context( const GLvisual *visual,
135 GLcontext *share_list,
136 void *driver_ctx,
137 GLboolean direct );
138
139 extern GLboolean
140 _mesa_initialize_context( GLcontext *ctx,
141 const GLvisual *visual,
142 GLcontext *share_list,
143 void *driver_ctx,
144 GLboolean direct );
145
146 extern void
147 _mesa_free_context_data( GLcontext *ctx );
148
149 extern void
150 _mesa_destroy_context( GLcontext *ctx );
151
152
153 extern void
154 _mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
155
156
157 extern void
158 _mesa_make_current( GLcontext *ctx, GLframebuffer *buffer );
159
160
161 extern void
162 _mesa_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer,
163 GLframebuffer *readBuffer );
164
165
166 extern GLcontext *
167 _mesa_get_current_context(void);
168
169 /*@}*/
170
171
172 /**
173 * Macro for declaration and fetching the current context.
174 *
175 * \param C local variable which will hold the current context.
176 *
177 * It should be used in the variable declaration area of a function:
178 * \code
179 * ...
180 * {
181 * GET_CURRENT_CONTEXT(ctx);
182 * ...
183 * \endcode
184 */
185 #ifdef THREADS
186
187 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
188
189 #else
190
191 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
192
193 #endif
194
195
196
197 /**********************************************************************/
198 /** \name OpenGL SI-style export functions. */
199 /*@{*/
200
201 extern GLboolean
202 _mesa_destroyContext(__GLcontext *gc);
203
204 extern GLboolean
205 _mesa_loseCurrent(__GLcontext *gc);
206
207 extern GLboolean
208 _mesa_makeCurrent(__GLcontext *gc);
209
210 extern GLboolean
211 _mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare);
212
213 extern GLboolean
214 _mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask);
215
216 extern GLboolean
217 _mesa_forceCurrent(__GLcontext *gc);
218
219 extern GLboolean
220 _mesa_notifyResize(__GLcontext *gc);
221
222 extern void
223 _mesa_notifyDestroy(__GLcontext *gc);
224
225 extern void
226 _mesa_notifySwapBuffers(__GLcontext *gc);
227
228 extern struct __GLdispatchStateRec *
229 _mesa_dispatchExec(__GLcontext *gc);
230
231 extern void
232 _mesa_beginDispatchOverride(__GLcontext *gc);
233
234 extern void
235 _mesa_endDispatchOverride(__GLcontext *gc);
236
237 /*@}*/
238
239
240 extern struct _glapi_table *
241 _mesa_get_dispatch(GLcontext *ctx);
242
243
244
245 /**********************************************************************/
246 /** \name Miscellaneous */
247 /*@{*/
248
249 extern void
250 _mesa_record_error( GLcontext *ctx, GLenum error );
251
252
253 extern void GLAPIENTRY
254 _mesa_Finish( void );
255
256 extern void GLAPIENTRY
257 _mesa_Flush( void );
258
259 /*@}*/
260
261
262
263 /**********************************************************************/
264 /** \name Macros for contexts/flushing. */
265 /*@{*/
266
267
268 /**
269 * Flush vertices.
270 *
271 * \param ctx GL context.
272 * \param newstate new state.
273 *
274 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
275 * and calls dd_function_table::FlushVertices if so. Marks
276 * __GLcontextRec::NewState with \p newstate.
277 */
278 #define FLUSH_VERTICES(ctx, newstate) \
279 do { \
280 if (MESA_VERBOSE & VERBOSE_STATE) \
281 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_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", MESA_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 || ((CTX)->VertexProgram.Enabled && \
379 ((CTX)->VertexProgram.Current->InputsRead & VERT_BIT_COLOR1)) \
380 || ((CTX)->FragmentProgram.Enabled && \
381 ((CTX)->FragmentProgram.Current->InputsRead & FRAG_BIT_COL1)) \
382 )
383
384
385 /**
386 * Is two-sided lighting in effect?
387 */
388 #define NEED_TWO_SIDED_LIGHTING(CTX) \
389 (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
390
391
392 /*@}*/
393
394
395 #endif