Godot Version
4.2.1
Question
Hello! I am trying to make drawing game with custom brush patterns. I am using shaders to combine:
- path texture
- pattern texture
The huge bottle neck is path texture’s data modification. I ended up by creating 2d array, filling it with path data manually (like I did many times using C/C++ on native platforms), and then updating texture:
var pathsData = Array();
pathsData.resize(4 * size.x * size.y);
…
var index = (f_y * width + f_x) * 4;
data[index] = brushIndex;
data[index + 1] = brushIndex;
data[index + 2] = brushIndex;
data[index + 3] = 255;
…
pathsImage.set_data(pathsImage.get_width(),
pathsImage.get_height(),pathsImage.has_mipmaps()
,pathsImage.get_format(),pathsData);
pathsTexture.update(pathsImage);
So I am wandering, is this approach makes sense? Looks like array modification takes quite alot of time, which is unexpected – I was expecting problem coping data from RAM to GPU memory.
Is it possible to modify pathTexture using shaders directly – ignoring moving data from RAM.
UPDATE:
It looks like I can just use viewport approach for drawing, updating initial texture on each iteration.