Allow re-create ThreadedTexLoader with suitable capacity

This commit is contained in:
Benau 2017-03-16 13:15:33 +08:00
parent feb66664f4
commit 0f218cff32
6 changed files with 48 additions and 14 deletions

View File

@ -716,13 +716,11 @@ void IrrDriver::initDevice()
// ----------------------------------------------------------------------------
void IrrDriver::setMaxTextureSize()
{
if( (UserConfigParams::m_high_definition_textures & 0x01) == 0)
{
io::IAttributes &att = m_video_driver->getNonConstDriverAttributes();
att.setAttribute("MAX_TEXTURE_SIZE", core::dimension2du(
UserConfigParams::m_max_texture_size,
UserConfigParams::m_max_texture_size));
}
const unsigned max =
(UserConfigParams::m_high_definition_textures & 0x01) == 0 ?
UserConfigParams::m_max_texture_size : 2048;
io::IAttributes &att = m_video_driver->getNonConstDriverAttributes();
att.setAttribute("MAX_TEXTURE_SIZE", core::dimension2du(max, max));
} // setMaxTextureSize
// ----------------------------------------------------------------------------

View File

@ -31,6 +31,19 @@
// ----------------------------------------------------------------------------
STKTexManager::STKTexManager() : m_pbo(0), m_thread_size(0),
m_threaded_load_textures_counter(0)
{
createThreadedTexLoaders();
} // STKTexManager
// ----------------------------------------------------------------------------
STKTexManager::~STKTexManager()
{
removeTexture(NULL/*texture*/, true/*remove_all*/);
destroyThreadedTexLoaders();
} // ~STKTexManager
// ----------------------------------------------------------------------------
void STKTexManager::createThreadedTexLoaders()
{
#if !(defined(SERVER_ONLY) || defined(USE_GLES2))
if (CVS->supportsThreadedTextureLoading())
@ -40,10 +53,14 @@ STKTexManager::STKTexManager() : m_pbo(0), m_thread_size(0),
m_thread_size = HardwareStats::getNumProcessors();
m_thread_size = core::clamp(m_thread_size, 1,
UserConfigParams::m_hq_mipmap ? m_thread_size : 3);
const unsigned each_capacity = 16 * 1024 * 1024;
const unsigned max_tex_size =
(UserConfigParams::m_high_definition_textures & 0x01) == 0 ?
UserConfigParams::m_max_texture_size : 2048;
const unsigned each_capacity = max_tex_size * max_tex_size * 4;
const unsigned pbo_size = each_capacity * m_thread_size;
Log::info("STKTexManager", "%d thread(s) for texture loading,"
" each capacity 16 MB.", m_thread_size);
" each capacity %d MB.", m_thread_size,
each_capacity / 1024 / 1024);
if (UserConfigParams::m_hq_mipmap)
Log::info("STKTexManager", "High quality mipmap enabled.");
glGenBuffers(1, &m_pbo);
@ -65,12 +82,11 @@ STKTexManager::STKTexManager() : m_pbo(0), m_thread_size(0),
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
#endif
} // STKTexManager
} // createThreadedTexLoaders
// ----------------------------------------------------------------------------
STKTexManager::~STKTexManager()
void STKTexManager::destroyThreadedTexLoaders()
{
removeTexture(NULL/*texture*/, true/*remove_all*/);
#if !(defined(SERVER_ONLY) || defined(USE_GLES2))
if (CVS->supportsThreadedTextureLoading())
{
@ -89,11 +105,15 @@ STKTexManager::~STKTexManager()
}
delete delete_ttl;
glDeleteBuffers(1, &m_pbo);
m_pbo = 0;
m_thread_size = 0;
m_threaded_load_textures_counter = 0;
m_all_tex_loaders.clear();
pthread_mutex_destroy(&m_threaded_load_textures_mutex);
pthread_cond_destroy(&m_cond_request);
}
#endif
} // ~STKTexManager
} // destroyThreadedTexLoaders
// ----------------------------------------------------------------------------
STKTexture* STKTexManager::findTextureInFileSystem(const std::string& filename,

View File

@ -182,6 +182,10 @@ public:
// ------------------------------------------------------------------------
bool isThreadedLoadTexturesEmpty()
{ return m_threaded_load_textures.empty(); }
// ------------------------------------------------------------------------
void createThreadedTexLoaders();
// ------------------------------------------------------------------------
void destroyThreadedTexLoaders();
}; // STKTexManager

View File

@ -54,10 +54,12 @@ void* ThreadedTexLoader::startRoutine(void *obj)
if (strcmp(target_tex->getName().getPtr(), "delete_ttl") == 0)
{
ttl->m_stktm->removeThreadedLoadTexture();
ttl->m_stktm->setThreadedLoadTextureCounter(-1);
pthread_mutex_unlock(ttl->m_texture_queue_mutex);
ttl->setCanBeDeleted();
return NULL;
}
assert(target_tex->getTextureSize() <= ttl->m_tex_capacity);
if (target_tex->getTextureSize() + ttl->m_tex_size_loaded >
ttl->m_tex_capacity)
{

View File

@ -23,6 +23,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
@ -210,7 +211,8 @@ void OptionsScreenVideo::setImageQuality(int quality)
// ----------------------------------------------------------------------------
OptionsScreenVideo::OptionsScreenVideo() : Screen("options_video.stkgui"),
m_prev_adv_pipline(false)
m_prev_adv_pipline(false),
m_prev_img_quality(-1)
{
m_inited = false;
initPresets();
@ -236,6 +238,7 @@ void OptionsScreenVideo::init()
{
Screen::init();
m_prev_adv_pipline = UserConfigParams::m_dynamic_lights;
m_prev_img_quality = getImageQuality();
RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice");
assert(ribbon != NULL);
ribbon->select( "tab_video", PLAYER_ID_GAME_MASTER );
@ -644,6 +647,12 @@ void OptionsScreenVideo::tearDown()
{
if (m_prev_adv_pipline != UserConfigParams::m_dynamic_lights)
irr_driver->sameRestart();
else if (m_prev_img_quality != getImageQuality())
{
irr_driver->setMaxTextureSize();
STKTexManager::getInstance()->destroyThreadedTexLoaders();
STKTexManager::getInstance()->createThreadedTexLoaders();
}
Screen::tearDown();
// save changes when leaving screen
user_config->saveConfig();

View File

@ -53,6 +53,7 @@ class OptionsScreenVideo : public GUIEngine::Screen, public GUIEngine::ScreenSin
{
private:
bool m_prev_adv_pipline;
int m_prev_img_quality;
OptionsScreenVideo();
bool m_inited;
std::vector<GFXPreset> m_presets;