3 * Mesa context/visual/framebuffer management functions.
5 * There are three Mesa data types which are meant to be used by device
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.
13 * These types should be encapsulated by corresponding device driver
14 * data types. See xmesa.h and xmesaP.h for an example.
16 * In OOP terms, GLcontext, GLvisual, and GLframebuffer are base classes
17 * which the device driver must derive from.
19 * The following functions create and destroy these data types.
23 * Mesa 3-D graphics library
26 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
35 * The above copyright notice and this permission notice shall be included
36 * in all copies or substantial portions of the Software.
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.
56 /**********************************************************************/
57 /** \name Create/destroy a GLvisual. */
61 _mesa_create_visual( GLboolean rgbFlag
,
78 _mesa_initialize_visual( GLvisual
*v
,
96 _mesa_destroy_visual( GLvisual
*vis
);
101 /**********************************************************************/
102 /** \name Create/destroy a GLcontext. */
106 _mesa_create_context( const GLvisual
*visual
,
107 GLcontext
*share_list
,
108 const struct dd_function_table
*driverFunctions
,
109 void *driverContext
);
112 _mesa_initialize_context( GLcontext
*ctx
,
113 const GLvisual
*visual
,
114 GLcontext
*share_list
,
115 const struct dd_function_table
*driverFunctions
,
116 void *driverContext
);
119 _mesa_free_context_data( GLcontext
*ctx
);
122 _mesa_destroy_context( GLcontext
*ctx
);
126 _mesa_copy_context(const GLcontext
*src
, GLcontext
*dst
, GLuint mask
);
130 _mesa_make_current( GLcontext
*ctx
, GLframebuffer
*drawBuffer
,
131 GLframebuffer
*readBuffer
);
134 _mesa_share_state(GLcontext
*ctx
, GLcontext
*ctxToShare
);
137 _mesa_get_current_context(void);
142 /**********************************************************************/
143 /** \name OpenGL SI-style export functions. */
147 _mesa_destroyContext(__GLcontext
*gc
);
150 _mesa_loseCurrent(__GLcontext
*gc
);
153 _mesa_makeCurrent(__GLcontext
*gc
);
156 _mesa_shareContext(__GLcontext
*gc
, __GLcontext
*gcShare
);
159 _mesa_copyContext(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
);
162 _mesa_forceCurrent(__GLcontext
*gc
);
165 _mesa_notifyResize(__GLcontext
*gc
);
168 _mesa_notifyDestroy(__GLcontext
*gc
);
171 _mesa_notifySwapBuffers(__GLcontext
*gc
);
173 extern struct __GLdispatchStateRec
*
174 _mesa_dispatchExec(__GLcontext
*gc
);
177 _mesa_beginDispatchOverride(__GLcontext
*gc
);
180 _mesa_endDispatchOverride(__GLcontext
*gc
);
185 extern struct _glapi_table
*
186 _mesa_get_dispatch(GLcontext
*ctx
);
190 /**********************************************************************/
191 /** \name Miscellaneous */
195 _mesa_record_error( GLcontext
*ctx
, GLenum error
);
198 extern void GLAPIENTRY
199 _mesa_Finish( void );
201 extern void GLAPIENTRY
208 /**********************************************************************/
209 /** \name Macros for contexts/flushing. */
216 * \param ctx GL context.
217 * \param newstate new state.
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.
223 #define FLUSH_VERTICES(ctx, newstate) \
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; \
233 * Flush current state.
235 * \param ctx GL context.
236 * \param newstate new state.
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.
242 #define FLUSH_CURRENT(ctx, newstate) \
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; \
252 * Macro to assert that the API call was made outside the
253 * glBegin()/glEnd() pair, with return value.
255 * \param ctx GL context.
256 * \param retval value to return value in case the assertion fails.
258 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
260 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
261 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
267 * Macro to assert that the API call was made outside the
268 * glBegin()/glEnd() pair.
270 * \param ctx GL context.
272 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
274 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
275 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
281 * Macro to assert that the API call was made outside the
282 * glBegin()/glEnd() pair and flush the vertices.
284 * \param ctx GL context.
286 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
288 ASSERT_OUTSIDE_BEGIN_END(ctx); \
289 FLUSH_VERTICES(ctx, 0); \
293 * Macro to assert that the API call was made outside the
294 * glBegin()/glEnd() pair and flush the vertices, with return value.
296 * \param ctx GL context.
297 * \param retval value to return value in case the assertion fails.
299 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
301 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
302 FLUSH_VERTICES(ctx, 0); \
311 * Macros to help evaluate current state conditions
317 * Is the secondary color needed?
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)) \
331 * Is two-sided lighting in effect?
333 #define NEED_TWO_SIDED_LIGHTING(CTX) \
334 (ctx->Light.Enabled && ctx->Light.Model.TwoSide)