YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Function to get which specific texture page a sprite/font/tileset is on #3640

Open iampremo opened 1 year ago

iampremo commented 1 year ago

Customer's description:

_Add the function texture_get_texturepage() that takes a texture pointer (returned by e.g. sprite_gettexture) and returns a texture page index that represents which texture page the asset is located on.

This texture page index should be global and be inclusive of all texture pages across all texture groups. For example, if we have two texture groups - TexGroupA and TexGroupB - each of which have 2 texture pages, then the 2nd texture page of TexGroupB would have index = 3. This ensures it's never ambiguous which specific texture an asset is located on.

_The index returned by texture_gettexturepage() should also respect sprites set to Separate Texture Page. The index associated with a texture page should never change at runtime (this wouldn't make sense anyway).

_For textures created at runtime (sprite_add/surfacecreate), a monotonically increasing index is sufficient, provided the index starts at a value greater than the number of texture pages generated on compile.

Customer's benefit:

_When trying to optimise draw calls by batching static assets onto vertex buffers, it's very hard to know which assets are actually on the same texture page. The texture pointer returned by e.g. sprite_gettexture() is unique for each image of each sprite, it cannot be used to determine which assets share a texture page. As a result, it's not possible to batch sprites together on a single texture page with certainty. Fiddling with texture groups to guarantee assets are on specific texture pages is brittle and usually suboptimal.

The proposed function is especially useful for graphics-heavy games that need to carefully manage memory, games that need adaptive and flexible vertex buffer batching, and for libraries that are trying to fit smoothly into a developer's existing workflow with minimal unnecessary configuration.

As an example, I wrote a system for The Swords of Ditto that parsed the asset compiler XML and used that to figure out how texture memory was being used. We were able to debug and track behaviour with runtime tools which informed management of our video memory budget; we categorically could not have released on console without doing this. Whilst the techniques we developed are super useful for loads of professional GameMaker users, it's such a pain in the arse to get texture information that I've never gotten round to sharing what we did in detail.

rwkay commented 1 year ago

font_get_info() and sprite_get_info() give the user this information already for fonts and for sprites...

currently no way to get it for tilesets though...