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