Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Loading large textures  (Read 2805 times)

0 Members and 1 Guest are viewing this topic.

gamecoder.nz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Loading large textures
« on: October 21, 2020, 03:18:54 am »
Hi everyone,

So I have a large map background which I have divided up into 3200x3200 images.  What I want to do is load these textures at runtime as the player moves.

I have tried to load them in threads but doing loadFromFile causes a lag.  Is there a better way to do this?

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Loading large textures
« Reply #1 on: October 21, 2020, 01:00:41 pm »
I don't know if it is still true nowadays, but it is said that textures sized by the power of 2 are better handled by the graphics card: 2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024, 2048x2048, 4096x4096 etc...
do you really need to use threads for that? how are you doing it? and have you tried not using it?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Paul

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: Loading large textures
« Reply #2 on: October 21, 2020, 03:12:39 pm »
Are you preloading images in advance before they are rendered?

gamecoder.nz

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Loading large textures
« Reply #3 on: October 22, 2020, 01:00:09 am »
I just tried a 2048x2048 texture and there was no improvement.  I did consider loading the textures when the game starts but there are seasons in the game which require different textures so that's four different map textures which is a lot of textures to keep in memory.  I want a system where it only loads the textures needed as the player walks.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Loading large textures
« Reply #4 on: October 22, 2020, 01:38:49 am »
so, do you have a minimal code that reproduces the problem?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Loading large textures
« Reply #5 on: October 22, 2020, 09:57:33 am »
 Reading data from disk is slow, as such you'll always have some time spent in the loading function.

If you really need it to be on the fly, you could do the load of an sf::Image in a separate thread and then call copyFromImage on a texture in the main thread.
You might still get a frame rate dip due to the amount of data, but it shouldn't necessarily cause too noticeable lag. This could be further refined, by splitting up the large image into multiple smaller ones and loading one after the other.

On the other hand, loading the images up front and keeping them in memory can make things easier and it's not like your PC couldn't handle a few MB or RAM usage. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/