2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * Mesa context and visual-related functions.
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.
38 * These types should be encapsulated by corresponding device driver
39 * data types. See xmesa.h and xmesaP.h for an example.
41 * In OOP terms, GLcontext, GLvisual, and GLframebuffer are base classes
42 * which the device driver must derive from.
44 * The following functions create and destroy these data types.
59 /** \name Visual-related functions */
63 _mesa_create_visual( GLboolean rgbFlag
,
80 _mesa_initialize_visual( GLvisual
*v
,
98 _mesa_destroy_visual( GLvisual
*vis
);
103 /** \name Context-related functions */
107 _mesa_create_context( const GLvisual
*visual
,
108 GLcontext
*share_list
,
109 const struct dd_function_table
*driverFunctions
,
110 void *driverContext
);
113 _mesa_initialize_context( GLcontext
*ctx
,
114 const GLvisual
*visual
,
115 GLcontext
*share_list
,
116 const struct dd_function_table
*driverFunctions
,
117 void *driverContext
);
120 _mesa_initialize_context_extra(GLcontext
*ctx
);
123 _mesa_free_context_data( GLcontext
*ctx
);
126 _mesa_destroy_context( GLcontext
*ctx
);
130 _mesa_copy_context(const GLcontext
*src
, GLcontext
*dst
, GLuint mask
);
134 _mesa_check_init_viewport(GLcontext
*ctx
, GLuint width
, GLuint height
);
137 _mesa_make_current( GLcontext
*ctx
, GLframebuffer
*drawBuffer
,
138 GLframebuffer
*readBuffer
);
141 _mesa_share_state(GLcontext
*ctx
, GLcontext
*ctxToShare
);
144 _mesa_get_current_context(void);
150 _mesa_notifySwapBuffers(__GLcontext
*gc
);
153 extern struct _glapi_table
*
154 _mesa_get_dispatch(GLcontext
*ctx
);
158 _mesa_set_mvp_with_dp4( GLcontext
*ctx
,
162 /** \name Miscellaneous */
166 _mesa_record_error( GLcontext
*ctx
, GLenum error
);
168 extern void GLAPIENTRY
169 _mesa_Finish( void );
171 extern void GLAPIENTRY
179 * \name Macros for flushing buffered rendering commands before state changes,
180 * checking if inside glBegin/glEnd, etc.
187 * \param ctx GL context.
188 * \param newstate new state.
190 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
191 * and calls dd_function_table::FlushVertices if so. Marks
192 * __GLcontextRec::NewState with \p newstate.
194 #define FLUSH_VERTICES(ctx, newstate) \
196 if (MESA_VERBOSE & VERBOSE_STATE) \
197 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
198 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
199 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
200 ctx->NewState |= newstate; \
204 * Flush current state.
206 * \param ctx GL context.
207 * \param newstate new state.
209 * Checks if dd_function_table::NeedFlush is marked to flush current state,
210 * and calls dd_function_table::FlushVertices if so. Marks
211 * __GLcontextRec::NewState with \p newstate.
213 #define FLUSH_CURRENT(ctx, newstate) \
215 if (MESA_VERBOSE & VERBOSE_STATE) \
216 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
217 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
218 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
219 ctx->NewState |= newstate; \
223 * Macro to assert that the API call was made outside the
224 * glBegin()/glEnd() pair, with return value.
226 * \param ctx GL context.
227 * \param retval value to return value in case the assertion fails.
229 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
231 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
232 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
238 * Macro to assert that the API call was made outside the
239 * glBegin()/glEnd() pair.
241 * \param ctx GL context.
243 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
245 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \
246 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
252 * Macro to assert that the API call was made outside the
253 * glBegin()/glEnd() pair and flush the vertices.
255 * \param ctx GL context.
257 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \
259 ASSERT_OUTSIDE_BEGIN_END(ctx); \
260 FLUSH_VERTICES(ctx, 0); \
264 * Macro to assert that the API call was made outside the
265 * glBegin()/glEnd() pair and flush the vertices, with return value.
267 * \param ctx GL context.
268 * \param retval value to return value in case the assertion fails.
270 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \
272 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \
273 FLUSH_VERTICES(ctx, 0); \
281 * Is the secondary color needed?
283 #define NEED_SECONDARY_COLOR(CTX) \
284 (((CTX)->Light.Enabled && \
285 (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \
286 || (CTX)->Fog.ColorSumEnabled \
287 || ((CTX)->VertexProgram._Current && \
288 ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) && \
289 ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
290 || ((CTX)->FragmentProgram._Current && \
291 ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) && \
292 ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
297 * Is RGBA LogicOp enabled?
299 #define RGBA_LOGICOP_ENABLED(CTX) \
300 ((CTX)->Color.ColorLogicOpEnabled || \
301 ((CTX)->Color.BlendEnabled && (CTX)->Color.BlendEquationRGB == GL_LOGIC_OP))
304 #endif /* CONTEXT_H */