Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Logical Scale and Texture Sizes — Gideros Forum

Logical Scale and Texture Sizes

troysandaltroysandal Member
edited June 17 in General questions
I am running into an assertion crash in my app and looking for help in understanding how Gideros chooses which assets to use based on the screen scaling. My app is built for 320x480, letterbox, portrait with base, @2x and @4x assets. This has traditionally worked fine on iPhones. However, I recently installed my app on an iPhone 15 Pro (960x1704) and starting getting a crash. The problem was that my code assumes that application:getLogicalScaleX() will always return 1, 2 or 4. However in this case it's getting 3 back for the scale and the dimensions of any Texture I load show that they are coming from my "@4x" texture files.

Getting 3 back for the scale makes sense and my app hasn't been built nor run on Gideros for 12 years so either it's never encountered a 3x scale iOS device OR a change in Gideros now returns 3 instead of 4 despite it appearing to use the 4x assets. I built my app originally according to the instructions in the Wiki.

So my questions are:
  1. Is my app just really old and never got a 3x scaling until these newer iOS devices? Or...
  2. Did Gideros change and used to only return 1, 2 or 4 given that's the only assets I have?
  3. If Gideros returns a scale of 3 but my Textures are being loaded from the 4x files, should I be detecting that and scaling things myself?
Thanks in advance for any help.

PS - application:getDeviceInfo() returns the following:
{["platform"]="iOS", ["version"]="18.5", ["model"]="iPhone16,1", ["ui"]="iPhone", ["height"]=1704, ["type"]="iPhone", ["width"]=960}

image

Comments

  • keszeghkeszegh Member
    maybe my answer is wrong, but the textures are scaled for what they need to be scaled. gideros just takes the closest among the provided textures. so it could happen that it needs to scale 3x and for the best quality it will use the x4 texture and scale appropriately.

    on the other hand this does not answer why you never had this crash in the past.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks for the reply. I agree that choosing the 4x textures is the right thing for a 3x scale, the issue still remains that all my textures are now too big on the screen. I would think that if getLogicalScaleX() is returning 3 then the texture size would be resized to 3x, but it's not. Conversely, if the Texture loaded was the 4x, then the scale would be 4. This is probably a misunderstanding on my part and me not using Gideros in 13 years.

    Where I'm scratching my head is that Gideros isn't telling me which texture assets (1x, 2x, 4x) it has chosen so I'm going to have to figure that out on my own (4x in this case). , create a bitmap from the texture, then resize it to fit the 3x returned by getLogicalScaleX() ? Or perhaps I should use the Pixel object which supports texture scaling.

    Will keep working on it.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    @troysandal , maybe you can attach a screenshot to see the issue as well, you are right that this should not be this complicated, the point of the multiple textures is that they are choosen and scaled correctly under the hood, so maybe there is indeed some bug that @hgy29 or somebody else can spot.
  • At this point I've got it working by hard coding the scale to 4 for textures and have moved on to something else. When I have time I'll get back to the scaling and post more info. Obviously my hard coding the scale is a hack and not scalabe. Thanks for your help.

    Likes: keszegh, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Late to the discussion, but let me clarify one thing: getLogicalScale returns the factor between logical stage units and physical pixels, whereas texture scale selection system tries to figure out which texture scale from the defined ones would be best.
    The relevant code is here: https://github.com/gideros/gideros/blob/master/2dsg/application.cpp#L835
    It basically selects the nearest texture scale based on logical scale

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • troysandaltroysandal Member
    edited 9:35PM
    Thanks for the reply. I think I figured that out. My question to you is, is there an API for asking the Texture scale selection system what scale it's using? I'd like to rely on that and not getLogicalScale() but I haven't found the API yet. Sorry if it's there and I missed it.

    I could also use the same logic as code you linked to, `float scale = (logicalScaleX_ + logicalScaleY_) / 2;` but if that were to change my app would break again.
Sign In or Register to comment.