trying to cut down on texture swaps with this trick, not sure if it works though

Mr Errorz

Member
I am trying to cut down the number of texture swaps in my game,
and I was wondering if something I came up with actually helps or not.
what I am doing, is putting a code inside various objects' step event,
that basically says, if you're inside the view visible = true,
else visible = false;

something like:
if (x < view_xview[0]+980 and x > view_xview[0]-20) and (y < view_yview[0]+605 and y > view_yview[0]-60)
visible = true;
else
visible = false;

so, does something like that actually helps?
if an object's visible is set to false, does GM actually isn't draw anything?
 
A

anomalous

Guest
Pretty sure default sprites are not drawn outside of view, you can check with debugger to see if there is a draw time difference.
You could also run the debug overlay to see texture swaps, but this isn't really how you'd reduce texture swaps.

Texture swaps are when you have a sprite/background on a different texture page, and can be an issue apparently on mobile in general (due to poor performance of hardware), or a problem any time if you have draws from different texture pages that are on staggered depths, such that it has to draw from one, then the other, over and over. This can ramp up texture swaps.
Drawing or not is really about draw calls/draw time, not necessarily having anything to do with texture swaps. If they are all on the same texture page anyway, it wouldn't matter.
 

Mr Errorz

Member
Pretty sure default sprites are not drawn outside of view, you can check with debugger to see if there is a draw time difference.
You could also run the debug overlay to see texture swaps, but this isn't really how you'd reduce texture swaps.

Texture swaps are when you have a sprite/background on a different texture page, and can be an issue apparently on mobile in general (due to poor performance of hardware), or a problem any time if you have draws from different texture pages that are on staggered depths, such that it has to draw from one, then the other, over and over. This can ramp up texture swaps.
Drawing or not is really about draw calls/draw time, not necessarily having anything to do with texture swaps. If they are all on the same texture page anyway, it wouldn't matter.
so while waiting for a reply, I just went ahead and applied that code to all the objects in a room,
and it did cut about half of the texture swaps according to show_debug_overlay.
so, it does work!

now, if i can only do the same for tiles...
is there a way to identify all the tiles in certain depth, and than switching their visibility according to their x,y positions?
 
R

renex

Guest
Fun little trick: setting instances to the same depth range according to texture page organization will optimize drawing greatly, since they will be drawn in order, minimizing swaps.

example: you have a boss and all of its attacks, segments, and particles at page 2, plus the player and all of their equipment and attachments at page 3, while the background decoration that sits between them is all on page 1.

Hud and interfaces: -50 > -1
Player and stuff: 0 > 49
Decoration: 50 > 99
Boss and its parts: 100 > 149

This will cause only four swaps for the instances even if you have hundreds upon hundreds of them.
 

obscene

Member
so while waiting for a reply, I just went ahead and applied that code to all the objects in a room,
and it did cut about half of the texture swaps according to show_debug_overlay.
so, it does work!

now, if i can only do the same for tiles...
is there a way to identify all the tiles in certain depth, and than switching their visibility according to their x,y positions?
If you are organizing things correctly, what you did here should not realy affects texture swaps, much less half. It will definately help the draw event, I do this alot myself and it's great for objects that have complicated draw code with lots of calculations/code in the draw event. Even better is if you do this from a controller object, on an alarm that fires every few steps instead of every step.

As renex said, arranging your object depths and texture groups to correlate is the way to reduce swaps. From the results you got from your code it sounds like you have many objects with the same depth on multiple groups which is the first thing you should change.
 

Mr Errorz

Member
Fun little trick: setting instances to the same depth range according to texture page organization will optimize drawing greatly, since they will be drawn in order, minimizing swaps.

example: you have a boss and all of its attacks, segments, and particles at page 2, plus the player and all of their equipment and attachments at page 3, while the background decoration that sits between them is all on page 1.

Hud and interfaces: -50 > -1
Player and stuff: 0 > 49
Decoration: 50 > 99
Boss and its parts: 100 > 149

This will cause only four swaps for the instances even if you have hundreds upon hundreds of them.
I think it's kinda setup that way [depth wise] already,
but I didn't mess w/ texture groups yet.
BTW, when you say page 2, page 3 and so on, you actually mean texture group 2 / texture group 3, right?
because I know how to control texture groups, but not texture pages.
or am I mixing it?
 

Mr Errorz

Member
Yep :) I had issues with that optimization for another project. Drawing to a surface would cut off tiles when the view moved.
actually, I haven't done anything w/ surfaces,
using the default surface thing that happens when you start a project.
so, is your answer still applicable?
does GM not draw tiles out of view if I haven't messed w/ surfaces at all?
 
R

renex

Guest
BTW, when you say page 2, page 3 and so on, you actually mean texture group 2 / texture group 3, right?
Yeah, that's the same thing. The numbers only differ if you have so much in a page that it ends up being split, and that shifts other pages forward.
 
Top