📄 hw_cache.c
字号:
// Emacs style mode select -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: hw_cache.c,v 1.35 2001/03/03 06:17:34 bpereira Exp $//// Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////// $Log: hw_cache.c,v $// Revision 1.35 2001/03/03 06:17:34 bpereira// no message//// Revision 1.34 2001/02/28 17:50:56 bpereira// no message//// Revision 1.33 2001/02/24 13:35:22 bpereira// no message//// Revision 1.32 2001/01/25 18:56:27 bpereira// no message//// Revision 1.31 2000/11/04 16:23:44 bpereira// no message//// Revision 1.30 2000/11/02 22:16:03 bpereira// no message//// Revision 1.29 2000/11/02 21:54:26 bpereira// no message//// Revision 1.28 2000/11/02 19:49:39 bpereira// no message//// Revision 1.27 2000/10/04 16:21:57 hurdler// small clean-up//// Revision 1.26 2000/09/28 20:57:20 bpereira// no message//// Revision 1.25 2000/08/31 14:30:57 bpereira// no message//// Revision 1.24 2000/08/11 19:11:57 metzgermeister// *** empty log message ***//// Revision 1.23 2000/08/03 17:57:42 bpereira// no message//// Revision 1.22 2000/07/13 21:07:47 metzgermeister// fixed memory leak//// Revision 1.21 2000/07/01 09:23:50 bpereira// no message//// Revision 1.20 2000/05/30 18:01:53 kegetys// Added the chromakey flag to sprites//// Revision 1.19 2000/05/09 22:08:53 hurdler// fix large sky problem//// Revision 1.18 2000/05/09 20:57:31 hurdler// use my own code for colormap (next time, join with Boris own code)// (necessary due to a small bug in Boris' code (not found) which shows strange effects under linux)//// Revision 1.17 2000/04/30 10:30:10 bpereira// no message//// Revision 1.16 2000/04/27 17:48:47 hurdler// colormap code in hardware mode is now the default//// Revision 1.15 2000/04/24 20:24:38 bpereira// no message//// Revision 1.14 2000/04/24 17:23:26 hurdler// Better support of colormap//// Revision 1.13 2000/04/24 15:46:34 hurdler// Support colormap for text//// Revision 1.12 2000/04/23 16:19:52 bpereira// no message//// Revision 1.11 2000/04/23 00:30:47 hurdler// fix a small bug in skin color//// Revision 1.10 2000/04/22 21:08:23 hurdler// I like it better like that//// Revision 1.9 2000/04/22 20:16:30 hurdler// I like it better like that//// Revision 1.8 2000/04/22 19:12:50 hurdler// support skin color in hardware mode//// Revision 1.7 2000/04/22 16:09:14 hurdler// support skin color in hardware mode//// Revision 1.6 2000/04/18 12:52:21 hurdler// join with Boris' code//// Revision 1.5 2000/04/16 18:38:07 bpereira// no message//// Revision 1.4 2000/04/09 17:18:01 hurdler// modified coronas' code for 16 bits video mode//// Revision 1.3 2000/04/06 20:50:23 hurdler// add Boris' changes for coronas in doom3.wad//// Revision 1.2 2000/02/27 00:42:11 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:33 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// load and convert graphics to the hardware format////-----------------------------------------------------------------------------#include "hw_glob.h"#include "hw_drv.h"#include "../doomstat.h" //gamemode#include "../i_video.h" //rendermode#include "../r_data.h"#include "../w_wad.h"#include "../z_zone.h"#include "../v_video.h"//Hurdler: 25/04/2000: used for new colormap code in hardware modebyte *gr_colormap = NULL; // by default it must be NULL ! (because colormap tables are not initialized)boolean firetranslucent = false;// --------------------------------------------------------------------------// Values set after a call to HWR_ResizeBlock()// --------------------------------------------------------------------------static int blocksize;static int blockwidth;static int blockheight;extern byte *transtables;int patchformat = GR_TEXFMT_AP_88; // use alpha for holesint textureformat = GR_TEXFMT_P_8; // use chromakey for hole// sprite, use alpha and chroma key for holestatic void HWR_DrawPatchInCache (GlideMipmap_t* mipmap, int blockwidth, int blockheight, int blockmodulo, int texturewidth, int textureheight, int originx, //where to draw the patch in the surface block int originy, patch_t* realpatch, int bpp){ int x,x1,x2; int col,ncols; fixed_t xfrac, xfracstep; fixed_t yfrac, yfracstep, position, count; fixed_t scale_y; byte *dest; byte *source; column_t *patchcol; byte alpha; byte *block = mipmap->grInfo.data; x1 = originx; x2 = x1 + SHORT(realpatch->width); if (x1<0) x = 0; else x = x1; if (x2 > texturewidth) x2 = texturewidth; if( !texturewidth ) return; col = x * blockwidth / texturewidth; ncols= ((x2-x) * blockwidth) / texturewidth;/* CONS_Printf("patch %dx%d texture %dx%d block %dx%d\n", SHORT(realpatch->width), SHORT(realpatch->height), texturewidth, textureheight, blockwidth,blockheight); CONS_Printf(" col %d ncols %d x %d\n", col, ncols, x);*/ // source advance xfrac = 0; if (x1<0) xfrac = -x1<<16; xfracstep = (texturewidth << 16) / blockwidth; yfracstep = (textureheight<< 16) / blockheight; if( bpp<1 || bpp > 4 ) I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); for (block += col*bpp; ncols--; block+=bpp, xfrac+=xfracstep) { patchcol = (column_t *)((byte *)realpatch + LONG(realpatch->columnofs[xfrac>>16])); scale_y = (blockheight << 16) / textureheight; while (patchcol->topdelta != 0xff) { source = (byte *)patchcol + 3; count = ((patchcol->length * scale_y) + (FRACUNIT/2)) >> 16; position = originy + patchcol->topdelta; yfrac = 0; //yfracstep = (patchcol->length << 16) / count; if (position < 0) { yfrac = -position<<16; count += (((position * scale_y) + (FRACUNIT/2)) >> 16); position = 0; } position = ((position * scale_y) + (FRACUNIT/2)) >> 16; if (position + count >= blockheight ) count = blockheight - position; dest = block + (position*blockmodulo); while (count>0) { byte texel; count--; texel = source[yfrac>>16]; if( firetranslucent && (transtables[(texel<<8)+0x40000]!=texel) ) alpha = 0x80; else alpha = 0xff; //Hurdler: not perfect, but better than holes if( texel == HWR_PATCHES_CHROMAKEY_COLORINDEX && (mipmap->flags & TF_CHROMAKEYED)) texel = HWR_CHROMAKEY_EQUIVALENTCOLORINDEX; //Hurdler: 25/04/2000: now support colormap in hardware mode else if (mipmap->colormap) texel = mipmap->colormap[texel]; // hope compiler will get this switch out of the loops (dreams...) // gcc do it ! but vcc not ! (why don't use cygnus gcc for win32 ?) switch (bpp) { case 2 : *((unsigned short*)dest) = SHORT((alpha<<8) | texel); break; case 3 : ((RGBA_t*)dest)->s.red = V_GetColor(texel).s.red; ((RGBA_t*)dest)->s.green = V_GetColor(texel).s.green; ((RGBA_t*)dest)->s.blue = V_GetColor(texel).s.blue; break; case 4 : *((RGBA_t*)dest) = V_GetColor(texel); ((RGBA_t*)dest)->s.alpha = alpha; break; // default is 1 default: *dest = texel; break; } dest += blockmodulo; yfrac += yfracstep; } patchcol = (column_t *)( (byte *)patchcol + patchcol->length + 4); } }}// resize the patch to be 3dfx complient// set : blocksize = blockwidth * blockheight (no bpp used)// blockwidth// blockheight//note : 8bit (1 byte per pixel) palettized formatstatic void HWR_ResizeBlock ( int originalwidth, int originalheight, GrTexInfo* grInfo ){ // Build the full textures from patches. static const GrLOD_t gr_lods[9] = { GR_LOD_LOG2_256, GR_LOD_LOG2_128, GR_LOD_LOG2_64, GR_LOD_LOG2_32, GR_LOD_LOG2_16, GR_LOD_LOG2_8, GR_LOD_LOG2_4, GR_LOD_LOG2_2, GR_LOD_LOG2_1 }; typedef struct { GrAspectRatio_t aspect; float max_s; float max_t; } booring_aspect_t; static const booring_aspect_t gr_aspects[8] = { {GR_ASPECT_LOG2_1x1, 255, 255}, {GR_ASPECT_LOG2_2x1, 255, 127},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -