Add a set of predicate functions for testing matrices instead of directly
[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: 6.1
25 *
26 * Copyright (C) 1999-2004 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 GLcontext. */
103 /*@{*/
104
105 extern GLcontext *
106 _mesa_create_context( const GLvisual *visual,
107 GLcontext *share_list,
108 const struct dd_function_table *driverFunctions,
109 void *driverContext );
110
111 extern GLboolean
112 _mesa_initialize_context( GLcontext *ctx,
113 const GLvisual *visual,
114 GLcontext *share_list,
115 const struct dd_function_table *driverFunctions,
116 void *driverContext );
117
118 extern void
119 _mesa_free_context_data( GLcontext *ctx );
120
121 extern void
122 _mesa_destroy_context( GLcontext *ctx );
123
124
125 extern void
126 _mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
127
128
129 extern void
130 _mesa_make_current( GLcontext *ctx, GLframebuffer *drawBuffer,
131 GLframebuffer *readBuffer );
132
133 extern GLboolean
134 _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare);
135
136 extern GLcontext *
137 _mesa_get_current_context(void);
138
139 /*@}*/
140
141
142 /**********************************************************************/
143 /** \name OpenGL SI-style export functions. */
144 /*@{*/
145
146 extern GLboolean
147 _mesa_destroyContext(__GLcontext *gc);
148
149 extern GLboolean
150 _mesa_loseCurrent(__GLcontext *gc);
151
152 extern GLboolean
153 _mesa_makeCurrent(__GLcontext *gc);
154
155 extern GLboolean
156 _mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare);
157
158 extern GLboolean
159 _mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask);
160
161 extern GLboolean
162 _mesa_forceCurrent(__GLcontext *gc);
163
164 extern GLboolean
165 _mesa_notifyResize(__GLcontext *gc);
166
167 extern void
168 _mesa_notifyDestroy(__GLcontext *gc);
169
170 extern void
171 _mesa_notifySwapBuffers(__GLcontext *gc);
172
173 extern struct __GLdispatchStateRec *
174 _mesa_dispatchExec(__GLcontext *gc);
175
176 extern void
177 _mesa_beginDispatchOverride(__GLcontext *gc);
178
179 extern void
180 _mesa_endDispatchOverride(__GLcontext *gc);
181
182 /*@}*/
183
184
185 extern struct _glapi_table *
186 _mesa_get_dispatch(GLcontext *ctx);
187
188
189
190 /**********************************************************************/
191 /** \name Miscellaneous */
192 /*@{*/
193
194 extern void
195 _mesa_record_error( GLcontext *ctx, GLenum error );
196
197
198 extern void GLAPIENTRY
199 _mesa_Finish( void );
200
201 extern void GLAPIENTRY
202 _mesa_Flush( void );
203
204 /*@}*/
205
206
207
208 /**********************************************************************/
209 /** \name Macros for contexts/flushing. */
210 /*@{*/
211
212
213 /**
214 * Flush vertices.
215 *
216 * \param ctx GL context.
217 * \param newstate new state.
218 *
219 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
220 * and calls dd_function_table::FlushVertices if so. Marks
221 * __GLcontextRec::NewState with \p newstate.
222 */
223 #define FLUSH_VERTICES(ctx, newstate) \
224 do { \
225 if (MESA_VERBOSE & VERBOSE_STATE) \
226 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
227 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
228 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
229 ctx->NewState |= newstate; \
230 } while (0)
231
232 /**
233 * Flush current state.
234 *
235 * \param ctx GL context.
236 * \param newstate new state.
237 *
238 * Checks if dd_function_table::NeedFlush is marked to flush current state,
239 * and calls dd_function_table::FlushVertices if so. Marks
240 * __GLcontextRec::NewState with \p newstate.
241 */
242 #define FLUSH_CURRENT(ctx, newstate) \
243 do { \
244 if (MESA_VERBOSE & VERBOSE_STATE) \
245 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
246 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
247 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
248 ctx->NewState |= newstate; \
249 } while (0)
250
251 /**
252 * Macro to assert that the API call was made outside the
253 * glBegin()/glEnd() pair, with return value.
254 *
255 * \param ctx GL context.
256 * \param retval value to return value in case the assertion fails.
257 */
258 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
259 do { \
260 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
261 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
262 return retval; \
263 } \
264 } while (0)
265
266 /**
267 * Macro to assert that the API call was made outside the
268 * glBegin()/glEnd() pair.
269 *
270 * \param ctx GL context.
271 */
272 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
273 do { \
274 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
275 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
276 return; \
277 } \
278 } while (0)
279
280 /**
281 * Macro to assert that the API call was made outside the
282 * glBegin()/glEnd() pair and flush the vertices.
283 *
284 * \param ctx GL context.
285 */
286 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
287 do { \
288 ASSERT_OUTSIDE_BEGIN_END(ctx); \
289 FLUSH_VERTICES(ctx, 0); \
290 } while (0)
291
292 /**
293 * Macro to assert that the API call was made outside the
294 * glBegin()/glEnd() pair and flush the vertices, with return value.
295 *
296 * \param ctx GL context.
297 * \param retval value to return value in case the assertion fails.
298 */
299 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
300 do { \
301 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
302 FLUSH_VERTICES(ctx, 0); \
303 } while (0)
304
305
306 /*@}*/
307
308
309
310 /**
311 * Macros to help evaluate current state conditions
312 */
313
314 /*@{*/
315
316 /**
317 * Is the secondary color needed?
318 */
319 #define NEED_SECONDARY_COLOR(CTX) \
320 (((CTX)->Light.Enabled && \
321 (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
322 || (CTX)->Fog.ColorSumEnabled \
323 || ((CTX)->VertexProgram._Enabled && \
324 ((CTX)->VertexProgram.Current->InputsRead & VERT_BIT_COLOR1)) \
325 || ((CTX)->FragmentProgram._Enabled && \
326 ((CTX)->FragmentProgram.Current->InputsRead & FRAG_BIT_COL1)) \
327 )
328
329
330 /**
331 * Is two-sided lighting in effect?
332 */
333 #define NEED_TWO_SIDED_LIGHTING(CTX) \
334 (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
335
336
337 /*@}*/
338
339
340 #endif