GFXTextureObject *GFXTextureManager::_createTexture( GBitmap *bmp, const String &resourceName, GFXTextureProfile *profile, bool deleteBmp, GFXTextureObject *inObj ) { PROFILE_SCOPE( GFXTextureManager_CreateTexture_Bitmap ); #ifdef DEBUG_SPEW Platform::outputDebugString( "[GFXTextureManager] _createTexture (GBitmap) '%s'", resourceName.c_str() ); #endif // Massage the bitmap based on any resize rules. U32 scalePower = getTextureDownscalePower( profile ); GBitmap *realBmp = bmp; U32 realWidth = bmp->getWidth(); U32 realHeight = bmp->getHeight(); if ( scalePower && isPow2(bmp->getWidth()) && isPow2(bmp->getHeight()) && profile->canDownscale() ) { // We only work with power of 2 textures for now, so we // don't have to worry about padding. // We downscale the bitmap on the CPU... this is the reason // you should be using DDS which already has good looking mips. GBitmap *padBmp = bmp; padBmp->extrudeMipLevels(); scalePower = getMin( scalePower, padBmp->getNumMipLevels() - 1 ); realWidth = getMax( (U32)1, padBmp->getWidth() >> scalePower ); realHeight = getMax( (U32)1, padBmp->getHeight() >> scalePower ); realBmp = new GBitmap( realWidth, realHeight, false, bmp->getFormat() ); // Copy to the new bitmap... dMemcpy( realBmp->getWritableBits(), padBmp->getBits(scalePower), padBmp->getBytesPerPixel() * realWidth * realHeight ); // This line is commented out because createPaddedBitmap is commented out. // If that line is added back in, this line should be added back in. // delete padBmp; }
void ClipMap::fillWithTestPattern() { AssertISV(false, "ClipMap::fillWithTestPattern - assumes bitmaps, which " "are no longer present, switch to lock() semantics if you need this!"); // Table of random colors. U8 colorTbl[16][3] = { { 0xFF, 0x00, 0x0F }, { 0xFF, 0x00, 0xA0 }, { 0xFF, 0x00, 0xFF }, { 0x00, 0xA0, 0x00 }, { 0x00, 0xA0, 0xAF }, { 0x00, 0xA0, 0xF0 }, { 0xA0, 0xFF, 0xA0 }, { 0x00, 0xF0, 0xA0 }, { 0x00, 0xF0, 0xFF }, { 0xA0, 0x00, 0x00 }, { 0xA0, 0x00, 0xAF }, { 0xA0, 0x00, 0xF0 }, { 0xA0, 0xF0, 0x0F }, { 0xA0, 0xF0, 0xA0 }, { 0xA0, 0xF0, 0xFF }, { 0x00, 0xFF, 0x00 }, }; // Lock each layer of each texture and write a test pattern in. // Base levels first. for(S32 i=0; i<mClipStackDepth; i++) { GTexHandle >h = mLevels[i].mTex; U8 *bmpData = (U8*)gth.getBitmap()->getWritableBits(0); for(S32 x=0; x<gth.getHeight(); x++) { for(S32 y=0; y<gth.getWidth(); y++) { S32 xFlag = x & 4; S32 yFlag = y & 4; U32 offset = (x * gth.getWidth() + y) * 4; if(xFlag ^ yFlag) { // Set bright. bmpData[offset+0] = colorTbl[i][0]; bmpData[offset+1] = colorTbl[i][1]; bmpData[offset+2] = colorTbl[i][2]; bmpData[offset+3] = 0xFF; } else { // Set dim. bmpData[offset+0] = colorTbl[i][0] / 3; bmpData[offset+1] = colorTbl[i][1] / 3; bmpData[offset+2] = colorTbl[i][2] / 3; bmpData[offset+3] = 0xFF; } } } if(i == mClipStackDepth - 1) gth.getBitmap()->extrudeMipLevels(); else { // Write black/translucent in the higher levels. GBitmap *gb = gth.getBitmap(); for(S32 j=1; j<gb->getNumMipLevels(); j++) { U8 *b = gb->getWritableBits(j); dMemset(b, 0, 4 * gb->getWidth(j) * gb->getHeight(j)); } } gth.refresh(); } }