Hi,
I’m making a top-down, tile based game. I had to optimize the tile because it was slow on android. The current process is:
- render the whole screen once the old-school way: render all the tiles but render this to a texture
- if nothing changes render this texture to the screen, update only the animated tiles
- when scrolling, offset the texture and render the new tiles. Update the stored texure to have the latest texture what we just created.
Everything works on PC, and it’s a lot faster. It also works on Android and it’s much faster than the old way (40-60 fps instead of 10 fps).
The problem is that on Android the offseted part of the picture gets more and more blurry. It only happens on Android, not on PC. The code is the same.
I’m doing the offsetting with renderTarget changes. Here is a skeleton:
changeRenderTargetTo(bufferTexture);
SDL_SetTextureBlendMode(bufferTexture, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_Rect dstRect;
sxVec2Int scrollOffsetMoved;
.. calculate scrollOffsetMoved ...
// logical size is the size what I use for rendering, not the physical size of the window.
sxVec2Int logicalSize = getMainConfig->getWindowLogicalSize();
dstRect.x = scrollOffsetMoved.x;
dstRect.y = scrollOffsetMoved.y;
dstRect.w = logicalSize.x;
dstRect.h = logicalSize.y;
SDL_SetTextureBlendMode(renderTexture, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(renderer, renderTexture, NULL, &dstRect);
changeRenderTargetTo(renderTexture);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
// after changing back the render texture, render the created texture into it
SDL_RenderCopy(renderer, bufferTexture, NULL, NULL);
Questions:
What does Android do differently? It’s like if the device is scaling down the texture to physical resolution immediately when calling SDL_RenderCopy() and the lot of scaling makes the texture blurry. Is this the case? If not, then what causes this?
How can I bypass this problem? Is there somewhere a magic bit what I should switch? How are things working here? If somebody has a different solution for texture offsetting what is fast and works on Android as well, please show me.
Thanks!