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 GLframebuffer. */
105 extern GLframebuffer
*
106 _mesa_create_framebuffer( const GLvisual
*visual
,
107 GLboolean softwareDepth
,
108 GLboolean softwareStencil
,
109 GLboolean softwareAccum
,
110 GLboolean softwareAlpha
);
113 _mesa_initialize_framebuffer( GLframebuffer
*fb
,
114 const GLvisual
*visual
,
115 GLboolean softwareDepth
,
116 GLboolean softwareStencil
,
117 GLboolean softwareAccum
,
118 GLboolean softwareAlpha
);
121 _mesa_free_framebuffer_data( GLframebuffer
*buffer
);
124 _mesa_destroy_framebuffer( GLframebuffer
*buffer
);
129 /**********************************************************************/
130 /** \name Create/destroy a GLcontext. */
134 _mesa_create_context( const GLvisual
*visual
,
135 GLcontext
*share_list
,
136 const struct dd_function_table
*driverFunctions
,
137 void *driverContext
);
140 _mesa_initialize_context( GLcontext
*ctx
,
141 const GLvisual
*visual
,
142 GLcontext
*share_list
,
143 const struct dd_function_table
*driverFunctions
,
144 void *driverContext
);
147 _mesa_free_context_data( GLcontext
*ctx
);
150 _mesa_destroy_context( GLcontext
*ctx
);
154 _mesa_copy_context(const GLcontext
*src
, GLcontext
*dst
, GLuint mask
);
158 _mesa_make_current( GLcontext
*ctx
, GLframebuffer
*buffer
);
162 _mesa_make_current2( GLcontext
*ctx
, GLframebuffer
*drawBuffer
,
163 GLframebuffer
*readBuffer
);
167 _mesa_get_current_context(void);
173 * Macro for declaration and fetching the current context.
175 * \param C local variable which will hold the current context.
177 * It should be used in the variable declaration area of a function:
181 * GET_CURRENT_CONTEXT(ctx);
187 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
191 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
197 /**********************************************************************/
198 /** \name OpenGL SI-style export functions. */
202 _mesa_destroyContext(__GLcontext
*gc
);
205 _mesa_loseCurrent(__GLcontext
*gc
);
208 _mesa_makeCurrent(__GLcontext
*gc
);
211 _mesa_shareContext(__GLcontext
*gc
, __GLcontext
*gcShare
);
214 _mesa_copyContext(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
);
217 _mesa_forceCurrent(__GLcontext
*gc
);
220 _mesa_notifyResize(__GLcontext
*gc
);
223 _mesa_notifyDestroy(__GLcontext
*gc
);
226 _mesa_notifySwapBuffers(__GLcontext
*gc
);
228 extern struct __GLdispatchStateRec
*
229 _mesa_dispatchExec(__GLcontext
*gc
);
232 _mesa_beginDispatchOverride(__GLcontext
*gc
);
235 _mesa_endDispatchOverride(__GLcontext
*gc
);
240 extern struct _glapi_table
*
241 _mesa_get_dispatch(GLcontext
*ctx
);
245 /**********************************************************************/
246 /** \name Miscellaneous */
250 _mesa_record_error( GLcontext
*ctx
, GLenum error
);
253 extern void GLAPIENTRY
254 _mesa_Finish( void );
256 extern void GLAPIENTRY
263 /**********************************************************************/
264 /** \name Macros for contexts/flushing. */
271 * \param ctx GL context.
272 * \param newstate new state.
274 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
275 * and calls dd_function_table::FlushVertices if so. Marks
276 * __GLcontextRec::NewState with \p newstate.
278 #define FLUSH_VERTICES(ctx, newstate) \
280 if (MESA_VERBOSE & VERBOSE_STATE) \
281 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
282 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
283 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
284 ctx->NewState |= newstate; \
288 * Flush current state.
290 * \param ctx GL context.
291 * \param newstate new state.
293 * Checks if dd_function_table::NeedFlush is marked to flush current state,
294 * and calls dd_function_table::FlushVertices if so. Marks
295 * __GLcontextRec::NewState with \p newstate.
297 #define FLUSH_CURRENT(ctx, newstate) \
299 if (MESA_VERBOSE & VERBOSE_STATE) \
300 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
301 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
302 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
303 ctx->NewState |= newstate; \
307 * Macro to assert that the API call was made outside the
308 * glBegin()/glEnd() pair, with return value.
310 * \param ctx GL context.
311 * \param retval value to return value in case the assertion fails.
313 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
315 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
316 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
322 * Macro to assert that the API call was made outside the
323 * glBegin()/glEnd() pair.
325 * \param ctx GL context.
327 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
329 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
330 _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" ); \
336 * Macro to assert that the API call was made outside the
337 * glBegin()/glEnd() pair and flush the vertices.
339 * \param ctx GL context.
341 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
343 ASSERT_OUTSIDE_BEGIN_END(ctx); \
344 FLUSH_VERTICES(ctx, 0); \
348 * Macro to assert that the API call was made outside the
349 * glBegin()/glEnd() pair and flush the vertices, with return value.
351 * \param ctx GL context.
352 * \param retval value to return value in case the assertion fails.
354 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
356 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
357 FLUSH_VERTICES(ctx, 0); \
366 * Macros to help evaluate current state conditions
372 * Is the secondary color needed?
374 #define NEED_SECONDARY_COLOR(CTX) \
375 (((CTX)->Light.Enabled && \
376 (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
377 || (CTX)->Fog.ColorSumEnabled \
378 || ((CTX)->VertexProgram._Enabled && \
379 ((CTX)->VertexProgram.Current->InputsRead & VERT_BIT_COLOR1)) \
380 || ((CTX)->FragmentProgram._Enabled && \
381 ((CTX)->FragmentProgram.Current->InputsRead & FRAG_BIT_COL1)) \
386 * Is two-sided lighting in effect?
388 #define NEED_TWO_SIDED_LIGHTING(CTX) \
389 (ctx->Light.Enabled && ctx->Light.Model.TwoSide)