context.h revision af69d88d
1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 26/** 27 * \file context.h 28 * Mesa context and visual-related functions. 29 * 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. 37 * 38 * These types should be encapsulated by corresponding device driver 39 * data types. See xmesa.h and xmesaP.h for an example. 40 * 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. 43 * 44 * The following functions create and destroy these data types. 45 */ 46 47 48#ifndef CONTEXT_H 49#define CONTEXT_H 50 51 52#include "imports.h" 53#include "mtypes.h" 54 55 56#ifdef __cplusplus 57extern "C" { 58#endif 59 60 61struct _glapi_table; 62 63 64/** \name Visual-related functions */ 65/*@{*/ 66 67extern struct gl_config * 68_mesa_create_visual( GLboolean dbFlag, 69 GLboolean stereoFlag, 70 GLint redBits, 71 GLint greenBits, 72 GLint blueBits, 73 GLint alphaBits, 74 GLint depthBits, 75 GLint stencilBits, 76 GLint accumRedBits, 77 GLint accumGreenBits, 78 GLint accumBlueBits, 79 GLint accumAlphaBits, 80 GLint numSamples ); 81 82extern GLboolean 83_mesa_initialize_visual( struct gl_config *v, 84 GLboolean dbFlag, 85 GLboolean stereoFlag, 86 GLint redBits, 87 GLint greenBits, 88 GLint blueBits, 89 GLint alphaBits, 90 GLint depthBits, 91 GLint stencilBits, 92 GLint accumRedBits, 93 GLint accumGreenBits, 94 GLint accumBlueBits, 95 GLint accumAlphaBits, 96 GLint numSamples ); 97 98extern void 99_mesa_destroy_visual( struct gl_config *vis ); 100 101/*@}*/ 102 103 104/** \name Context-related functions */ 105/*@{*/ 106 107extern GLboolean 108_mesa_initialize_context( struct gl_context *ctx, 109 gl_api api, 110 const struct gl_config *visual, 111 struct gl_context *share_list, 112 const struct dd_function_table *driverFunctions); 113 114extern 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); 119 120extern void 121_mesa_free_context_data( struct gl_context *ctx ); 122 123extern void 124_mesa_destroy_context( struct gl_context *ctx ); 125 126 127extern void 128_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask); 129 130 131extern void 132_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height); 133 134extern GLboolean 135_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer, 136 struct gl_framebuffer *readBuffer ); 137 138extern GLboolean 139_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare); 140 141extern struct gl_context * 142_mesa_get_current_context(void); 143 144/*@}*/ 145 146extern void 147_mesa_init_constants(struct gl_constants *consts, gl_api api); 148 149extern void 150_mesa_init_get_hash(struct gl_context *ctx); 151 152extern void 153_mesa_notifySwapBuffers(struct gl_context *gc); 154 155 156extern struct _glapi_table * 157_mesa_get_dispatch(struct gl_context *ctx); 158 159 160extern GLboolean 161_mesa_valid_to_render(struct gl_context *ctx, const char *where); 162 163 164 165/** \name Miscellaneous */ 166/*@{*/ 167 168extern void 169_mesa_record_error( struct gl_context *ctx, GLenum error ); 170 171 172extern void 173_mesa_finish(struct gl_context *ctx); 174 175extern void 176_mesa_flush(struct gl_context *ctx); 177 178extern int 179_mesa_generic_nop(void); 180 181extern void GLAPIENTRY 182_mesa_Finish( void ); 183 184extern void GLAPIENTRY 185_mesa_Flush( void ); 186 187/*@}*/ 188 189 190/** 191 * Are we currently between glBegin and glEnd? 192 * During execution, not display list compilation. 193 */ 194static inline GLboolean 195_mesa_inside_begin_end(const struct gl_context *ctx) 196{ 197 return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END; 198} 199 200 201/** 202 * Are we currently between glBegin and glEnd in a display list? 203 */ 204static inline GLboolean 205_mesa_inside_dlist_begin_end(const struct gl_context *ctx) 206{ 207 return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX; 208} 209 210 211 212/** 213 * \name Macros for flushing buffered rendering commands before state changes, 214 * checking if inside glBegin/glEnd, etc. 215 */ 216/*@{*/ 217 218/** 219 * Flush vertices. 220 * 221 * \param ctx GL context. 222 * \param newstate new state. 223 * 224 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices, 225 * and calls dd_function_table::FlushVertices if so. Marks 226 * __struct gl_contextRec::NewState with \p newstate. 227 */ 228#define FLUSH_VERTICES(ctx, newstate) \ 229do { \ 230 if (MESA_VERBOSE & VERBOSE_STATE) \ 231 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\ 232 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \ 233 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \ 234 ctx->NewState |= newstate; \ 235} while (0) 236 237/** 238 * Flush current state. 239 * 240 * \param ctx GL context. 241 * \param newstate new state. 242 * 243 * Checks if dd_function_table::NeedFlush is marked to flush current state, 244 * and calls dd_function_table::FlushVertices if so. Marks 245 * __struct gl_contextRec::NewState with \p newstate. 246 */ 247#define FLUSH_CURRENT(ctx, newstate) \ 248do { \ 249 if (MESA_VERBOSE & VERBOSE_STATE) \ 250 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \ 251 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \ 252 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \ 253 ctx->NewState |= newstate; \ 254} while (0) 255 256/** 257 * Macro to assert that the API call was made outside the 258 * glBegin()/glEnd() pair, with return value. 259 * 260 * \param ctx GL context. 261 * \param retval value to return in case the assertion fails. 262 */ 263#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \ 264do { \ 265 if (_mesa_inside_begin_end(ctx)) { \ 266 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 267 return retval; \ 268 } \ 269} while (0) 270 271/** 272 * Macro to assert that the API call was made outside the 273 * glBegin()/glEnd() pair. 274 * 275 * \param ctx GL context. 276 */ 277#define ASSERT_OUTSIDE_BEGIN_END(ctx) \ 278do { \ 279 if (_mesa_inside_begin_end(ctx)) { \ 280 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 281 return; \ 282 } \ 283} while (0) 284 285/*@}*/ 286 287 288/** 289 * Checks if the context is for Desktop GL (Compatibility or Core) 290 */ 291static inline GLboolean 292_mesa_is_desktop_gl(const struct gl_context *ctx) 293{ 294 return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE; 295} 296 297 298/** 299 * Checks if the context is for any GLES version 300 */ 301static inline GLboolean 302_mesa_is_gles(const struct gl_context *ctx) 303{ 304 return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2; 305} 306 307 308/** 309 * Checks if the context is for GLES 3.x 310 */ 311static inline GLboolean 312_mesa_is_gles3(const struct gl_context *ctx) 313{ 314 return ctx->API == API_OPENGLES2 && ctx->Version >= 30; 315} 316 317 318/** 319 * Checks if the context supports geometry shaders. 320 */ 321static inline GLboolean 322_mesa_has_geometry_shaders(const struct gl_context *ctx) 323{ 324 return _mesa_is_desktop_gl(ctx) && 325 (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4); 326} 327 328 329#ifdef __cplusplus 330} 331#endif 332 333 334#endif /* CONTEXT_H */ 335