Android progressbar fix (#5601)
* Fix progressbar for Android Fixes #5599 Fixed #5403 * draw_load_screen: use texturesource this permits to unify texture loading code * scale progress bar * Add gl version check for GL_OES_texture_npot. This fixed the texture on loading screen * Remove two sanity checks pointed by @celeron55 * sfan5 comments + android ratio fixesmaster
parent
d17636484d
commit
73de17afa8
|
@ -1782,6 +1782,7 @@ typedef struct TextureUpdateArgs {
|
|||
u32 last_time_ms;
|
||||
u16 last_percent;
|
||||
const wchar_t* text_base;
|
||||
ITextureSource *tsrc;
|
||||
} TextureUpdateArgs;
|
||||
|
||||
void texture_update_progress(void *args, u32 progress, u32 max_progress)
|
||||
|
@ -1803,8 +1804,8 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress)
|
|||
targs->last_time_ms = time_ms;
|
||||
std::basic_stringstream<wchar_t> strm;
|
||||
strm << targs->text_base << " " << targs->last_percent << "%...";
|
||||
draw_load_screen(strm.str(), targs->device, targs->guienv, 0,
|
||||
72 + (u16) ((18. / 100.) * (double) targs->last_percent));
|
||||
draw_load_screen(strm.str(), targs->device, targs->guienv, targs->tsrc, 0,
|
||||
72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1824,21 +1825,21 @@ void Client::afterContentReceived(IrrlichtDevice *device)
|
|||
|
||||
// Rebuild inherited images and recreate textures
|
||||
infostream<<"- Rebuilding images and textures"<<std::endl;
|
||||
draw_load_screen(text,device, guienv, 0, 70);
|
||||
draw_load_screen(text,device, guienv, m_tsrc, 0, 70);
|
||||
m_tsrc->rebuildImagesAndTextures();
|
||||
delete[] text;
|
||||
|
||||
// Rebuild shaders
|
||||
infostream<<"- Rebuilding shaders"<<std::endl;
|
||||
text = wgettext("Rebuilding shaders...");
|
||||
draw_load_screen(text, device, guienv, 0, 71);
|
||||
draw_load_screen(text, device, guienv, m_tsrc, 0, 71);
|
||||
m_shsrc->rebuildShaders();
|
||||
delete[] text;
|
||||
|
||||
// Update node aliases
|
||||
infostream<<"- Updating node aliases"<<std::endl;
|
||||
text = wgettext("Initializing nodes...");
|
||||
draw_load_screen(text, device, guienv, 0, 72);
|
||||
draw_load_screen(text, device, guienv, m_tsrc, 0, 72);
|
||||
m_nodedef->updateAliases(m_itemdef);
|
||||
std::string texture_path = g_settings->get("texture_path");
|
||||
if (texture_path != "" && fs::IsDir(texture_path))
|
||||
|
@ -1855,6 +1856,7 @@ void Client::afterContentReceived(IrrlichtDevice *device)
|
|||
tu_args.last_time_ms = getTimeMs();
|
||||
tu_args.last_percent = 0;
|
||||
tu_args.text_base = wgettext("Initializing nodes");
|
||||
tu_args.tsrc = m_tsrc;
|
||||
m_nodedef->updateTextures(this, texture_update_progress, &tu_args);
|
||||
delete[] tu_args.text_base;
|
||||
|
||||
|
@ -1871,7 +1873,7 @@ void Client::afterContentReceived(IrrlichtDevice *device)
|
|||
}
|
||||
|
||||
text = wgettext("Done!");
|
||||
draw_load_screen(text, device, guienv, 0, 100);
|
||||
draw_load_screen(text, device, guienv, m_tsrc, 0, 100);
|
||||
infostream<<"Client::afterContentReceived() done"<<std::endl;
|
||||
delete[] text;
|
||||
}
|
||||
|
|
|
@ -790,8 +790,6 @@ void TextureSource::rebuildImagesAndTextures()
|
|||
video::IImage *img = generateImage(ti->name);
|
||||
#ifdef __ANDROID__
|
||||
img = Align2Npot2(img, driver);
|
||||
sanity_check(img->getDimension().Height == npot2(img->getDimension().Height));
|
||||
sanity_check(img->getDimension().Width == npot2(img->getDimension().Width));
|
||||
#endif
|
||||
// Create texture from resulting image
|
||||
video::ITexture *t = NULL;
|
||||
|
@ -1124,6 +1122,14 @@ video::IImage* TextureSource::generateImage(const std::string &name)
|
|||
* @param driver driver to use for image operations
|
||||
* @return image or copy of image aligned to npot2
|
||||
*/
|
||||
|
||||
inline u16 get_GL_major_version()
|
||||
{
|
||||
const GLubyte *gl_version = glGetString(GL_VERSION);
|
||||
std::string gl_ver((const char *)gl_version);
|
||||
return (u16) (gl_version[0] - '0');
|
||||
}
|
||||
|
||||
video::IImage * Align2Npot2(video::IImage * image,
|
||||
video::IVideoDriver* driver)
|
||||
{
|
||||
|
@ -1134,7 +1140,10 @@ video::IImage * Align2Npot2(video::IImage * image,
|
|||
core::dimension2d<u32> dim = image->getDimension();
|
||||
|
||||
std::string extensions = (char*) glGetString(GL_EXTENSIONS);
|
||||
if (extensions.find("GL_OES_texture_npot") != std::string::npos) {
|
||||
|
||||
// Only GLES2 is trusted to correctly report npot support
|
||||
if (get_GL_major_version() > 1 &&
|
||||
extensions.find("GL_OES_texture_npot") != std::string::npos) {
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
@ -599,7 +599,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
|||
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
|
||||
*/
|
||||
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
|
||||
gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
|
||||
gui::IGUIEnvironment* guienv, ITextureSource *tsrc,
|
||||
float dtime, int percent, bool clouds)
|
||||
{
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
v2u32 screensize = porting::getWindowSize();
|
||||
|
@ -625,27 +626,20 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
|
|||
|
||||
// draw progress bar
|
||||
if ((percent >= 0) && (percent <= 100)) {
|
||||
const std::string &texture_path = g_settings->get("texture_path");
|
||||
std::string tp_progress_bar = texture_path + "/progress_bar.png";
|
||||
std::string tp_progress_bar_bg = texture_path + "/progress_bar_bg.png";
|
||||
|
||||
if (!(fs::PathExists(tp_progress_bar) &&
|
||||
fs::PathExists(tp_progress_bar_bg))) {
|
||||
std::string gamepath = fs::RemoveRelativePathComponents(
|
||||
porting::path_share + DIR_DELIM + "textures");
|
||||
tp_progress_bar = gamepath + "/base/pack/progress_bar.png";
|
||||
tp_progress_bar_bg = gamepath + "/base/pack/progress_bar_bg.png";
|
||||
}
|
||||
|
||||
video::ITexture *progress_img =
|
||||
driver->getTexture(tp_progress_bar.c_str());
|
||||
video::ITexture *progress_img_bg =
|
||||
driver->getTexture(tp_progress_bar_bg.c_str());
|
||||
video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
|
||||
video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
|
||||
|
||||
if (progress_img && progress_img_bg) {
|
||||
#ifndef __ANDROID__
|
||||
const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
|
||||
u32 imgW = rangelim(img_size.Width, 200, 600);
|
||||
u32 imgH = rangelim(img_size.Height, 24, 72);
|
||||
#else
|
||||
const core::dimension2d<u32> img_size(256, 48);
|
||||
float imgRatio = (float) img_size.Height / img_size.Width;
|
||||
u32 imgW = screensize.X / 2.2f;
|
||||
u32 imgH = floor(imgW * imgRatio);
|
||||
#endif
|
||||
v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
|
||||
|
||||
draw2DImageFilterScaled(
|
||||
|
|
|
@ -27,8 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
|
||||
void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
|
||||
gui::IGUIEnvironment *guienv, float dtime = 0, int percent = 0,
|
||||
bool clouds = true);
|
||||
gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime = 0,
|
||||
int percent = 0, bool clouds = true);
|
||||
|
||||
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
||||
Camera &camera, Client &client, LocalPlayer *player,
|
||||
|
|
14
src/game.cpp
14
src/game.cpp
|
@ -1725,9 +1725,10 @@ bool Game::init(
|
|||
u16 port,
|
||||
const SubgameSpec &gamespec)
|
||||
{
|
||||
texture_src = createTextureSource(device);
|
||||
|
||||
showOverlayMessage(wgettext("Loading..."), 0, 0);
|
||||
|
||||
texture_src = createTextureSource(device);
|
||||
shader_src = createShaderSource(device);
|
||||
|
||||
itemdef_manager = createItemDefManager();
|
||||
|
@ -2183,12 +2184,14 @@ bool Game::getServerContent(bool *aborted)
|
|||
if (!client->itemdefReceived()) {
|
||||
const wchar_t *text = wgettext("Item definitions...");
|
||||
progress = 25;
|
||||
draw_load_screen(text, device, guienv, dtime, progress);
|
||||
draw_load_screen(text, device, guienv, texture_src,
|
||||
dtime, progress);
|
||||
delete[] text;
|
||||
} else if (!client->nodedefReceived()) {
|
||||
const wchar_t *text = wgettext("Node definitions...");
|
||||
progress = 30;
|
||||
draw_load_screen(text, device, guienv, dtime, progress);
|
||||
draw_load_screen(text, device, guienv, texture_src,
|
||||
dtime, progress);
|
||||
delete[] text;
|
||||
} else {
|
||||
std::stringstream message;
|
||||
|
@ -2212,7 +2215,7 @@ bool Game::getServerContent(bool *aborted)
|
|||
|
||||
progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
|
||||
draw_load_screen(utf8_to_wide(message.str()), device,
|
||||
guienv, dtime, progress);
|
||||
guienv, texture_src, dtime, progress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4357,7 +4360,8 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
|
|||
void Game::showOverlayMessage(const wchar_t *msg, float dtime,
|
||||
int percent, bool draw_clouds)
|
||||
{
|
||||
draw_load_screen(msg, device, guienv, dtime, percent, draw_clouds);
|
||||
draw_load_screen(msg, device, guienv, texture_src, dtime, percent,
|
||||
draw_clouds);
|
||||
delete[] msg;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue