>1000 draw_texture_rect_region calls on mobile GPU

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ursul_fram

I have a 46x46 texture and I’m drawing irregular chunks of it 1200 times.
On a PowerVR Rogue GE8100, a budget mobile GPU I’m getting 40 FPS.

It’s this performance expected from Godot?
What can I do to speed it up?

Below is a simplified example of my code.

Thanks!

export(Texture) var myTexture

var myTextureRegions = [
	Rect2(0,0,23,23), 
	Rect2(23,0,23,23),
	Rect2(0,23,20,20),
	Rect2(23,23,2,14)
]
var cellSize = 23

func _draw():
	for i in range(0, 40):
		for j in range(0, 30):
			draw_texture_rect_region(myTexture,
				Rect2(i*cellSize,j*cellSize,cellSize,cellSize),
				myTextureRegions[0],Color.white)

Just as a comment because I have no clue what exactly you are trying to achieve.

But this sounds like this would be performing much better by using a shader.

Keep in mind that gdscript is an (byte code) interpreted language. 1200 iterations/function calls (single thread) per frame won’t be ideal in terms of performance.

Shaders can work in parallel (depending on how many shaders the GPU has) and in the GPU. So the CPU can do other work.

wombatstampede | 2020-02-07 08:46

I’m trying to draw something like this (see image below). I have a texture atlas containing sprites for every number from 0 to 9 and a couple of square textures representing grid cells

wikipedia mario picross

ursul_fram | 2020-02-07 15:37

Ok, not really a shader specific task (although some poeple would do it).

If I understand correctly, then _draw() is called for every frame.

I guess that you only have to update your screen every now and then and not every frame.

So perhaps you could just show a texture (texturearea or similar) and set the image data of the texture when required for the region which is updated.

Image — Godot Engine (3.2) documentation in English

wombatstampede | 2020-02-07 20:54

Sorry to waste your time, but this engine is not for me. I’m going back to love2d, it can render this kind of things at 60 fps with no problem.

ursul_fram | 2020-02-08 08:35

If you’re happy with love2d then fine.

New engines usually take some time to figure out the optimal approach. Personally, I use Godot for 3D apps (also on mobile) so my qualification to help you with 3D topics isn’t very high. :slight_smile:

wombatstampede | 2020-02-08 10:43