From e9fe2303817c9d4d7efd84054733f146ee84b8ab Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 12 Feb 2011 14:01:23 +0200 Subject: Use random-generated fallback textures when real textures are not found --- src/CMakeLists.txt | 1 + src/tile.cpp | 99 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 71 insertions(+), 29 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f44b0930f..b8a369187 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,7 @@ else() find_package(ZLIB REQUIRED) set(PLATFORM_LIBS -lpthread) #set(CLIENT_PLATFORM_LIBS -lXxf86vm) + # This way Xxf86vm is found on OpenBSD too find_library(XXF86VM_LIBRARY, Xxf86vm) set(CLIENT_PLATFORM_LIBS ${XXF86VM_LIBRARY}) endif() diff --git a/src/tile.cpp b/src/tile.cpp index 13550b2e4..c3ca5837c 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -247,23 +247,32 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) SourceAtlasPointer ap = m_atlaspointer_cache[base_image_id]; video::IImage *image = ap.atlas_img; + + if(image == NULL) + { + dstream<<"WARNING: getTextureIdDirect(): NULL image in " + <<"cache: \""< dim = ap.intsize; - core::dimension2d dim = ap.intsize; - - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - core::position2d pos_to(0,0); - core::position2d pos_from = ap.intpos; - - image->copyTo( - baseimg, // target - v2s32(0,0), // position in target - core::rect(pos_from, dim) // from - ); - - dstream<<"INFO: getTextureIdDirect(): Loaded \"" - < pos_to(0,0); + core::position2d pos_from = ap.intpos; + + image->copyTo( + baseimg, // target + v2s32(0,0), // position in target + core::rect(pos_from, dim) // from + ); + + dstream<<"INFO: getTextureIdDirect(): Loaded \"" + <addTexture(name.c_str(), baseimg); - // If no texture - if(t == NULL) - return 0; - + if(baseimg != NULL) + { + // Create texture from resulting image + t = driver->addTexture(name.c_str(), baseimg); + } + /* - Add texture to caches + Add texture to caches (add NULL textures too) */ JMutexAutoLock lock(m_atlaspointer_cache_mutex); @@ -310,7 +316,10 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) ap.pos = v2f(0,0); ap.size = v2f(1,1); ap.tiled = 0; - SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg->getDimension()); + core::dimension2d baseimg_dim(0,0); + if(baseimg) + baseimg_dim = baseimg->getDimension(); + SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim); m_atlaspointer_cache.push_back(nap); m_name_to_id.insert(name, id); @@ -361,6 +370,7 @@ void TextureSource::buildMainAtlas() core::dimension2d atlas_dim(1024,1024); video::IImage *atlas_img = driver->createImage(video::ECF_A8R8G8B8, atlas_dim); + assert(atlas_img); /* A list of stuff to add. This should contain as much of the @@ -415,6 +425,12 @@ void TextureSource::buildMainAtlas() // Generate image by name video::IImage *img2 = generate_image_from_scratch(name, driver); + if(img2 == NULL) + { + dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""< dim = img2->getDimension(); // Tile it a few times in the X direction @@ -490,7 +506,10 @@ void TextureSource::buildMainAtlas() for(u32 i=0; i dim(2,2); + core::dimension2d dim(1,1); + image = driver->createImage(video::ECF_A8R8G8B8, dim); + assert(image); + /*image->setPixel(0,0, video::SColor(255,255,0,0)); + image->setPixel(1,0, video::SColor(255,0,255,0)); + image->setPixel(0,1, video::SColor(255,0,0,255)); + image->setPixel(1,1, video::SColor(255,255,0,255));*/ + image->setPixel(0,0, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256)); + /*image->setPixel(1,0, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256)); + image->setPixel(0,1, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256)); + image->setPixel(1,1, video::SColor(255,myrand()%256, + myrand()%256,myrand()%256));*/ } // If base image is NULL, load as base. -- cgit v1.2.3