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