Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTF_RenderUTF8_Blended very very slow in Android #193

Closed
iBruCe07 opened this issue Apr 4, 2022 · 8 comments
Closed

TTF_RenderUTF8_Blended very very slow in Android #193

iBruCe07 opened this issue Apr 4, 2022 · 8 comments

Comments

@iBruCe07
Copy link

iBruCe07 commented Apr 4, 2022

It takes more than 1 second to run this function...

QQ20220404-200106@2x

SDL_Color oColor = {0xFF, 0xFF, 0xFF};

for (auto s : oMsgVec)
{
auto nStart = SDL_GetTicks64();

TTF_RenderUTF8_Blended(pFontHelper->m_pFont, s.c_str(), oColor);

auto nEnd = SDL_GetTicks64();

SDL_Log("%s: time = %d", s.c_str(), nEnd - nStart);

}

@1bsyl
Copy link
Contributor

1bsyl commented Apr 6, 2022

First, this is the emulator. so times are maybe wrong ?

otherwise:
What you can do is to render a string a first time, then a second time.

first fime: it will render each glyph. then cache them. then render the string.
second time: use the glyph cache, to render the string.
compare the times. ( there can be cache misses in the second time also if two glyph share the same cache slot).

more issue:
big size size, or style can have an impact.
also: using subpixel + blending.
What do you use ?

@iBruCe07
Copy link
Author

首先,这是模拟器。所以时间可能是错误的?

否则: 您可以做的是第一次渲染字符串,然后再渲染第二次。

第一次:它将渲染每个字形。然后缓存它们。然后渲染字符串。 第二次:使用字形缓存来渲染字符串。 比较时代。(如果两个字形共享相同的缓存槽,第二次也可能存在缓存未命中)。

更多问题: 大尺寸尺寸或款式可能会产生影响。 另外:使用亚像素+混合。 你用什么 ?

Thank you for your help.

I'm run this app on huawei p40.

I don't understand your solution, can you give me more information?

@iBruCe07
Copy link
Author

Help

@cjwijtmans
Copy link

dont render the font every frame. Render the font when the text changes only on a texture. And render the texture every frame.

@iBruCe07
Copy link
Author

iBruCe07 commented Oct 7, 2023

I render different texts that it cost more 5 seconds on HUAWEI p40...
help~

@madebr
Copy link
Contributor

madebr commented Oct 7, 2023

Store SDL_Texture *'s in your oMsgVec, update them only when the std::string's change and render them using SDL_RenderCopy.

@iBruCe07
Copy link
Author

iBruCe07 commented Oct 8, 2023

Store SDL_Texture *'s in your oMsgVec, update them only when the std::string's change and render them using SDL_RenderCopy.

I encountered a problem that it was run this function(TTF_RenderUTF8_Blended) cost more than 0.5 seconds to render one char(chinese) on HUAWEI p40 or virtual machine.I uploaded the test code,help~
android-project.zip

@baidwwy
Copy link

baidwwy commented May 13, 2024

安卓的apk,zip是压缩的ttf,你应该把整个ttf读到内存,或者先从assets复制到 SDL_GetPrefPath
In Android, the APK is a compressed file, and the TTF files are also compressed within it. You should either load the entire TTF file into memory or first copy it from the assets directory to SDL_GetPrefPath.

@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants