📄 r200_tex.c
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_tex.c,v 1.2 2002/11/05 17:46:08 tsi Exp $ *//*Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.The Weather Channel (TM) funded Tungsten Graphics to develop theinitial release of the Radeon 8500 driver under the XFree86 license.This notice must be preserved.Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantialportions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*//* * Authors: * Keith Whitwell <keith@tungstengraphics.com> */#include "glheader.h"#include "imports.h"#include "colormac.h"#include "context.h"#include "enums.h"#include "image.h"#include "simple_list.h"#include "texformat.h"#include "texstore.h"#include "texmem.h"#include "teximage.h"#include "texobj.h"#include "r200_context.h"#include "r200_state.h"#include "r200_ioctl.h"#include "r200_swtcl.h"#include "r200_tex.h"#include "xmlpool.h"/** * Set the texture wrap modes. * * \param t Texture object whose wrap modes are to be set * \param swrap Wrap mode for the \a s texture coordinate * \param twrap Wrap mode for the \a t texture coordinate */static void r200SetTexWrap( r200TexObjPtr t, GLenum swrap, GLenum twrap, GLenum rwrap ){ GLboolean is_clamp = GL_FALSE; GLboolean is_clamp_to_border = GL_FALSE; t->pp_txfilter &= ~(R200_CLAMP_S_MASK | R200_CLAMP_T_MASK | R200_BORDER_MODE_D3D); switch ( swrap ) { case GL_REPEAT: t->pp_txfilter |= R200_CLAMP_S_WRAP; break; case GL_CLAMP: t->pp_txfilter |= R200_CLAMP_S_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_CLAMP_TO_EDGE: t->pp_txfilter |= R200_CLAMP_S_CLAMP_LAST; break; case GL_CLAMP_TO_BORDER: t->pp_txfilter |= R200_CLAMP_S_CLAMP_GL; is_clamp_to_border = GL_TRUE; break; case GL_MIRRORED_REPEAT: t->pp_txfilter |= R200_CLAMP_S_MIRROR; break; case GL_MIRROR_CLAMP_EXT: t->pp_txfilter |= R200_CLAMP_S_MIRROR_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_MIRROR_CLAMP_TO_EDGE_EXT: t->pp_txfilter |= R200_CLAMP_S_MIRROR_CLAMP_LAST; break; case GL_MIRROR_CLAMP_TO_BORDER_EXT: t->pp_txfilter |= R200_CLAMP_S_MIRROR_CLAMP_GL; is_clamp_to_border = GL_TRUE; break; default: _mesa_problem(NULL, "bad S wrap mode in %s", __FUNCTION__); } switch ( twrap ) { case GL_REPEAT: t->pp_txfilter |= R200_CLAMP_T_WRAP; break; case GL_CLAMP: t->pp_txfilter |= R200_CLAMP_T_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_CLAMP_TO_EDGE: t->pp_txfilter |= R200_CLAMP_T_CLAMP_LAST; break; case GL_CLAMP_TO_BORDER: t->pp_txfilter |= R200_CLAMP_T_CLAMP_GL | R200_BORDER_MODE_D3D; is_clamp_to_border = GL_TRUE; break; case GL_MIRRORED_REPEAT: t->pp_txfilter |= R200_CLAMP_T_MIRROR; break; case GL_MIRROR_CLAMP_EXT: t->pp_txfilter |= R200_CLAMP_T_MIRROR_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_MIRROR_CLAMP_TO_EDGE_EXT: t->pp_txfilter |= R200_CLAMP_T_MIRROR_CLAMP_LAST; break; case GL_MIRROR_CLAMP_TO_BORDER_EXT: t->pp_txfilter |= R200_CLAMP_T_MIRROR_CLAMP_GL; is_clamp_to_border = GL_TRUE; break; default: _mesa_problem(NULL, "bad T wrap mode in %s", __FUNCTION__); } t->pp_txformat_x &= ~R200_CLAMP_Q_MASK; switch ( rwrap ) { case GL_REPEAT: t->pp_txformat_x |= R200_CLAMP_Q_WRAP; break; case GL_CLAMP: t->pp_txformat_x |= R200_CLAMP_Q_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_CLAMP_TO_EDGE: t->pp_txformat_x |= R200_CLAMP_Q_CLAMP_LAST; break; case GL_CLAMP_TO_BORDER: t->pp_txformat_x |= R200_CLAMP_Q_CLAMP_GL; is_clamp_to_border = GL_TRUE; break; case GL_MIRRORED_REPEAT: t->pp_txformat_x |= R200_CLAMP_Q_MIRROR; break; case GL_MIRROR_CLAMP_EXT: t->pp_txformat_x |= R200_CLAMP_Q_MIRROR_CLAMP_GL; is_clamp = GL_TRUE; break; case GL_MIRROR_CLAMP_TO_EDGE_EXT: t->pp_txformat_x |= R200_CLAMP_Q_MIRROR_CLAMP_LAST; break; case GL_MIRROR_CLAMP_TO_BORDER_EXT: t->pp_txformat_x |= R200_CLAMP_Q_MIRROR_CLAMP_GL; is_clamp_to_border = GL_TRUE; break; default: _mesa_problem(NULL, "bad R wrap mode in %s", __FUNCTION__); } if ( is_clamp_to_border ) { t->pp_txfilter |= R200_BORDER_MODE_D3D; } t->border_fallback = (is_clamp && is_clamp_to_border);}static void r200SetTexMaxAnisotropy( r200TexObjPtr t, GLfloat max ){ t->pp_txfilter &= ~R200_MAX_ANISO_MASK; if ( max == 1.0 ) { t->pp_txfilter |= R200_MAX_ANISO_1_TO_1; } else if ( max <= 2.0 ) { t->pp_txfilter |= R200_MAX_ANISO_2_TO_1; } else if ( max <= 4.0 ) { t->pp_txfilter |= R200_MAX_ANISO_4_TO_1; } else if ( max <= 8.0 ) { t->pp_txfilter |= R200_MAX_ANISO_8_TO_1; } else { t->pp_txfilter |= R200_MAX_ANISO_16_TO_1; }}/** * Set the texture magnification and minification modes. * * \param t Texture whose filter modes are to be set * \param minf Texture minification mode * \param magf Texture magnification mode */static void r200SetTexFilter( r200TexObjPtr t, GLenum minf, GLenum magf ){ GLuint anisotropy = (t->pp_txfilter & R200_MAX_ANISO_MASK); t->pp_txfilter &= ~(R200_MIN_FILTER_MASK | R200_MAG_FILTER_MASK); t->pp_txformat_x &= ~R200_VOLUME_FILTER_MASK; if ( anisotropy == R200_MAX_ANISO_1_TO_1 ) { switch ( minf ) { case GL_NEAREST: t->pp_txfilter |= R200_MIN_FILTER_NEAREST; break; case GL_LINEAR: t->pp_txfilter |= R200_MIN_FILTER_LINEAR; break; case GL_NEAREST_MIPMAP_NEAREST: t->pp_txfilter |= R200_MIN_FILTER_NEAREST_MIP_NEAREST; break; case GL_NEAREST_MIPMAP_LINEAR: t->pp_txfilter |= R200_MIN_FILTER_LINEAR_MIP_NEAREST; break; case GL_LINEAR_MIPMAP_NEAREST: t->pp_txfilter |= R200_MIN_FILTER_NEAREST_MIP_LINEAR; break; case GL_LINEAR_MIPMAP_LINEAR: t->pp_txfilter |= R200_MIN_FILTER_LINEAR_MIP_LINEAR; break; } } else { switch ( minf ) { case GL_NEAREST: t->pp_txfilter |= R200_MIN_FILTER_ANISO_NEAREST; break; case GL_LINEAR: t->pp_txfilter |= R200_MIN_FILTER_ANISO_LINEAR; break; case GL_NEAREST_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST: t->pp_txfilter |= R200_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST; break; case GL_NEAREST_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR: t->pp_txfilter |= R200_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR; break; } } /* Note we don't have 3D mipmaps so only use the mag filter setting * to set the 3D texture filter mode. */ switch ( magf ) { case GL_NEAREST: t->pp_txfilter |= R200_MAG_FILTER_NEAREST; t->pp_txformat_x |= R200_VOLUME_FILTER_NEAREST; break; case GL_LINEAR: t->pp_txfilter |= R200_MAG_FILTER_LINEAR; t->pp_txformat_x |= R200_VOLUME_FILTER_LINEAR; break; }}static void r200SetTexBorderColor( r200TexObjPtr t, GLubyte c[4] ){ t->pp_border_color = r200PackColor( 4, c[0], c[1], c[2], c[3] );}/** * Allocate space for and load the mesa images into the texture memory block. * This will happen before drawing with a new texture, or drawing with a * texture after it was swapped out or teximaged again. */static r200TexObjPtr r200AllocTexObj( struct gl_texture_object *texObj ){ r200TexObjPtr t; t = CALLOC_STRUCT( r200_tex_obj ); texObj->DriverData = t; if ( t != NULL ) { if ( R200_DEBUG & DEBUG_TEXTURE ) { fprintf( stderr, "%s( %p, %p )\n", __FUNCTION__, (void *)texObj, (void *)t ); } /* Initialize non-image-dependent parts of the state: */ t->base.tObj = texObj; t->border_fallback = GL_FALSE; make_empty_list( & t->base ); r200SetTexWrap( t, texObj->WrapS, texObj->WrapT, texObj->WrapR ); r200SetTexMaxAnisotropy( t, texObj->MaxAnisotropy ); r200SetTexFilter( t, texObj->MinFilter, texObj->MagFilter ); r200SetTexBorderColor( t, texObj->_BorderChan ); } return t;}static const struct gl_texture_format *r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, GLenum format, GLenum type ){ r200ContextPtr rmesa = R200_CONTEXT(ctx); const GLboolean do32bpt = ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 ); const GLboolean force16bpt = ( rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 ); (void) format; switch ( internalFormat ) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: return do32bpt ? _dri_texformat_argb8888 : _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: return _dri_texformat_argb1555; default: return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; } case 3: case GL_RGB: case GL_COMPRESSED_RGB: switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: return _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: return _dri_texformat_rgb565; default: return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; } case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16: return !force16bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; case GL_RGBA4: case GL_RGBA2: return _dri_texformat_argb4444; case GL_RGB5_A1: return _dri_texformat_argb1555; case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: return !force16bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: return _dri_texformat_rgb565; case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: return _dri_texformat_a8; case 1: case GL_LUMINANCE: case GL_LUMINANCE4: case GL_LUMINANCE8: case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: return _dri_texformat_l8;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -