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

📄 r200_texmem.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************Copyright (C) Tungsten Graphics 2002.  All Rights Reserved.  The Weather Channel, Inc. funded Tungsten Graphics to develop theinitial release of the Radeon 8500 driver under the XFree86license. 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 on the rights to use, copy, modify, merge, publish,distribute, sub license, 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 ANDNON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR THEIRSUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHERIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF ORIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.**************************************************************************//* * Authors: *   Kevin E. Martin <martin@valinux.com> *   Gareth Hughes <gareth@valinux.com> * */ #include <errno.h>#include "glheader.h"#include "imports.h"#include "context.h"#include "colormac.h"#include "macros.h"#include "r200_context.h"#include "r200_ioctl.h"#include "r200_tex.h"#include "radeon_reg.h"#include <unistd.h>  /* for usleep() *//** * Destroy any device-dependent state associated with the texture.  This may * include NULLing out hardware state that points to the texture. */voidr200DestroyTexObj( r200ContextPtr rmesa, r200TexObjPtr t ){   if ( R200_DEBUG & DEBUG_TEXTURE ) {      fprintf( stderr, "%s( %p, %p )\n", __FUNCTION__, 	       (void *)t, (void *)t->base.tObj );   }   if ( rmesa != NULL ) {      unsigned   i;      for ( i = 0 ; i < rmesa->glCtx->Const.MaxTextureUnits ; i++ ) {	 if ( t == rmesa->state.texture.unit[i].texobj ) {	    rmesa->state.texture.unit[i].texobj = NULL;	    rmesa->hw.tex[i].dirty = GL_FALSE;	    rmesa->hw.cube[i].dirty = GL_FALSE;	 }      }   }}/* ------------------------------------------------------------ * Texture image conversions */static void r200UploadGARTClientSubImage( r200ContextPtr rmesa,					  r200TexObjPtr t, 					  struct gl_texture_image *texImage,					  GLint hwlevel,					  GLint x, GLint y, 					  GLint width, GLint height ){   const struct gl_texture_format *texFormat = texImage->TexFormat;   GLuint srcPitch, dstPitch;   int blit_format;   int srcOffset;   /*    * XXX it appears that we always upload the full image, not a subimage.    * I.e. x==0, y==0, width=texWidth, height=texWidth.  If this is ever    * changed, the src pitch will have to change.    */   switch ( texFormat->TexelBytes ) {   case 1:      blit_format = R200_CP_COLOR_FORMAT_CI8;      srcPitch = t->image[0][0].width * texFormat->TexelBytes;      dstPitch = t->image[0][0].width * texFormat->TexelBytes;      break;   case 2:      blit_format = R200_CP_COLOR_FORMAT_RGB565;      srcPitch = t->image[0][0].width * texFormat->TexelBytes;      dstPitch = t->image[0][0].width * texFormat->TexelBytes;      break;   case 4:      blit_format = R200_CP_COLOR_FORMAT_ARGB8888;      srcPitch = t->image[0][0].width * texFormat->TexelBytes;      dstPitch = t->image[0][0].width * texFormat->TexelBytes;      break;   default:      return;   }   t->image[0][hwlevel].data = texImage->Data;   srcOffset = r200GartOffsetFromVirtual( rmesa, texImage->Data );   assert( srcOffset != ~0 );   /* Don't currently need to cope with small pitches?    */   width = texImage->Width;   height = texImage->Height;   r200EmitWait( rmesa, RADEON_WAIT_3D );   r200EmitBlit( rmesa, blit_format, 		 srcPitch,  		 srcOffset,   		 dstPitch,		 t->bufAddr,		 x, 		 y, 		 t->image[0][hwlevel].x + x,		 t->image[0][hwlevel].y + y, 		 width,		 height );   r200EmitWait( rmesa, RADEON_WAIT_2D );}static void r200UploadRectSubImage( r200ContextPtr rmesa,				    r200TexObjPtr t, 				    struct gl_texture_image *texImage,				    GLint x, GLint y, 				    GLint width, GLint height ){   const struct gl_texture_format *texFormat = texImage->TexFormat;   int blit_format, dstPitch, done;   switch ( texFormat->TexelBytes ) {   case 1:      blit_format = R200_CP_COLOR_FORMAT_CI8;      break;   case 2:      blit_format = R200_CP_COLOR_FORMAT_RGB565;      break;   case 4:      blit_format = R200_CP_COLOR_FORMAT_ARGB8888;      break;   default:      return;   }   t->image[0][0].data = texImage->Data;   /* Currently don't need to cope with small pitches.    */   width = texImage->Width;   height = texImage->Height;   dstPitch = t->pp_txpitch + 32;   if (rmesa->prefer_gart_client_texturing && texImage->IsClientData) {      /* In this case, could also use GART texturing.  This is       * currently disabled, but has been tested & works.       */      if ( !t->image_override )         t->pp_txoffset = r200GartOffsetFromVirtual( rmesa, texImage->Data );      t->pp_txpitch = texImage->RowStride * texFormat->TexelBytes - 32;      if (R200_DEBUG & DEBUG_TEXTURE)	 fprintf(stderr, 		 "Using GART texturing for rectangular client texture\n");      /* Release FB memory allocated for this image:       */      /* FIXME This may not be correct as driSwapOutTextureObject sets       * FIXME dirty_images.  It may be fine, though.       */      if ( t->base.memBlock ) {	 driSwapOutTextureObject( (driTextureObject *) t );      }   }   else if (texImage->IsClientData) {      /* Data already in GART memory, with usable pitch.       */      GLuint srcPitch;      srcPitch = texImage->RowStride * texFormat->TexelBytes;      r200EmitBlit( rmesa, 		    blit_format, 		    srcPitch,		    r200GartOffsetFromVirtual( rmesa, texImage->Data ),   		    dstPitch, t->bufAddr,		    0, 0, 		    0, 0, 		    width, height );   }   else {      /* Data not in GART memory, or bad pitch.       */      for (done = 0; done < height ; ) {	 struct r200_dma_region region;	 int lines = MIN2( height - done, RADEON_BUFFER_SIZE / dstPitch );	 int src_pitch;	 char *tex;         src_pitch = texImage->RowStride * texFormat->TexelBytes;	 tex = (char *)texImage->Data + done * src_pitch;	 memset(&region, 0, sizeof(region));	 r200AllocDmaRegion( rmesa, &region, lines * dstPitch, 1024 );	 /* Copy texdata to dma:	  */	 if (0)	    fprintf(stderr, "%s: src_pitch %d dst_pitch %d\n",		    __FUNCTION__, src_pitch, dstPitch);	 if (src_pitch == dstPitch) {	    memcpy( region.address + region.start, tex, lines * src_pitch );	 } 	 else {	    char *buf = region.address + region.start;	    int i;	    for (i = 0 ; i < lines ; i++) {	       memcpy( buf, tex, src_pitch );	       buf += dstPitch;	       tex += src_pitch;	    }	 }	 r200EmitWait( rmesa, RADEON_WAIT_3D );	 /* Blit to framebuffer	  */	 r200EmitBlit( rmesa,		       blit_format,		       dstPitch, GET_START( &region ),		       dstPitch | (t->tile_bits >> 16),		       t->bufAddr,		       0, 0,		       0, done,		       width, lines );	 	 r200EmitWait( rmesa, RADEON_WAIT_2D );	 r200ReleaseDmaRegion( rmesa, &region, __FUNCTION__ );	 done += lines;

⌨️ 快捷键说明

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