Merge branch 'mesa_7_6_branch'
[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 "imports.h"
53 #include "mtypes.h"
54
55
56 struct _glapi_table;
57
58
59 /** \name Visual-related functions */
60 /*@{*/
61
62 extern GLvisual *
63 _mesa_create_visual( GLboolean rgbFlag,
64 GLboolean dbFlag,
65 GLboolean stereoFlag,
66 GLint redBits,
67 GLint greenBits,
68 GLint blueBits,
69 GLint alphaBits,
70 GLint indexBits,
71 GLint depthBits,
72 GLint stencilBits,
73 GLint accumRedBits,
74 GLint accumGreenBits,
75 GLint accumBlueBits,
76 GLint accumAlphaBits,
77 GLint numSamples );
78
79 extern GLboolean
80 _mesa_initialize_visual( GLvisual *v,
81 GLboolean rgbFlag,
82 GLboolean dbFlag,
83 GLboolean stereoFlag,
84 GLint redBits,
85 GLint greenBits,
86 GLint blueBits,
87 GLint alphaBits,
88 GLint indexBits,
89 GLint depthBits,
90 GLint stencilBits,
91 GLint accumRedBits,
92 GLint accumGreenBits,
93 GLint accumBlueBits,
94 GLint accumAlphaBits,
95 GLint numSamples );
96
97 extern void
98 _mesa_destroy_visual( GLvisual *vis );
99
100 /*@}*/
101
102
103 /** \name Context-related functions */
104 /*@{*/
105
106 extern GLcontext *
107 _mesa_create_context( const GLvisual *visual,
108 GLcontext *share_list,
109 const struct dd_function_table *driverFunctions,
110 void *driverContext );
111
112 extern GLboolean
113 _mesa_initialize_context( GLcontext *ctx,
114 const GLvisual *visual,
115 GLcontext *share_list,
116 const struct dd_function_table *driverFunctions,
117 void *driverContext );
118
119 extern void
120 _mesa_initialize_context_extra(GLcontext *ctx);
121
122 extern void
123 _mesa_free_context_data( GLcontext *ctx );
124
125 extern void
126 _mesa_destroy_context( GLcontext *ctx );
127
128
129 extern void
130 _mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
131
132
133 extern void
134 _mesa_check_init_viewport(GLcontext *ctx, GLuint width, GLuint height);
135
136 extern GLboolean
137 _mesa_make_current( GLcontext *ctx, GLframebuffer *drawBuffer,
138 GLframebuffer *readBuffer );
139
140 extern GLboolean
141 _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare);
142
143 extern GLcontext *
144 _mesa_get_current_context(void);
145
146 /*@}*/
147
148
149 extern void
150 _mesa_notifySwapBuffers(__GLcontext *gc);
151
152
153 extern struct _glapi_table *
154 _mesa_get_dispatch(GLcontext *ctx);
155
156
157 void
158 _mesa_set_mvp_with_dp4( GLcontext *ctx,
159 GLboolean flag );
160
161
162 extern GLboolean
163 _mesa_valid_to_render(GLcontext *ctx, const char *where);
164
165
166
167 /** \name Miscellaneous */
168 /*@{*/
169
170 extern void
171 _mesa_record_error( GLcontext *ctx, GLenum error );
172
173 extern void GLAPIENTRY
174 _mesa_Finish( void );
175
176 extern void GLAPIENTRY
177 _mesa_Flush( void );
178
179 /*@}*/
180
181
182 /**
183 * \name Macros for flushing buffered rendering commands before state changes,
184 * checking if inside glBegin/glEnd, etc.
185 */
186 /*@{*/
187
188 /**
189 * Flush vertices.
190 *
191 * \param ctx GL context.
192 * \param newstate new state.
193 *
194 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
195 * and calls dd_function_table::FlushVertices if so. Marks
196 * __GLcontextRec::NewState with \p newstate.
197 */
198 #define FLUSH_VERTICES(ctx, newstate) \
199 do { \
200 if (MESA_VERBOSE & VERBOSE_STATE) \
201 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
202 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
203 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
204 ctx->NewState |= newstate; \
205 } while (0)
206
207 /**
208 * Flush current state.
209 *
210 * \param ctx GL context.
211 * \param newstate new state.
212 *
213 * Checks if dd_function_table::NeedFlush is marked to flush current state,
214 * and calls dd_function_table::FlushVertices if so. Marks
215 * __GLcontextRec::NewState with \p newstate.
216 */
217 #define FLUSH_CURRENT(ctx, newstate) \
218 do { \
219 if (MESA_VERBOSE & VERBOSE_STATE) \
220 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
221 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
222 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
223 ctx->NewState |= newstate; \
224 } while (0)
225
226 /**
227 * Macro to assert that the API call was made outside the
228 * glBegin()/glEnd() pair, with return value.
229 *
230 * \param ctx GL context.
231 * \param retval value to return value in case the assertion fails.
232 */
233 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
234 do { \
235 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
236 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
237 return retval; \
238 } \
239 } while (0)
240
241 /**
242 * Macro to assert that the API call was made outside the
243 * glBegin()/glEnd() pair.
244 *
245 * \param ctx GL context.
246 */
247 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
248 do { \
249 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
250 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
251 return; \
252 } \
253 } while (0)
254
255 /**
256 * Macro to assert that the API call was made outside the
257 * glBegin()/glEnd() pair and flush the vertices.
258 *
259 * \param ctx GL context.
260 */
261 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
262 do { \
263 ASSERT_OUTSIDE_BEGIN_END(ctx); \
264 FLUSH_VERTICES(ctx, 0); \
265 } while (0)
266
267 /**
268 * Macro to assert that the API call was made outside the
269 * glBegin()/glEnd() pair and flush the vertices, with return value.
270 *
271 * \param ctx GL context.
272 * \param retval value to return value in case the assertion fails.
273 */
274 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
275 do { \
276 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
277 FLUSH_VERTICES(ctx, 0); \
278 } while (0)
279
280 /*@}*/
281
282
283
284 /**
285 * Is the secondary color needed?
286 */
287 #define NEED_SECONDARY_COLOR(CTX) \
288 (((CTX)->Light.Enabled && \
289 (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
290 || (CTX)->Fog.ColorSumEnabled \
291 || ((CTX)->VertexProgram._Current && \
292 ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) && \
293 ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
294 || ((CTX)->FragmentProgram._Current && \
295 ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) && \
296 ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
297 )
298
299
300 /**
301 * Is RGBA LogicOp enabled?
302 */
303 #define RGBA_LOGICOP_ENABLED(CTX) \
304 ((CTX)->Color.ColorLogicOpEnabled || \
305 ((CTX)->Color.BlendEnabled && (CTX)->Color.BlendEquationRGB == GL_LOGIC_OP))
306
307
308 #endif /* CONTEXT_H */