📄 hw_cache.c
字号:
//Hurdler 16/10/99: added for OpenGL gamma correction gamma_correction.s.red = cv_grgammared.value; gamma_correction.s.green = cv_grgammagreen.value; gamma_correction.s.blue = cv_grgammablue.value; HWD.pfnSetPalette( palette, &gamma_correction ); // hardware driver will flush there own cache if cache is non paletized // now flush data texture cache so 32 bit texture are recomputed if( patchformat == GR_RGBA || textureformat == GR_RGBA ) Z_FreeTags (PU_HWRCACHE, PU_HWRCACHE);}// --------------------------------------------------------------------------// Make sure texture is downloaded and set it as the source// --------------------------------------------------------------------------GlideTexture_t* HWR_GetTexture (int tex){ GlideTexture_t* grtex;#ifdef PARANOIA if( tex>=gr_numtextures ) I_Error(" HWR_GetTexture : tex>=numtextures\n");#endif grtex = &gr_textures[tex]; if ( !grtex->mipmap.grInfo.data && !grtex->mipmap.downloaded ) HWR_GenerateTexture (tex, grtex); HWD.pfnSetTexture (&grtex->mipmap); return grtex;}static void HWR_CacheFlat (GlideMipmap_t* grMipmap, int flatlumpnum){ byte *block; // setup the texture info grMipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_64; grMipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_64; grMipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; grMipmap->grInfo.format = GR_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY; grMipmap->width = 64; grMipmap->height = 64; // the flat raw data needn't be converted with palettized textures block = Z_Malloc (W_LumpLength(flatlumpnum), PU_HWRCACHE, &grMipmap->grInfo.data); W_ReadLump (flatlumpnum,grMipmap->grInfo.data);}// Download a Doom 'flat' to the hardware cache and make it ready for usevoid HWR_GetFlat (int flatlumpnum){ GlideMipmap_t* grmip; grmip = &(wadfiles[flatlumpnum>>16]->hwrcache[flatlumpnum & 0xffff].mipmap); if (!grmip->downloaded && !grmip->grInfo.data) HWR_CacheFlat (grmip, flatlumpnum); HWD.pfnSetTexture (grmip);}//// HWR_LoadMappedPatch(): replace the skin color of the sprite in cache// : load it first in doom cache if not already//static void HWR_LoadMappedPatch(GlideMipmap_t *grmip, GlidePatch_t *gpatch){ if( !grmip->downloaded && !grmip->grInfo.data ) { patch_t *patch = W_CacheLumpNum(gpatch->patchlump, PU_STATIC); HWR_MakePatch(patch, gpatch, grmip); Z_Free(patch); } HWD.pfnSetTexture(grmip);}// -----------------+// HWR_GetPatch : Download a patch to the hardware cache and make it ready for use// -----------------+void HWR_GetPatch( GlidePatch_t* gpatch ){ // is it in hardware cache if ( !gpatch->mipmap.downloaded && !gpatch->mipmap.grInfo.data ) { // load the software patch, PU_STATIC or the Z_Malloc for hardware patch will // flush the software patch before the conversion! oh yeah I suffered patch_t *ptr = W_CacheLumpNum(gpatch->patchlump, PU_STATIC); HWR_MakePatch ( ptr, gpatch, &gpatch->mipmap); // this is inefficient.. but the hardware patch in heap is purgeable so it should // not fragment memory, and besides the REAL cache here is the hardware memory Z_Free (ptr); } HWD.pfnSetTexture( &gpatch->mipmap );}// -------------------+// HWR_GetMappedPatch : Same as HWR_GetPatch for sprite color// -------------------+void HWR_GetMappedPatch(GlidePatch_t* gpatch, byte *colormap){ GlideMipmap_t *grmip, *newmip; if( (colormap==colormaps) || (colormap==NULL) ) { // Load the default (green) color in doom cache (temporary?) AND hardware cache HWR_GetPatch(gpatch); return; } // search for the mimmap // skip the first (no colormap translated) for(grmip = &gpatch->mipmap ; grmip->nextcolormap ;) { grmip = grmip->nextcolormap; if (grmip->colormap==colormap) { HWR_LoadMappedPatch( grmip, gpatch ); return; } } // not found, create it ! // If we are here, the sprite with the current colormap is not already in hardware memory //BP: WARNING : don't free it manualy without clearing the cache of harware renderer // (it have a liste of mipmap) // this malloc is cleared in HWR_FreeTextureCache // (...) unfortunately z_malloc fragment alot the memory :( so malloc is better newmip = malloc(sizeof(GlideMipmap_t)); grmip->nextcolormap = newmip; memset(newmip, 0, sizeof(GlideMipmap_t)); newmip->colormap = colormap; HWR_LoadMappedPatch(newmip, gpatch);}static const int picmode2GR[] = { GR_TEXFMT_P_8, // PALETTE 0, // INTENSITY (unsuported yet) GR_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this) 0, // RGB24 (unsuported yet) GR_RGBA, // RGBA32 (opengl only)};static void HWR_DrawPicInCache (byte* block, int blockwidth, int blockheight, int blockmodulo, pic_t* pic, int bpp){ int i,j; fixed_t posx,posy,stepx,stepy; byte *dest,*src,texel; int picbpp; stepy = ((int)SHORT(pic->height)<<16)/blockheight; stepx = ((int)SHORT(pic->width )<<16)/blockwidth; picbpp = format2bpp[picmode2GR[pic->mode]]; posy = 0; for( j=0 ;j<blockheight;j++) { posx = 0; dest = &block[j*blockmodulo]; src = &pic->data[(posy>>16)*SHORT(pic->width)*picbpp]; for( i=0 ;i<blockwidth;i++) { switch (pic->mode) { // source bpp case PALETTE : texel = src[(posx+FRACUNIT/2)>>16]; switch( bpp ) { // destination bpp case 1 : *dest++ = texel; break; case 2 : *(USHORT *)dest = texel | 0xff00; dest +=2; 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; dest += 3; break; case 4 : *(RGBA_t*)dest = V_GetColor(texel); dest += 4; break; } break; case INTENSITY : *dest++ = src[(posx+FRACUNIT/2)>>16]; break; case INTENSITY_ALPHA : // assume dest bpp = 2 *(USHORT*)dest = *((short *)src + ((posx+FRACUNIT/2)>>16)); dest+=2; break; case RGB24 : break; // not supported yet case RGBA32 : // assume dest bpp = 4 dest += 4; *(ULONG *)dest = *((ULONG *)src + ((posx+FRACUNIT/2)>>16)); break; } posx += stepx; } posy += stepy; }}// -----------------+// HWR_GetPic : Download a Doom pic (raw row encoded with no 'holes')// Returns :// -----------------+GlidePatch_t *HWR_GetPic( int lumpnum ){ GlidePatch_t *grpatch; grpatch = &(wadfiles[lumpnum>>16]->hwrcache[lumpnum & 0xffff]); if( !grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data ) { pic_t *pic; int len; byte *block; int newwidth,newheight; if( grpatch->mipmap.flags & TF_RAWASPIC ) { // raw pic : so get size from grpatch since it is save in v_drawrawscreen pic = W_CacheRawAsPic( lumpnum, grpatch->width, grpatch->height, PU_STATIC ); len = W_LumpLength(lumpnum); } else { pic = W_CacheLumpNum( lumpnum, PU_STATIC ); grpatch->width = SHORT(pic->width); grpatch->height = SHORT(pic->height); len = W_LumpLength(lumpnum)-sizeof(pic_t); } grpatch->leftoffset = 0; grpatch->topoffset = 0; // find the good 3dfx size (boring spec) HWR_ResizeBlock (grpatch->width, grpatch->height, &grpatch->mipmap.grInfo); grpatch->mipmap.width = blockwidth; grpatch->mipmap.height = blockheight; if( pic->mode == PALETTE ) grpatch->mipmap.grInfo.format = textureformat; // can be set by driver else grpatch->mipmap.grInfo.format = picmode2GR[pic->mode]; if( grpatch->mipmap.grInfo.data != NULL ) Z_Free(grpatch->mipmap.grInfo.data); // allocate block block = MakeBlock(&grpatch->mipmap); // if rounddown, rounddown patches as well as textures if (cv_grrounddown.value) { newwidth = blockwidth; newheight = blockheight; } else { // no rounddown, do not size up patches, so they don't look 'scaled' newwidth = min(SHORT(pic->width ),blockwidth); newheight = min(SHORT(pic->height),blockheight); } if( grpatch->width == blockwidth && grpatch->height == blockheight && format2bpp[grpatch->mipmap.grInfo.format] == format2bpp[picmode2GR[pic->mode]] ) { // no conversion needed memcpy(grpatch->mipmap.grInfo.data, pic->data,len); } else HWR_DrawPicInCache(block, newwidth, newheight, blockwidth*format2bpp[grpatch->mipmap.grInfo.format], pic, format2bpp[grpatch->mipmap.grInfo.format]); Z_ChangeTag(pic, PU_CACHE); Z_ChangeTag(block, PU_HWRCACHE); grpatch->mipmap.flags &= TF_RAWASPIC; grpatch->max_s = (float)newwidth / (float)blockwidth; grpatch->max_t = (float)newheight / (float)blockheight; } HWD.pfnSetTexture( &grpatch->mipmap ); //CONS_Printf("picloaded at %x as texture %d\n",grpatch->mipmap.grInfo.data, grpatch->mipmap.downloaded); return grpatch;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -