17117f1b4Smrg/** 27117f1b4Smrg * \file enable.c 37117f1b4Smrg * Enable/disable/query GL capabilities. 47117f1b4Smrg */ 57117f1b4Smrg 67117f1b4Smrg/* 77117f1b4Smrg * Mesa 3-D graphics library 87117f1b4Smrg * 97117f1b4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 107117f1b4Smrg * 117117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 127117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 137117f1b4Smrg * to deal in the Software without restriction, including without limitation 147117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 157117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 167117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 177117f1b4Smrg * 187117f1b4Smrg * The above copyright notice and this permission notice shall be included 197117f1b4Smrg * in all copies or substantial portions of the Software. 207117f1b4Smrg * 217117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 227117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 237117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 287117f1b4Smrg */ 297117f1b4Smrg 307117f1b4Smrg 317117f1b4Smrg#include "glheader.h" 3201e04c3fSmrg#include "arrayobj.h" 3301e04c3fSmrg#include "blend.h" 343464ebd5Sriastradh#include "clip.h" 357117f1b4Smrg#include "context.h" 3601e04c3fSmrg#include "debug_output.h" 377ec681f3Smrg#include "draw_validate.h" 387117f1b4Smrg#include "enable.h" 39af69d88dSmrg#include "errors.h" 407117f1b4Smrg#include "light.h" 417117f1b4Smrg#include "mtypes.h" 427117f1b4Smrg#include "enums.h" 4301e04c3fSmrg#include "state.h" 444a49301eSmrg#include "texstate.h" 4501e04c3fSmrg#include "varray.h" 467117f1b4Smrg 477117f1b4Smrg 487ec681f3Smrgvoid 497ec681f3Smrg_mesa_update_derived_primitive_restart_state(struct gl_context *ctx) 50af69d88dSmrg{ 517ec681f3Smrg if (ctx->Array.PrimitiveRestart || 527ec681f3Smrg ctx->Array.PrimitiveRestartFixedIndex) { 537ec681f3Smrg unsigned restart_index[3] = { 547ec681f3Smrg _mesa_primitive_restart_index(ctx, 1), 557ec681f3Smrg _mesa_primitive_restart_index(ctx, 2), 567ec681f3Smrg _mesa_primitive_restart_index(ctx, 4), 577ec681f3Smrg }; 587ec681f3Smrg 597ec681f3Smrg ctx->Array._RestartIndex[0] = restart_index[0]; 607ec681f3Smrg ctx->Array._RestartIndex[1] = restart_index[1]; 617ec681f3Smrg ctx->Array._RestartIndex[2] = restart_index[2]; 627ec681f3Smrg 637ec681f3Smrg /* Enable primitive restart only when the restart index can have an 647ec681f3Smrg * effect. This is required for correctness in AMD GFX8 support. 657ec681f3Smrg * Other hardware may also benefit from taking a faster, non-restart path 667ec681f3Smrg * when possible. 677ec681f3Smrg */ 687ec681f3Smrg ctx->Array._PrimitiveRestart[0] = true && restart_index[0] <= UINT8_MAX; 697ec681f3Smrg ctx->Array._PrimitiveRestart[1] = true && restart_index[1] <= UINT16_MAX; 707ec681f3Smrg ctx->Array._PrimitiveRestart[2] = true; 717ec681f3Smrg } else { 727ec681f3Smrg ctx->Array._PrimitiveRestart[0] = false; 737ec681f3Smrg ctx->Array._PrimitiveRestart[1] = false; 747ec681f3Smrg ctx->Array._PrimitiveRestart[2] = false; 757ec681f3Smrg } 76af69d88dSmrg} 77af69d88dSmrg 7801e04c3fSmrg 7901e04c3fSmrg/** 8001e04c3fSmrg * Helper to enable/disable VAO client-side state. 8101e04c3fSmrg */ 8201e04c3fSmrgstatic void 837ec681f3Smrgvao_state(struct gl_context *ctx, struct gl_vertex_array_object* vao, 847ec681f3Smrg gl_vert_attrib attr, GLboolean state) 8501e04c3fSmrg{ 8601e04c3fSmrg if (state) 877ec681f3Smrg _mesa_enable_vertex_array_attrib(ctx, vao, attr); 8801e04c3fSmrg else 897ec681f3Smrg _mesa_disable_vertex_array_attrib(ctx, vao, attr); 9001e04c3fSmrg} 9101e04c3fSmrg 9201e04c3fSmrg 937117f1b4Smrg/** 947117f1b4Smrg * Helper to enable/disable client-side state. 957117f1b4Smrg */ 967117f1b4Smrgstatic void 977ec681f3Smrgclient_state(struct gl_context *ctx, struct gl_vertex_array_object* vao, 987ec681f3Smrg GLenum cap, GLboolean state) 997117f1b4Smrg{ 1007117f1b4Smrg switch (cap) { 1017117f1b4Smrg case GL_VERTEX_ARRAY: 1027ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_POS, state); 1037117f1b4Smrg break; 1047117f1b4Smrg case GL_NORMAL_ARRAY: 1057ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_NORMAL, state); 1067117f1b4Smrg break; 1077117f1b4Smrg case GL_COLOR_ARRAY: 1087ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_COLOR0, state); 1097117f1b4Smrg break; 1107117f1b4Smrg case GL_INDEX_ARRAY: 1117ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_COLOR_INDEX, state); 1127117f1b4Smrg break; 1137117f1b4Smrg case GL_TEXTURE_COORD_ARRAY: 1147ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state); 1157117f1b4Smrg break; 1167117f1b4Smrg case GL_EDGE_FLAG_ARRAY: 1177ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_EDGEFLAG, state); 1187117f1b4Smrg break; 1197117f1b4Smrg case GL_FOG_COORDINATE_ARRAY_EXT: 1207ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_FOG, state); 1217117f1b4Smrg break; 1227117f1b4Smrg case GL_SECONDARY_COLOR_ARRAY_EXT: 1237ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_COLOR1, state); 1247117f1b4Smrg break; 1257117f1b4Smrg 126c1f859d4Smrg case GL_POINT_SIZE_ARRAY_OES: 1277ec681f3Smrg if (ctx->VertexProgram.PointSizeEnabled != state) { 1287ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, 0); 1297ec681f3Smrg ctx->VertexProgram.PointSizeEnabled = state; 1307ec681f3Smrg } 1317ec681f3Smrg vao_state(ctx, vao, VERT_ATTRIB_POINT_SIZE, state); 1327117f1b4Smrg break; 1337117f1b4Smrg 1343464ebd5Sriastradh /* GL_NV_primitive_restart */ 1353464ebd5Sriastradh case GL_PRIMITIVE_RESTART_NV: 1367ec681f3Smrg if (!_mesa_has_NV_primitive_restart(ctx)) 1373464ebd5Sriastradh goto invalid_enum_error; 13801e04c3fSmrg if (ctx->Array.PrimitiveRestart == state) 13901e04c3fSmrg return; 14001e04c3fSmrg 14101e04c3fSmrg ctx->Array.PrimitiveRestart = state; 1427ec681f3Smrg _mesa_update_derived_primitive_restart_state(ctx); 14301e04c3fSmrg return; 1443464ebd5Sriastradh 1457117f1b4Smrg default: 1463464ebd5Sriastradh goto invalid_enum_error; 1477117f1b4Smrg } 1487117f1b4Smrg 1497117f1b4Smrg if (ctx->Driver.Enable) { 1507117f1b4Smrg ctx->Driver.Enable( ctx, cap, state ); 1517117f1b4Smrg } 1523464ebd5Sriastradh 1533464ebd5Sriastradh return; 1543464ebd5Sriastradh 1553464ebd5Sriastradhinvalid_enum_error: 156af69d88dSmrg _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)", 15701e04c3fSmrg state ? "Enable" : "Disable", _mesa_enum_to_string(cap)); 1587117f1b4Smrg} 1597117f1b4Smrg 1607117f1b4Smrg 1617ec681f3Smrg/* Helper for GL_EXT_direct_state_access following functions: 1627ec681f3Smrg * - EnableClientStateIndexedEXT 1637ec681f3Smrg * - EnableClientStateiEXT 1647ec681f3Smrg * - DisableClientStateIndexedEXT 1657ec681f3Smrg * - DisableClientStateiEXT 1667ec681f3Smrg */ 1677ec681f3Smrgstatic void 1687ec681f3Smrgclient_state_i(struct gl_context *ctx, struct gl_vertex_array_object* vao, 1697ec681f3Smrg GLenum cap, GLuint index, GLboolean state) 1707ec681f3Smrg{ 1717ec681f3Smrg int saved_active; 1727ec681f3Smrg 1737ec681f3Smrg if (cap != GL_TEXTURE_COORD_ARRAY) { 1747ec681f3Smrg _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientStateiEXT(cap=%s)", 1757ec681f3Smrg state ? "Enable" : "Disable", 1767ec681f3Smrg _mesa_enum_to_string(cap)); 1777ec681f3Smrg return; 1787ec681f3Smrg } 1797ec681f3Smrg 1807ec681f3Smrg if (index >= ctx->Const.MaxTextureCoordUnits) { 1817ec681f3Smrg _mesa_error(ctx, GL_INVALID_VALUE, "gl%sClientStateiEXT(index=%d)", 1827ec681f3Smrg state ? "Enable" : "Disable", 1837ec681f3Smrg index); 1847ec681f3Smrg return; 1857ec681f3Smrg } 1867ec681f3Smrg 1877ec681f3Smrg saved_active = ctx->Array.ActiveTexture; 1887ec681f3Smrg _mesa_ClientActiveTexture(GL_TEXTURE0 + index); 1897ec681f3Smrg client_state(ctx, vao, cap, state); 1907ec681f3Smrg _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active); 1917ec681f3Smrg} 1927ec681f3Smrg 1937ec681f3Smrg 1947117f1b4Smrg/** 1957117f1b4Smrg * Enable GL capability. 1967117f1b4Smrg * \param cap state to enable/disable. 1977117f1b4Smrg * 1987117f1b4Smrg * Get's the current context, assures that we're outside glBegin()/glEnd() and 1997117f1b4Smrg * calls client_state(). 2007117f1b4Smrg */ 2017117f1b4Smrgvoid GLAPIENTRY 2027117f1b4Smrg_mesa_EnableClientState( GLenum cap ) 2037117f1b4Smrg{ 2047117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 2057ec681f3Smrg client_state( ctx, ctx->Array.VAO, cap, GL_TRUE ); 2067ec681f3Smrg} 2077ec681f3Smrg 2087ec681f3Smrg 2097ec681f3Smrgvoid GLAPIENTRY 2107ec681f3Smrg_mesa_EnableVertexArrayEXT( GLuint vaobj, GLenum cap ) 2117ec681f3Smrg{ 2127ec681f3Smrg GET_CURRENT_CONTEXT(ctx); 2137ec681f3Smrg struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj, 2147ec681f3Smrg true, 2157ec681f3Smrg "glEnableVertexArrayEXT"); 2167ec681f3Smrg if (!vao) 2177ec681f3Smrg return; 2187ec681f3Smrg 2197ec681f3Smrg /* The EXT_direct_state_access spec says: 2207ec681f3Smrg * "Additionally EnableVertexArrayEXT and DisableVertexArrayEXT accept 2217ec681f3Smrg * the tokens TEXTURE0 through TEXTUREn where n is less than the 2227ec681f3Smrg * implementation-dependent limit of MAX_TEXTURE_COORDS. For these 2237ec681f3Smrg * GL_TEXTUREi tokens, EnableVertexArrayEXT and DisableVertexArrayEXT 2247ec681f3Smrg * act identically to EnableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) 2257ec681f3Smrg * or DisableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) respectively 2267ec681f3Smrg * as if the active client texture is set to texture coordinate set i 2277ec681f3Smrg * based on the token TEXTUREi indicated by array." 2287ec681f3Smrg */ 2297ec681f3Smrg if (GL_TEXTURE0 <= cap && cap < GL_TEXTURE0 + ctx->Const.MaxTextureCoordUnits) { 2307ec681f3Smrg GLuint saved_active = ctx->Array.ActiveTexture; 2317ec681f3Smrg _mesa_ClientActiveTexture(cap); 2327ec681f3Smrg client_state(ctx, vao, GL_TEXTURE_COORD_ARRAY, GL_TRUE); 2337ec681f3Smrg _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active); 2347ec681f3Smrg } else { 2357ec681f3Smrg client_state(ctx, vao, cap, GL_TRUE); 2367ec681f3Smrg } 2377ec681f3Smrg} 2387ec681f3Smrg 2397ec681f3Smrg 2407ec681f3Smrgvoid GLAPIENTRY 2417ec681f3Smrg_mesa_EnableClientStateiEXT( GLenum cap, GLuint index ) 2427ec681f3Smrg{ 2437ec681f3Smrg GET_CURRENT_CONTEXT(ctx); 2447ec681f3Smrg client_state_i(ctx, ctx->Array.VAO, cap, index, GL_TRUE); 2457117f1b4Smrg} 2467117f1b4Smrg 2477117f1b4Smrg 2487117f1b4Smrg/** 2497117f1b4Smrg * Disable GL capability. 2507117f1b4Smrg * \param cap state to enable/disable. 2517117f1b4Smrg * 2527117f1b4Smrg * Get's the current context, assures that we're outside glBegin()/glEnd() and 2537117f1b4Smrg * calls client_state(). 2547117f1b4Smrg */ 2557117f1b4Smrgvoid GLAPIENTRY 2567117f1b4Smrg_mesa_DisableClientState( GLenum cap ) 2577117f1b4Smrg{ 2587117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 2597ec681f3Smrg client_state( ctx, ctx->Array.VAO, cap, GL_FALSE ); 2607117f1b4Smrg} 2617117f1b4Smrg 2627ec681f3Smrgvoid GLAPIENTRY 2637ec681f3Smrg_mesa_DisableVertexArrayEXT( GLuint vaobj, GLenum cap ) 2647ec681f3Smrg{ 2657ec681f3Smrg GET_CURRENT_CONTEXT(ctx); 2667ec681f3Smrg struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj, 2677ec681f3Smrg true, 2687ec681f3Smrg "glDisableVertexArrayEXT"); 2697ec681f3Smrg if (!vao) 2707ec681f3Smrg return; 2717117f1b4Smrg 2727ec681f3Smrg /* The EXT_direct_state_access spec says: 2737ec681f3Smrg * "Additionally EnableVertexArrayEXT and DisableVertexArrayEXT accept 2747ec681f3Smrg * the tokens TEXTURE0 through TEXTUREn where n is less than the 2757ec681f3Smrg * implementation-dependent limit of MAX_TEXTURE_COORDS. For these 2767ec681f3Smrg * GL_TEXTUREi tokens, EnableVertexArrayEXT and DisableVertexArrayEXT 2777ec681f3Smrg * act identically to EnableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) 2787ec681f3Smrg * or DisableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) respectively 2797ec681f3Smrg * as if the active client texture is set to texture coordinate set i 2807ec681f3Smrg * based on the token TEXTUREi indicated by array." 2817ec681f3Smrg */ 2827ec681f3Smrg if (GL_TEXTURE0 <= cap && cap < GL_TEXTURE0 + ctx->Const.MaxTextureCoordUnits) { 2837ec681f3Smrg GLuint saved_active = ctx->Array.ActiveTexture; 2847ec681f3Smrg _mesa_ClientActiveTexture(cap); 2857ec681f3Smrg client_state(ctx, vao, GL_TEXTURE_COORD_ARRAY, GL_FALSE); 2867ec681f3Smrg _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active); 2877ec681f3Smrg } else { 2887ec681f3Smrg client_state(ctx, vao, cap, GL_FALSE); 2897117f1b4Smrg } 2907ec681f3Smrg} 2917117f1b4Smrg 2927ec681f3Smrgvoid GLAPIENTRY 2937ec681f3Smrg_mesa_DisableClientStateiEXT( GLenum cap, GLuint index ) 2947ec681f3Smrg{ 2957ec681f3Smrg GET_CURRENT_CONTEXT(ctx); 2967ec681f3Smrg client_state_i(ctx, ctx->Array.VAO, cap, index, GL_FALSE); 2977ec681f3Smrg} 2987117f1b4Smrg 299c1f859d4Smrg/** 300c1f859d4Smrg * Return pointer to current texture unit for setting/getting coordinate 301c1f859d4Smrg * state. 3023464ebd5Sriastradh * Note that we'll set GL_INVALID_OPERATION and return NULL if the active 3033464ebd5Sriastradh * texture unit is higher than the number of supported coordinate units. 304c1f859d4Smrg */ 30501e04c3fSmrgstatic struct gl_fixedfunc_texture_unit * 3063464ebd5Sriastradhget_texcoord_unit(struct gl_context *ctx) 307c1f859d4Smrg{ 308c1f859d4Smrg if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { 309c1f859d4Smrg _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)"); 310c1f859d4Smrg return NULL; 311c1f859d4Smrg } 312c1f859d4Smrg else { 31301e04c3fSmrg return &ctx->Texture.FixedFuncUnit[ctx->Texture.CurrentUnit]; 314c1f859d4Smrg } 315c1f859d4Smrg} 316c1f859d4Smrg 317c1f859d4Smrg 3187117f1b4Smrg/** 3197117f1b4Smrg * Helper function to enable or disable a texture target. 3204a49301eSmrg * \param bit one of the TEXTURE_x_BIT values 3214a49301eSmrg * \return GL_TRUE if state is changing or GL_FALSE if no change 3227117f1b4Smrg */ 3237117f1b4Smrgstatic GLboolean 3243464ebd5Sriastradhenable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit) 3257117f1b4Smrg{ 32601e04c3fSmrg struct gl_fixedfunc_texture_unit *texUnit = 3277ec681f3Smrg _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit); 32801e04c3fSmrg if (!texUnit) 32901e04c3fSmrg return GL_FALSE; 33001e04c3fSmrg 3314a49301eSmrg const GLbitfield newenabled = state 3324a49301eSmrg ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit); 3337117f1b4Smrg 3344a49301eSmrg if (texUnit->Enabled == newenabled) 3357117f1b4Smrg return GL_FALSE; 3367117f1b4Smrg 3377ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE, GL_TEXTURE_BIT | GL_ENABLE_BIT); 3387117f1b4Smrg texUnit->Enabled = newenabled; 3397117f1b4Smrg return GL_TRUE; 3407117f1b4Smrg} 3417117f1b4Smrg 3427117f1b4Smrg 343af69d88dSmrg/** 344af69d88dSmrg * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for 345af69d88dSmrg * whether the API supports it (GLES doesn't). 346af69d88dSmrg */ 347af69d88dSmrgvoid 348af69d88dSmrg_mesa_set_multisample(struct gl_context *ctx, GLboolean state) 349af69d88dSmrg{ 350af69d88dSmrg if (ctx->Multisample.Enabled == state) 351af69d88dSmrg return; 35201e04c3fSmrg 35301e04c3fSmrg /* GL compatibility needs Multisample.Enable to determine program state 35401e04c3fSmrg * constants. 35501e04c3fSmrg */ 35601e04c3fSmrg if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES || 35701e04c3fSmrg !ctx->DriverFlags.NewMultisampleEnable) { 3587ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE, GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 35901e04c3fSmrg } else { 3607ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 36101e04c3fSmrg } 36201e04c3fSmrg 36301e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable; 364af69d88dSmrg ctx->Multisample.Enabled = state; 365af69d88dSmrg 366af69d88dSmrg if (ctx->Driver.Enable) { 367af69d88dSmrg ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state); 368af69d88dSmrg } 369af69d88dSmrg} 370af69d88dSmrg 371af69d88dSmrg/** 372af69d88dSmrg * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the 373af69d88dSmrg * check for whether the API supports it (GLES doesn't). 374af69d88dSmrg */ 375af69d88dSmrgvoid 376af69d88dSmrg_mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state) 377af69d88dSmrg{ 378af69d88dSmrg if (ctx->Color.sRGBEnabled == state) 379af69d88dSmrg return; 38001e04c3fSmrg 38101e04c3fSmrg /* TODO: Switch i965 to the new flag and remove the conditional */ 3827ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewFramebufferSRGB ? 0 : _NEW_BUFFERS, 3837ec681f3Smrg GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); 38401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewFramebufferSRGB; 385af69d88dSmrg ctx->Color.sRGBEnabled = state; 386af69d88dSmrg 387af69d88dSmrg if (ctx->Driver.Enable) { 388af69d88dSmrg ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state); 389af69d88dSmrg } 390af69d88dSmrg} 391af69d88dSmrg 3927117f1b4Smrg/** 3937117f1b4Smrg * Helper function to enable or disable state. 3947117f1b4Smrg * 3957117f1b4Smrg * \param ctx GL context. 3967117f1b4Smrg * \param cap the state to enable/disable 3977117f1b4Smrg * \param state whether to enable or disable the specified capability. 3987117f1b4Smrg * 3997117f1b4Smrg * Updates the current context and flushes the vertices as needed. For 4007117f1b4Smrg * capabilities associated with extensions it verifies that those extensions 4017117f1b4Smrg * are effectivly present before updating. Notifies the driver via 4027117f1b4Smrg * dd_function_table::Enable. 4037117f1b4Smrg */ 4047117f1b4Smrgvoid 4053464ebd5Sriastradh_mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state) 4067117f1b4Smrg{ 4077117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 4087117f1b4Smrg _mesa_debug(ctx, "%s %s (newstate is %x)\n", 4097117f1b4Smrg state ? "glEnable" : "glDisable", 41001e04c3fSmrg _mesa_enum_to_string(cap), 4117117f1b4Smrg ctx->NewState); 4127117f1b4Smrg 4137117f1b4Smrg switch (cap) { 4147117f1b4Smrg case GL_ALPHA_TEST: 415af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 416af69d88dSmrg goto invalid_enum_error; 4177117f1b4Smrg if (ctx->Color.AlphaEnabled == state) 4187117f1b4Smrg return; 41901e04c3fSmrg /* AlphaEnabled is used by the fixed-func fragment program */ 4207ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_COLOR | _NEW_FF_FRAG_PROGRAM, 4217ec681f3Smrg GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); 42201e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest; 4237117f1b4Smrg ctx->Color.AlphaEnabled = state; 4247117f1b4Smrg break; 4257117f1b4Smrg case GL_AUTO_NORMAL: 426af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 427af69d88dSmrg goto invalid_enum_error; 4287117f1b4Smrg if (ctx->Eval.AutoNormal == state) 4297117f1b4Smrg return; 4307ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 4317ec681f3Smrg vbo_exec_update_eval_maps(ctx); 4327117f1b4Smrg ctx->Eval.AutoNormal = state; 4337117f1b4Smrg break; 4347117f1b4Smrg case GL_BLEND: 435cdc920a0Smrg { 4363464ebd5Sriastradh GLbitfield newEnabled = 4373464ebd5Sriastradh state * ((1 << ctx->Const.MaxDrawBuffers) - 1); 438cdc920a0Smrg if (newEnabled != ctx->Color.BlendEnabled) { 43901e04c3fSmrg _mesa_flush_vertices_for_blend_adv(ctx, newEnabled, 44001e04c3fSmrg ctx->Color._AdvancedBlendMode); 4417ec681f3Smrg ctx->PopAttribState |= GL_ENABLE_BIT; 442cdc920a0Smrg ctx->Color.BlendEnabled = newEnabled; 4437ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 4447ec681f3Smrg _mesa_update_valid_to_render_state(ctx); 445cdc920a0Smrg } 446cdc920a0Smrg } 4477117f1b4Smrg break; 448af69d88dSmrg case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */ 449af69d88dSmrg case GL_CLIP_DISTANCE1: 450af69d88dSmrg case GL_CLIP_DISTANCE2: 451af69d88dSmrg case GL_CLIP_DISTANCE3: 452af69d88dSmrg case GL_CLIP_DISTANCE4: 453af69d88dSmrg case GL_CLIP_DISTANCE5: 454af69d88dSmrg case GL_CLIP_DISTANCE6: 455af69d88dSmrg case GL_CLIP_DISTANCE7: 4567117f1b4Smrg { 457af69d88dSmrg const GLuint p = cap - GL_CLIP_DISTANCE0; 458af69d88dSmrg 459af69d88dSmrg if (p >= ctx->Const.MaxClipPlanes) 460af69d88dSmrg goto invalid_enum_error; 4617117f1b4Smrg 4623464ebd5Sriastradh if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) 4633464ebd5Sriastradh == ((GLuint) state << p)) 4647117f1b4Smrg return; 4657117f1b4Smrg 46601e04c3fSmrg /* The compatibility profile needs _NEW_TRANSFORM to transform 46701e04c3fSmrg * clip planes according to the projection matrix. 46801e04c3fSmrg */ 46901e04c3fSmrg if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES || 47001e04c3fSmrg !ctx->DriverFlags.NewClipPlaneEnable) { 4717ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TRANSFORM, 4727ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 47301e04c3fSmrg } else { 4747ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_TRANSFORM_BIT | GL_ENABLE_BIT); 47501e04c3fSmrg } 47601e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewClipPlaneEnable; 4777117f1b4Smrg 4787117f1b4Smrg if (state) { 4797117f1b4Smrg ctx->Transform.ClipPlanesEnabled |= (1 << p); 48001e04c3fSmrg 48101e04c3fSmrg /* The projection matrix transforms the clip plane. */ 48201e04c3fSmrg /* TODO: glEnable might not be the best place to do it. */ 48301e04c3fSmrg if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) { 48401e04c3fSmrg _mesa_update_clip_plane(ctx, p); 48501e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewClipPlane; 48601e04c3fSmrg } 4877117f1b4Smrg } 4887117f1b4Smrg else { 4897117f1b4Smrg ctx->Transform.ClipPlanesEnabled &= ~(1 << p); 49001e04c3fSmrg } 4917117f1b4Smrg } 4927117f1b4Smrg break; 4937117f1b4Smrg case GL_COLOR_MATERIAL: 494af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 495af69d88dSmrg goto invalid_enum_error; 4967117f1b4Smrg if (ctx->Light.ColorMaterialEnabled == state) 4977117f1b4Smrg return; 4987ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM, 4997ec681f3Smrg GL_LIGHTING_BIT | GL_ENABLE_BIT); 5007117f1b4Smrg FLUSH_CURRENT(ctx, 0); 5017117f1b4Smrg ctx->Light.ColorMaterialEnabled = state; 5027117f1b4Smrg if (state) { 5037117f1b4Smrg _mesa_update_color_material( ctx, 5047117f1b4Smrg ctx->Current.Attrib[VERT_ATTRIB_COLOR0] ); 5057117f1b4Smrg } 5067117f1b4Smrg break; 5077117f1b4Smrg case GL_CULL_FACE: 5087117f1b4Smrg if (ctx->Polygon.CullFlag == state) 5097117f1b4Smrg return; 51001e04c3fSmrg FLUSH_VERTICES(ctx, 5117ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 5127ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 51301e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 5147117f1b4Smrg ctx->Polygon.CullFlag = state; 5157117f1b4Smrg break; 5167117f1b4Smrg case GL_DEPTH_TEST: 5177117f1b4Smrg if (ctx->Depth.Test == state) 5187117f1b4Smrg return; 5197ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH, 5207ec681f3Smrg GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT); 52101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepth; 5227117f1b4Smrg ctx->Depth.Test = state; 5237ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 5247117f1b4Smrg break; 525af69d88dSmrg case GL_DEBUG_OUTPUT: 526af69d88dSmrg case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: 52701e04c3fSmrg _mesa_set_debug_state_int(ctx, cap, state); 528af69d88dSmrg break; 5297117f1b4Smrg case GL_DITHER: 5307117f1b4Smrg if (ctx->Color.DitherFlag == state) 5317117f1b4Smrg return; 5327ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR, 5337ec681f3Smrg GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); 53401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewBlend; 5357117f1b4Smrg ctx->Color.DitherFlag = state; 5367117f1b4Smrg break; 5377117f1b4Smrg case GL_FOG: 538af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 539af69d88dSmrg goto invalid_enum_error; 5407117f1b4Smrg if (ctx->Fog.Enabled == state) 5417117f1b4Smrg return; 5427ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_FRAG_PROGRAM, 5437ec681f3Smrg GL_FOG_BIT | GL_ENABLE_BIT); 5447117f1b4Smrg ctx->Fog.Enabled = state; 54501e04c3fSmrg ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE; 5467117f1b4Smrg break; 5477117f1b4Smrg case GL_LIGHT0: 5487117f1b4Smrg case GL_LIGHT1: 5497117f1b4Smrg case GL_LIGHT2: 5507117f1b4Smrg case GL_LIGHT3: 5517117f1b4Smrg case GL_LIGHT4: 5527117f1b4Smrg case GL_LIGHT5: 5537117f1b4Smrg case GL_LIGHT6: 5547117f1b4Smrg case GL_LIGHT7: 555af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 556af69d88dSmrg goto invalid_enum_error; 5577117f1b4Smrg if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state) 5587117f1b4Smrg return; 5597ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM, 5607ec681f3Smrg GL_LIGHTING_BIT | GL_ENABLE_BIT); 5617117f1b4Smrg ctx->Light.Light[cap-GL_LIGHT0].Enabled = state; 5627117f1b4Smrg if (state) { 56301e04c3fSmrg ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0); 5647117f1b4Smrg } 5657117f1b4Smrg else { 56601e04c3fSmrg ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0)); 5677117f1b4Smrg } 5687117f1b4Smrg break; 5697117f1b4Smrg case GL_LIGHTING: 570af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 571af69d88dSmrg goto invalid_enum_error; 5727117f1b4Smrg if (ctx->Light.Enabled == state) 5737117f1b4Smrg return; 5747ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM | 5757ec681f3Smrg _NEW_FF_FRAG_PROGRAM | _NEW_LIGHT_STATE, 5767ec681f3Smrg GL_LIGHTING_BIT | GL_ENABLE_BIT); 5777117f1b4Smrg ctx->Light.Enabled = state; 5787117f1b4Smrg break; 5797117f1b4Smrg case GL_LINE_SMOOTH: 580af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 581af69d88dSmrg goto invalid_enum_error; 5827117f1b4Smrg if (ctx->Line.SmoothFlag == state) 5837117f1b4Smrg return; 5847ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE, 5857ec681f3Smrg GL_LINE_BIT | GL_ENABLE_BIT); 58601e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewLineState; 5877117f1b4Smrg ctx->Line.SmoothFlag = state; 5887117f1b4Smrg break; 5897117f1b4Smrg case GL_LINE_STIPPLE: 590af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 591af69d88dSmrg goto invalid_enum_error; 5927117f1b4Smrg if (ctx->Line.StippleFlag == state) 5937117f1b4Smrg return; 5947ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE, 5957ec681f3Smrg GL_LINE_BIT | GL_ENABLE_BIT); 59601e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewLineState; 5977117f1b4Smrg ctx->Line.StippleFlag = state; 5987117f1b4Smrg break; 5997117f1b4Smrg case GL_INDEX_LOGIC_OP: 600af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 601af69d88dSmrg goto invalid_enum_error; 6027117f1b4Smrg if (ctx->Color.IndexLogicOpEnabled == state) 6037117f1b4Smrg return; 6047ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR, 6057ec681f3Smrg GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); 60601e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp; 6077117f1b4Smrg ctx->Color.IndexLogicOpEnabled = state; 6087117f1b4Smrg break; 60901e04c3fSmrg case GL_CONSERVATIVE_RASTERIZATION_INTEL: 61001e04c3fSmrg if (!_mesa_has_INTEL_conservative_rasterization(ctx)) 61101e04c3fSmrg goto invalid_enum_error; 61201e04c3fSmrg if (ctx->IntelConservativeRasterization == state) 61301e04c3fSmrg return; 6147ec681f3Smrg FLUSH_VERTICES(ctx, 0, 0); 61501e04c3fSmrg ctx->NewDriverState |= 61601e04c3fSmrg ctx->DriverFlags.NewIntelConservativeRasterization; 61701e04c3fSmrg ctx->IntelConservativeRasterization = state; 6187ec681f3Smrg _mesa_update_valid_to_render_state(ctx); 61901e04c3fSmrg break; 62001e04c3fSmrg case GL_CONSERVATIVE_RASTERIZATION_NV: 62101e04c3fSmrg if (!_mesa_has_NV_conservative_raster(ctx)) 62201e04c3fSmrg goto invalid_enum_error; 62301e04c3fSmrg if (ctx->ConservativeRasterization == state) 62401e04c3fSmrg return; 6257ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT); 62601e04c3fSmrg ctx->NewDriverState |= 62701e04c3fSmrg ctx->DriverFlags.NewNvConservativeRasterization; 62801e04c3fSmrg ctx->ConservativeRasterization = state; 62901e04c3fSmrg break; 6307117f1b4Smrg case GL_COLOR_LOGIC_OP: 631af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 632af69d88dSmrg goto invalid_enum_error; 6337117f1b4Smrg if (ctx->Color.ColorLogicOpEnabled == state) 6347117f1b4Smrg return; 6357ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR, 6367ec681f3Smrg GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); 63701e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp; 6387117f1b4Smrg ctx->Color.ColorLogicOpEnabled = state; 6397ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 6407117f1b4Smrg break; 6417117f1b4Smrg case GL_MAP1_COLOR_4: 642af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 643af69d88dSmrg goto invalid_enum_error; 6447117f1b4Smrg if (ctx->Eval.Map1Color4 == state) 6457117f1b4Smrg return; 6467ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6477ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6487117f1b4Smrg ctx->Eval.Map1Color4 = state; 6497117f1b4Smrg break; 6507117f1b4Smrg case GL_MAP1_INDEX: 651af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 652af69d88dSmrg goto invalid_enum_error; 6537117f1b4Smrg if (ctx->Eval.Map1Index == state) 6547117f1b4Smrg return; 6557ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6567ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6577117f1b4Smrg ctx->Eval.Map1Index = state; 6587117f1b4Smrg break; 6597117f1b4Smrg case GL_MAP1_NORMAL: 660af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 661af69d88dSmrg goto invalid_enum_error; 6627117f1b4Smrg if (ctx->Eval.Map1Normal == state) 6637117f1b4Smrg return; 6647ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6657ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6667117f1b4Smrg ctx->Eval.Map1Normal = state; 6677117f1b4Smrg break; 6687117f1b4Smrg case GL_MAP1_TEXTURE_COORD_1: 669af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 670af69d88dSmrg goto invalid_enum_error; 6717117f1b4Smrg if (ctx->Eval.Map1TextureCoord1 == state) 6727117f1b4Smrg return; 6737ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6747ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6757117f1b4Smrg ctx->Eval.Map1TextureCoord1 = state; 6767117f1b4Smrg break; 6777117f1b4Smrg case GL_MAP1_TEXTURE_COORD_2: 678af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 679af69d88dSmrg goto invalid_enum_error; 6807117f1b4Smrg if (ctx->Eval.Map1TextureCoord2 == state) 6817117f1b4Smrg return; 6827ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6837ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6847117f1b4Smrg ctx->Eval.Map1TextureCoord2 = state; 6857117f1b4Smrg break; 6867117f1b4Smrg case GL_MAP1_TEXTURE_COORD_3: 687af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 688af69d88dSmrg goto invalid_enum_error; 6897117f1b4Smrg if (ctx->Eval.Map1TextureCoord3 == state) 6907117f1b4Smrg return; 6917ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 6927ec681f3Smrg vbo_exec_update_eval_maps(ctx); 6937117f1b4Smrg ctx->Eval.Map1TextureCoord3 = state; 6947117f1b4Smrg break; 6957117f1b4Smrg case GL_MAP1_TEXTURE_COORD_4: 696af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 697af69d88dSmrg goto invalid_enum_error; 6987117f1b4Smrg if (ctx->Eval.Map1TextureCoord4 == state) 6997117f1b4Smrg return; 7007ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7017ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7027117f1b4Smrg ctx->Eval.Map1TextureCoord4 = state; 7037117f1b4Smrg break; 7047117f1b4Smrg case GL_MAP1_VERTEX_3: 705af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 706af69d88dSmrg goto invalid_enum_error; 7077117f1b4Smrg if (ctx->Eval.Map1Vertex3 == state) 7087117f1b4Smrg return; 7097ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7107ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7117117f1b4Smrg ctx->Eval.Map1Vertex3 = state; 7127117f1b4Smrg break; 7137117f1b4Smrg case GL_MAP1_VERTEX_4: 714af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 715af69d88dSmrg goto invalid_enum_error; 7167117f1b4Smrg if (ctx->Eval.Map1Vertex4 == state) 7177117f1b4Smrg return; 7187ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7197ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7207117f1b4Smrg ctx->Eval.Map1Vertex4 = state; 7217117f1b4Smrg break; 7227117f1b4Smrg case GL_MAP2_COLOR_4: 723af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 724af69d88dSmrg goto invalid_enum_error; 7257117f1b4Smrg if (ctx->Eval.Map2Color4 == state) 7267117f1b4Smrg return; 7277ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7287ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7297117f1b4Smrg ctx->Eval.Map2Color4 = state; 7307117f1b4Smrg break; 7317117f1b4Smrg case GL_MAP2_INDEX: 732af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 733af69d88dSmrg goto invalid_enum_error; 7347117f1b4Smrg if (ctx->Eval.Map2Index == state) 7357117f1b4Smrg return; 7367ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7377ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7387117f1b4Smrg ctx->Eval.Map2Index = state; 7397117f1b4Smrg break; 7407117f1b4Smrg case GL_MAP2_NORMAL: 741af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 742af69d88dSmrg goto invalid_enum_error; 7437117f1b4Smrg if (ctx->Eval.Map2Normal == state) 7447117f1b4Smrg return; 7457ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7467ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7477117f1b4Smrg ctx->Eval.Map2Normal = state; 7487117f1b4Smrg break; 7497117f1b4Smrg case GL_MAP2_TEXTURE_COORD_1: 750af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 751af69d88dSmrg goto invalid_enum_error; 7527117f1b4Smrg if (ctx->Eval.Map2TextureCoord1 == state) 7537117f1b4Smrg return; 7547ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7557ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7567117f1b4Smrg ctx->Eval.Map2TextureCoord1 = state; 7577117f1b4Smrg break; 7587117f1b4Smrg case GL_MAP2_TEXTURE_COORD_2: 759af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 760af69d88dSmrg goto invalid_enum_error; 7617117f1b4Smrg if (ctx->Eval.Map2TextureCoord2 == state) 7627117f1b4Smrg return; 7637ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7647ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7657117f1b4Smrg ctx->Eval.Map2TextureCoord2 = state; 7667117f1b4Smrg break; 7677117f1b4Smrg case GL_MAP2_TEXTURE_COORD_3: 768af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 769af69d88dSmrg goto invalid_enum_error; 7707117f1b4Smrg if (ctx->Eval.Map2TextureCoord3 == state) 7717117f1b4Smrg return; 7727ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7737ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7747117f1b4Smrg ctx->Eval.Map2TextureCoord3 = state; 7757117f1b4Smrg break; 7767117f1b4Smrg case GL_MAP2_TEXTURE_COORD_4: 777af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 778af69d88dSmrg goto invalid_enum_error; 7797117f1b4Smrg if (ctx->Eval.Map2TextureCoord4 == state) 7807117f1b4Smrg return; 7817ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7827ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7837117f1b4Smrg ctx->Eval.Map2TextureCoord4 = state; 7847117f1b4Smrg break; 7857117f1b4Smrg case GL_MAP2_VERTEX_3: 786af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 787af69d88dSmrg goto invalid_enum_error; 7887117f1b4Smrg if (ctx->Eval.Map2Vertex3 == state) 7897117f1b4Smrg return; 7907ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 7917ec681f3Smrg vbo_exec_update_eval_maps(ctx); 7927117f1b4Smrg ctx->Eval.Map2Vertex3 = state; 7937117f1b4Smrg break; 7947117f1b4Smrg case GL_MAP2_VERTEX_4: 795af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 796af69d88dSmrg goto invalid_enum_error; 7977117f1b4Smrg if (ctx->Eval.Map2Vertex4 == state) 7987117f1b4Smrg return; 7997ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT); 8007ec681f3Smrg vbo_exec_update_eval_maps(ctx); 8017117f1b4Smrg ctx->Eval.Map2Vertex4 = state; 8027117f1b4Smrg break; 8037117f1b4Smrg case GL_NORMALIZE: 804af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 805af69d88dSmrg goto invalid_enum_error; 8067117f1b4Smrg if (ctx->Transform.Normalize == state) 8077117f1b4Smrg return; 8087ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_FF_VERT_PROGRAM, 8097ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 8107117f1b4Smrg ctx->Transform.Normalize = state; 8117117f1b4Smrg break; 8127117f1b4Smrg case GL_POINT_SMOOTH: 813af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 814af69d88dSmrg goto invalid_enum_error; 8157117f1b4Smrg if (ctx->Point.SmoothFlag == state) 8167117f1b4Smrg return; 8177ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT | GL_ENABLE_BIT); 8187117f1b4Smrg ctx->Point.SmoothFlag = state; 8197117f1b4Smrg break; 8207117f1b4Smrg case GL_POLYGON_SMOOTH: 821af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 822af69d88dSmrg goto invalid_enum_error; 8237117f1b4Smrg if (ctx->Polygon.SmoothFlag == state) 8247117f1b4Smrg return; 82501e04c3fSmrg FLUSH_VERTICES(ctx, 8267ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 8277ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 82801e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 8297117f1b4Smrg ctx->Polygon.SmoothFlag = state; 8307117f1b4Smrg break; 8317117f1b4Smrg case GL_POLYGON_STIPPLE: 832af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 833af69d88dSmrg goto invalid_enum_error; 8347117f1b4Smrg if (ctx->Polygon.StippleFlag == state) 8357117f1b4Smrg return; 83601e04c3fSmrg FLUSH_VERTICES(ctx, 8377ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 8387ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 83901e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 8407117f1b4Smrg ctx->Polygon.StippleFlag = state; 8417117f1b4Smrg break; 8427117f1b4Smrg case GL_POLYGON_OFFSET_POINT: 843af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 844af69d88dSmrg goto invalid_enum_error; 8457117f1b4Smrg if (ctx->Polygon.OffsetPoint == state) 8467117f1b4Smrg return; 84701e04c3fSmrg FLUSH_VERTICES(ctx, 8487ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 8497ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 85001e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 8517117f1b4Smrg ctx->Polygon.OffsetPoint = state; 8527117f1b4Smrg break; 8537117f1b4Smrg case GL_POLYGON_OFFSET_LINE: 854af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 855af69d88dSmrg goto invalid_enum_error; 8567117f1b4Smrg if (ctx->Polygon.OffsetLine == state) 8577117f1b4Smrg return; 85801e04c3fSmrg FLUSH_VERTICES(ctx, 8597ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 8607ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 86101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 8627117f1b4Smrg ctx->Polygon.OffsetLine = state; 8637117f1b4Smrg break; 8647117f1b4Smrg case GL_POLYGON_OFFSET_FILL: 8657117f1b4Smrg if (ctx->Polygon.OffsetFill == state) 8667117f1b4Smrg return; 86701e04c3fSmrg FLUSH_VERTICES(ctx, 8687ec681f3Smrg ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON, 8697ec681f3Smrg GL_POLYGON_BIT | GL_ENABLE_BIT); 87001e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState; 8717117f1b4Smrg ctx->Polygon.OffsetFill = state; 8727117f1b4Smrg break; 8737117f1b4Smrg case GL_RESCALE_NORMAL_EXT: 874af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 875af69d88dSmrg goto invalid_enum_error; 8767117f1b4Smrg if (ctx->Transform.RescaleNormals == state) 8777117f1b4Smrg return; 8787ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_FF_VERT_PROGRAM, 8797ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 8807117f1b4Smrg ctx->Transform.RescaleNormals = state; 8817117f1b4Smrg break; 8827117f1b4Smrg case GL_SCISSOR_TEST: 883af69d88dSmrg { 884af69d88dSmrg /* Must expand glEnable to all scissors */ 885af69d88dSmrg GLbitfield newEnabled = 886af69d88dSmrg state * ((1 << ctx->Const.MaxViewports) - 1); 887af69d88dSmrg if (newEnabled != ctx->Scissor.EnableFlags) { 88801e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewScissorTest ? 0 : 8897ec681f3Smrg _NEW_SCISSOR, 8907ec681f3Smrg GL_SCISSOR_BIT | GL_ENABLE_BIT); 89101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest; 892af69d88dSmrg ctx->Scissor.EnableFlags = newEnabled; 893af69d88dSmrg } 894af69d88dSmrg } 8957117f1b4Smrg break; 8967117f1b4Smrg case GL_STENCIL_TEST: 8977117f1b4Smrg if (ctx->Stencil.Enabled == state) 8987117f1b4Smrg return; 8997ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL, 9007ec681f3Smrg GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT); 90101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewStencil; 9027117f1b4Smrg ctx->Stencil.Enabled = state; 9037ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 9047117f1b4Smrg break; 9057117f1b4Smrg case GL_TEXTURE_1D: 906af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 907af69d88dSmrg goto invalid_enum_error; 9087117f1b4Smrg if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) { 9097117f1b4Smrg return; 9107117f1b4Smrg } 9117117f1b4Smrg break; 9127117f1b4Smrg case GL_TEXTURE_2D: 913af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 914af69d88dSmrg goto invalid_enum_error; 9157117f1b4Smrg if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) { 9167117f1b4Smrg return; 9177117f1b4Smrg } 9187117f1b4Smrg break; 9197117f1b4Smrg case GL_TEXTURE_3D: 920af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 921af69d88dSmrg goto invalid_enum_error; 9227117f1b4Smrg if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) { 9237117f1b4Smrg return; 9247117f1b4Smrg } 9257117f1b4Smrg break; 926c1f859d4Smrg case GL_TEXTURE_GEN_S: 9273464ebd5Sriastradh case GL_TEXTURE_GEN_T: 9283464ebd5Sriastradh case GL_TEXTURE_GEN_R: 9293464ebd5Sriastradh case GL_TEXTURE_GEN_Q: 930c1f859d4Smrg { 93101e04c3fSmrg struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx); 932af69d88dSmrg 933af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 934af69d88dSmrg goto invalid_enum_error; 935af69d88dSmrg 936c1f859d4Smrg if (texUnit) { 9373464ebd5Sriastradh GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S); 9383464ebd5Sriastradh GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit; 939c1f859d4Smrg if (state) 9403464ebd5Sriastradh newenabled |= coordBit; 941c1f859d4Smrg if (texUnit->TexGenEnabled == newenabled) 942c1f859d4Smrg return; 9437ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE | _NEW_FF_VERT_PROGRAM | 9447ec681f3Smrg _NEW_FF_FRAG_PROGRAM, 9457ec681f3Smrg GL_TEXTURE_BIT | GL_ENABLE_BIT); 946c1f859d4Smrg texUnit->TexGenEnabled = newenabled; 947c1f859d4Smrg } 948c1f859d4Smrg } 9497117f1b4Smrg break; 9503464ebd5Sriastradh 9513464ebd5Sriastradh case GL_TEXTURE_GEN_STR_OES: 95201e04c3fSmrg /* disable S, T, and R at the same time */ 95301e04c3fSmrg { 95401e04c3fSmrg struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx); 955af69d88dSmrg 956af69d88dSmrg if (ctx->API != API_OPENGLES) 957af69d88dSmrg goto invalid_enum_error; 958af69d88dSmrg 959c1f859d4Smrg if (texUnit) { 9603464ebd5Sriastradh GLuint newenabled = 96101e04c3fSmrg texUnit->TexGenEnabled & ~STR_BITS; 962c1f859d4Smrg if (state) 9633464ebd5Sriastradh newenabled |= STR_BITS; 964c1f859d4Smrg if (texUnit->TexGenEnabled == newenabled) 965c1f859d4Smrg return; 9667ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE | _NEW_FF_VERT_PROGRAM | 9677ec681f3Smrg _NEW_FF_FRAG_PROGRAM, 0); 968c1f859d4Smrg texUnit->TexGenEnabled = newenabled; 969c1f859d4Smrg } 970c1f859d4Smrg } 9717117f1b4Smrg break; 9727117f1b4Smrg 973af69d88dSmrg /* client-side state */ 9747117f1b4Smrg case GL_VERTEX_ARRAY: 9757117f1b4Smrg case GL_NORMAL_ARRAY: 9767117f1b4Smrg case GL_COLOR_ARRAY: 9777117f1b4Smrg case GL_TEXTURE_COORD_ARRAY: 97801e04c3fSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 97901e04c3fSmrg goto invalid_enum_error; 9807ec681f3Smrg client_state( ctx, ctx->Array.VAO, cap, state ); 98101e04c3fSmrg return; 98201e04c3fSmrg case GL_INDEX_ARRAY: 9837117f1b4Smrg case GL_EDGE_FLAG_ARRAY: 9847117f1b4Smrg case GL_FOG_COORDINATE_ARRAY_EXT: 9857117f1b4Smrg case GL_SECONDARY_COLOR_ARRAY_EXT: 98601e04c3fSmrg if (ctx->API != API_OPENGL_COMPAT) 98701e04c3fSmrg goto invalid_enum_error; 9887ec681f3Smrg client_state( ctx, ctx->Array.VAO, cap, state ); 98901e04c3fSmrg return; 990c1f859d4Smrg case GL_POINT_SIZE_ARRAY_OES: 99101e04c3fSmrg if (ctx->API != API_OPENGLES) 99201e04c3fSmrg goto invalid_enum_error; 9937ec681f3Smrg client_state( ctx, ctx->Array.VAO, cap, state ); 9947117f1b4Smrg return; 9957117f1b4Smrg 9967117f1b4Smrg /* GL_ARB_texture_cube_map */ 99701e04c3fSmrg case GL_TEXTURE_CUBE_MAP: 9987ec681f3Smrg if (!_mesa_has_ARB_texture_cube_map(ctx) && 9997ec681f3Smrg !_mesa_has_OES_texture_cube_map(ctx)) 1000af69d88dSmrg goto invalid_enum_error; 10017117f1b4Smrg if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) { 10027117f1b4Smrg return; 10037117f1b4Smrg } 10047117f1b4Smrg break; 10057117f1b4Smrg 10067117f1b4Smrg /* GL_EXT_secondary_color */ 10077117f1b4Smrg case GL_COLOR_SUM_EXT: 1008af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1009af69d88dSmrg goto invalid_enum_error; 10107117f1b4Smrg if (ctx->Fog.ColorSumEnabled == state) 10117117f1b4Smrg return; 10127ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_FRAG_PROGRAM, 10137ec681f3Smrg GL_FOG_BIT | GL_ENABLE_BIT); 10147117f1b4Smrg ctx->Fog.ColorSumEnabled = state; 10157117f1b4Smrg break; 10167117f1b4Smrg 10177117f1b4Smrg /* GL_ARB_multisample */ 10187117f1b4Smrg case GL_MULTISAMPLE_ARB: 1019af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1020af69d88dSmrg goto invalid_enum_error; 1021af69d88dSmrg _mesa_set_multisample(ctx, state); 1022af69d88dSmrg return; 10237117f1b4Smrg case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB: 10247117f1b4Smrg if (ctx->Multisample.SampleAlphaToCoverage == state) 10257117f1b4Smrg return; 102601e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 : 10277ec681f3Smrg _NEW_MULTISAMPLE, 10287ec681f3Smrg GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 102901e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable; 10307117f1b4Smrg ctx->Multisample.SampleAlphaToCoverage = state; 10317117f1b4Smrg break; 10327117f1b4Smrg case GL_SAMPLE_ALPHA_TO_ONE_ARB: 1033af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1034af69d88dSmrg goto invalid_enum_error; 10357117f1b4Smrg if (ctx->Multisample.SampleAlphaToOne == state) 10367117f1b4Smrg return; 103701e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 : 10387ec681f3Smrg _NEW_MULTISAMPLE, 10397ec681f3Smrg GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 104001e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable; 10417117f1b4Smrg ctx->Multisample.SampleAlphaToOne = state; 10427117f1b4Smrg break; 10437117f1b4Smrg case GL_SAMPLE_COVERAGE_ARB: 10447117f1b4Smrg if (ctx->Multisample.SampleCoverage == state) 10457117f1b4Smrg return; 104601e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 : 10477ec681f3Smrg _NEW_MULTISAMPLE, 10487ec681f3Smrg GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 104901e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask; 10507117f1b4Smrg ctx->Multisample.SampleCoverage = state; 10517117f1b4Smrg break; 10527117f1b4Smrg case GL_SAMPLE_COVERAGE_INVERT_ARB: 1053af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 1054af69d88dSmrg goto invalid_enum_error; 10557117f1b4Smrg if (ctx->Multisample.SampleCoverageInvert == state) 10567117f1b4Smrg return; 105701e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 : 10587ec681f3Smrg _NEW_MULTISAMPLE, 10597ec681f3Smrg GL_MULTISAMPLE_BIT); 106001e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask; 10617117f1b4Smrg ctx->Multisample.SampleCoverageInvert = state; 10627117f1b4Smrg break; 10637117f1b4Smrg 1064af69d88dSmrg /* GL_ARB_sample_shading */ 1065af69d88dSmrg case GL_SAMPLE_SHADING: 10667ec681f3Smrg if (!_mesa_has_ARB_sample_shading(ctx) && !_mesa_is_gles3(ctx)) 1067af69d88dSmrg goto invalid_enum_error; 1068af69d88dSmrg if (ctx->Multisample.SampleShading == state) 1069af69d88dSmrg return; 107001e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 : 10717ec681f3Smrg _NEW_MULTISAMPLE, 10727ec681f3Smrg GL_MULTISAMPLE_BIT | GL_ENABLE_BIT); 107301e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading; 1074af69d88dSmrg ctx->Multisample.SampleShading = state; 1075af69d88dSmrg break; 1076af69d88dSmrg 10777117f1b4Smrg /* GL_IBM_rasterpos_clip */ 10787117f1b4Smrg case GL_RASTER_POSITION_UNCLIPPED_IBM: 1079af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1080af69d88dSmrg goto invalid_enum_error; 10817117f1b4Smrg if (ctx->Transform.RasterPositionUnclipped == state) 10827117f1b4Smrg return; 10837ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_TRANSFORM_BIT | GL_ENABLE_BIT); 10847117f1b4Smrg ctx->Transform.RasterPositionUnclipped = state; 10857117f1b4Smrg break; 10867117f1b4Smrg 10877ec681f3Smrg /* GL_ARB_point_sprite */ 10887ec681f3Smrg case GL_POINT_SPRITE: 10897ec681f3Smrg if (!(ctx->API == API_OPENGL_COMPAT && 10907ec681f3Smrg _mesa_has_ARB_point_sprite(ctx)) && 10917ec681f3Smrg !_mesa_has_OES_point_sprite(ctx)) 1092af69d88dSmrg goto invalid_enum_error; 10937117f1b4Smrg if (ctx->Point.PointSprite == state) 10947117f1b4Smrg return; 10957ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_FF_VERT_PROGRAM | 10967ec681f3Smrg _NEW_FF_FRAG_PROGRAM, GL_POINT_BIT | GL_ENABLE_BIT); 10977117f1b4Smrg ctx->Point.PointSprite = state; 10987117f1b4Smrg break; 10997117f1b4Smrg 11007117f1b4Smrg case GL_VERTEX_PROGRAM_ARB: 11017ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx)) 1102af69d88dSmrg goto invalid_enum_error; 11037117f1b4Smrg if (ctx->VertexProgram.Enabled == state) 11047117f1b4Smrg return; 11057ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT); 11067117f1b4Smrg ctx->VertexProgram.Enabled = state; 110701e04c3fSmrg _mesa_update_vertex_processing_mode(ctx); 11087ec681f3Smrg _mesa_update_valid_to_render_state(ctx); 11097117f1b4Smrg break; 11107117f1b4Smrg case GL_VERTEX_PROGRAM_POINT_SIZE_ARB: 1111af69d88dSmrg /* This was added with ARB_vertex_program, but it is also used with 1112af69d88dSmrg * GLSL vertex shaders on desktop. 1113af69d88dSmrg */ 11147ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx) && 11157ec681f3Smrg ctx->API != API_OPENGL_CORE) 1116af69d88dSmrg goto invalid_enum_error; 11177117f1b4Smrg if (ctx->VertexProgram.PointSizeEnabled == state) 11187117f1b4Smrg return; 11197ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT); 11207117f1b4Smrg ctx->VertexProgram.PointSizeEnabled = state; 11217117f1b4Smrg break; 11227117f1b4Smrg case GL_VERTEX_PROGRAM_TWO_SIDE_ARB: 11237ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx)) 1124af69d88dSmrg goto invalid_enum_error; 11257117f1b4Smrg if (ctx->VertexProgram.TwoSideEnabled == state) 11267117f1b4Smrg return; 11277ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT); 11287117f1b4Smrg ctx->VertexProgram.TwoSideEnabled = state; 11297117f1b4Smrg break; 11307117f1b4Smrg 11317117f1b4Smrg /* GL_NV_texture_rectangle */ 11327117f1b4Smrg case GL_TEXTURE_RECTANGLE_NV: 11337ec681f3Smrg if (!_mesa_has_NV_texture_rectangle(ctx)) 1134af69d88dSmrg goto invalid_enum_error; 11357117f1b4Smrg if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) { 11367117f1b4Smrg return; 11377117f1b4Smrg } 11387117f1b4Smrg break; 11397117f1b4Smrg 11407117f1b4Smrg /* GL_EXT_stencil_two_side */ 11417117f1b4Smrg case GL_STENCIL_TEST_TWO_SIDE_EXT: 11427ec681f3Smrg if (!_mesa_has_EXT_stencil_two_side(ctx)) 1143af69d88dSmrg goto invalid_enum_error; 11447117f1b4Smrg if (ctx->Stencil.TestTwoSide == state) 11457117f1b4Smrg return; 11467ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL, 11477ec681f3Smrg GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT); 114801e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewStencil; 11497117f1b4Smrg ctx->Stencil.TestTwoSide = state; 1150c1f859d4Smrg if (state) { 1151c1f859d4Smrg ctx->Stencil._BackFace = 2; 1152c1f859d4Smrg } else { 1153c1f859d4Smrg ctx->Stencil._BackFace = 1; 1154c1f859d4Smrg } 11557117f1b4Smrg break; 11567117f1b4Smrg 11577117f1b4Smrg case GL_FRAGMENT_PROGRAM_ARB: 11587ec681f3Smrg if (!_mesa_has_ARB_fragment_program(ctx)) 1159af69d88dSmrg goto invalid_enum_error; 11607117f1b4Smrg if (ctx->FragmentProgram.Enabled == state) 11617117f1b4Smrg return; 11627ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT); 11637117f1b4Smrg ctx->FragmentProgram.Enabled = state; 11647ec681f3Smrg _mesa_update_valid_to_render_state(ctx); 11657117f1b4Smrg break; 11667117f1b4Smrg 11677117f1b4Smrg /* GL_EXT_depth_bounds_test */ 11687117f1b4Smrg case GL_DEPTH_BOUNDS_TEST_EXT: 11697ec681f3Smrg if (!_mesa_has_EXT_depth_bounds_test(ctx)) 1170af69d88dSmrg goto invalid_enum_error; 11717117f1b4Smrg if (ctx->Depth.BoundsTest == state) 11727117f1b4Smrg return; 11737ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH, 11747ec681f3Smrg GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT); 117501e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepth; 11767117f1b4Smrg ctx->Depth.BoundsTest = state; 11777117f1b4Smrg break; 11787117f1b4Smrg 11794a49301eSmrg case GL_DEPTH_CLAMP: 1180a8bb7a65Smaya if (!_mesa_has_ARB_depth_clamp(ctx) && 1181a8bb7a65Smaya !_mesa_has_EXT_depth_clamp(ctx)) 1182af69d88dSmrg goto invalid_enum_error; 118301e04c3fSmrg if (ctx->Transform.DepthClampNear == state && 118401e04c3fSmrg ctx->Transform.DepthClampFar == state) 11854a49301eSmrg return; 118601e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 : 11877ec681f3Smrg _NEW_TRANSFORM, 11887ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 118901e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp; 119001e04c3fSmrg ctx->Transform.DepthClampNear = state; 119101e04c3fSmrg ctx->Transform.DepthClampFar = state; 119201e04c3fSmrg break; 119301e04c3fSmrg 119401e04c3fSmrg case GL_DEPTH_CLAMP_NEAR_AMD: 11957ec681f3Smrg if (!_mesa_has_AMD_depth_clamp_separate(ctx)) 119601e04c3fSmrg goto invalid_enum_error; 119701e04c3fSmrg if (ctx->Transform.DepthClampNear == state) 119801e04c3fSmrg return; 119901e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 : 12007ec681f3Smrg _NEW_TRANSFORM, 12017ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 120201e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp; 120301e04c3fSmrg ctx->Transform.DepthClampNear = state; 120401e04c3fSmrg break; 120501e04c3fSmrg 120601e04c3fSmrg case GL_DEPTH_CLAMP_FAR_AMD: 12077ec681f3Smrg if (!_mesa_has_AMD_depth_clamp_separate(ctx)) 120801e04c3fSmrg goto invalid_enum_error; 120901e04c3fSmrg if (ctx->Transform.DepthClampFar == state) 121001e04c3fSmrg return; 121101e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 : 12127ec681f3Smrg _NEW_TRANSFORM, 12137ec681f3Smrg GL_TRANSFORM_BIT | GL_ENABLE_BIT); 121401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp; 121501e04c3fSmrg ctx->Transform.DepthClampFar = state; 121601e04c3fSmrg break; 12177117f1b4Smrg 12187117f1b4Smrg case GL_FRAGMENT_SHADER_ATI: 12197ec681f3Smrg if (!_mesa_has_ATI_fragment_shader(ctx)) 12207ec681f3Smrg goto invalid_enum_error; 122101e04c3fSmrg if (ctx->ATIFragmentShader.Enabled == state) 122201e04c3fSmrg return; 12237ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT); 122401e04c3fSmrg ctx->ATIFragmentShader.Enabled = state; 12257117f1b4Smrg break; 1226c1f859d4Smrg 12274a49301eSmrg case GL_TEXTURE_CUBE_MAP_SEAMLESS: 12287ec681f3Smrg if (!_mesa_has_ARB_seamless_cube_map(ctx)) 1229af69d88dSmrg goto invalid_enum_error; 123001e04c3fSmrg if (ctx->Texture.CubeMapSeamless != state) { 12317ec681f3Smrg FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, 0); 123201e04c3fSmrg ctx->Texture.CubeMapSeamless = state; 123301e04c3fSmrg } 123401e04c3fSmrg break; 12354a49301eSmrg 12363464ebd5Sriastradh case GL_RASTERIZER_DISCARD: 12377ec681f3Smrg if (!(_mesa_has_EXT_transform_feedback(ctx) || _mesa_is_gles3(ctx))) 1238af69d88dSmrg goto invalid_enum_error; 1239af69d88dSmrg if (ctx->RasterDiscard != state) { 12407ec681f3Smrg FLUSH_VERTICES(ctx, 0, 0); 1241af69d88dSmrg ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard; 1242af69d88dSmrg ctx->RasterDiscard = state; 12433464ebd5Sriastradh } 12443464ebd5Sriastradh break; 12453464ebd5Sriastradh 124601e04c3fSmrg case GL_TILE_RASTER_ORDER_FIXED_MESA: 12477ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 12487ec681f3Smrg goto invalid_enum_error; 124901e04c3fSmrg if (ctx->TileRasterOrderFixed != state) { 12507ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT); 125101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder; 125201e04c3fSmrg ctx->TileRasterOrderFixed = state; 125301e04c3fSmrg } 125401e04c3fSmrg break; 125501e04c3fSmrg 125601e04c3fSmrg case GL_TILE_RASTER_ORDER_INCREASING_X_MESA: 12577ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 12587ec681f3Smrg goto invalid_enum_error; 125901e04c3fSmrg if (ctx->TileRasterOrderIncreasingX != state) { 12607ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT); 126101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder; 126201e04c3fSmrg ctx->TileRasterOrderIncreasingX = state; 126301e04c3fSmrg } 126401e04c3fSmrg break; 126501e04c3fSmrg 126601e04c3fSmrg case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA: 12677ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 12687ec681f3Smrg goto invalid_enum_error; 126901e04c3fSmrg if (ctx->TileRasterOrderIncreasingY != state) { 12707ec681f3Smrg FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT); 127101e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder; 127201e04c3fSmrg ctx->TileRasterOrderIncreasingY = state; 127301e04c3fSmrg } 127401e04c3fSmrg break; 127501e04c3fSmrg 12763464ebd5Sriastradh /* GL 3.1 primitive restart. Note: this enum is different from 12773464ebd5Sriastradh * GL_PRIMITIVE_RESTART_NV (which is client state). 12783464ebd5Sriastradh */ 12793464ebd5Sriastradh case GL_PRIMITIVE_RESTART: 1280af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) { 12813464ebd5Sriastradh goto invalid_enum_error; 12823464ebd5Sriastradh } 12833464ebd5Sriastradh if (ctx->Array.PrimitiveRestart != state) { 12843464ebd5Sriastradh ctx->Array.PrimitiveRestart = state; 12857ec681f3Smrg _mesa_update_derived_primitive_restart_state(ctx); 1286af69d88dSmrg } 1287af69d88dSmrg break; 1288af69d88dSmrg 1289af69d88dSmrg case GL_PRIMITIVE_RESTART_FIXED_INDEX: 12907ec681f3Smrg if (!_mesa_is_gles3(ctx) && !_mesa_has_ARB_ES3_compatibility(ctx)) 1291af69d88dSmrg goto invalid_enum_error; 1292af69d88dSmrg if (ctx->Array.PrimitiveRestartFixedIndex != state) { 1293af69d88dSmrg ctx->Array.PrimitiveRestartFixedIndex = state; 12947ec681f3Smrg _mesa_update_derived_primitive_restart_state(ctx); 12953464ebd5Sriastradh } 12963464ebd5Sriastradh break; 12973464ebd5Sriastradh 12983464ebd5Sriastradh /* GL3.0 - GL_framebuffer_sRGB */ 12993464ebd5Sriastradh case GL_FRAMEBUFFER_SRGB_EXT: 13007ec681f3Smrg if (!_mesa_has_EXT_framebuffer_sRGB(ctx) && 13017ec681f3Smrg !_mesa_has_EXT_sRGB_write_control(ctx)) 13027ec681f3Smrg goto invalid_enum_error; 1303af69d88dSmrg _mesa_set_framebuffer_srgb(ctx, state); 1304af69d88dSmrg return; 1305af69d88dSmrg 1306af69d88dSmrg /* GL_OES_EGL_image_external */ 1307af69d88dSmrg case GL_TEXTURE_EXTERNAL_OES: 13087ec681f3Smrg if (!_mesa_has_OES_EGL_image_external(ctx)) 1309af69d88dSmrg goto invalid_enum_error; 1310af69d88dSmrg if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) { 1311af69d88dSmrg return; 1312af69d88dSmrg } 1313af69d88dSmrg break; 1314af69d88dSmrg 1315af69d88dSmrg /* ARB_texture_multisample */ 1316af69d88dSmrg case GL_SAMPLE_MASK: 13177ec681f3Smrg if (!_mesa_has_ARB_texture_multisample(ctx) && !_mesa_is_gles31(ctx)) 1318af69d88dSmrg goto invalid_enum_error; 1319af69d88dSmrg if (ctx->Multisample.SampleMask == state) 1320af69d88dSmrg return; 132101e04c3fSmrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 : 13227ec681f3Smrg _NEW_MULTISAMPLE, 0); 132301e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask; 1324af69d88dSmrg ctx->Multisample.SampleMask = state; 13253464ebd5Sriastradh break; 13263464ebd5Sriastradh 132701e04c3fSmrg case GL_BLEND_ADVANCED_COHERENT_KHR: 13287ec681f3Smrg if (!_mesa_has_KHR_blend_equation_advanced_coherent(ctx)) 13297ec681f3Smrg goto invalid_enum_error; 133001e04c3fSmrg if (ctx->Color.BlendCoherent == state) 133101e04c3fSmrg return; 13327ec681f3Smrg FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR, 13337ec681f3Smrg GL_COLOR_BUFFER_BIT); 133401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewBlend; 133501e04c3fSmrg ctx->Color.BlendCoherent = state; 133601e04c3fSmrg break; 133701e04c3fSmrg 13387ec681f3Smrg case GL_BLACKHOLE_RENDER_INTEL: 13397ec681f3Smrg if (!_mesa_has_INTEL_blackhole_render(ctx)) 13407ec681f3Smrg goto invalid_enum_error; 13417ec681f3Smrg if (ctx->IntelBlackholeRender == state) 13427ec681f3Smrg return; 13437ec681f3Smrg FLUSH_VERTICES(ctx, 0, 0); 13447ec681f3Smrg ctx->IntelBlackholeRender = state; 13457ec681f3Smrg break; 13467ec681f3Smrg 13477117f1b4Smrg default: 13483464ebd5Sriastradh goto invalid_enum_error; 13497117f1b4Smrg } 13507117f1b4Smrg 13517117f1b4Smrg if (ctx->Driver.Enable) { 13527117f1b4Smrg ctx->Driver.Enable( ctx, cap, state ); 13537117f1b4Smrg } 13543464ebd5Sriastradh 13553464ebd5Sriastradh return; 13563464ebd5Sriastradh 13573464ebd5Sriastradhinvalid_enum_error: 1358af69d88dSmrg _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)", 135901e04c3fSmrg state ? "Enable" : "Disable", _mesa_enum_to_string(cap)); 13607117f1b4Smrg} 13617117f1b4Smrg 13627117f1b4Smrg 13637117f1b4Smrg/** 13647117f1b4Smrg * Enable GL capability. Called by glEnable() 13657117f1b4Smrg * \param cap state to enable. 13667117f1b4Smrg */ 13677117f1b4Smrgvoid GLAPIENTRY 13687117f1b4Smrg_mesa_Enable( GLenum cap ) 13697117f1b4Smrg{ 13707117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 13717117f1b4Smrg 13727117f1b4Smrg _mesa_set_enable( ctx, cap, GL_TRUE ); 13737117f1b4Smrg} 13747117f1b4Smrg 13757117f1b4Smrg 13767117f1b4Smrg/** 13777117f1b4Smrg * Disable GL capability. Called by glDisable() 13787117f1b4Smrg * \param cap state to disable. 13797117f1b4Smrg */ 13807117f1b4Smrgvoid GLAPIENTRY 13817117f1b4Smrg_mesa_Disable( GLenum cap ) 13827117f1b4Smrg{ 13837117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 13847117f1b4Smrg 13857117f1b4Smrg _mesa_set_enable( ctx, cap, GL_FALSE ); 13867117f1b4Smrg} 13877117f1b4Smrg 13887117f1b4Smrg 1389cdc920a0Smrg 1390cdc920a0Smrg/** 1391cdc920a0Smrg * Enable/disable an indexed state var. 1392cdc920a0Smrg */ 1393cdc920a0Smrgvoid 13943464ebd5Sriastradh_mesa_set_enablei(struct gl_context *ctx, GLenum cap, 13953464ebd5Sriastradh GLuint index, GLboolean state) 1396cdc920a0Smrg{ 139701e04c3fSmrg assert(state == 0 || state == 1); 1398cdc920a0Smrg switch (cap) { 1399cdc920a0Smrg case GL_BLEND: 1400cdc920a0Smrg if (!ctx->Extensions.EXT_draw_buffers2) { 14013464ebd5Sriastradh goto invalid_enum_error; 1402cdc920a0Smrg } 1403cdc920a0Smrg if (index >= ctx->Const.MaxDrawBuffers) { 1404cdc920a0Smrg _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", 1405cdc920a0Smrg state ? "glEnableIndexed" : "glDisableIndexed", index); 1406cdc920a0Smrg return; 1407cdc920a0Smrg } 1408cdc920a0Smrg if (((ctx->Color.BlendEnabled >> index) & 1) != state) { 140901e04c3fSmrg GLbitfield enabled = ctx->Color.BlendEnabled; 141001e04c3fSmrg 1411cdc920a0Smrg if (state) 141201e04c3fSmrg enabled |= (1 << index); 1413cdc920a0Smrg else 141401e04c3fSmrg enabled &= ~(1 << index); 141501e04c3fSmrg 141601e04c3fSmrg _mesa_flush_vertices_for_blend_adv(ctx, enabled, 141701e04c3fSmrg ctx->Color._AdvancedBlendMode); 14187ec681f3Smrg ctx->PopAttribState |= GL_ENABLE_BIT; 141901e04c3fSmrg ctx->Color.BlendEnabled = enabled; 14207ec681f3Smrg _mesa_update_allow_draw_out_of_order(ctx); 14217ec681f3Smrg _mesa_update_valid_to_render_state(ctx); 1422cdc920a0Smrg } 1423cdc920a0Smrg break; 1424af69d88dSmrg case GL_SCISSOR_TEST: 1425af69d88dSmrg if (index >= ctx->Const.MaxViewports) { 1426af69d88dSmrg _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", 1427af69d88dSmrg state ? "glEnablei" : "glDisablei", index); 1428af69d88dSmrg return; 1429af69d88dSmrg } 1430af69d88dSmrg if (((ctx->Scissor.EnableFlags >> index) & 1) != state) { 143101e04c3fSmrg FLUSH_VERTICES(ctx, 14327ec681f3Smrg ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR, 14337ec681f3Smrg GL_SCISSOR_BIT | GL_ENABLE_BIT); 143401e04c3fSmrg ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest; 1435af69d88dSmrg if (state) 1436af69d88dSmrg ctx->Scissor.EnableFlags |= (1 << index); 1437af69d88dSmrg else 1438af69d88dSmrg ctx->Scissor.EnableFlags &= ~(1 << index); 1439af69d88dSmrg } 1440af69d88dSmrg break; 14417ec681f3Smrg /* EXT_direct_state_access */ 14427ec681f3Smrg case GL_TEXTURE_1D: 14437ec681f3Smrg case GL_TEXTURE_2D: 14447ec681f3Smrg case GL_TEXTURE_3D: 14457ec681f3Smrg case GL_TEXTURE_CUBE_MAP: 14467ec681f3Smrg case GL_TEXTURE_GEN_S: 14477ec681f3Smrg case GL_TEXTURE_GEN_T: 14487ec681f3Smrg case GL_TEXTURE_GEN_R: 14497ec681f3Smrg case GL_TEXTURE_GEN_Q: 14507ec681f3Smrg case GL_TEXTURE_RECTANGLE_ARB: { 14517ec681f3Smrg const GLuint curTexUnitSave = ctx->Texture.CurrentUnit; 14527ec681f3Smrg if (index >= MAX2(ctx->Const.MaxCombinedTextureImageUnits, 14537ec681f3Smrg ctx->Const.MaxTextureCoordUnits)) { 14547ec681f3Smrg _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", 14557ec681f3Smrg state ? "glEnablei" : "glDisablei", index); 14567ec681f3Smrg return; 14577ec681f3Smrg } 14587ec681f3Smrg _mesa_ActiveTexture(GL_TEXTURE0 + index); 14597ec681f3Smrg _mesa_set_enable( ctx, cap, state ); 14607ec681f3Smrg _mesa_ActiveTexture(GL_TEXTURE0 + curTexUnitSave); 14617ec681f3Smrg break; 14627ec681f3Smrg } 1463cdc920a0Smrg default: 14643464ebd5Sriastradh goto invalid_enum_error; 1465cdc920a0Smrg } 1466cdc920a0Smrg return; 1467cdc920a0Smrg 14683464ebd5Sriastradhinvalid_enum_error: 1469cdc920a0Smrg _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)", 1470cdc920a0Smrg state ? "glEnablei" : "glDisablei", 147101e04c3fSmrg _mesa_enum_to_string(cap)); 1472cdc920a0Smrg} 1473cdc920a0Smrg 1474cdc920a0Smrg 1475cdc920a0Smrgvoid GLAPIENTRY 1476af69d88dSmrg_mesa_Disablei( GLenum cap, GLuint index ) 1477cdc920a0Smrg{ 1478cdc920a0Smrg GET_CURRENT_CONTEXT(ctx); 1479cdc920a0Smrg _mesa_set_enablei(ctx, cap, index, GL_FALSE); 1480cdc920a0Smrg} 1481cdc920a0Smrg 1482cdc920a0Smrg 1483cdc920a0Smrgvoid GLAPIENTRY 1484af69d88dSmrg_mesa_Enablei( GLenum cap, GLuint index ) 1485cdc920a0Smrg{ 1486cdc920a0Smrg GET_CURRENT_CONTEXT(ctx); 1487cdc920a0Smrg _mesa_set_enablei(ctx, cap, index, GL_TRUE); 1488cdc920a0Smrg} 1489cdc920a0Smrg 1490cdc920a0Smrg 1491cdc920a0SmrgGLboolean GLAPIENTRY 1492af69d88dSmrg_mesa_IsEnabledi( GLenum cap, GLuint index ) 1493cdc920a0Smrg{ 1494cdc920a0Smrg GET_CURRENT_CONTEXT(ctx); 14953464ebd5Sriastradh ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); 1496cdc920a0Smrg switch (cap) { 1497cdc920a0Smrg case GL_BLEND: 1498cdc920a0Smrg if (index >= ctx->Const.MaxDrawBuffers) { 1499cdc920a0Smrg _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)", 1500cdc920a0Smrg index); 1501cdc920a0Smrg return GL_FALSE; 1502cdc920a0Smrg } 1503cdc920a0Smrg return (ctx->Color.BlendEnabled >> index) & 1; 1504af69d88dSmrg case GL_SCISSOR_TEST: 1505af69d88dSmrg if (index >= ctx->Const.MaxViewports) { 1506af69d88dSmrg _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)", 1507af69d88dSmrg index); 1508af69d88dSmrg return GL_FALSE; 1509af69d88dSmrg } 1510af69d88dSmrg return (ctx->Scissor.EnableFlags >> index) & 1; 15117ec681f3Smrg /* EXT_direct_state_access */ 15127ec681f3Smrg case GL_TEXTURE_1D: 15137ec681f3Smrg case GL_TEXTURE_2D: 15147ec681f3Smrg case GL_TEXTURE_3D: 15157ec681f3Smrg case GL_TEXTURE_CUBE_MAP: 15167ec681f3Smrg case GL_TEXTURE_GEN_S: 15177ec681f3Smrg case GL_TEXTURE_GEN_T: 15187ec681f3Smrg case GL_TEXTURE_GEN_R: 15197ec681f3Smrg case GL_TEXTURE_GEN_Q: 15207ec681f3Smrg case GL_TEXTURE_RECTANGLE_ARB: { 15217ec681f3Smrg GLboolean state; 15227ec681f3Smrg const GLuint curTexUnitSave = ctx->Texture.CurrentUnit; 15237ec681f3Smrg if (index >= MAX2(ctx->Const.MaxCombinedTextureImageUnits, 15247ec681f3Smrg ctx->Const.MaxTextureCoordUnits)) { 15257ec681f3Smrg _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)", 15267ec681f3Smrg index); 15277ec681f3Smrg return GL_FALSE; 15287ec681f3Smrg } 15297ec681f3Smrg _mesa_ActiveTexture(GL_TEXTURE0 + index); 15307ec681f3Smrg state = _mesa_IsEnabled(cap); 15317ec681f3Smrg _mesa_ActiveTexture(GL_TEXTURE0 + curTexUnitSave); 15327ec681f3Smrg return state; 15337ec681f3Smrg } 1534cdc920a0Smrg default: 1535cdc920a0Smrg _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)", 153601e04c3fSmrg _mesa_enum_to_string(cap)); 1537cdc920a0Smrg return GL_FALSE; 1538cdc920a0Smrg } 1539cdc920a0Smrg} 1540cdc920a0Smrg 1541cdc920a0Smrg 1542cdc920a0Smrg 15437117f1b4Smrg/** 15447117f1b4Smrg * Helper function to determine whether a texture target is enabled. 15457117f1b4Smrg */ 15467117f1b4Smrgstatic GLboolean 15473464ebd5Sriastradhis_texture_enabled(struct gl_context *ctx, GLbitfield bit) 15487117f1b4Smrg{ 154901e04c3fSmrg const struct gl_fixedfunc_texture_unit *const texUnit = 15507ec681f3Smrg _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit); 155101e04c3fSmrg 155201e04c3fSmrg if (!texUnit) 155301e04c3fSmrg return GL_FALSE; 155401e04c3fSmrg 15557117f1b4Smrg return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE; 15567117f1b4Smrg} 15577117f1b4Smrg 15587117f1b4Smrg 15597117f1b4Smrg/** 15607117f1b4Smrg * Return simple enable/disable state. 15617117f1b4Smrg * 15627117f1b4Smrg * \param cap state variable to query. 15637117f1b4Smrg * 15647117f1b4Smrg * Returns the state of the specified capability from the current GL context. 15657117f1b4Smrg * For the capabilities associated with extensions verifies that those 15667117f1b4Smrg * extensions are effectively present before reporting. 15677117f1b4Smrg */ 15687117f1b4SmrgGLboolean GLAPIENTRY 15697117f1b4Smrg_mesa_IsEnabled( GLenum cap ) 15707117f1b4Smrg{ 15717117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 15723464ebd5Sriastradh ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); 15733464ebd5Sriastradh 15747117f1b4Smrg switch (cap) { 15757117f1b4Smrg case GL_ALPHA_TEST: 1576af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1577af69d88dSmrg goto invalid_enum_error; 15787117f1b4Smrg return ctx->Color.AlphaEnabled; 15797117f1b4Smrg case GL_AUTO_NORMAL: 1580af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1581af69d88dSmrg goto invalid_enum_error; 158201e04c3fSmrg return ctx->Eval.AutoNormal; 15837117f1b4Smrg case GL_BLEND: 1584cdc920a0Smrg return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */ 1585af69d88dSmrg case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */ 1586af69d88dSmrg case GL_CLIP_DISTANCE1: 1587af69d88dSmrg case GL_CLIP_DISTANCE2: 1588af69d88dSmrg case GL_CLIP_DISTANCE3: 1589af69d88dSmrg case GL_CLIP_DISTANCE4: 1590af69d88dSmrg case GL_CLIP_DISTANCE5: 1591af69d88dSmrg case GL_CLIP_DISTANCE6: 1592af69d88dSmrg case GL_CLIP_DISTANCE7: { 1593af69d88dSmrg const GLuint p = cap - GL_CLIP_DISTANCE0; 1594af69d88dSmrg 1595af69d88dSmrg if (p >= ctx->Const.MaxClipPlanes) 1596af69d88dSmrg goto invalid_enum_error; 1597af69d88dSmrg 159801e04c3fSmrg return (ctx->Transform.ClipPlanesEnabled >> p) & 1; 1599af69d88dSmrg } 16007117f1b4Smrg case GL_COLOR_MATERIAL: 1601af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1602af69d88dSmrg goto invalid_enum_error; 160301e04c3fSmrg return ctx->Light.ColorMaterialEnabled; 16047117f1b4Smrg case GL_CULL_FACE: 16057117f1b4Smrg return ctx->Polygon.CullFlag; 1606af69d88dSmrg case GL_DEBUG_OUTPUT: 1607af69d88dSmrg case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: 160801e04c3fSmrg return (GLboolean) _mesa_get_debug_state_int(ctx, cap); 16097117f1b4Smrg case GL_DEPTH_TEST: 16107117f1b4Smrg return ctx->Depth.Test; 16117117f1b4Smrg case GL_DITHER: 161201e04c3fSmrg return ctx->Color.DitherFlag; 16137117f1b4Smrg case GL_FOG: 1614af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1615af69d88dSmrg goto invalid_enum_error; 161601e04c3fSmrg return ctx->Fog.Enabled; 16177117f1b4Smrg case GL_LIGHTING: 1618af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1619af69d88dSmrg goto invalid_enum_error; 16207117f1b4Smrg return ctx->Light.Enabled; 16217117f1b4Smrg case GL_LIGHT0: 16227117f1b4Smrg case GL_LIGHT1: 16237117f1b4Smrg case GL_LIGHT2: 16247117f1b4Smrg case GL_LIGHT3: 16257117f1b4Smrg case GL_LIGHT4: 16267117f1b4Smrg case GL_LIGHT5: 16277117f1b4Smrg case GL_LIGHT6: 16287117f1b4Smrg case GL_LIGHT7: 1629af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1630af69d88dSmrg goto invalid_enum_error; 16317117f1b4Smrg return ctx->Light.Light[cap-GL_LIGHT0].Enabled; 16327117f1b4Smrg case GL_LINE_SMOOTH: 1633af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1634af69d88dSmrg goto invalid_enum_error; 163501e04c3fSmrg return ctx->Line.SmoothFlag; 16367117f1b4Smrg case GL_LINE_STIPPLE: 1637af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1638af69d88dSmrg goto invalid_enum_error; 163901e04c3fSmrg return ctx->Line.StippleFlag; 16407117f1b4Smrg case GL_INDEX_LOGIC_OP: 1641af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1642af69d88dSmrg goto invalid_enum_error; 164301e04c3fSmrg return ctx->Color.IndexLogicOpEnabled; 16447117f1b4Smrg case GL_COLOR_LOGIC_OP: 1645af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1646af69d88dSmrg goto invalid_enum_error; 164701e04c3fSmrg return ctx->Color.ColorLogicOpEnabled; 16487117f1b4Smrg case GL_MAP1_COLOR_4: 1649af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1650af69d88dSmrg goto invalid_enum_error; 165101e04c3fSmrg return ctx->Eval.Map1Color4; 16527117f1b4Smrg case GL_MAP1_INDEX: 1653af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1654af69d88dSmrg goto invalid_enum_error; 165501e04c3fSmrg return ctx->Eval.Map1Index; 16567117f1b4Smrg case GL_MAP1_NORMAL: 1657af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1658af69d88dSmrg goto invalid_enum_error; 165901e04c3fSmrg return ctx->Eval.Map1Normal; 16607117f1b4Smrg case GL_MAP1_TEXTURE_COORD_1: 1661af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1662af69d88dSmrg goto invalid_enum_error; 166301e04c3fSmrg return ctx->Eval.Map1TextureCoord1; 16647117f1b4Smrg case GL_MAP1_TEXTURE_COORD_2: 1665af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1666af69d88dSmrg goto invalid_enum_error; 166701e04c3fSmrg return ctx->Eval.Map1TextureCoord2; 16687117f1b4Smrg case GL_MAP1_TEXTURE_COORD_3: 1669af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1670af69d88dSmrg goto invalid_enum_error; 167101e04c3fSmrg return ctx->Eval.Map1TextureCoord3; 16727117f1b4Smrg case GL_MAP1_TEXTURE_COORD_4: 1673af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1674af69d88dSmrg goto invalid_enum_error; 167501e04c3fSmrg return ctx->Eval.Map1TextureCoord4; 16767117f1b4Smrg case GL_MAP1_VERTEX_3: 1677af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1678af69d88dSmrg goto invalid_enum_error; 167901e04c3fSmrg return ctx->Eval.Map1Vertex3; 16807117f1b4Smrg case GL_MAP1_VERTEX_4: 1681af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1682af69d88dSmrg goto invalid_enum_error; 168301e04c3fSmrg return ctx->Eval.Map1Vertex4; 16847117f1b4Smrg case GL_MAP2_COLOR_4: 1685af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1686af69d88dSmrg goto invalid_enum_error; 168701e04c3fSmrg return ctx->Eval.Map2Color4; 16887117f1b4Smrg case GL_MAP2_INDEX: 1689af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1690af69d88dSmrg goto invalid_enum_error; 169101e04c3fSmrg return ctx->Eval.Map2Index; 16927117f1b4Smrg case GL_MAP2_NORMAL: 1693af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1694af69d88dSmrg goto invalid_enum_error; 169501e04c3fSmrg return ctx->Eval.Map2Normal; 16967117f1b4Smrg case GL_MAP2_TEXTURE_COORD_1: 1697af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1698af69d88dSmrg goto invalid_enum_error; 169901e04c3fSmrg return ctx->Eval.Map2TextureCoord1; 17007117f1b4Smrg case GL_MAP2_TEXTURE_COORD_2: 1701af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1702af69d88dSmrg goto invalid_enum_error; 170301e04c3fSmrg return ctx->Eval.Map2TextureCoord2; 17047117f1b4Smrg case GL_MAP2_TEXTURE_COORD_3: 1705af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1706af69d88dSmrg goto invalid_enum_error; 170701e04c3fSmrg return ctx->Eval.Map2TextureCoord3; 17087117f1b4Smrg case GL_MAP2_TEXTURE_COORD_4: 1709af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1710af69d88dSmrg goto invalid_enum_error; 171101e04c3fSmrg return ctx->Eval.Map2TextureCoord4; 17127117f1b4Smrg case GL_MAP2_VERTEX_3: 1713af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1714af69d88dSmrg goto invalid_enum_error; 171501e04c3fSmrg return ctx->Eval.Map2Vertex3; 17167117f1b4Smrg case GL_MAP2_VERTEX_4: 1717af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1718af69d88dSmrg goto invalid_enum_error; 171901e04c3fSmrg return ctx->Eval.Map2Vertex4; 17207117f1b4Smrg case GL_NORMALIZE: 1721af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1722af69d88dSmrg goto invalid_enum_error; 172301e04c3fSmrg return ctx->Transform.Normalize; 17247117f1b4Smrg case GL_POINT_SMOOTH: 1725af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1726af69d88dSmrg goto invalid_enum_error; 172701e04c3fSmrg return ctx->Point.SmoothFlag; 17287117f1b4Smrg case GL_POLYGON_SMOOTH: 1729af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 1730af69d88dSmrg goto invalid_enum_error; 173101e04c3fSmrg return ctx->Polygon.SmoothFlag; 17327117f1b4Smrg case GL_POLYGON_STIPPLE: 1733af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1734af69d88dSmrg goto invalid_enum_error; 173501e04c3fSmrg return ctx->Polygon.StippleFlag; 17367117f1b4Smrg case GL_POLYGON_OFFSET_POINT: 1737af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 1738af69d88dSmrg goto invalid_enum_error; 173901e04c3fSmrg return ctx->Polygon.OffsetPoint; 17407117f1b4Smrg case GL_POLYGON_OFFSET_LINE: 1741af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 1742af69d88dSmrg goto invalid_enum_error; 174301e04c3fSmrg return ctx->Polygon.OffsetLine; 17447117f1b4Smrg case GL_POLYGON_OFFSET_FILL: 174501e04c3fSmrg return ctx->Polygon.OffsetFill; 17467117f1b4Smrg case GL_RESCALE_NORMAL_EXT: 1747af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1748af69d88dSmrg goto invalid_enum_error; 17497117f1b4Smrg return ctx->Transform.RescaleNormals; 17507117f1b4Smrg case GL_SCISSOR_TEST: 175101e04c3fSmrg return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */ 17527117f1b4Smrg case GL_STENCIL_TEST: 175301e04c3fSmrg return ctx->Stencil.Enabled; 17547117f1b4Smrg case GL_TEXTURE_1D: 1755af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1756af69d88dSmrg goto invalid_enum_error; 17577117f1b4Smrg return is_texture_enabled(ctx, TEXTURE_1D_BIT); 17587117f1b4Smrg case GL_TEXTURE_2D: 1759af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1760af69d88dSmrg goto invalid_enum_error; 17617117f1b4Smrg return is_texture_enabled(ctx, TEXTURE_2D_BIT); 17627117f1b4Smrg case GL_TEXTURE_3D: 1763af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1764af69d88dSmrg goto invalid_enum_error; 17657117f1b4Smrg return is_texture_enabled(ctx, TEXTURE_3D_BIT); 17667117f1b4Smrg case GL_TEXTURE_GEN_S: 17673464ebd5Sriastradh case GL_TEXTURE_GEN_T: 17683464ebd5Sriastradh case GL_TEXTURE_GEN_R: 17693464ebd5Sriastradh case GL_TEXTURE_GEN_Q: 17707117f1b4Smrg { 177101e04c3fSmrg const struct gl_fixedfunc_texture_unit *texUnit = 177201e04c3fSmrg get_texcoord_unit(ctx); 1773af69d88dSmrg 1774af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1775af69d88dSmrg goto invalid_enum_error; 1776af69d88dSmrg 1777c1f859d4Smrg if (texUnit) { 17783464ebd5Sriastradh GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S); 17793464ebd5Sriastradh return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE; 1780c1f859d4Smrg } 17817117f1b4Smrg } 1782c1f859d4Smrg return GL_FALSE; 17833464ebd5Sriastradh case GL_TEXTURE_GEN_STR_OES: 178401e04c3fSmrg { 178501e04c3fSmrg const struct gl_fixedfunc_texture_unit *texUnit = 178601e04c3fSmrg get_texcoord_unit(ctx); 1787af69d88dSmrg 1788af69d88dSmrg if (ctx->API != API_OPENGLES) 1789af69d88dSmrg goto invalid_enum_error; 1790af69d88dSmrg 1791c1f859d4Smrg if (texUnit) { 17923464ebd5Sriastradh return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS 17933464ebd5Sriastradh ? GL_TRUE : GL_FALSE; 1794c1f859d4Smrg } 17957ec681f3Smrg 17967ec681f3Smrg return GL_FALSE; 17977117f1b4Smrg } 17987117f1b4Smrg 1799af69d88dSmrg /* client-side state */ 18007117f1b4Smrg case GL_VERTEX_ARRAY: 1801af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1802af69d88dSmrg goto invalid_enum_error; 1803a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_POS); 18047117f1b4Smrg case GL_NORMAL_ARRAY: 1805af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1806af69d88dSmrg goto invalid_enum_error; 1807a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_NORMAL); 18087117f1b4Smrg case GL_COLOR_ARRAY: 1809af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1810af69d88dSmrg goto invalid_enum_error; 1811a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR0); 18127117f1b4Smrg case GL_INDEX_ARRAY: 1813af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1814af69d88dSmrg goto invalid_enum_error; 1815a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR_INDEX); 18167117f1b4Smrg case GL_TEXTURE_COORD_ARRAY: 1817af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) 1818af69d88dSmrg goto invalid_enum_error; 1819a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & 1820a8bb7a65Smaya VERT_BIT_TEX(ctx->Array.ActiveTexture)); 18217117f1b4Smrg case GL_EDGE_FLAG_ARRAY: 1822af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1823af69d88dSmrg goto invalid_enum_error; 1824a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_EDGEFLAG); 18257117f1b4Smrg case GL_FOG_COORDINATE_ARRAY_EXT: 1826af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1827af69d88dSmrg goto invalid_enum_error; 1828a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_FOG); 18297117f1b4Smrg case GL_SECONDARY_COLOR_ARRAY_EXT: 1830af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1831af69d88dSmrg goto invalid_enum_error; 1832a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR1); 1833c1f859d4Smrg case GL_POINT_SIZE_ARRAY_OES: 1834af69d88dSmrg if (ctx->API != API_OPENGLES) 1835af69d88dSmrg goto invalid_enum_error; 1836a8bb7a65Smaya return !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE); 18377117f1b4Smrg 18387117f1b4Smrg /* GL_ARB_texture_cube_map */ 183901e04c3fSmrg case GL_TEXTURE_CUBE_MAP: 18407ec681f3Smrg if (!_mesa_has_ARB_texture_cube_map(ctx) && 18417ec681f3Smrg !_mesa_has_OES_texture_cube_map(ctx)) 18427ec681f3Smrg goto invalid_enum_error; 18437117f1b4Smrg return is_texture_enabled(ctx, TEXTURE_CUBE_BIT); 18447117f1b4Smrg 18457117f1b4Smrg /* GL_EXT_secondary_color */ 18467117f1b4Smrg case GL_COLOR_SUM_EXT: 1847af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1848af69d88dSmrg goto invalid_enum_error; 18497117f1b4Smrg return ctx->Fog.ColorSumEnabled; 18507117f1b4Smrg 18517117f1b4Smrg /* GL_ARB_multisample */ 18527117f1b4Smrg case GL_MULTISAMPLE_ARB: 1853af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1854af69d88dSmrg goto invalid_enum_error; 18557117f1b4Smrg return ctx->Multisample.Enabled; 18567117f1b4Smrg case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB: 18577117f1b4Smrg return ctx->Multisample.SampleAlphaToCoverage; 18587117f1b4Smrg case GL_SAMPLE_ALPHA_TO_ONE_ARB: 1859af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) 1860af69d88dSmrg goto invalid_enum_error; 18617117f1b4Smrg return ctx->Multisample.SampleAlphaToOne; 18627117f1b4Smrg case GL_SAMPLE_COVERAGE_ARB: 18637117f1b4Smrg return ctx->Multisample.SampleCoverage; 18647117f1b4Smrg case GL_SAMPLE_COVERAGE_INVERT_ARB: 1865af69d88dSmrg if (!_mesa_is_desktop_gl(ctx)) 1866af69d88dSmrg goto invalid_enum_error; 18677117f1b4Smrg return ctx->Multisample.SampleCoverageInvert; 18687117f1b4Smrg 18697117f1b4Smrg /* GL_IBM_rasterpos_clip */ 18707117f1b4Smrg case GL_RASTER_POSITION_UNCLIPPED_IBM: 1871af69d88dSmrg if (ctx->API != API_OPENGL_COMPAT) 1872af69d88dSmrg goto invalid_enum_error; 18737117f1b4Smrg return ctx->Transform.RasterPositionUnclipped; 18747117f1b4Smrg 18757ec681f3Smrg /* GL_ARB_point_sprite */ 18767ec681f3Smrg case GL_POINT_SPRITE: 18777ec681f3Smrg if (!(ctx->API == API_OPENGL_COMPAT && 18787ec681f3Smrg _mesa_has_ARB_point_sprite(ctx)) && 18797ec681f3Smrg !_mesa_has_OES_point_sprite(ctx)) 1880af69d88dSmrg goto invalid_enum_error; 18817117f1b4Smrg return ctx->Point.PointSprite; 18827117f1b4Smrg 18837117f1b4Smrg case GL_VERTEX_PROGRAM_ARB: 18847ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx)) 1885af69d88dSmrg goto invalid_enum_error; 18867117f1b4Smrg return ctx->VertexProgram.Enabled; 18877117f1b4Smrg case GL_VERTEX_PROGRAM_POINT_SIZE_ARB: 1888af69d88dSmrg /* This was added with ARB_vertex_program, but it is also used with 1889af69d88dSmrg * GLSL vertex shaders on desktop. 1890af69d88dSmrg */ 18917ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx) && 18927ec681f3Smrg ctx->API != API_OPENGL_CORE) 1893af69d88dSmrg goto invalid_enum_error; 18947117f1b4Smrg return ctx->VertexProgram.PointSizeEnabled; 18957117f1b4Smrg case GL_VERTEX_PROGRAM_TWO_SIDE_ARB: 18967ec681f3Smrg if (!_mesa_has_ARB_vertex_program(ctx)) 1897af69d88dSmrg goto invalid_enum_error; 18987117f1b4Smrg return ctx->VertexProgram.TwoSideEnabled; 18997117f1b4Smrg 19007117f1b4Smrg /* GL_NV_texture_rectangle */ 19017117f1b4Smrg case GL_TEXTURE_RECTANGLE_NV: 19027ec681f3Smrg if (!_mesa_has_NV_texture_rectangle(ctx)) 1903af69d88dSmrg goto invalid_enum_error; 19047117f1b4Smrg return is_texture_enabled(ctx, TEXTURE_RECT_BIT); 19057117f1b4Smrg 19067117f1b4Smrg /* GL_EXT_stencil_two_side */ 19077117f1b4Smrg case GL_STENCIL_TEST_TWO_SIDE_EXT: 19087ec681f3Smrg if (!_mesa_has_EXT_stencil_two_side(ctx)) 1909af69d88dSmrg goto invalid_enum_error; 19107117f1b4Smrg return ctx->Stencil.TestTwoSide; 19117117f1b4Smrg 19127117f1b4Smrg case GL_FRAGMENT_PROGRAM_ARB: 19137ec681f3Smrg if (!_mesa_has_ARB_fragment_program(ctx)) 1914af69d88dSmrg goto invalid_enum_error; 19157117f1b4Smrg return ctx->FragmentProgram.Enabled; 19167117f1b4Smrg 19177117f1b4Smrg /* GL_EXT_depth_bounds_test */ 19187117f1b4Smrg case GL_DEPTH_BOUNDS_TEST_EXT: 19197ec681f3Smrg if (!_mesa_has_EXT_depth_bounds_test(ctx)) 1920af69d88dSmrg goto invalid_enum_error; 19217117f1b4Smrg return ctx->Depth.BoundsTest; 19227117f1b4Smrg 19234a49301eSmrg /* GL_ARB_depth_clamp */ 19244a49301eSmrg case GL_DEPTH_CLAMP: 1925a8bb7a65Smaya if (!_mesa_has_ARB_depth_clamp(ctx) && 1926a8bb7a65Smaya !_mesa_has_EXT_depth_clamp(ctx)) 1927af69d88dSmrg goto invalid_enum_error; 192801e04c3fSmrg return ctx->Transform.DepthClampNear || 192901e04c3fSmrg ctx->Transform.DepthClampFar; 193001e04c3fSmrg 193101e04c3fSmrg case GL_DEPTH_CLAMP_NEAR_AMD: 19327ec681f3Smrg if (!_mesa_has_AMD_depth_clamp_separate(ctx)) 193301e04c3fSmrg goto invalid_enum_error; 193401e04c3fSmrg return ctx->Transform.DepthClampNear; 193501e04c3fSmrg 193601e04c3fSmrg case GL_DEPTH_CLAMP_FAR_AMD: 19377ec681f3Smrg if (!_mesa_has_AMD_depth_clamp_separate(ctx)) 193801e04c3fSmrg goto invalid_enum_error; 193901e04c3fSmrg return ctx->Transform.DepthClampFar; 19404a49301eSmrg 19417117f1b4Smrg case GL_FRAGMENT_SHADER_ATI: 19427ec681f3Smrg if (!_mesa_has_ATI_fragment_shader(ctx)) 1943af69d88dSmrg goto invalid_enum_error; 194401e04c3fSmrg return ctx->ATIFragmentShader.Enabled; 19454a49301eSmrg 19464a49301eSmrg case GL_TEXTURE_CUBE_MAP_SEAMLESS: 19477ec681f3Smrg if (!_mesa_has_ARB_seamless_cube_map(ctx)) 1948af69d88dSmrg goto invalid_enum_error; 194901e04c3fSmrg return ctx->Texture.CubeMapSeamless; 19504a49301eSmrg 19513464ebd5Sriastradh case GL_RASTERIZER_DISCARD: 19527ec681f3Smrg if (!(_mesa_has_EXT_transform_feedback(ctx) || _mesa_is_gles3(ctx))) 1953af69d88dSmrg goto invalid_enum_error; 1954af69d88dSmrg return ctx->RasterDiscard; 19553464ebd5Sriastradh 19563464ebd5Sriastradh /* GL_NV_primitive_restart */ 19573464ebd5Sriastradh case GL_PRIMITIVE_RESTART_NV: 19587ec681f3Smrg if (!_mesa_has_NV_primitive_restart(ctx)) 19593464ebd5Sriastradh goto invalid_enum_error; 19603464ebd5Sriastradh return ctx->Array.PrimitiveRestart; 19613464ebd5Sriastradh 19623464ebd5Sriastradh /* GL 3.1 primitive restart */ 19633464ebd5Sriastradh case GL_PRIMITIVE_RESTART: 1964af69d88dSmrg if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) { 19653464ebd5Sriastradh goto invalid_enum_error; 19663464ebd5Sriastradh } 19673464ebd5Sriastradh return ctx->Array.PrimitiveRestart; 19683464ebd5Sriastradh 1969af69d88dSmrg case GL_PRIMITIVE_RESTART_FIXED_INDEX: 19707ec681f3Smrg if (!_mesa_is_gles3(ctx) && !_mesa_has_ARB_ES3_compatibility(ctx)) 1971af69d88dSmrg goto invalid_enum_error; 1972af69d88dSmrg return ctx->Array.PrimitiveRestartFixedIndex; 1973af69d88dSmrg 19743464ebd5Sriastradh /* GL3.0 - GL_framebuffer_sRGB */ 19753464ebd5Sriastradh case GL_FRAMEBUFFER_SRGB_EXT: 19767ec681f3Smrg if (!_mesa_has_EXT_framebuffer_sRGB(ctx) && 19777ec681f3Smrg !_mesa_has_EXT_sRGB_write_control(ctx)) 19787ec681f3Smrg goto invalid_enum_error; 197901e04c3fSmrg return ctx->Color.sRGBEnabled; 19803464ebd5Sriastradh 1981af69d88dSmrg /* GL_OES_EGL_image_external */ 1982af69d88dSmrg case GL_TEXTURE_EXTERNAL_OES: 19837ec681f3Smrg if (!_mesa_has_OES_EGL_image_external(ctx)) 1984af69d88dSmrg goto invalid_enum_error; 1985af69d88dSmrg return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT); 1986af69d88dSmrg 1987af69d88dSmrg /* ARB_texture_multisample */ 1988af69d88dSmrg case GL_SAMPLE_MASK: 19897ec681f3Smrg if (!_mesa_has_ARB_texture_multisample(ctx) && !_mesa_is_gles31(ctx)) 1990af69d88dSmrg goto invalid_enum_error; 1991af69d88dSmrg return ctx->Multisample.SampleMask; 1992af69d88dSmrg 1993af69d88dSmrg /* ARB_sample_shading */ 1994af69d88dSmrg case GL_SAMPLE_SHADING: 19957ec681f3Smrg if (!_mesa_has_ARB_sample_shading(ctx) && !_mesa_is_gles3(ctx)) 1996af69d88dSmrg goto invalid_enum_error; 1997af69d88dSmrg return ctx->Multisample.SampleShading; 1998af69d88dSmrg 199901e04c3fSmrg case GL_BLEND_ADVANCED_COHERENT_KHR: 20007ec681f3Smrg if (!_mesa_has_KHR_blend_equation_advanced_coherent(ctx)) 20017ec681f3Smrg goto invalid_enum_error; 200201e04c3fSmrg return ctx->Color.BlendCoherent; 200301e04c3fSmrg 200401e04c3fSmrg case GL_CONSERVATIVE_RASTERIZATION_INTEL: 20057ec681f3Smrg if (!_mesa_has_INTEL_conservative_rasterization(ctx)) 20067ec681f3Smrg goto invalid_enum_error; 200701e04c3fSmrg return ctx->IntelConservativeRasterization; 200801e04c3fSmrg 200901e04c3fSmrg case GL_CONSERVATIVE_RASTERIZATION_NV: 20107ec681f3Smrg if (!_mesa_has_NV_conservative_raster(ctx)) 20117ec681f3Smrg goto invalid_enum_error; 201201e04c3fSmrg return ctx->ConservativeRasterization; 201301e04c3fSmrg 201401e04c3fSmrg case GL_TILE_RASTER_ORDER_FIXED_MESA: 20157ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 20167ec681f3Smrg goto invalid_enum_error; 201701e04c3fSmrg return ctx->TileRasterOrderFixed; 201801e04c3fSmrg 201901e04c3fSmrg case GL_TILE_RASTER_ORDER_INCREASING_X_MESA: 20207ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 20217ec681f3Smrg goto invalid_enum_error; 202201e04c3fSmrg return ctx->TileRasterOrderIncreasingX; 202301e04c3fSmrg 202401e04c3fSmrg case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA: 20257ec681f3Smrg if (!_mesa_has_MESA_tile_raster_order(ctx)) 20267ec681f3Smrg goto invalid_enum_error; 202701e04c3fSmrg return ctx->TileRasterOrderIncreasingY; 202801e04c3fSmrg 20297ec681f3Smrg case GL_BLACKHOLE_RENDER_INTEL: 20307ec681f3Smrg if (!_mesa_has_INTEL_blackhole_render(ctx)) 20317ec681f3Smrg goto invalid_enum_error; 20327ec681f3Smrg return ctx->IntelBlackholeRender; 20337ec681f3Smrg 20347117f1b4Smrg default: 20353464ebd5Sriastradh goto invalid_enum_error; 20367117f1b4Smrg } 20373464ebd5Sriastradh 20383464ebd5Sriastradh return GL_FALSE; 20393464ebd5Sriastradh 20403464ebd5Sriastradhinvalid_enum_error: 2041af69d88dSmrg _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)", 204201e04c3fSmrg _mesa_enum_to_string(cap)); 20433464ebd5Sriastradh return GL_FALSE; 20447117f1b4Smrg} 2045