The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Texture-to-texture copy with offset makes target blurry
SX


Joined: 02 Sep 2015
Posts: 2
Location: Hungary
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:
1. render the whole screen once the old-school way: render all the tiles but render this to a texture
2. if nothing changes render this texture to the screen, update only the animated tiles
3. 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:

Code:

  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? Smile 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!
SX


Joined: 02 Sep 2015
Posts: 2
Location: Hungary
I found a solution. The SDL_HINT_RENDER_SCALE_QUALITY was set to LINEAR for all platforms. On PC, it was perfect. On Android it caused the before mentioned problem. I set it to NEAREST on Android and it got fixed. On PC this scaling method looks terrible on certain scaling so I stay with LINEAR on PC and NEARSET on Android (although I have to test on several devices to check image quality).
I would be still happy if someone could explain me why is this difference. Smile
Also is there a fast and reliable way to do part of the rendering with NEAREST and other parts with LINEAR scaling?
And could anyone give me an advice how could I increase image quality if I have to render with the NEAREST setting?

Thanks