📄 attrib.c
字号:
/*
* Mesa 3-D graphics library
* Version: 6.3
*
* Copyright (C) 1999-2005 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 "imports.h"
#include "accum.h"
#include "attrib.h"
#include "blend.h"
#include "buffers.h"
#include "bufferobj.h"
#include "colormac.h"
#include "colortab.h"
#include "context.h"
#include "depth.h"
#include "enable.h"
#include "enums.h"
#include "fog.h"
#include "hint.h"
#include "light.h"
#include "lines.h"
#include "matrix.h"
#include "points.h"
#include "polygon.h"
#include "simple_list.h"
#include "stencil.h"
#include "texobj.h"
#include "texstate.h"
#include "mtypes.h"
#include "math/m_xform.h"
/*
* Allocate a new attribute state node. These nodes have a
* "kind" value and a pointer to a struct of state data.
*/
static struct gl_attrib_node *
new_attrib_node( GLbitfield kind )
{
struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
if (an) {
an->kind = kind;
}
return an;
}
void GLAPIENTRY
_mesa_PushAttrib(GLbitfield mask)
{
struct gl_attrib_node *newnode;
struct gl_attrib_node *head;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glPushAttrib %x\n", (int) mask);
if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
_mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
return;
}
/* Build linked list of attribute nodes which save all attribute */
/* groups specified by the mask. */
head = NULL;
if (mask & GL_ACCUM_BUFFER_BIT) {
struct gl_accum_attrib *attr;
attr = MALLOC_STRUCT( gl_accum_attrib );
MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_COLOR_BUFFER_BIT) {
struct gl_colorbuffer_attrib *attr;
attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_CURRENT_BIT) {
struct gl_current_attrib *attr;
FLUSH_CURRENT( ctx, 0 );
attr = MALLOC_STRUCT( gl_current_attrib );
MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
newnode = new_attrib_node( GL_CURRENT_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_DEPTH_BUFFER_BIT) {
struct gl_depthbuffer_attrib *attr;
attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_ENABLE_BIT) {
struct gl_enable_attrib *attr;
GLuint i;
attr = MALLOC_STRUCT( gl_enable_attrib );
/* Copy enable flags from all other attributes into the enable struct. */
attr->AlphaTest = ctx->Color.AlphaEnabled;
attr->AutoNormal = ctx->Eval.AutoNormal;
attr->Blend = ctx->Color.BlendEnabled;
attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
attr->ColorTable = ctx->Pixel.ColorTableEnabled;
attr->PostColorMatrixColorTable = ctx->Pixel.PostColorMatrixColorTableEnabled;
attr->PostConvolutionColorTable = ctx->Pixel.PostConvolutionColorTableEnabled;
attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
attr->Separable2D = ctx->Pixel.Separable2DEnabled;
attr->CullFace = ctx->Polygon.CullFlag;
attr->DepthTest = ctx->Depth.Test;
attr->Dither = ctx->Color.DitherFlag;
attr->Fog = ctx->Fog.Enabled;
for (i=0;i<MAX_LIGHTS;i++) {
attr->Light[i] = ctx->Light.Light[i].Enabled;
}
attr->Lighting = ctx->Light.Enabled;
attr->LineSmooth = ctx->Line.SmoothFlag;
attr->LineStipple = ctx->Line.StippleFlag;
attr->Histogram = ctx->Pixel.HistogramEnabled;
attr->MinMax = ctx->Pixel.MinMaxEnabled;
attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
attr->Map1Color4 = ctx->Eval.Map1Color4;
attr->Map1Index = ctx->Eval.Map1Index;
attr->Map1Normal = ctx->Eval.Map1Normal;
attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
MEMCPY(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib));
attr->Map2Color4 = ctx->Eval.Map2Color4;
attr->Map2Index = ctx->Eval.Map2Index;
attr->Map2Normal = ctx->Eval.Map2Normal;
attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
MEMCPY(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
attr->Normalize = ctx->Transform.Normalize;
attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
attr->PointSmooth = ctx->Point.SmoothFlag;
attr->PointSprite = ctx->Point.PointSprite;
attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
attr->PolygonStipple = ctx->Polygon.StippleFlag;
attr->RescaleNormals = ctx->Transform.RescaleNormals;
attr->Scissor = ctx->Scissor.Enabled;
attr->Stencil = ctx->Stencil.Enabled;
attr->StencilTwoSide = ctx->Stencil.TestTwoSide;
attr->MultisampleEnabled = ctx->Multisample.Enabled;
attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
attr->SampleCoverage = ctx->Multisample.SampleCoverage;
attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
for (i=0; i<MAX_TEXTURE_UNITS; i++) {
attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled;
}
/* GL_NV_vertex_program */
attr->VertexProgram = ctx->VertexProgram.Enabled;
attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
newnode = new_attrib_node( GL_ENABLE_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_EVAL_BIT) {
struct gl_eval_attrib *attr;
attr = MALLOC_STRUCT( gl_eval_attrib );
MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
newnode = new_attrib_node( GL_EVAL_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_FOG_BIT) {
struct gl_fog_attrib *attr;
attr = MALLOC_STRUCT( gl_fog_attrib );
MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
newnode = new_attrib_node( GL_FOG_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_HINT_BIT) {
struct gl_hint_attrib *attr;
attr = MALLOC_STRUCT( gl_hint_attrib );
MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
newnode = new_attrib_node( GL_HINT_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_LIGHTING_BIT) {
struct gl_light_attrib *attr;
FLUSH_CURRENT(ctx, 0); /* flush material changes */
attr = MALLOC_STRUCT( gl_light_attrib );
MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
newnode = new_attrib_node( GL_LIGHTING_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_LINE_BIT) {
struct gl_line_attrib *attr;
attr = MALLOC_STRUCT( gl_line_attrib );
MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
newnode = new_attrib_node( GL_LINE_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_LIST_BIT) {
struct gl_list_attrib *attr;
attr = MALLOC_STRUCT( gl_list_attrib );
MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
newnode = new_attrib_node( GL_LIST_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_PIXEL_MODE_BIT) {
struct gl_pixel_attrib *attr;
attr = MALLOC_STRUCT( gl_pixel_attrib );
MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_POINT_BIT) {
struct gl_point_attrib *attr;
attr = MALLOC_STRUCT( gl_point_attrib );
MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
newnode = new_attrib_node( GL_POINT_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_POLYGON_BIT) {
struct gl_polygon_attrib *attr;
attr = MALLOC_STRUCT( gl_polygon_attrib );
MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
newnode = new_attrib_node( GL_POLYGON_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_POLYGON_STIPPLE_BIT) {
GLuint *stipple;
stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
newnode->data = stipple;
newnode->next = head;
head = newnode;
}
if (mask & GL_SCISSOR_BIT) {
struct gl_scissor_attrib *attr;
attr = MALLOC_STRUCT( gl_scissor_attrib );
MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
newnode = new_attrib_node( GL_SCISSOR_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
if (mask & GL_STENCIL_BUFFER_BIT) {
struct gl_stencil_attrib *attr;
attr = MALLOC_STRUCT( gl_stencil_attrib );
MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
newnode->data = attr;
newnode->next = head;
head = newnode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -