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-2001 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.
55 /**********************************************************************/
56 /** \name Create/destroy a GLvisual. */
60 _mesa_create_visual( GLboolean rgbFlag
,
77 _mesa_initialize_visual( GLvisual
*v
,
95 _mesa_destroy_visual( GLvisual
*vis
);
100 /**********************************************************************/
101 /** \name Create/destroy a GLframebuffer. */
104 extern GLframebuffer
*
105 _mesa_create_framebuffer( const GLvisual
*visual
,
106 GLboolean softwareDepth
,
107 GLboolean softwareStencil
,
108 GLboolean softwareAccum
,
109 GLboolean softwareAlpha
);
112 _mesa_initialize_framebuffer( GLframebuffer
*fb
,
113 const GLvisual
*visual
,
114 GLboolean softwareDepth
,
115 GLboolean softwareStencil
,
116 GLboolean softwareAccum
,
117 GLboolean softwareAlpha
);
120 _mesa_free_framebuffer_data( GLframebuffer
*buffer
);
123 _mesa_destroy_framebuffer( GLframebuffer
*buffer
);
128 /**********************************************************************/
129 /** \name Create/destroy a GLcontext. */
133 _mesa_create_context( const GLvisual
*visual
,
134 GLcontext
*share_list
,
139 _mesa_initialize_context( GLcontext
*ctx
,
140 const GLvisual
*visual
,
141 GLcontext
*share_list
,
146 _mesa_free_context_data( GLcontext
*ctx
);
149 _mesa_destroy_context( GLcontext
*ctx
);
153 _mesa_copy_context(const GLcontext
*src
, GLcontext
*dst
, GLuint mask
);
157 _mesa_make_current( GLcontext
*ctx
, GLframebuffer
*buffer
);
161 _mesa_make_current2( GLcontext
*ctx
, GLframebuffer
*drawBuffer
,
162 GLframebuffer
*readBuffer
);
166 _mesa_get_current_context(void);
172 * Macro for declaration and fetching the current context.
174 * \param C local variable which will hold the current context.
176 * It should be used in the variable declaration area of a function:
180 * GET_CURRENT_CONTEXT(ctx);
186 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
190 #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context
196 /**********************************************************************/
197 /** \name OpenGL SI-style export functions. */
201 _mesa_destroyContext(__GLcontext
*gc
);
204 _mesa_loseCurrent(__GLcontext
*gc
);
207 _mesa_makeCurrent(__GLcontext
*gc
);
210 _mesa_shareContext(__GLcontext
*gc
, __GLcontext
*gcShare
);
213 _mesa_copyContext(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
);
216 _mesa_forceCurrent(__GLcontext
*gc
);
219 _mesa_notifyResize(__GLcontext
*gc
);
222 _mesa_notifyDestroy(__GLcontext
*gc
);
225 _mesa_notifySwapBuffers(__GLcontext
*gc
);
227 extern struct __GLdispatchStateRec
*
228 _mesa_dispatchExec(__GLcontext
*gc
);
231 _mesa_beginDispatchOverride(__GLcontext
*gc
);
234 _mesa_endDispatchOverride(__GLcontext
*gc
);
239 extern struct _glapi_table
*
240 _mesa_get_dispatch(GLcontext
*ctx
);
244 /**********************************************************************/
245 /** \name Miscellaneous */
249 _mesa_record_error( GLcontext
*ctx
, GLenum error
);
253 _mesa_Finish( void );
262 /**********************************************************************/
263 /** \name Macros for contexts/flushing. */
269 * \param ctx GL context.
270 * \param newstate new state.
272 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
273 * and calls dd_function_table::FlushVertices if so. Marks
274 * __GLcontextRec::NewState with \p newstate.
276 * \todo Eventually let the driver specify what state changes require a flush:
278 #define FLUSH_VERTICES(ctx, newstate) \
280 if (MESA_VERBOSE & VERBOSE_STATE) \
281 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", __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", __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); \