How to change Texture for each RID using RenderingServer?

Godot Version



How do I use Rendering Server to replace the Texture for each RID? Or replace the Texture Region?

I can’t use the CanvasItemAddTextureRect method, which will cause additional losses.

		private Texture2D _texture1;
		private Texture2D _texture2;
		private Vector2I _size;
		private Rid[] _rids;

		public override void _Ready() {
			_size = new Vector2I(64, 64);
			_rids = new Rid[_size.X * _size.Y];
			_texture1 = GD.Load<Texture2D>("res://texture/tile/tile-1.png");
			_texture2 = GD.Load<Texture2D>("res://texture/tile/tile-2.png");

			Engine.PhysicsTicksPerSecond = 10;
			for (int i = 0; i < _rids.Length; i++) {
				_rids[i] = RenderingServer.CanvasItemCreate();
				RenderingServer.CanvasItemSetParent(_rids[i], GetCanvasItem());
				RenderingServer.CanvasItemAddTextureRect(_rids[i], new Rect2(_texture1.GetSize(), _texture1.GetSize()),
				Transform2D transform =
					Transform2D.Identity.Translated(new Vector2(32 * i / _size.X, 32 * i % _size.Y));
				RenderingServer.CanvasItemSetTransform(_rids[i], transform);

Does anyone know what I should do?The CanvasItemAddTextureRect method will add a Texture to the Render Queue again, so if you want to change the Texture of each RID, you should not use the CanvasItemAddTextureRect method.