mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 22:52:25 +01:00
Use random-generated fallback textures when real textures are not found
This commit is contained in:
parent
cabe6f1d65
commit
e9fe230381
@ -35,6 +35,7 @@ else()
|
|||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
set(PLATFORM_LIBS -lpthread)
|
set(PLATFORM_LIBS -lpthread)
|
||||||
#set(CLIENT_PLATFORM_LIBS -lXxf86vm)
|
#set(CLIENT_PLATFORM_LIBS -lXxf86vm)
|
||||||
|
# This way Xxf86vm is found on OpenBSD too
|
||||||
find_library(XXF86VM_LIBRARY, Xxf86vm)
|
find_library(XXF86VM_LIBRARY, Xxf86vm)
|
||||||
set(CLIENT_PLATFORM_LIBS ${XXF86VM_LIBRARY})
|
set(CLIENT_PLATFORM_LIBS ${XXF86VM_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
61
src/tile.cpp
61
src/tile.cpp
@ -248,6 +248,14 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
|
|
||||||
video::IImage *image = ap.atlas_img;
|
video::IImage *image = ap.atlas_img;
|
||||||
|
|
||||||
|
if(image == NULL)
|
||||||
|
{
|
||||||
|
dstream<<"WARNING: getTextureIdDirect(): NULL image in "
|
||||||
|
<<"cache: \""<<base_image_name<<"\""
|
||||||
|
<<std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
core::dimension2d<u32> dim = ap.intsize;
|
core::dimension2d<u32> dim = ap.intsize;
|
||||||
|
|
||||||
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
||||||
@ -265,6 +273,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
<<base_image_name<<"\" from image cache"
|
<<base_image_name<<"\" from image cache"
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse out the last part of the name of the image and act
|
Parse out the last part of the name of the image and act
|
||||||
@ -280,26 +289,23 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
dstream<<"INFO: getTextureIdDirect(): "
|
dstream<<"INFO: getTextureIdDirect(): "
|
||||||
"failed to generate \""<<last_part_of_name<<"\""
|
"failed to generate \""<<last_part_of_name<<"\""
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no resulting image, return NULL
|
// If no resulting image, print a warning
|
||||||
if(baseimg == NULL)
|
if(baseimg == NULL)
|
||||||
{
|
{
|
||||||
dstream<<"WARNING: getTextureIdDirect(): baseimg is NULL (attempted to"
|
dstream<<"WARNING: getTextureIdDirect(): baseimg is NULL (attempted to"
|
||||||
" create texture \""<<name<<"\""<<std::endl;
|
" create texture \""<<name<<"\""<<std::endl;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(baseimg != NULL)
|
||||||
|
{
|
||||||
// Create texture from resulting image
|
// Create texture from resulting image
|
||||||
t = driver->addTexture(name.c_str(), baseimg);
|
t = driver->addTexture(name.c_str(), baseimg);
|
||||||
|
}
|
||||||
// If no texture
|
|
||||||
if(t == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add texture to caches
|
Add texture to caches (add NULL textures too)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||||
@ -310,7 +316,10 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
ap.pos = v2f(0,0);
|
ap.pos = v2f(0,0);
|
||||||
ap.size = v2f(1,1);
|
ap.size = v2f(1,1);
|
||||||
ap.tiled = 0;
|
ap.tiled = 0;
|
||||||
SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg->getDimension());
|
core::dimension2d<u32> 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_atlaspointer_cache.push_back(nap);
|
||||||
m_name_to_id.insert(name, id);
|
m_name_to_id.insert(name, id);
|
||||||
|
|
||||||
@ -361,6 +370,7 @@ void TextureSource::buildMainAtlas()
|
|||||||
core::dimension2d<u32> atlas_dim(1024,1024);
|
core::dimension2d<u32> atlas_dim(1024,1024);
|
||||||
video::IImage *atlas_img =
|
video::IImage *atlas_img =
|
||||||
driver->createImage(video::ECF_A8R8G8B8, atlas_dim);
|
driver->createImage(video::ECF_A8R8G8B8, atlas_dim);
|
||||||
|
assert(atlas_img);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A list of stuff to add. This should contain as much of the
|
A list of stuff to add. This should contain as much of the
|
||||||
@ -415,6 +425,12 @@ void TextureSource::buildMainAtlas()
|
|||||||
|
|
||||||
// Generate image by name
|
// Generate image by name
|
||||||
video::IImage *img2 = generate_image_from_scratch(name, driver);
|
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 \""<<name<<"\""<<std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
core::dimension2d<u32> dim = img2->getDimension();
|
core::dimension2d<u32> dim = img2->getDimension();
|
||||||
|
|
||||||
// Tile it a few times in the X direction
|
// Tile it a few times in the X direction
|
||||||
@ -490,7 +506,10 @@ void TextureSource::buildMainAtlas()
|
|||||||
for(u32 i=0; i<sourcelist.size(); i++)
|
for(u32 i=0; i<sourcelist.size(); i++)
|
||||||
{
|
{
|
||||||
std::string name = sourcelist[i];
|
std::string name = sourcelist[i];
|
||||||
|
if(m_name_to_id.find(name) == NULL)
|
||||||
|
continue;
|
||||||
u32 id = m_name_to_id[name];
|
u32 id = m_name_to_id[name];
|
||||||
|
//dstream<<"id of name "<<name<<" is "<<id<<std::endl;
|
||||||
m_atlaspointer_cache[id].a.atlas = t;
|
m_atlaspointer_cache[id].a.atlas = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,7 +601,29 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
|||||||
dstream<<"WARNING: Could not load image \""<<part_of_name
|
dstream<<"WARNING: Could not load image \""<<part_of_name
|
||||||
<<"\" from path \""<<path<<"\""
|
<<"\" from path \""<<path<<"\""
|
||||||
<<" while building texture"<<std::endl;
|
<<" while building texture"<<std::endl;
|
||||||
return false;
|
|
||||||
|
//return false;
|
||||||
|
|
||||||
|
dstream<<"WARNING: Creating a dummy"<<" image for \""
|
||||||
|
<<part_of_name<<"\""<<std::endl;
|
||||||
|
|
||||||
|
// Just create a dummy image
|
||||||
|
//core::dimension2d<u32> dim(2,2);
|
||||||
|
core::dimension2d<u32> 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.
|
// If base image is NULL, load as base.
|
||||||
|
Loading…
Reference in New Issue
Block a user