context.h revision b8e80941
1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg 26848b8605Smrg/** 27848b8605Smrg * \file context.h 28848b8605Smrg * Mesa context and visual-related functions. 29848b8605Smrg * 30848b8605Smrg * There are three large Mesa data types/classes which are meant to be 31848b8605Smrg * used by device drivers: 32848b8605Smrg * - struct gl_context: this contains the Mesa rendering state 33848b8605Smrg * - struct gl_config: this describes the color buffer (RGB vs. ci), whether 34848b8605Smrg * or not there's a depth buffer, stencil buffer, etc. 35848b8605Smrg * - struct gl_framebuffer: contains pointers to the depth buffer, stencil 36848b8605Smrg * buffer, accum buffer and alpha buffers. 37848b8605Smrg * 38848b8605Smrg * These types should be encapsulated by corresponding device driver 39848b8605Smrg * data types. See xmesa.h and xmesaP.h for an example. 40848b8605Smrg * 41848b8605Smrg * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer 42848b8605Smrg * are base classes which the device driver must derive from. 43848b8605Smrg * 44848b8605Smrg * The following functions create and destroy these data types. 45848b8605Smrg */ 46848b8605Smrg 47848b8605Smrg 48848b8605Smrg#ifndef CONTEXT_H 49848b8605Smrg#define CONTEXT_H 50848b8605Smrg 51848b8605Smrg 52b8e80941Smrg#include "errors.h" 53848b8605Smrg#include "imports.h" 54b8e80941Smrg#include "extensions.h" 55848b8605Smrg#include "mtypes.h" 56b8e80941Smrg#include "vbo/vbo.h" 57848b8605Smrg 58848b8605Smrg 59848b8605Smrg#ifdef __cplusplus 60848b8605Smrgextern "C" { 61848b8605Smrg#endif 62848b8605Smrg 63848b8605Smrg 64848b8605Smrgstruct _glapi_table; 65848b8605Smrg 66848b8605Smrg 67848b8605Smrg/** \name Visual-related functions */ 68848b8605Smrg/*@{*/ 69848b8605Smrg 70848b8605Smrgextern struct gl_config * 71848b8605Smrg_mesa_create_visual( GLboolean dbFlag, 72848b8605Smrg GLboolean stereoFlag, 73848b8605Smrg GLint redBits, 74848b8605Smrg GLint greenBits, 75848b8605Smrg GLint blueBits, 76848b8605Smrg GLint alphaBits, 77848b8605Smrg GLint depthBits, 78848b8605Smrg GLint stencilBits, 79848b8605Smrg GLint accumRedBits, 80848b8605Smrg GLint accumGreenBits, 81848b8605Smrg GLint accumBlueBits, 82848b8605Smrg GLint accumAlphaBits, 83b8e80941Smrg GLuint numSamples ); 84848b8605Smrg 85848b8605Smrgextern GLboolean 86848b8605Smrg_mesa_initialize_visual( struct gl_config *v, 87848b8605Smrg GLboolean dbFlag, 88848b8605Smrg GLboolean stereoFlag, 89848b8605Smrg GLint redBits, 90848b8605Smrg GLint greenBits, 91848b8605Smrg GLint blueBits, 92848b8605Smrg GLint alphaBits, 93848b8605Smrg GLint depthBits, 94848b8605Smrg GLint stencilBits, 95848b8605Smrg GLint accumRedBits, 96848b8605Smrg GLint accumGreenBits, 97848b8605Smrg GLint accumBlueBits, 98848b8605Smrg GLint accumAlphaBits, 99b8e80941Smrg GLuint numSamples ); 100848b8605Smrg 101848b8605Smrgextern void 102848b8605Smrg_mesa_destroy_visual( struct gl_config *vis ); 103848b8605Smrg 104848b8605Smrg/*@}*/ 105848b8605Smrg 106848b8605Smrg 107848b8605Smrg/** \name Context-related functions */ 108848b8605Smrg/*@{*/ 109848b8605Smrg 110848b8605Smrgextern GLboolean 111848b8605Smrg_mesa_initialize_context( struct gl_context *ctx, 112848b8605Smrg gl_api api, 113848b8605Smrg const struct gl_config *visual, 114848b8605Smrg struct gl_context *share_list, 115848b8605Smrg const struct dd_function_table *driverFunctions); 116848b8605Smrg 117848b8605Smrgextern void 118b8e80941Smrg_mesa_free_context_data(struct gl_context *ctx, bool destroy_compiler_types); 119848b8605Smrg 120848b8605Smrgextern void 121848b8605Smrg_mesa_destroy_context( struct gl_context *ctx ); 122848b8605Smrg 123848b8605Smrg 124848b8605Smrgextern void 125848b8605Smrg_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask); 126848b8605Smrg 127848b8605Smrgextern GLboolean 128848b8605Smrg_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer, 129848b8605Smrg struct gl_framebuffer *readBuffer ); 130848b8605Smrg 131848b8605Smrgextern GLboolean 132848b8605Smrg_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare); 133848b8605Smrg 134848b8605Smrgextern struct gl_context * 135848b8605Smrg_mesa_get_current_context(void); 136848b8605Smrg 137848b8605Smrg/*@}*/ 138848b8605Smrg 139848b8605Smrgextern void 140848b8605Smrg_mesa_init_constants(struct gl_constants *consts, gl_api api); 141848b8605Smrg 142848b8605Smrgextern void 143848b8605Smrg_mesa_notifySwapBuffers(struct gl_context *gc); 144848b8605Smrg 145848b8605Smrg 146848b8605Smrgextern struct _glapi_table * 147848b8605Smrg_mesa_get_dispatch(struct gl_context *ctx); 148848b8605Smrg 149b8e80941Smrgextern void 150b8e80941Smrg_mesa_set_context_lost_dispatch(struct gl_context *ctx); 151848b8605Smrg 152848b8605Smrg 153848b8605Smrg 154848b8605Smrg/** \name Miscellaneous */ 155848b8605Smrg/*@{*/ 156848b8605Smrg 157848b8605Smrgextern void 158848b8605Smrg_mesa_flush(struct gl_context *ctx); 159848b8605Smrg 160848b8605Smrgextern void GLAPIENTRY 161848b8605Smrg_mesa_Finish( void ); 162848b8605Smrg 163848b8605Smrgextern void GLAPIENTRY 164848b8605Smrg_mesa_Flush( void ); 165848b8605Smrg 166848b8605Smrg/*@}*/ 167848b8605Smrg 168848b8605Smrg 169848b8605Smrg/** 170848b8605Smrg * Are we currently between glBegin and glEnd? 171848b8605Smrg * During execution, not display list compilation. 172848b8605Smrg */ 173848b8605Smrgstatic inline GLboolean 174848b8605Smrg_mesa_inside_begin_end(const struct gl_context *ctx) 175848b8605Smrg{ 176848b8605Smrg return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END; 177848b8605Smrg} 178848b8605Smrg 179848b8605Smrg 180848b8605Smrg/** 181848b8605Smrg * Are we currently between glBegin and glEnd in a display list? 182848b8605Smrg */ 183848b8605Smrgstatic inline GLboolean 184848b8605Smrg_mesa_inside_dlist_begin_end(const struct gl_context *ctx) 185848b8605Smrg{ 186848b8605Smrg return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX; 187848b8605Smrg} 188848b8605Smrg 189848b8605Smrg 190848b8605Smrg 191848b8605Smrg/** 192848b8605Smrg * \name Macros for flushing buffered rendering commands before state changes, 193848b8605Smrg * checking if inside glBegin/glEnd, etc. 194848b8605Smrg */ 195848b8605Smrg/*@{*/ 196848b8605Smrg 197848b8605Smrg/** 198848b8605Smrg * Flush vertices. 199848b8605Smrg * 200848b8605Smrg * \param ctx GL context. 201848b8605Smrg * \param newstate new state. 202848b8605Smrg * 203848b8605Smrg * Checks if dd_function_table::NeedFlush is marked to flush stored vertices, 204848b8605Smrg * and calls dd_function_table::FlushVertices if so. Marks 205848b8605Smrg * __struct gl_contextRec::NewState with \p newstate. 206848b8605Smrg */ 207848b8605Smrg#define FLUSH_VERTICES(ctx, newstate) \ 208848b8605Smrgdo { \ 209848b8605Smrg if (MESA_VERBOSE & VERBOSE_STATE) \ 210b8e80941Smrg _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", __func__); \ 211848b8605Smrg if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \ 212b8e80941Smrg vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \ 213848b8605Smrg ctx->NewState |= newstate; \ 214848b8605Smrg} while (0) 215848b8605Smrg 216848b8605Smrg/** 217848b8605Smrg * Flush current state. 218848b8605Smrg * 219848b8605Smrg * \param ctx GL context. 220848b8605Smrg * \param newstate new state. 221848b8605Smrg * 222848b8605Smrg * Checks if dd_function_table::NeedFlush is marked to flush current state, 223848b8605Smrg * and calls dd_function_table::FlushVertices if so. Marks 224848b8605Smrg * __struct gl_contextRec::NewState with \p newstate. 225848b8605Smrg */ 226848b8605Smrg#define FLUSH_CURRENT(ctx, newstate) \ 227848b8605Smrgdo { \ 228848b8605Smrg if (MESA_VERBOSE & VERBOSE_STATE) \ 229b8e80941Smrg _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", __func__); \ 230848b8605Smrg if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \ 231b8e80941Smrg vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \ 232848b8605Smrg ctx->NewState |= newstate; \ 233848b8605Smrg} while (0) 234848b8605Smrg 235b8e80941Smrg/** 236b8e80941Smrg * Flush vertices. 237b8e80941Smrg * 238b8e80941Smrg * \param ctx GL context. 239b8e80941Smrg * 240b8e80941Smrg * Checks if dd_function_table::NeedFlush is marked to flush stored vertices 241b8e80941Smrg * or current state and calls dd_function_table::FlushVertices if so. 242b8e80941Smrg */ 243b8e80941Smrg#define FLUSH_FOR_DRAW(ctx) \ 244b8e80941Smrgdo { \ 245b8e80941Smrg if (MESA_VERBOSE & VERBOSE_STATE) \ 246b8e80941Smrg _mesa_debug(ctx, "FLUSH_FOR_DRAW in %s\n", __func__); \ 247b8e80941Smrg if (ctx->Driver.NeedFlush) \ 248b8e80941Smrg vbo_exec_FlushVertices(ctx, ctx->Driver.NeedFlush); \ 249b8e80941Smrg} while (0) 250b8e80941Smrg 251848b8605Smrg/** 252848b8605Smrg * Macro to assert that the API call was made outside the 253848b8605Smrg * glBegin()/glEnd() pair, with return value. 254848b8605Smrg * 255848b8605Smrg * \param ctx GL context. 256848b8605Smrg * \param retval value to return in case the assertion fails. 257848b8605Smrg */ 258848b8605Smrg#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \ 259848b8605Smrgdo { \ 260848b8605Smrg if (_mesa_inside_begin_end(ctx)) { \ 261848b8605Smrg _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 262848b8605Smrg return retval; \ 263848b8605Smrg } \ 264848b8605Smrg} while (0) 265848b8605Smrg 266848b8605Smrg/** 267848b8605Smrg * Macro to assert that the API call was made outside the 268848b8605Smrg * glBegin()/glEnd() pair. 269848b8605Smrg * 270848b8605Smrg * \param ctx GL context. 271848b8605Smrg */ 272848b8605Smrg#define ASSERT_OUTSIDE_BEGIN_END(ctx) \ 273848b8605Smrgdo { \ 274848b8605Smrg if (_mesa_inside_begin_end(ctx)) { \ 275848b8605Smrg _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 276848b8605Smrg return; \ 277848b8605Smrg } \ 278848b8605Smrg} while (0) 279848b8605Smrg 280848b8605Smrg/*@}*/ 281848b8605Smrg 282848b8605Smrg 283848b8605Smrg/** 284848b8605Smrg * Checks if the context is for Desktop GL (Compatibility or Core) 285848b8605Smrg */ 286b8e80941Smrgstatic inline bool 287848b8605Smrg_mesa_is_desktop_gl(const struct gl_context *ctx) 288848b8605Smrg{ 289848b8605Smrg return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE; 290848b8605Smrg} 291848b8605Smrg 292848b8605Smrg 293848b8605Smrg/** 294848b8605Smrg * Checks if the context is for any GLES version 295848b8605Smrg */ 296b8e80941Smrgstatic inline bool 297848b8605Smrg_mesa_is_gles(const struct gl_context *ctx) 298848b8605Smrg{ 299848b8605Smrg return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2; 300848b8605Smrg} 301848b8605Smrg 302848b8605Smrg 303848b8605Smrg/** 304b8e80941Smrg * Checks if the context is for GLES 3.0 or later 305848b8605Smrg */ 306b8e80941Smrgstatic inline bool 307848b8605Smrg_mesa_is_gles3(const struct gl_context *ctx) 308848b8605Smrg{ 309848b8605Smrg return ctx->API == API_OPENGLES2 && ctx->Version >= 30; 310848b8605Smrg} 311848b8605Smrg 312848b8605Smrg 313b8e80941Smrg/** 314b8e80941Smrg * Checks if the context is for GLES 3.1 or later 315b8e80941Smrg */ 316b8e80941Smrgstatic inline bool 317b8e80941Smrg_mesa_is_gles31(const struct gl_context *ctx) 318b8e80941Smrg{ 319b8e80941Smrg return ctx->API == API_OPENGLES2 && ctx->Version >= 31; 320b8e80941Smrg} 321b8e80941Smrg 322b8e80941Smrg 323b8e80941Smrg/** 324b8e80941Smrg * Checks if the context is for GLES 3.2 or later 325b8e80941Smrg */ 326b8e80941Smrgstatic inline bool 327b8e80941Smrg_mesa_is_gles32(const struct gl_context *ctx) 328b8e80941Smrg{ 329b8e80941Smrg return ctx->API == API_OPENGLES2 && ctx->Version >= 32; 330b8e80941Smrg} 331b8e80941Smrg 332b8e80941Smrg 333b8e80941Smrgstatic inline bool 334b8e80941Smrg_mesa_is_no_error_enabled(const struct gl_context *ctx) 335b8e80941Smrg{ 336b8e80941Smrg return ctx->Const.ContextFlags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; 337b8e80941Smrg} 338b8e80941Smrg 339b8e80941Smrg 340b8e80941Smrgstatic inline bool 341b8e80941Smrg_mesa_has_integer_textures(const struct gl_context *ctx) 342b8e80941Smrg{ 343b8e80941Smrg return _mesa_has_EXT_texture_integer(ctx) || _mesa_is_gles3(ctx); 344b8e80941Smrg} 345b8e80941Smrg 346b8e80941Smrgstatic inline bool 347b8e80941Smrg_mesa_has_half_float_textures(const struct gl_context *ctx) 348b8e80941Smrg{ 349b8e80941Smrg return _mesa_has_ARB_texture_float(ctx) || 350b8e80941Smrg _mesa_has_OES_texture_half_float(ctx) || _mesa_is_gles3(ctx); 351b8e80941Smrg} 352b8e80941Smrg 353b8e80941Smrgstatic inline bool 354b8e80941Smrg_mesa_has_float_textures(const struct gl_context *ctx) 355b8e80941Smrg{ 356b8e80941Smrg return _mesa_has_ARB_texture_float(ctx) || 357b8e80941Smrg _mesa_has_OES_texture_float(ctx) || _mesa_is_gles3(ctx); 358b8e80941Smrg } 359b8e80941Smrg 360b8e80941Smrgstatic inline bool 361b8e80941Smrg_mesa_has_texture_rgb10_a2ui(const struct gl_context *ctx) 362b8e80941Smrg{ 363b8e80941Smrg return _mesa_has_ARB_texture_rgb10_a2ui(ctx) || _mesa_is_gles3(ctx); 364b8e80941Smrg} 365b8e80941Smrg 366b8e80941Smrgstatic inline bool 367b8e80941Smrg_mesa_has_float_depth_buffer(const struct gl_context *ctx) 368b8e80941Smrg{ 369b8e80941Smrg return _mesa_has_ARB_depth_buffer_float(ctx) || _mesa_is_gles3(ctx); 370b8e80941Smrg} 371b8e80941Smrg 372b8e80941Smrgstatic inline bool 373b8e80941Smrg_mesa_has_packed_float(const struct gl_context *ctx) 374b8e80941Smrg{ 375b8e80941Smrg return _mesa_has_EXT_packed_float(ctx) || _mesa_is_gles3(ctx); 376b8e80941Smrg} 377b8e80941Smrg 378b8e80941Smrgstatic inline bool 379b8e80941Smrg_mesa_has_rg_textures(const struct gl_context *ctx) 380b8e80941Smrg{ 381b8e80941Smrg return _mesa_has_ARB_texture_rg(ctx) || _mesa_has_EXT_texture_rg(ctx) || 382b8e80941Smrg _mesa_is_gles3(ctx); 383b8e80941Smrg} 384b8e80941Smrg 385b8e80941Smrgstatic inline bool 386b8e80941Smrg_mesa_has_texture_shared_exponent(const struct gl_context *ctx) 387b8e80941Smrg{ 388b8e80941Smrg return _mesa_has_EXT_texture_shared_exponent(ctx) || _mesa_is_gles3(ctx); 389b8e80941Smrg} 390b8e80941Smrg 391b8e80941Smrgstatic inline bool 392b8e80941Smrg_mesa_has_texture_type_2_10_10_10_REV(const struct gl_context *ctx) 393b8e80941Smrg{ 394b8e80941Smrg return _mesa_is_desktop_gl(ctx) || 395b8e80941Smrg _mesa_has_EXT_texture_type_2_10_10_10_REV(ctx); 396b8e80941Smrg} 397b8e80941Smrg 398848b8605Smrg/** 399848b8605Smrg * Checks if the context supports geometry shaders. 400848b8605Smrg */ 401b8e80941Smrgstatic inline bool 402848b8605Smrg_mesa_has_geometry_shaders(const struct gl_context *ctx) 403848b8605Smrg{ 404b8e80941Smrg return _mesa_has_OES_geometry_shader(ctx) || 405b8e80941Smrg (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32); 406b8e80941Smrg} 407b8e80941Smrg 408b8e80941Smrg 409b8e80941Smrg/** 410b8e80941Smrg * Checks if the context supports compute shaders. 411b8e80941Smrg */ 412b8e80941Smrgstatic inline bool 413b8e80941Smrg_mesa_has_compute_shaders(const struct gl_context *ctx) 414b8e80941Smrg{ 415b8e80941Smrg return _mesa_has_ARB_compute_shader(ctx) || 416b8e80941Smrg (ctx->API == API_OPENGLES2 && ctx->Version >= 31); 417848b8605Smrg} 418848b8605Smrg 419b8e80941Smrg/** 420b8e80941Smrg * Checks if the context supports tessellation. 421b8e80941Smrg */ 422b8e80941Smrgstatic inline bool 423b8e80941Smrg_mesa_has_tessellation(const struct gl_context *ctx) 424b8e80941Smrg{ 425b8e80941Smrg /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES 426b8e80941Smrg * check, so don't bother calling it. 427b8e80941Smrg */ 428b8e80941Smrg return _mesa_has_OES_tessellation_shader(ctx) || 429b8e80941Smrg _mesa_has_ARB_tessellation_shader(ctx); 430b8e80941Smrg} 431b8e80941Smrg 432b8e80941Smrgstatic inline bool 433b8e80941Smrg_mesa_has_texture_cube_map_array(const struct gl_context *ctx) 434b8e80941Smrg{ 435b8e80941Smrg return _mesa_has_ARB_texture_cube_map_array(ctx) || 436b8e80941Smrg _mesa_has_OES_texture_cube_map_array(ctx); 437b8e80941Smrg} 438b8e80941Smrg 439b8e80941Smrgstatic inline bool 440b8e80941Smrg_mesa_has_texture_view(const struct gl_context *ctx) 441b8e80941Smrg{ 442b8e80941Smrg return _mesa_has_ARB_texture_view(ctx) || 443b8e80941Smrg _mesa_has_OES_texture_view(ctx); 444b8e80941Smrg} 445848b8605Smrg 446848b8605Smrg#ifdef __cplusplus 447848b8605Smrg} 448848b8605Smrg#endif 449848b8605Smrg 450848b8605Smrg 451848b8605Smrg#endif /* CONTEXT_H */ 452