📄 i810tex.c
字号:
/* * GLX Hardware Device Driver for Intel i810 * Copyright (C) 1999 Keith Whitwell * * 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 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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. * *//* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810tex.c,v 1.9 2002/10/30 12:51:33 alanh Exp $ */#include "glheader.h"#include "mtypes.h"#include "imports.h"#include "simple_list.h"#include "enums.h"#include "texstore.h"#include "texformat.h"#include "teximage.h"#include "texmem.h"#include "texobj.h"#include "swrast/swrast.h"#include "colormac.h"#include "texobj.h"#include "mm.h"#include "i810screen.h"#include "i810_dri.h"#include "i810context.h"#include "i810tex.h"#include "i810state.h"#include "i810ioctl.h"/* * Compute the 'S2.4' lod bias factor from the floating point OpenGL bias. */static GLuint i810ComputeLodBias(GLfloat bias){ int b = (int) (bias * 16.0) + 12; if (b > 63) b = 63; else if (b < -64) b = -64; return (GLuint) (b & MLC_LOD_BIAS_MASK);}static void i810SetTexWrapping(i810TextureObjectPtr tex, GLenum swrap, GLenum twrap){ tex->Setup[I810_TEXREG_MCS] &= ~(MCS_U_STATE_MASK| MCS_V_STATE_MASK); switch( swrap ) { case GL_REPEAT: tex->Setup[I810_TEXREG_MCS] |= MCS_U_WRAP; break; case GL_CLAMP: case GL_CLAMP_TO_EDGE: tex->Setup[I810_TEXREG_MCS] |= MCS_U_CLAMP; break; case GL_MIRRORED_REPEAT: tex->Setup[I810_TEXREG_MCS] |= MCS_U_MIRROR; break; default: _mesa_problem(NULL, "bad S wrap mode in %s", __FUNCTION__); } switch( twrap ) { case GL_REPEAT: tex->Setup[I810_TEXREG_MCS] |= MCS_V_WRAP; break; case GL_CLAMP: case GL_CLAMP_TO_EDGE: tex->Setup[I810_TEXREG_MCS] |= MCS_V_CLAMP; break; case GL_MIRRORED_REPEAT: tex->Setup[I810_TEXREG_MCS] |= MCS_V_MIRROR; break; default: _mesa_problem(NULL, "bad T wrap mode in %s", __FUNCTION__); }}static void i810SetTexFilter(i810ContextPtr imesa, i810TextureObjectPtr t, GLenum minf, GLenum magf, GLfloat bias){ t->Setup[I810_TEXREG_MF] &= ~(MF_MIN_MASK| MF_MAG_MASK| MF_MIP_MASK); t->Setup[I810_TEXREG_MLC] &= ~(MLC_LOD_BIAS_MASK); switch (minf) { case GL_NEAREST: t->Setup[I810_TEXREG_MF] |= MF_MIN_NEAREST | MF_MIP_NONE; break; case GL_LINEAR: t->Setup[I810_TEXREG_MF] |= MF_MIN_LINEAR | MF_MIP_NONE; break; case GL_NEAREST_MIPMAP_NEAREST: t->Setup[I810_TEXREG_MF] |= MF_MIN_NEAREST | MF_MIP_NEAREST; if (magf == GL_LINEAR) { /*bias -= 0.5;*/ /* this doesn't work too good */ } break; case GL_LINEAR_MIPMAP_NEAREST: t->Setup[I810_TEXREG_MF] |= MF_MIN_LINEAR | MF_MIP_NEAREST; break; case GL_NEAREST_MIPMAP_LINEAR: if (IS_I815(imesa)) t->Setup[I810_TEXREG_MF] |= MF_MIN_NEAREST | MF_MIP_LINEAR; else t->Setup[I810_TEXREG_MF] |= MF_MIN_NEAREST | MF_MIP_DITHER; /* if (magf == GL_LINEAR) { bias -= 0.5; } */ bias -= 0.5; /* always biasing here looks better */ break; case GL_LINEAR_MIPMAP_LINEAR: if (IS_I815(imesa)) t->Setup[I810_TEXREG_MF] |= MF_MIN_LINEAR | MF_MIP_LINEAR; else t->Setup[I810_TEXREG_MF] |= MF_MIN_LINEAR | MF_MIP_DITHER; break; default: return; } switch (magf) { case GL_NEAREST: t->Setup[I810_TEXREG_MF] |= MF_MAG_NEAREST; break; case GL_LINEAR: t->Setup[I810_TEXREG_MF] |= MF_MAG_LINEAR; break; default: return; } t->Setup[I810_TEXREG_MLC] |= i810ComputeLodBias(bias);}static voidi810SetTexBorderColor( i810TextureObjectPtr t, GLubyte color[4] ){ /* Need a fallback. */}static i810TextureObjectPtri810AllocTexObj( GLcontext *ctx, struct gl_texture_object *texObj ){ i810TextureObjectPtr t; i810ContextPtr imesa = I810_CONTEXT(ctx); t = CALLOC_STRUCT( i810_texture_object_t ); texObj->DriverData = t; if ( t != NULL ) { GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias; /* Initialize non-image-dependent parts of the state: */ t->base.tObj = texObj; t->Setup[I810_TEXREG_MI0] = GFX_OP_MAP_INFO; t->Setup[I810_TEXREG_MI1] = MI1_MAP_0; t->Setup[I810_TEXREG_MI2] = MI2_DIMENSIONS_ARE_LOG2; t->Setup[I810_TEXREG_MLC] = (GFX_OP_MAP_LOD_CTL | MLC_MAP_0 | /*MLC_DITHER_WEIGHT_FULL |*/ MLC_DITHER_WEIGHT_12 | MLC_UPDATE_LOD_BIAS | 0x0); t->Setup[I810_TEXREG_MCS] = (GFX_OP_MAP_COORD_SETS | MCS_COORD_0 | MCS_UPDATE_NORMALIZED | MCS_NORMALIZED_COORDS | MCS_UPDATE_V_STATE | MCS_V_WRAP | MCS_UPDATE_U_STATE | MCS_U_WRAP); t->Setup[I810_TEXREG_MF] = (GFX_OP_MAP_FILTER | MF_MAP_0 | MF_UPDATE_ANISOTROPIC | MF_UPDATE_MIP_FILTER | MF_UPDATE_MAG_FILTER | MF_UPDATE_MIN_FILTER); make_empty_list( & t->base ); i810SetTexWrapping( t, texObj->WrapS, texObj->WrapT ); /*i830SetTexMaxAnisotropy( t, texObj->MaxAnisotropy );*/ i810SetTexFilter( imesa, t, texObj->MinFilter, texObj->MagFilter, bias ); i810SetTexBorderColor( t, texObj->_BorderChan ); } return t;}static void i810TexParameter( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLenum pname, const GLfloat *params ){ i810ContextPtr imesa = I810_CONTEXT(ctx); i810TextureObjectPtr t = (i810TextureObjectPtr) tObj->DriverData; if (!t) return; if ( target != GL_TEXTURE_2D ) return; /* Can't do the update now as we don't know whether to flush * vertices or not. Setting imesa->new_state means that * i810UpdateTextureState() will be called before any triangles are * rendered. If a statechange has occurred, it will be detected at * that point, and buffered vertices flushed. */ switch (pname) { case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: { GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias; i810SetTexFilter( imesa, t, tObj->MinFilter, tObj->MagFilter, bias ); } break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: i810SetTexWrapping( t, tObj->WrapS, tObj->WrapT ); break; case GL_TEXTURE_BORDER_COLOR: i810SetTexBorderColor( t, tObj->_BorderChan ); break; case GL_TEXTURE_BASE_LEVEL: case GL_TEXTURE_MAX_LEVEL: case GL_TEXTURE_MIN_LOD: case GL_TEXTURE_MAX_LOD: /* This isn't the most efficient solution but there doesn't appear to * be a nice alternative for Radeon. Since there's no LOD clamping, * we just have to rely on loading the right subset of mipmap levels * to simulate a clamped LOD. */ I810_FIREVERTICES( I810_CONTEXT(ctx) ); driSwapOutTextureObject( (driTextureObject *) t ); break; default: return; } if (t == imesa->CurrentTexObj[0]) { I810_STATECHANGE( imesa, I810_UPLOAD_TEX0 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -