05251849b575156761b2fbf853724e7bb3f3b8e0
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 * - struct gl_context: this contains the Mesa rendering state
33 * - struct gl_config: this describes the color buffer (RGB vs. ci), whether
34 * or not there's a depth buffer, stencil buffer, etc.
35 * - struct gl_framebuffer: contains pointers to the depth buffer, stencil
36 * buffer, 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, struct gl_context, struct gl_config, and struct gl_framebuffer
42 * are base classes which the device driver must derive from.
44 * The following functions create and destroy these data types.
64 /** \name Visual-related functions */
67 extern struct gl_config
*
68 _mesa_create_visual( GLboolean dbFlag
,
83 _mesa_initialize_visual( struct gl_config
*v
,
99 _mesa_destroy_visual( struct gl_config
*vis
);
104 /** \name Context-related functions */
108 _mesa_initialize_context( struct gl_context
*ctx
,
110 const struct gl_config
*visual
,
111 struct gl_context
*share_list
,
112 const struct dd_function_table
*driverFunctions
);
114 extern struct gl_context
*
115 _mesa_create_context(gl_api api
,
116 const struct gl_config
*visual
,
117 struct gl_context
*share_list
,
118 const struct dd_function_table
*driverFunctions
);
121 _mesa_free_context_data( struct gl_context
*ctx
);
124 _mesa_destroy_context( struct gl_context
*ctx
);
128 _mesa_copy_context(const struct gl_context
*src
, struct gl_context
*dst
, GLuint mask
);
132 _mesa_check_init_viewport(struct gl_context
*ctx
, GLuint width
, GLuint height
);
135 _mesa_make_current( struct gl_context
*ctx
, struct gl_framebuffer
*drawBuffer
,
136 struct gl_framebuffer
*readBuffer
);
139 _mesa_share_state(struct gl_context
*ctx
, struct gl_context
*ctxToShare
);
141 extern struct gl_context
*
142 _mesa_get_current_context(void);
147 _mesa_init_get_hash(struct gl_context
*ctx
);
150 _mesa_notifySwapBuffers(struct gl_context
*gc
);
153 extern struct _glapi_table
*
154 _mesa_get_dispatch(struct gl_context
*ctx
);
158 _mesa_set_mvp_with_dp4( struct gl_context
*ctx
,
163 _mesa_valid_to_render(struct gl_context
*ctx
, const char *where
);
167 /** \name Miscellaneous */
171 _mesa_record_error( struct gl_context
*ctx
, GLenum error
);
175 _mesa_finish(struct gl_context
*ctx
);
178 _mesa_flush(struct gl_context
*ctx
);
181 _mesa_generic_nop(void);
183 extern void GLAPIENTRY
184 _mesa_Finish( void );
186 extern void GLAPIENTRY
193 * Are we currently between glBegin and glEnd?
194 * During execution, not display list compilation.
196 static inline GLboolean
197 _mesa_inside_begin_end(const struct gl_context
*ctx
)
199 return ctx
->Driver
.CurrentExecPrimitive
!= PRIM_OUTSIDE_BEGIN_END
;
204 * \name Macros for flushing buffered rendering commands before state changes,
205 * checking if inside glBegin/glEnd, etc.
212 * \param ctx GL context.
213 * \param newstate new state.
215 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
216 * and calls dd_function_table::FlushVertices if so. Marks
217 * __struct gl_contextRec::NewState with \p newstate.
219 #define FLUSH_VERTICES(ctx, newstate) \
221 if (MESA_VERBOSE & VERBOSE_STATE) \
222 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
223 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
224 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \
225 ctx->NewState |= newstate; \
229 * Flush current state.
231 * \param ctx GL context.
232 * \param newstate new state.
234 * Checks if dd_function_table::NeedFlush is marked to flush current state,
235 * and calls dd_function_table::FlushVertices if so. Marks
236 * __struct gl_contextRec::NewState with \p newstate.
238 #define FLUSH_CURRENT(ctx, newstate) \
240 if (MESA_VERBOSE & VERBOSE_STATE) \
241 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \
242 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
243 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
244 ctx->NewState |= newstate; \
248 * Macro to assert that the API call was made outside the
249 * glBegin()/glEnd() pair, with return value.
251 * \param ctx GL context.
252 * \param retval value to return in case the assertion fails.
254 #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
256 if (_mesa_inside_begin_end(ctx)) { \
257 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
263 * Macro to assert that the API call was made outside the
264 * glBegin()/glEnd() pair.
266 * \param ctx GL context.
268 #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
270 if (_mesa_inside_begin_end(ctx)) { \
271 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
280 * Checks if the context is for Desktop GL (Compatibility or Core)
282 static inline GLboolean
283 _mesa_is_desktop_gl(const struct gl_context
*ctx
)
285 return ctx
->API
== API_OPENGL_COMPAT
|| ctx
->API
== API_OPENGL_CORE
;
290 * Checks if the context is for any GLES version
292 static inline GLboolean
293 _mesa_is_gles(const struct gl_context
*ctx
)
295 return ctx
->API
== API_OPENGLES
|| ctx
->API
== API_OPENGLES2
;
300 * Checks if the context is for GLES 3.x
302 static inline GLboolean
303 _mesa_is_gles3(const struct gl_context
*ctx
)
305 return ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30;
314 #endif /* CONTEXT_H */