void CRTC::create (LPCSTR Name, u32 size, D3DFORMAT f) { R_ASSERT (HW.pDevice && Name && Name[0] && size && btwIsPow2(size)); _order = CPU::GetCLK(); //Device.GetTimerGlobal()->GetElapsed_clk(); HRESULT _hr; dwSize = size; fmt = f; // Get caps D3DCAPS9 caps; R_CHK (HW.pDevice->GetDeviceCaps(&caps)); // Check width-and-height of render target surface if (size>caps.MaxTextureWidth) return; if (size>caps.MaxTextureHeight) return; // Validate render-target usage _hr = HW.pD3D->CheckDeviceFormat( HW.DevAdapter, HW.DevT, HW.Caps.fTarget, D3DUSAGE_RENDERTARGET, D3DRTYPE_CUBETEXTURE, f ); if (FAILED(_hr)) return; // Try to create texture/surface Device.Resources->Evict (); _hr = HW.pDevice->CreateCubeTexture (size, 1, D3DUSAGE_RENDERTARGET, f, D3DPOOL_DEFAULT, &pSurface,NULL); if (FAILED(_hr) || (0==pSurface)) return; // OK Msg ("* created RTc(%s), 6(%d)",Name,size); for (u32 face=0; face<6; face++) R_CHK (pSurface->GetCubeMapSurface ((D3DCUBEMAP_FACES)face, 0, pRT+face)); pTexture = Device.Resources->_CreateTexture (Name); pTexture->surface_set (pSurface); }
void CRT::create (LPCSTR Name, u32 w, u32 h, D3DFORMAT f) { if (pSurface) return; R_ASSERT (HW.pDevice && Name && Name[0] && w && h); _order = CPU::GetCLK() ; //Device.GetTimerGlobal()->GetElapsed_clk(); HRESULT _hr; dwWidth = w; dwHeight = h; fmt = f; // Get caps D3DCAPS9 caps; R_CHK (HW.pDevice->GetDeviceCaps(&caps)); // Pow2 if (!btwIsPow2(w) || !btwIsPow2(h)) { if (!HW.Caps.raster.bNonPow2) return; } // Check width-and-height of render target surface if (w>caps.MaxTextureWidth) return; if (h>caps.MaxTextureHeight) return; // Select usage u32 usage = 0; if (D3DFMT_D24X8==fmt) usage = D3DUSAGE_DEPTHSTENCIL; else if (D3DFMT_D24S8 ==fmt) usage = D3DUSAGE_DEPTHSTENCIL; else if (D3DFMT_D15S1 ==fmt) usage = D3DUSAGE_DEPTHSTENCIL; else if (D3DFMT_D16 ==fmt) usage = D3DUSAGE_DEPTHSTENCIL; else if (D3DFMT_D16_LOCKABLE==fmt) usage = D3DUSAGE_DEPTHSTENCIL; else if ((D3DFORMAT)MAKEFOURCC('D','F','2','4') == fmt) usage = D3DUSAGE_DEPTHSTENCIL; else usage = D3DUSAGE_RENDERTARGET; // Validate render-target usage _hr = HW.pD3D->CheckDeviceFormat( HW.DevAdapter, HW.DevT, HW.Caps.fTarget, usage, D3DRTYPE_TEXTURE, f ); if (FAILED(_hr)) return; // Try to create texture/surface Device.Resources->Evict (); _hr = HW.pDevice->CreateTexture (w, h, 1, usage, f, D3DPOOL_DEFAULT, &pSurface,NULL); if (FAILED(_hr) || (0==pSurface)) return; // OK #ifdef DEBUG Msg ("* created RT(%s), %dx%d",Name,w,h); #endif // DEBUG R_CHK (pSurface->GetSurfaceLevel (0,&pRT)); pTexture = Device.Resources->_CreateTexture (Name); pTexture->surface_set (pSurface); }
bool CImage::LoadTGA(LPCSTR name) { destructor<IReader> TGA(FS.r_open(name)); TGAHeader hdr; BOOL hflip, vflip; TGA().r(&hdr,sizeof(TGAHeader)); if (!((hdr.imgtype==2)||(hdr.imgtype==10))){ Msg("Unsupported texture format (%s)",name); return false; } if (!((hdr.pixsize==24)||(hdr.pixsize==32))){ Msg("Texture (%s) - invalid pixsize: %d",name,hdr.pixsize); return false; } #ifndef _EDITOR if (!btwIsPow2(hdr.width)){ Msg("Texture (%s) - invalid width: %d",name,hdr.width); return false; } if (!btwIsPow2(hdr.height)){ Msg("Texture (%s) - invalid height: %d",name,hdr.height); return false; } #endif // Skip funky stuff if (hdr.idlen) TGA().advance(hdr.idlen); if (hdr.cmlen) TGA().advance(hdr.cmlen*((hdr.cmes+7)/8)); hflip = (hdr.desc & 0x10) ? TRUE : FALSE; // Need hflip vflip = (hdr.desc & 0x20) ? TRUE : FALSE; // Need vflip dwWidth = hdr.width; dwHeight = hdr.height; bAlpha = (hdr.pixsize==32); // Alloc memory pData = (u32*)xr_malloc(dwWidth*dwHeight*4); u32 pixel; u32* ptr = pData; for( int y=0; y<hdr.height; y++ ){ u32 dwOffset = y*hdr.width; if( 0 == ( hdr.desc & 0x0010 ) ) dwOffset = (hdr.height-y-1)*hdr.width; for( int x=0; x<hdr.width; ){ if( hdr.imgtype == 10 ){ BYTE PacketInfo; TGA().r(&PacketInfo,1); u16 PacketType = u16(0x80 & PacketInfo); u16 PixelCount = u16(( 0x007f & PacketInfo ) + 1); if( PacketType ){ pixel = 0xffffffff; if(hdr.pixsize==32) TGA().r(&pixel,4); else TGA().r(&pixel,3); while( PixelCount-- ){ *(ptr+dwOffset+x)=pixel; x++; } }else{ while( PixelCount-- ){ pixel = 0xffffffff; if(hdr.pixsize==32) TGA().r(&pixel,4); else TGA().r(&pixel,3); *(ptr+dwOffset+x)=pixel; x++; } } }else{ pixel = 0xffffffff; if(hdr.pixsize==32) TGA().r(&pixel,4); else TGA().r(&pixel,3); *(ptr+dwOffset+x) =pixel; x++; } } } /* if (hdr.pixsize==24) { // 24bpp bAlpha = FALSE; u32 pixel = 0; u32* ptr = pData; for(int iy = 0; iy<hdr.height; ++iy) { for(int ix=0; ix<hdr.width; ++ix) { TGA.r(&pixel,3); *ptr++=pixel; // u32 R = RGBA_GETRED (pixel)/2; // u32 G = RGBA_GETGREEN (pixel)/2; // u32 B = RGBA_GETBLUE (pixel)/2; // *ptr++ = D3DCOLOR_XRGB(R,G,B); } } } else { // 32bpp bAlpha = TRUE; TGA.r(pData,hdr.width*hdr.height*4); } */ if (vflip) Vflip(); if (hflip) Hflip(); return true; }