📄 enable.c
字号:
/** * \file enable.c * Enable/disable/query GL capabilities. *//* * Mesa 3-D graphics library * Version: 7.0.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "glheader.h"#include "context.h"#include "enable.h"#include "light.h"#include "macros.h"#include "simple_list.h"#include "mtypes.h"#include "enums.h"#include "math/m_matrix.h"#include "math/m_xform.h"#include "api_arrayelt.h"#define CHECK_EXTENSION(EXTNAME, CAP) \ if (!ctx->Extensions.EXTNAME) { \ _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)", \ state ? "Enable" : "Disable", CAP); \ return; \ }/** * Helper to enable/disable client-side state. */static voidclient_state(GLcontext *ctx, GLenum cap, GLboolean state){ GLuint flag; GLboolean *var; switch (cap) { case GL_VERTEX_ARRAY: var = &ctx->Array.ArrayObj->Vertex.Enabled; flag = _NEW_ARRAY_VERTEX; break; case GL_NORMAL_ARRAY: var = &ctx->Array.ArrayObj->Normal.Enabled; flag = _NEW_ARRAY_NORMAL; break; case GL_COLOR_ARRAY: var = &ctx->Array.ArrayObj->Color.Enabled; flag = _NEW_ARRAY_COLOR0; break; case GL_INDEX_ARRAY: var = &ctx->Array.ArrayObj->Index.Enabled; flag = _NEW_ARRAY_INDEX; break; case GL_TEXTURE_COORD_ARRAY: var = &ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled; flag = _NEW_ARRAY_TEXCOORD(ctx->Array.ActiveTexture); break; case GL_EDGE_FLAG_ARRAY: var = &ctx->Array.ArrayObj->EdgeFlag.Enabled; flag = _NEW_ARRAY_EDGEFLAG; break; case GL_FOG_COORDINATE_ARRAY_EXT: var = &ctx->Array.ArrayObj->FogCoord.Enabled; flag = _NEW_ARRAY_FOGCOORD; break; case GL_SECONDARY_COLOR_ARRAY_EXT: var = &ctx->Array.ArrayObj->SecondaryColor.Enabled; flag = _NEW_ARRAY_COLOR1; break;#if FEATURE_NV_vertex_program case GL_VERTEX_ATTRIB_ARRAY0_NV: case GL_VERTEX_ATTRIB_ARRAY1_NV: case GL_VERTEX_ATTRIB_ARRAY2_NV: case GL_VERTEX_ATTRIB_ARRAY3_NV: case GL_VERTEX_ATTRIB_ARRAY4_NV: case GL_VERTEX_ATTRIB_ARRAY5_NV: case GL_VERTEX_ATTRIB_ARRAY6_NV: case GL_VERTEX_ATTRIB_ARRAY7_NV: case GL_VERTEX_ATTRIB_ARRAY8_NV: case GL_VERTEX_ATTRIB_ARRAY9_NV: case GL_VERTEX_ATTRIB_ARRAY10_NV: case GL_VERTEX_ATTRIB_ARRAY11_NV: case GL_VERTEX_ATTRIB_ARRAY12_NV: case GL_VERTEX_ATTRIB_ARRAY13_NV: case GL_VERTEX_ATTRIB_ARRAY14_NV: case GL_VERTEX_ATTRIB_ARRAY15_NV: CHECK_EXTENSION(NV_vertex_program, cap); { GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV; var = &ctx->Array.ArrayObj->VertexAttrib[n].Enabled; flag = _NEW_ARRAY_ATTRIB(n); } break;#endif /* FEATURE_NV_vertex_program */ default: _mesa_error( ctx, GL_INVALID_ENUM, "glEnable/DisableClientState(0x%x)", cap); return; } if (*var == state) return; FLUSH_VERTICES(ctx, _NEW_ARRAY); ctx->Array.NewState |= flag; _ae_invalidate_state(ctx, _NEW_ARRAY); *var = state; if (state) ctx->Array.ArrayObj->_Enabled |= flag; else ctx->Array.ArrayObj->_Enabled &= ~flag; if (ctx->Driver.Enable) { ctx->Driver.Enable( ctx, cap, state ); }}/** * Enable GL capability. * \param cap state to enable/disable. * * Get's the current context, assures that we're outside glBegin()/glEnd() and * calls client_state(). */void GLAPIENTRY_mesa_EnableClientState( GLenum cap ){ GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); client_state( ctx, cap, GL_TRUE );}/** * Disable GL capability. * \param cap state to enable/disable. * * Get's the current context, assures that we're outside glBegin()/glEnd() and * calls client_state(). */void GLAPIENTRY_mesa_DisableClientState( GLenum cap ){ GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); client_state( ctx, cap, GL_FALSE );}#undef CHECK_EXTENSION#define CHECK_EXTENSION(EXTNAME, CAP) \ if (!ctx->Extensions.EXTNAME) { \ _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)", \ state ? "Enable" : "Disable", CAP); \ return; \ }#define CHECK_EXTENSION2(EXT1, EXT2, CAP) \ if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \ _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)", \ state ? "Enable" : "Disable", CAP); \ return; \ }/** * Helper function to enable or disable a texture target. */static GLbooleanenable_texture(GLcontext *ctx, GLboolean state, GLbitfield bit){ const GLuint curr = ctx->Texture.CurrentUnit; struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr]; const GLuint newenabled = (!state) ? (texUnit->Enabled & ~bit) : (texUnit->Enabled | bit); if (!ctx->DrawBuffer->Visual.rgbMode || texUnit->Enabled == newenabled) return GL_FALSE; FLUSH_VERTICES(ctx, _NEW_TEXTURE); texUnit->Enabled = newenabled; return GL_TRUE;}/** * Helper function to enable or disable state. * * \param ctx GL context. * \param cap the state to enable/disable * \param state whether to enable or disable the specified capability. * * Updates the current context and flushes the vertices as needed. For * capabilities associated with extensions it verifies that those extensions * are effectivly present before updating. Notifies the driver via * dd_function_table::Enable. */void_mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state){ if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "%s %s (newstate is %x)\n", state ? "glEnable" : "glDisable", _mesa_lookup_enum_by_nr(cap), ctx->NewState); switch (cap) { case GL_ALPHA_TEST: if (ctx->Color.AlphaEnabled == state) return; FLUSH_VERTICES(ctx, _NEW_COLOR); ctx->Color.AlphaEnabled = state; break; case GL_AUTO_NORMAL: if (ctx->Eval.AutoNormal == state) return; FLUSH_VERTICES(ctx, _NEW_EVAL); ctx->Eval.AutoNormal = state; break; case GL_BLEND: if (ctx->Color.BlendEnabled == state) return; FLUSH_VERTICES(ctx, _NEW_COLOR); ctx->Color.BlendEnabled = state; break;#if FEATURE_userclip case GL_CLIP_PLANE0: case GL_CLIP_PLANE1: case GL_CLIP_PLANE2: case GL_CLIP_PLANE3: case GL_CLIP_PLANE4: case GL_CLIP_PLANE5: { const GLuint p = cap - GL_CLIP_PLANE0; if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) == ((GLuint) state << p)) return; FLUSH_VERTICES(ctx, _NEW_TRANSFORM); if (state) { ctx->Transform.ClipPlanesEnabled |= (1 << p); if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top)) _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); /* This derived state also calculated in clip.c and * from _mesa_update_state() on changes to EyeUserPlane * and ctx->ProjectionMatrix respectively. */ _mesa_transform_vector( ctx->Transform._ClipUserPlane[p], ctx->Transform.EyeUserPlane[p], ctx->ProjectionMatrixStack.Top->inv ); } else { ctx->Transform.ClipPlanesEnabled &= ~(1 << p); } } break;#endif case GL_COLOR_MATERIAL: if (ctx->Light.ColorMaterialEnabled == state) return; FLUSH_VERTICES(ctx, _NEW_LIGHT); FLUSH_CURRENT(ctx, 0); ctx->Light.ColorMaterialEnabled = state; if (state) { _mesa_update_color_material( ctx, ctx->Current.Attrib[VERT_ATTRIB_COLOR0] ); } break; case GL_CULL_FACE: if (ctx->Polygon.CullFlag == state) return; FLUSH_VERTICES(ctx, _NEW_POLYGON); ctx->Polygon.CullFlag = state; break; case GL_CULL_VERTEX_EXT: CHECK_EXTENSION(EXT_cull_vertex, cap); if (ctx->Transform.CullVertexFlag == state) return; FLUSH_VERTICES(ctx, _NEW_TRANSFORM); ctx->Transform.CullVertexFlag = state; break; case GL_DEPTH_TEST: if (state && ctx->DrawBuffer->Visual.depthBits == 0) { _mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer"); return; } if (ctx->Depth.Test == state) return; FLUSH_VERTICES(ctx, _NEW_DEPTH); ctx->Depth.Test = state; break; case GL_DITHER: if (ctx->NoDither) { state = GL_FALSE; /* MESA_NO_DITHER env var */ } if (ctx->Color.DitherFlag == state) return; FLUSH_VERTICES(ctx, _NEW_COLOR); ctx->Color.DitherFlag = state; break; case GL_FOG: if (ctx->Fog.Enabled == state) return; FLUSH_VERTICES(ctx, _NEW_FOG); ctx->Fog.Enabled = state; break; case GL_HISTOGRAM: CHECK_EXTENSION(EXT_histogram, cap); if (ctx->Pixel.HistogramEnabled == state) return; FLUSH_VERTICES(ctx, _NEW_PIXEL); ctx->Pixel.HistogramEnabled = state; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -