⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac_import.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Mesa 3-D graphics library * Version:  6.5 * * Copyright (C) 1999-2006  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. * * Authors: *    Keith Whitwell <keith@tungstengraphics.com> */#include "glheader.h"#include "macros.h"#include "imports.h"#include "mtypes.h"#include "math/m_translate.h"#include "array_cache/ac_context.h"#include "math/m_translate.h"#define STRIDE_ARRAY( array, offset ) 					\do {									\   GLubyte *tmp = ADD_POINTERS( (array).BufferObj->Data, (array).Ptr )	\                + (offset) * (array).StrideB;				\   (array).Ptr = tmp;							\} while (0)/* Set the array pointer back to its source when the cached data is * invalidated: */static voidreset_texcoord( GLcontext *ctx, GLuint unit ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.TexCoord[unit].Enabled) {      ac->Raw.TexCoord[unit] = ctx->Array.TexCoord[unit];      STRIDE_ARRAY(ac->Raw.TexCoord[unit], ac->start);   }   else {      ac->Raw.TexCoord[unit] = ac->Fallback.TexCoord[unit];      if (ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3] != 1.0)	 ac->Raw.TexCoord[unit].Size = 4;      else if (ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2] != 0.0)	 ac->Raw.TexCoord[unit].Size = 3;      else	 ac->Raw.TexCoord[unit].Size = 2;   }   ac->IsCached.TexCoord[unit] = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_TEXCOORD(unit);}static voidreset_vertex( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   ASSERT(ctx->Array.Vertex.Enabled          || (ctx->VertexProgram._Enabled && ctx->Array.VertexAttrib[0].Enabled));   ac->Raw.Vertex = ctx->Array.Vertex;   STRIDE_ARRAY(ac->Raw.Vertex, ac->start);   ac->IsCached.Vertex = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_VERTEX;}static voidreset_normal( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.Normal.Enabled) {      ac->Raw.Normal = ctx->Array.Normal;      STRIDE_ARRAY(ac->Raw.Normal, ac->start);   }   else {      ac->Raw.Normal = ac->Fallback.Normal;   }   ac->IsCached.Normal = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_NORMAL;}static voidreset_color( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.Color.Enabled) {      ac->Raw.Color = ctx->Array.Color;      STRIDE_ARRAY(ac->Raw.Color, ac->start);   }   else      ac->Raw.Color = ac->Fallback.Color;   ac->IsCached.Color = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_COLOR0;}static voidreset_secondarycolor( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.SecondaryColor.Enabled) {      ac->Raw.SecondaryColor = ctx->Array.SecondaryColor;      STRIDE_ARRAY(ac->Raw.SecondaryColor, ac->start);   }   else      ac->Raw.SecondaryColor = ac->Fallback.SecondaryColor;   ac->IsCached.SecondaryColor = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_COLOR1;}static voidreset_index( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.Index.Enabled) {      ac->Raw.Index = ctx->Array.Index;      STRIDE_ARRAY(ac->Raw.Index, ac->start);   }   else      ac->Raw.Index = ac->Fallback.Index;   ac->IsCached.Index = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_INDEX;}static voidreset_fogcoord( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.FogCoord.Enabled) {      ac->Raw.FogCoord = ctx->Array.FogCoord;      STRIDE_ARRAY(ac->Raw.FogCoord, ac->start);   }   else      ac->Raw.FogCoord = ac->Fallback.FogCoord;   ac->IsCached.FogCoord = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_FOGCOORD;}static voidreset_edgeflag( GLcontext *ctx ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.EdgeFlag.Enabled) {      ac->Raw.EdgeFlag = ctx->Array.EdgeFlag;      STRIDE_ARRAY(ac->Raw.EdgeFlag, ac->start);   }   else      ac->Raw.EdgeFlag = ac->Fallback.EdgeFlag;   ac->IsCached.EdgeFlag = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_EDGEFLAG;}static voidreset_attrib( GLcontext *ctx, GLuint index ){   ACcontext *ac = AC_CONTEXT(ctx);   if (ctx->Array.VertexAttrib[index].Enabled) {      ac->Raw.Attrib[index] = ctx->Array.VertexAttrib[index];      STRIDE_ARRAY(ac->Raw.Attrib[index], ac->start);   }   else      ac->Raw.Attrib[index] = ac->Fallback.Attrib[index];   ac->IsCached.Attrib[index] = GL_FALSE;   ac->NewArrayState &= ~_NEW_ARRAY_ATTRIB(index);}/** * Generic import function for color data */static voidimport( const GLcontext *ctx,        GLenum destType,        struct gl_client_array *to,        const struct gl_client_array *from ){   const ACcontext *ac = AC_CONTEXT(ctx);   if (destType == 0)       destType = from->Type;   switch (destType) {   case GL_FLOAT:      _math_trans_4fc( (GLfloat (*)[4]) to->Ptr,                       from->Ptr,		       from->StrideB,		       from->Type,		       from->Size,		       0,		       ac->count - ac->start);      to->StrideB = 4 * sizeof(GLfloat);      to->Type = GL_FLOAT;      break;         case GL_UNSIGNED_BYTE:      _math_trans_4ub( (GLubyte (*)[4]) to->Ptr,                       from->Ptr,		       from->StrideB,		       from->Type,		       from->Size,		       0,		       ac->count - ac->start);      to->StrideB = 4 * sizeof(GLubyte);      to->Type = GL_UNSIGNED_BYTE;      break;   case GL_UNSIGNED_SHORT:      _math_trans_4us( (GLushort (*)[4]) to->Ptr,                       from->Ptr,		       from->StrideB,		       from->Type,		       from->Size,		       0,		       ac->count - ac->start);      to->StrideB = 4 * sizeof(GLushort);      to->Type = GL_UNSIGNED_SHORT;      break;         default:      _mesa_problem(ctx, "Unexpected dest format in import()");      break;   }}/* * Functions to import array ranges with specified types and strides. * For example, if the vertex data is GLshort[2] and we want GLfloat[3] * we'll use an import function to do the data conversion. */static voidimport_texcoord( GLcontext *ctx, GLuint unit, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.TexCoord[unit];   struct gl_client_array *to = &ac->Cache.TexCoord[unit];   (void) type; (void) stride;   ASSERT(unit < ctx->Const.MaxTextureCoordUnits);   /* Limited choices at this stage:    */   ASSERT(type == GL_FLOAT);   ASSERT(stride == 4*sizeof(GLfloat) || stride == 0);   ASSERT(ac->count - ac->start < ctx->Const.MaxArrayLockSize);   _math_trans_4f( (GLfloat (*)[4]) to->Ptr,		   from->Ptr,		   from->StrideB,		   from->Type,		   from->Size,		   0,		   ac->count - ac->start);   to->Size = from->Size;   to->StrideB = 4 * sizeof(GLfloat);   to->Type = GL_FLOAT;   ac->IsCached.TexCoord[unit] = GL_TRUE;}static voidimport_vertex( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.Vertex;   struct gl_client_array *to = &ac->Cache.Vertex;   (void) type; (void) stride;   /* Limited choices at this stage:    */   ASSERT(type == GL_FLOAT);   ASSERT(stride == 4*sizeof(GLfloat) || stride == 0);   _math_trans_4f( (GLfloat (*)[4]) to->Ptr,		   from->Ptr,		   from->StrideB,		   from->Type,		   from->Size,		   0,		   ac->count - ac->start);   to->Size = from->Size;   to->StrideB = 4 * sizeof(GLfloat);   to->Type = GL_FLOAT;   ac->IsCached.Vertex = GL_TRUE;}static voidimport_normal( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.Normal;   struct gl_client_array *to = &ac->Cache.Normal;   (void) type; (void) stride;   /* Limited choices at this stage:    */   ASSERT(type == GL_FLOAT);   ASSERT(stride == 3*sizeof(GLfloat) || stride == 0);   _math_trans_3f( (GLfloat (*)[3]) to->Ptr,		   from->Ptr,		   from->StrideB,		   from->Type,		   0,		   ac->count - ac->start);   to->StrideB = 3 * sizeof(GLfloat);   to->Type = GL_FLOAT;   ac->IsCached.Normal = GL_TRUE;}static voidimport_color( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.Color;   struct gl_client_array *to = &ac->Cache.Color;   (void) stride;   import( ctx, type, to, from );      ac->IsCached.Color = GL_TRUE;}static voidimport_index( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.Index;   struct gl_client_array *to = &ac->Cache.Index;   (void) type; (void) stride;   /* Limited choices at this stage:    */   ASSERT(type == GL_UNSIGNED_INT);   ASSERT(stride == sizeof(GLuint) || stride == 0);   _math_trans_1ui( (GLuint *) to->Ptr,		    from->Ptr,		    from->StrideB,		    from->Type,		    0,		    ac->count - ac->start);   to->StrideB = sizeof(GLuint);   to->Type = GL_UNSIGNED_INT;   ac->IsCached.Index = GL_TRUE;}static voidimport_secondarycolor( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.SecondaryColor;   struct gl_client_array *to = &ac->Cache.SecondaryColor;   (void) stride;   import( ctx, type, to, from );   ac->IsCached.SecondaryColor = GL_TRUE;}static voidimport_fogcoord( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.FogCoord;   struct gl_client_array *to = &ac->Cache.FogCoord;   (void) type; (void) stride;   /* Limited choices at this stage:    */   ASSERT(type == GL_FLOAT);   ASSERT(stride == sizeof(GLfloat) || stride == 0);   _math_trans_1f( (GLfloat *) to->Ptr,		   from->Ptr,		   from->StrideB,		   from->Type,		   0,		   ac->count - ac->start);   to->StrideB = sizeof(GLfloat);   to->Type = GL_FLOAT;   ac->IsCached.FogCoord = GL_TRUE;}static voidimport_edgeflag( GLcontext *ctx, GLenum type, GLuint stride ){   ACcontext *ac = AC_CONTEXT(ctx);   const struct gl_client_array *from = &ac->Raw.EdgeFlag;   struct gl_client_array *to = &ac->Cache.EdgeFlag;   (void) type; (void) stride;   /* Limited choices at this stage:    */   ASSERT(type == GL_UNSIGNED_BYTE);   ASSERT(stride == sizeof(GLubyte) || stride == 0);   _math_trans_1ub( (GLubyte *) to->Ptr,		    from->Ptr,		    from->StrideB,		    from->Type,		    0,		    ac->count - ac->start);   to->StrideB = sizeof(GLubyte);   to->Type = GL_UNSIGNED_BYTE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -